1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/kernel.h>
14#include <linux/pci.h>
15#include <linux/mv643xx_eth.h>
16#include <linux/timex.h>
17#include <linux/serial_reg.h>
18#include "orion5x.h"
19#include "tsx09-common.h"
20#include "common.h"
21
22
23
24
25
26#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
27
28void qnap_tsx09_power_off(void)
29{
30
31 const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200));
32
33 pr_info("%s: triggering power-off...\n", __func__);
34
35
36 writel(0x83, UART1_REG(LCR));
37 writel(divisor & 0xff, UART1_REG(DLL));
38 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
39 writel(0x03, UART1_REG(LCR));
40 writel(0x00, UART1_REG(IER));
41 writel(0x00, UART1_REG(FCR));
42 writel(0x00, UART1_REG(MCR));
43
44
45 writel('A', UART1_REG(TX));
46}
47
48
49
50
51
52struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
53 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
54};
55
56static int __init qnap_tsx09_parse_hex_nibble(char n)
57{
58 if (n >= '0' && n <= '9')
59 return n - '0';
60
61 if (n >= 'A' && n <= 'F')
62 return n - 'A' + 10;
63
64 if (n >= 'a' && n <= 'f')
65 return n - 'a' + 10;
66
67 return -1;
68}
69
70static int __init qnap_tsx09_parse_hex_byte(const char *b)
71{
72 int hi;
73 int lo;
74
75 hi = qnap_tsx09_parse_hex_nibble(b[0]);
76 lo = qnap_tsx09_parse_hex_nibble(b[1]);
77
78 if (hi < 0 || lo < 0)
79 return -1;
80
81 return (hi << 4) | lo;
82}
83
84static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
85{
86 u_int8_t addr[6];
87 int i;
88
89 for (i = 0; i < 6; i++) {
90 int byte;
91
92
93
94
95 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
96 return -1;
97
98 byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
99 if (byte < 0)
100 return -1;
101 addr[i] = byte;
102 }
103
104 printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr);
105
106 memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
107
108 return 0;
109}
110
111
112
113
114
115
116void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
117{
118 unsigned long addr;
119
120 for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
121 char *nor_page;
122 int ret = 0;
123
124 nor_page = ioremap(addr, 1024);
125 if (nor_page != NULL) {
126 ret = qnap_tsx09_check_mac_addr(nor_page);
127 iounmap(nor_page);
128 }
129
130 if (ret == 0)
131 break;
132 }
133}
134