1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * QNAP TS-x09 Boards common functions
5 * Maintainers: Lennert Buytenhek <buytenh@marvell.com>
6 * Byron Bradley <byron.bbradley@gmail.com>
9 #include <linux/kernel.h>
10 #include <linux/pci.h>
11 #include <linux/mv643xx_eth.h>
12 #include <linux/timex.h>
13 #include <linux/serial_reg.h>
15 #include "tsx09-common.h"
18 /*****************************************************************************
19 * QNAP TS-x09 specific power off method via UART1-attached PIC
20 ****************************************************************************/
22 #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
24 void qnap_tsx09_power_off(void)
26 /* 19200 baud divisor */
27 const unsigned divisor
= ((orion5x_tclk
+ (8 * 19200)) / (16 * 19200));
29 pr_info("%s: triggering power-off...\n", __func__
);
31 /* hijack uart1 and reset into sane state (19200,8n1) */
32 writel(0x83, UART1_REG(LCR
));
33 writel(divisor
& 0xff, UART1_REG(DLL
));
34 writel((divisor
>> 8) & 0xff, UART1_REG(DLM
));
35 writel(0x03, UART1_REG(LCR
));
36 writel(0x00, UART1_REG(IER
));
37 writel(0x00, UART1_REG(FCR
));
38 writel(0x00, UART1_REG(MCR
));
40 /* send the power-off command 'A' to PIC */
41 writel('A', UART1_REG(TX
));
44 /*****************************************************************************
46 ****************************************************************************/
48 struct mv643xx_eth_platform_data qnap_tsx09_eth_data
= {
49 .phy_addr
= MV643XX_ETH_PHY_ADDR(8),
52 static int __init
qnap_tsx09_parse_hex_nibble(char n
)
54 if (n
>= '0' && n
<= '9')
57 if (n
>= 'A' && n
<= 'F')
60 if (n
>= 'a' && n
<= 'f')
66 static int __init
qnap_tsx09_parse_hex_byte(const char *b
)
71 hi
= qnap_tsx09_parse_hex_nibble(b
[0]);
72 lo
= qnap_tsx09_parse_hex_nibble(b
[1]);
77 return (hi
<< 4) | lo
;
80 static int __init
qnap_tsx09_check_mac_addr(const char *addr_str
)
85 for (i
= 0; i
< 6; i
++) {
89 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
91 if (addr_str
[(i
* 3) + 2] != ((i
< 5) ? ':' : '\n'))
94 byte
= qnap_tsx09_parse_hex_byte(addr_str
+ (i
* 3));
100 printk(KERN_INFO
"tsx09: found ethernet mac address %pM\n", addr
);
102 memcpy(qnap_tsx09_eth_data
.mac_addr
, addr
, 6);
108 * The 'NAS Config' flash partition has an ext2 filesystem which
109 * contains a file that has the ethernet MAC address in plain text
110 * (format "xx:xx:xx:xx:xx:xx\n").
112 void __init
qnap_tsx09_find_mac_addr(u32 mem_base
, u32 size
)
116 for (addr
= mem_base
; addr
< (mem_base
+ size
); addr
+= 1024) {
120 nor_page
= ioremap(addr
, 1024);
121 if (nor_page
!= NULL
) {
122 ret
= qnap_tsx09_check_mac_addr(nor_page
);