/kern_2.6.32/arch/arm/mach-orion5x/tsx09-common.c

http://omnia2droid.googlecode.com/ · C · 134 lines · 78 code · 28 blank · 28 comment · 18 complexity · d212d03ab74f90e55d8dfe760a13992b MD5 · raw file

  1. /*
  2. * QNAP TS-x09 Boards common functions
  3. *
  4. * Maintainers: Lennert Buytenhek <buytenh@marvell.com>
  5. * Byron Bradley <byron.bbradley@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/mv643xx_eth.h>
  15. #include <linux/timex.h>
  16. #include <linux/serial_reg.h>
  17. #include "tsx09-common.h"
  18. #include "common.h"
  19. /*****************************************************************************
  20. * QNAP TS-x09 specific power off method via UART1-attached PIC
  21. ****************************************************************************/
  22. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  23. void qnap_tsx09_power_off(void)
  24. {
  25. /* 19200 baud divisor */
  26. const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200));
  27. pr_info("%s: triggering power-off...\n", __func__);
  28. /* hijack uart1 and reset into sane state (19200,8n1) */
  29. writel(0x83, UART1_REG(LCR));
  30. writel(divisor & 0xff, UART1_REG(DLL));
  31. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  32. writel(0x03, UART1_REG(LCR));
  33. writel(0x00, UART1_REG(IER));
  34. writel(0x00, UART1_REG(FCR));
  35. writel(0x00, UART1_REG(MCR));
  36. /* send the power-off command 'A' to PIC */
  37. writel('A', UART1_REG(TX));
  38. }
  39. /*****************************************************************************
  40. * Ethernet
  41. ****************************************************************************/
  42. struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
  43. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  44. };
  45. static int __init qnap_tsx09_parse_hex_nibble(char n)
  46. {
  47. if (n >= '0' && n <= '9')
  48. return n - '0';
  49. if (n >= 'A' && n <= 'F')
  50. return n - 'A' + 10;
  51. if (n >= 'a' && n <= 'f')
  52. return n - 'a' + 10;
  53. return -1;
  54. }
  55. static int __init qnap_tsx09_parse_hex_byte(const char *b)
  56. {
  57. int hi;
  58. int lo;
  59. hi = qnap_tsx09_parse_hex_nibble(b[0]);
  60. lo = qnap_tsx09_parse_hex_nibble(b[1]);
  61. if (hi < 0 || lo < 0)
  62. return -1;
  63. return (hi << 4) | lo;
  64. }
  65. static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
  66. {
  67. u_int8_t addr[6];
  68. int i;
  69. for (i = 0; i < 6; i++) {
  70. int byte;
  71. /*
  72. * Enforce "xx:xx:xx:xx:xx:xx\n" format.
  73. */
  74. if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
  75. return -1;
  76. byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
  77. if (byte < 0)
  78. return -1;
  79. addr[i] = byte;
  80. }
  81. printk(KERN_INFO "tsx09: found ethernet mac address ");
  82. for (i = 0; i < 6; i++)
  83. printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
  84. memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
  85. return 0;
  86. }
  87. /*
  88. * The 'NAS Config' flash partition has an ext2 filesystem which
  89. * contains a file that has the ethernet MAC address in plain text
  90. * (format "xx:xx:xx:xx:xx:xx\n").
  91. */
  92. void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
  93. {
  94. unsigned long addr;
  95. for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
  96. char *nor_page;
  97. int ret = 0;
  98. nor_page = ioremap(addr, 1024);
  99. if (nor_page != NULL) {
  100. ret = qnap_tsx09_check_mac_addr(nor_page);
  101. iounmap(nor_page);
  102. }
  103. if (ret == 0)
  104. break;
  105. }
  106. }