diff options
author | Sylver Bruneau <sylver.bruneau@googlemail.com> | 2008-05-31 12:21:49 -0400 |
---|---|---|
committer | Lennert Buytenhek <buytenh@marvell.com> | 2008-06-22 16:44:54 -0400 |
commit | 530c854aa351b2c7b3b3b6bedae8143310875206 (patch) | |
tree | 97274996c022b14a235152ef5dce809e915634ab /arch/arm/mach-orion5x/ts409-setup.c | |
parent | b08d5af39616fd32a1fafbcb51c36d4c99c4e02f (diff) |
[ARM] Orion: remove code duplication in TS209 and TS409 setup files
Signed-off-by: Sylver Bruneau <sylver.bruneau@googlemail.com>
Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Diffstat (limited to 'arch/arm/mach-orion5x/ts409-setup.c')
-rw-r--r-- | arch/arm/mach-orion5x/ts409-setup.c | 126 |
1 files changed, 7 insertions, 119 deletions
diff --git a/arch/arm/mach-orion5x/ts409-setup.c b/arch/arm/mach-orion5x/ts409-setup.c index 524e4249f082..32f0ff073b7e 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) | |||
152 | subsys_initcall(qnap_ts409_pci_init); | 153 | subsys_initcall(qnap_ts409_pci_init); |
153 | 154 | ||
154 | /***************************************************************************** | 155 | /***************************************************************************** |
155 | * Ethernet | ||
156 | ****************************************************************************/ | ||
157 | |||
158 | static struct mv643xx_eth_platform_data qnap_ts409_eth_data = { | ||
159 | .phy_addr = 8, | ||
160 | }; | ||
161 | |||
162 | static 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 | |||
176 | static 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 | |||
190 | static 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 | */ | ||
224 | static 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 | |||
316 | static 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 | |||
336 | static void __init qnap_ts409_init(void) | 222 | static 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 | ||
375 | MACHINE_START(TS409, "QNAP TS-409") | 263 | MACHINE_START(TS409, "QNAP TS-409") |