aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/mach-orion5x/Makefile4
-rw-r--r--arch/arm/mach-orion5x/ts209-setup.c125
-rw-r--r--arch/arm/mach-orion5x/ts409-setup.c126
-rw-r--r--arch/arm/mach-orion5x/tsx09-common.c132
-rw-r--r--arch/arm/mach-orion5x/tsx09-common.h20
5 files changed, 168 insertions, 239 deletions
diff --git a/arch/arm/mach-orion5x/Makefile b/arch/arm/mach-orion5x/Makefile
index c333cd7baed..1d1f8556303 100644
--- a/arch/arm/mach-orion5x/Makefile
+++ b/arch/arm/mach-orion5x/Makefile
@@ -4,7 +4,7 @@ obj-$(CONFIG_MACH_RD88F5182) += rd88f5182-setup.o
4obj-$(CONFIG_MACH_KUROBOX_PRO) += kurobox_pro-setup.o 4obj-$(CONFIG_MACH_KUROBOX_PRO) += kurobox_pro-setup.o
5obj-$(CONFIG_MACH_LINKSTATION_PRO) += kurobox_pro-setup.o 5obj-$(CONFIG_MACH_LINKSTATION_PRO) += kurobox_pro-setup.o
6obj-$(CONFIG_MACH_DNS323) += dns323-setup.o 6obj-$(CONFIG_MACH_DNS323) += dns323-setup.o
7obj-$(CONFIG_MACH_TS209) += ts209-setup.o 7obj-$(CONFIG_MACH_TS209) += ts209-setup.o tsx09-common.o
8obj-$(CONFIG_MACH_TS409) += ts409-setup.o 8obj-$(CONFIG_MACH_TS409) += ts409-setup.o tsx09-common.o
9obj-$(CONFIG_MACH_WRT350N_V2) += wrt350n-v2-setup.o 9obj-$(CONFIG_MACH_WRT350N_V2) += wrt350n-v2-setup.o
10obj-$(CONFIG_MACH_MV2120) += mv2120-setup.o 10obj-$(CONFIG_MACH_MV2120) += mv2120-setup.o
diff --git a/arch/arm/mach-orion5x/ts209-setup.c b/arch/arm/mach-orion5x/ts209-setup.c
index 80b62329f58..a9cef9703d5 100644
--- a/arch/arm/mach-orion5x/ts209-setup.c
+++ b/arch/arm/mach-orion5x/ts209-setup.c
@@ -29,6 +29,7 @@
29#include <asm/arch/orion5x.h> 29#include <asm/arch/orion5x.h>
30#include "common.h" 30#include "common.h"
31#include "mpp.h" 31#include "mpp.h"
32#include "tsx09-common.h"
32 33
33#define QNAP_TS209_NOR_BOOT_BASE 0xf4000000 34#define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
34#define QNAP_TS209_NOR_BOOT_SIZE SZ_8M 35#define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
@@ -186,95 +187,6 @@ static int __init qnap_ts209_pci_init(void)
186subsys_initcall(qnap_ts209_pci_init); 187subsys_initcall(qnap_ts209_pci_init);
187 188
188/***************************************************************************** 189/*****************************************************************************
189 * Ethernet
190 ****************************************************************************/
191
192static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
193 .phy_addr = 8,
194};
195
196static int __init parse_hex_nibble(char n)
197{
198 if (n >= '0' && n <= '9')
199 return n - '0';
200
201 if (n >= 'A' && n <= 'F')
202 return n - 'A' + 10;
203
204 if (n >= 'a' && n <= 'f')
205 return n - 'a' + 10;
206
207 return -1;
208}
209
210static int __init parse_hex_byte(const char *b)
211{
212 int hi;
213 int lo;
214
215 hi = parse_hex_nibble(b[0]);
216 lo = parse_hex_nibble(b[1]);
217
218 if (hi < 0 || lo < 0)
219 return -1;
220
221 return (hi << 4) | lo;
222}
223
224static int __init check_mac_addr(const char *addr_str)
225{
226 u_int8_t addr[6];
227 int i;
228
229 for (i = 0; i < 6; i++) {
230 int byte;
231
232 /*
233 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
234 */
235 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
236 return -1;
237
238 byte = parse_hex_byte(addr_str + (i * 3));
239 if (byte < 0)
240 return -1;
241 addr[i] = byte;
242 }
243
244 printk(KERN_INFO "ts209: found ethernet mac address ");
245 for (i = 0; i < 6; i++)
246 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
247
248 memcpy(qnap_ts209_eth_data.mac_addr, addr, 6);
249
250 return 0;
251}
252
253/*
254 * The 'NAS Config' flash partition has an ext2 filesystem which
255 * contains a file that has the ethernet MAC address in plain text
256 * (format "xx:xx:xx:xx:xx:xx\n".)
257 */
258static void __init ts209_find_mac_addr(void)
259{
260 unsigned long addr;
261
262 for (addr = 0x00700000; addr < 0x00760000; addr += 1024) {
263 char *nor_page;
264 int ret = 0;
265
266 nor_page = ioremap(QNAP_TS209_NOR_BOOT_BASE + addr, 1024);
267 if (nor_page != NULL) {
268 ret = check_mac_addr(nor_page);
269 iounmap(nor_page);
270 }
271
272 if (ret == 0)
273 break;
274 }
275}
276
277/*****************************************************************************
278 * RTC S35390A on I2C bus 190 * RTC S35390A on I2C bus
279 ****************************************************************************/ 191 ****************************************************************************/
280 192
@@ -356,31 +268,6 @@ static struct orion5x_mpp_mode ts209_mpp_modes[] __initdata = {
356 { -1 }, 268 { -1 },
357}; 269};
358 270
359/*
360 * QNAP TS-[12]09 specific power off method via UART1-attached PIC
361 */
362#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
363
364static void qnap_ts209_power_off(void)
365{
366 /* 19200 baud divisor */
367 const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
368
369 pr_info("%s: triggering power-off...\n", __func__);
370
371 /* hijack uart1 and reset into sane state (19200,8n1) */
372 orion5x_write(UART1_REG(LCR), 0x83);
373 orion5x_write(UART1_REG(DLL), divisor & 0xff);
374 orion5x_write(UART1_REG(DLM), (divisor >> 8) & 0xff);
375 orion5x_write(UART1_REG(LCR), 0x03);
376 orion5x_write(UART1_REG(IER), 0x00);
377 orion5x_write(UART1_REG(FCR), 0x00);
378 orion5x_write(UART1_REG(MCR), 0x00);
379
380 /* send the power-off command 'A' to PIC */
381 orion5x_write(UART1_REG(TX), 'A');
382}
383
384static void __init qnap_ts209_init(void) 271static void __init qnap_ts209_init(void)
385{ 272{
386 /* 273 /*
@@ -402,8 +289,10 @@ static void __init qnap_ts209_init(void)
402 */ 289 */
403 orion5x_ehci0_init(); 290 orion5x_ehci0_init();
404 orion5x_ehci1_init(); 291 orion5x_ehci1_init();
405 ts209_find_mac_addr(); 292 qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE +
406 orion5x_eth_init(&qnap_ts209_eth_data); 293 qnap_ts209_partitions[5].offset,
294 qnap_ts209_partitions[5].size);
295 orion5x_eth_init(&qnap_tsx09_eth_data);
407 orion5x_i2c_init(); 296 orion5x_i2c_init();
408 orion5x_sata_init(&qnap_ts209_sata_data); 297 orion5x_sata_init(&qnap_ts209_sata_data);
409 orion5x_uart0_init(); 298 orion5x_uart0_init();
@@ -425,8 +314,8 @@ static void __init qnap_ts209_init(void)
425 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n"); 314 pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
426 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1); 315 i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
427 316
428 /* register ts209 specific power-off method */ 317 /* register tsx09 specific power-off method */
429 pm_power_off = qnap_ts209_power_off; 318 pm_power_off = qnap_tsx09_power_off;
430} 319}
431 320
432MACHINE_START(TS209, "QNAP TS-109/TS-209") 321MACHINE_START(TS209, "QNAP TS-109/TS-209")
diff --git a/arch/arm/mach-orion5x/ts409-setup.c b/arch/arm/mach-orion5x/ts409-setup.c
index 524e4249f08..32f0ff073b7 100644
--- a/arch/arm/mach-orion5x/ts409-setup.c
+++ b/arch/arm/mach-orion5x/ts409-setup.c
@@ -27,6 +27,7 @@
27#include <asm/arch/orion5x.h> 27#include <asm/arch/orion5x.h>
28#include "common.h" 28#include "common.h"
29#include "mpp.h" 29#include "mpp.h"
30#include "tsx09-common.h"
30 31
31/***************************************************************************** 32/*****************************************************************************
32 * QNAP TS-409 Info 33 * QNAP TS-409 Info
@@ -152,95 +153,6 @@ static int __init qnap_ts409_pci_init(void)
152subsys_initcall(qnap_ts409_pci_init); 153subsys_initcall(qnap_ts409_pci_init);
153 154
154/***************************************************************************** 155/*****************************************************************************
155 * Ethernet
156 ****************************************************************************/
157
158static struct mv643xx_eth_platform_data qnap_ts409_eth_data = {
159 .phy_addr = 8,
160};
161
162static int __init parse_hex_nibble(char n)
163{
164 if (n >= '0' && n <= '9')
165 return n - '0';
166
167 if (n >= 'A' && n <= 'F')
168 return n - 'A' + 10;
169
170 if (n >= 'a' && n <= 'f')
171 return n - 'a' + 10;
172
173 return -1;
174}
175
176static int __init parse_hex_byte(const char *b)
177{
178 int hi;
179 int lo;
180
181 hi = parse_hex_nibble(b[0]);
182 lo = parse_hex_nibble(b[1]);
183
184 if (hi < 0 || lo < 0)
185 return -1;
186
187 return (hi << 4) | lo;
188}
189
190static int __init check_mac_addr(const char *addr_str)
191{
192 u_int8_t addr[6];
193 int i;
194
195 for (i = 0; i < 6; i++) {
196 int byte;
197
198 /*
199 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
200 */
201 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
202 return -1;
203
204 byte = parse_hex_byte(addr_str + (i * 3));
205 if (byte < 0)
206 return -1;
207 addr[i] = byte;
208 }
209
210 printk(KERN_INFO "ts409: found ethernet mac address ");
211 for (i = 0; i < 6; i++)
212 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
213
214 memcpy(qnap_ts409_eth_data.mac_addr, addr, 6);
215
216 return 0;
217}
218
219/*
220 * The 'NAS Config' flash partition has an ext2 filesystem which
221 * contains a file that has the ethernet MAC address in plain text
222 * (format "xx:xx:xx:xx:xx:xx\n").
223 */
224static void __init ts409_find_mac_addr(void)
225{
226 unsigned long addr;
227
228 for (addr = 0x00700000; addr < 0x00760000; addr += 1024) {
229 char *nor_page;
230 int ret = 0;
231
232 nor_page = ioremap(QNAP_TS409_NOR_BOOT_BASE + addr, 1024);
233 if (nor_page != NULL) {
234 ret = check_mac_addr(nor_page);
235 iounmap(nor_page);
236 }
237
238 if (ret == 0)
239 break;
240 }
241}
242
243/*****************************************************************************
244 * RTC S35390A on I2C bus 156 * RTC S35390A on I2C bus
245 ****************************************************************************/ 157 ****************************************************************************/
246 158
@@ -307,32 +219,6 @@ static struct orion5x_mpp_mode ts409_mpp_modes[] __initdata = {
307 { -1 }, 219 { -1 },
308}; 220};
309 221
310/*
311 * QNAP TS-409 specific power off method via UART1-attached PIC
312 */
313
314#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
315
316static void qnap_ts409_power_off(void)
317{
318 /* 19200 baud divisor */
319 const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
320
321 pr_info("%s: triggering power-off...\n", __func__);
322
323 /* hijack uart1 and reset into sane state (19200,8n1) */
324 writel(0x83, UART1_REG(LCR));
325 writel(divisor & 0xff, UART1_REG(DLL));
326 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
327 writel(0x03, UART1_REG(LCR));
328 writel(0x00, UART1_REG(IER));
329 writel(0x00, UART1_REG(FCR));
330 writel(0x00, UART1_REG(MCR));
331
332 /* send the power-off command 'A' to PIC */
333 writel('A', UART1_REG(TX));
334}
335
336static void __init qnap_ts409_init(void) 222static void __init qnap_ts409_init(void)
337{ 223{
338 /* 224 /*
@@ -346,8 +232,10 @@ static void __init qnap_ts409_init(void)
346 * Configure peripherals. 232 * Configure peripherals.
347 */ 233 */
348 orion5x_ehci0_init(); 234 orion5x_ehci0_init();
349 ts409_find_mac_addr(); 235 qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
350 orion5x_eth_init(&qnap_ts409_eth_data); 236 qnap_ts409_partitions[5].offset,
237 qnap_ts409_partitions[5].size);
238 orion5x_eth_init(&qnap_tsx09_eth_data);
351 orion5x_i2c_init(); 239 orion5x_i2c_init();
352 orion5x_uart0_init(); 240 orion5x_uart0_init();
353 241
@@ -368,8 +256,8 @@ static void __init qnap_ts409_init(void)
368 pr_warning("qnap_ts409_init: failed to get RTC IRQ\n"); 256 pr_warning("qnap_ts409_init: failed to get RTC IRQ\n");
369 i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1); 257 i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
370 258
371 /* register ts409 specific power-off method */ 259 /* register tsx09 specific power-off method */
372 pm_power_off = qnap_ts409_power_off; 260 pm_power_off = qnap_tsx09_power_off;
373} 261}
374 262
375MACHINE_START(TS409, "QNAP TS-409") 263MACHINE_START(TS409, "QNAP TS-409")
diff --git a/arch/arm/mach-orion5x/tsx09-common.c b/arch/arm/mach-orion5x/tsx09-common.c
new file mode 100644
index 00000000000..820603919c4
--- /dev/null
+++ b/arch/arm/mach-orion5x/tsx09-common.c
@@ -0,0 +1,132 @@
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
13#include <linux/kernel.h>
14#include <linux/pci.h>
15#include <linux/mv643xx_eth.h>
16#include <linux/serial_reg.h>
17#include "tsx09-common.h"
18
19/*****************************************************************************
20 * QNAP TS-x09 specific power off method via UART1-attached PIC
21 ****************************************************************************/
22
23#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
24
25void qnap_tsx09_power_off(void)
26{
27 /* 19200 baud divisor */
28 const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
29
30 pr_info("%s: triggering power-off...\n", __func__);
31
32 /* hijack uart1 and reset into sane state (19200,8n1) */
33 writel(0x83, UART1_REG(LCR));
34 writel(divisor & 0xff, UART1_REG(DLL));
35 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
36 writel(0x03, UART1_REG(LCR));
37 writel(0x00, UART1_REG(IER));
38 writel(0x00, UART1_REG(FCR));
39 writel(0x00, UART1_REG(MCR));
40
41 /* send the power-off command 'A' to PIC */
42 writel('A', UART1_REG(TX));
43}
44
45/*****************************************************************************
46 * Ethernet
47 ****************************************************************************/
48
49struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
50 .phy_addr = 8,
51};
52
53static int __init qnap_tsx09_parse_hex_nibble(char n)
54{
55 if (n >= '0' && n <= '9')
56 return n - '0';
57
58 if (n >= 'A' && n <= 'F')
59 return n - 'A' + 10;
60
61 if (n >= 'a' && n <= 'f')
62 return n - 'a' + 10;
63
64 return -1;
65}
66
67static int __init qnap_tsx09_parse_hex_byte(const char *b)
68{
69 int hi;
70 int lo;
71
72 hi = qnap_tsx09_parse_hex_nibble(b[0]);
73 lo = qnap_tsx09_parse_hex_nibble(b[1]);
74
75 if (hi < 0 || lo < 0)
76 return -1;
77
78 return (hi << 4) | lo;
79}
80
81static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
82{
83 u_int8_t addr[6];
84 int i;
85
86 for (i = 0; i < 6; i++) {
87 int byte;
88
89 /*
90 * Enforce "xx:xx:xx:xx:xx:xx\n" format.
91 */
92 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
93 return -1;
94
95 byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
96 if (byte < 0)
97 return -1;
98 addr[i] = byte;
99 }
100
101 printk(KERN_INFO "tsx09: found ethernet mac address ");
102 for (i = 0; i < 6; i++)
103 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
104
105 memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
106
107 return 0;
108}
109
110/*
111 * The 'NAS Config' flash partition has an ext2 filesystem which
112 * contains a file that has the ethernet MAC address in plain text
113 * (format "xx:xx:xx:xx:xx:xx\n").
114 */
115void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
116{
117 unsigned long addr;
118
119 for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
120 char *nor_page;
121 int ret = 0;
122
123 nor_page = ioremap(addr, 1024);
124 if (nor_page != NULL) {
125 ret = qnap_tsx09_check_mac_addr(nor_page);
126 iounmap(nor_page);
127 }
128
129 if (ret == 0)
130 break;
131 }
132}
diff --git a/arch/arm/mach-orion5x/tsx09-common.h b/arch/arm/mach-orion5x/tsx09-common.h
new file mode 100644
index 00000000000..0984264616f
--- /dev/null
+++ b/arch/arm/mach-orion5x/tsx09-common.h
@@ -0,0 +1,20 @@
1#ifndef __ARCH_ORION5X_TSX09_COMMON_H
2#define __ARCH_ORION5X_TSX09_COMMON_H
3
4/*
5 * QNAP TS-x09 Boards power-off function
6 */
7extern void qnap_tsx09_power_off(void);
8
9/*
10 * QNAP TS-x09 Boards function to find Ethernet MAC address in flash memory
11 */
12extern void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size);
13
14/*
15 * QNAP TS-x09 Boards ethernet declaration
16 */
17extern struct mv643xx_eth_platform_data qnap_tsx09_eth_data;
18
19
20#endif