0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/kernel.h>
0010 #include <linux/pci.h>
0011 #include <linux/mv643xx_eth.h>
0012 #include <linux/timex.h>
0013 #include <linux/serial_reg.h>
0014 #include "orion5x.h"
0015 #include "tsx09-common.h"
0016 #include "common.h"
0017
0018
0019
0020
0021
0022 #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
0023
0024 void qnap_tsx09_power_off(void)
0025 {
0026
0027 const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200));
0028
0029 pr_info("%s: triggering power-off...\n", __func__);
0030
0031
0032 writel(0x83, UART1_REG(LCR));
0033 writel(divisor & 0xff, UART1_REG(DLL));
0034 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
0035 writel(0x03, UART1_REG(LCR));
0036 writel(0x00, UART1_REG(IER));
0037 writel(0x00, UART1_REG(FCR));
0038 writel(0x00, UART1_REG(MCR));
0039
0040
0041 writel('A', UART1_REG(TX));
0042 }
0043
0044
0045
0046
0047
0048 struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
0049 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
0050 };
0051
0052 static int __init qnap_tsx09_parse_hex_nibble(char n)
0053 {
0054 if (n >= '0' && n <= '9')
0055 return n - '0';
0056
0057 if (n >= 'A' && n <= 'F')
0058 return n - 'A' + 10;
0059
0060 if (n >= 'a' && n <= 'f')
0061 return n - 'a' + 10;
0062
0063 return -1;
0064 }
0065
0066 static int __init qnap_tsx09_parse_hex_byte(const char *b)
0067 {
0068 int hi;
0069 int lo;
0070
0071 hi = qnap_tsx09_parse_hex_nibble(b[0]);
0072 lo = qnap_tsx09_parse_hex_nibble(b[1]);
0073
0074 if (hi < 0 || lo < 0)
0075 return -1;
0076
0077 return (hi << 4) | lo;
0078 }
0079
0080 static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
0081 {
0082 u_int8_t addr[6];
0083 int i;
0084
0085 for (i = 0; i < 6; i++) {
0086 int byte;
0087
0088
0089
0090
0091 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
0092 return -1;
0093
0094 byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
0095 if (byte < 0)
0096 return -1;
0097 addr[i] = byte;
0098 }
0099
0100 printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr);
0101
0102 memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
0103
0104 return 0;
0105 }
0106
0107
0108
0109
0110
0111
0112 void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
0113 {
0114 unsigned long addr;
0115
0116 for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
0117 char *nor_page;
0118 int ret = 0;
0119
0120 nor_page = ioremap(addr, 1024);
0121 if (nor_page != NULL) {
0122 ret = qnap_tsx09_check_mac_addr(nor_page);
0123 iounmap(nor_page);
0124 }
0125
0126 if (ret == 0)
0127 break;
0128 }
0129 }