tsx09-common.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "orion5x.h"
  18. #include "tsx09-common.h"
  19. #include "common.h"
  20. /*****************************************************************************
  21. * QNAP TS-x09 specific power off method via UART1-attached PIC
  22. ****************************************************************************/
  23. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  24. void qnap_tsx09_power_off(void)
  25. {
  26. /* 19200 baud divisor */
  27. const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200));
  28. pr_info("%s: triggering power-off...\n", __func__);
  29. /* hijack uart1 and reset into sane state (19200,8n1) */
  30. writel(0x83, UART1_REG(LCR));
  31. writel(divisor & 0xff, UART1_REG(DLL));
  32. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  33. writel(0x03, UART1_REG(LCR));
  34. writel(0x00, UART1_REG(IER));
  35. writel(0x00, UART1_REG(FCR));
  36. writel(0x00, UART1_REG(MCR));
  37. /* send the power-off command 'A' to PIC */
  38. writel('A', UART1_REG(TX));
  39. }
  40. /*****************************************************************************
  41. * Ethernet
  42. ****************************************************************************/
  43. struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
  44. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  45. };
  46. static int __init qnap_tsx09_parse_hex_nibble(char n)
  47. {
  48. if (n >= '0' && n <= '9')
  49. return n - '0';
  50. if (n >= 'A' && n <= 'F')
  51. return n - 'A' + 10;
  52. if (n >= 'a' && n <= 'f')
  53. return n - 'a' + 10;
  54. return -1;
  55. }
  56. static int __init qnap_tsx09_parse_hex_byte(const char *b)
  57. {
  58. int hi;
  59. int lo;
  60. hi = qnap_tsx09_parse_hex_nibble(b[0]);
  61. lo = qnap_tsx09_parse_hex_nibble(b[1]);
  62. if (hi < 0 || lo < 0)
  63. return -1;
  64. return (hi << 4) | lo;
  65. }
  66. static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
  67. {
  68. u_int8_t addr[6];
  69. int i;
  70. for (i = 0; i < 6; i++) {
  71. int byte;
  72. /*
  73. * Enforce "xx:xx:xx:xx:xx:xx\n" format.
  74. */
  75. if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
  76. return -1;
  77. byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
  78. if (byte < 0)
  79. return -1;
  80. addr[i] = byte;
  81. }
  82. printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr);
  83. memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
  84. return 0;
  85. }
  86. /*
  87. * The 'NAS Config' flash partition has an ext2 filesystem which
  88. * contains a file that has the ethernet MAC address in plain text
  89. * (format "xx:xx:xx:xx:xx:xx\n").
  90. */
  91. void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
  92. {
  93. unsigned long addr;
  94. for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
  95. char *nor_page;
  96. int ret = 0;
  97. nor_page = ioremap(addr, 1024);
  98. if (nor_page != NULL) {
  99. ret = qnap_tsx09_check_mac_addr(nor_page);
  100. iounmap(nor_page);
  101. }
  102. if (ret == 0)
  103. break;
  104. }
  105. }