blob: 8f159db4d08a8b80e6498efe738c936ba0376380 [file] [log] [blame]
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +01001/*
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -04002 * arch/arm/mach-orion5x/dns323-setup.c
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +01003 *
4 * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
Erik Benadacf110522010-01-24 13:43:04 -080015#include <linux/delay.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010016#include <linux/platform_device.h>
17#include <linux/pci.h>
18#include <linux/irq.h>
19#include <linux/mtd/physmap.h>
20#include <linux/mv643xx_eth.h>
21#include <linux/leds.h>
22#include <linux/gpio_keys.h>
23#include <linux/input.h>
24#include <linux/i2c.h>
Matt Palmerf93e4152008-10-22 10:16:36 +020025#include <linux/ata_platform.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010026#include <asm/mach-types.h>
27#include <asm/gpio.h>
28#include <asm/mach/arch.h>
29#include <asm/mach/pci.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/orion5x.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010031#include "common.h"
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +020032#include "mpp.h"
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010033
34#define DNS323_GPIO_LED_RIGHT_AMBER 1
35#define DNS323_GPIO_LED_LEFT_AMBER 2
Erik Benadacf110522010-01-24 13:43:04 -080036#define DNS323_GPIO_SYSTEM_UP 3
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010037#define DNS323_GPIO_LED_POWER 5
38#define DNS323_GPIO_OVERTEMP 6
39#define DNS323_GPIO_RTC 7
40#define DNS323_GPIO_POWER_OFF 8
41#define DNS323_GPIO_KEY_POWER 9
42#define DNS323_GPIO_KEY_RESET 10
43
44/****************************************************************************
45 * PCI setup
46 */
47
48static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
49{
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040050 int irq;
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010051
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040052 /*
53 * Check for devices with hard-wired IRQs.
54 */
55 irq = orion5x_pci_map_irq(dev, slot, pin);
56 if (irq != -1)
57 return irq;
58
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010059 return -1;
60}
61
62static struct hw_pci dns323_pci __initdata = {
Lennert Buytenhekbbdf1c12008-05-15 10:31:14 +010063 .nr_controllers = 2,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010064 .swizzle = pci_std_swizzle,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -040065 .setup = orion5x_pci_sys_setup,
66 .scan = orion5x_pci_sys_scan_bus,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010067 .map_irq = dns323_pci_map_irq,
68};
69
Matt Palmerf93e4152008-10-22 10:16:36 +020070static int __init dns323_dev_id(void)
71{
72 u32 dev, rev;
73
74 orion5x_pcie_id(&dev, &rev);
75
76 return dev;
77}
78
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010079static int __init dns323_pci_init(void)
80{
Martin Michlmayrace14b82009-03-10 08:59:58 +010081 /* The 5182 doesn't really use its PCI bus, and initialising PCI
Matt Palmerf93e4152008-10-22 10:16:36 +020082 * gets in the way of initialising the SATA controller.
83 */
84 if (machine_is_dns323() && dns323_dev_id() != MV88F5182_DEV_ID)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010085 pci_common_init(&dns323_pci);
86
87 return 0;
88}
89
90subsys_initcall(dns323_pci_init);
91
92/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010093 * 8MiB NOR flash (Spansion S29GL064M90TFIR4)
94 *
95 * Layout as used by D-Link:
96 * 0x00000000-0x00010000 : "MTD1"
97 * 0x00010000-0x00020000 : "MTD2"
98 * 0x00020000-0x001a0000 : "Linux Kernel"
99 * 0x001a0000-0x007d0000 : "File System"
100 * 0x007d0000-0x00800000 : "u-boot"
101 */
102
103#define DNS323_NOR_BOOT_BASE 0xf4000000
104#define DNS323_NOR_BOOT_SIZE SZ_8M
105
106static struct mtd_partition dns323_partitions[] = {
107 {
108 .name = "MTD1",
109 .size = 0x00010000,
110 .offset = 0,
111 }, {
112 .name = "MTD2",
113 .size = 0x00010000,
114 .offset = 0x00010000,
115 }, {
116 .name = "Linux Kernel",
117 .size = 0x00180000,
118 .offset = 0x00020000,
119 }, {
120 .name = "File System",
121 .size = 0x00630000,
122 .offset = 0x001A0000,
123 }, {
124 .name = "u-boot",
125 .size = 0x00030000,
126 .offset = 0x007d0000,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200127 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100128};
129
130static struct physmap_flash_data dns323_nor_flash_data = {
131 .width = 1,
132 .parts = dns323_partitions,
133 .nr_parts = ARRAY_SIZE(dns323_partitions)
134};
135
136static struct resource dns323_nor_flash_resource = {
137 .flags = IORESOURCE_MEM,
138 .start = DNS323_NOR_BOOT_BASE,
139 .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1,
140};
141
142static struct platform_device dns323_nor_flash = {
143 .name = "physmap-flash",
144 .id = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200145 .dev = {
146 .platform_data = &dns323_nor_flash_data,
147 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100148 .resource = &dns323_nor_flash_resource,
149 .num_resources = 1,
150};
151
152/****************************************************************************
Matt Palmera93f44c2008-10-19 08:15:09 +1100153 * Ethernet
154 */
155
156static struct mv643xx_eth_platform_data dns323_eth_data = {
157 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
158};
159
160/* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these
161 * functions be kept somewhere?
162 */
163static int __init dns323_parse_hex_nibble(char n)
164{
165 if (n >= '0' && n <= '9')
166 return n - '0';
167
168 if (n >= 'A' && n <= 'F')
169 return n - 'A' + 10;
170
171 if (n >= 'a' && n <= 'f')
172 return n - 'a' + 10;
173
174 return -1;
175}
176
177static int __init dns323_parse_hex_byte(const char *b)
178{
179 int hi;
180 int lo;
181
182 hi = dns323_parse_hex_nibble(b[0]);
183 lo = dns323_parse_hex_nibble(b[1]);
184
185 if (hi < 0 || lo < 0)
186 return -1;
187
188 return (hi << 4) | lo;
189}
190
191static int __init dns323_read_mac_addr(void)
192{
193 u_int8_t addr[6];
194 int i;
195 char *mac_page;
196
197 /* MAC address is stored as a regular ol' string in /dev/mtdblock4
198 * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80).
199 */
200 mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024);
201 if (!mac_page)
202 return -ENOMEM;
203
204 /* Sanity check the string we're looking at */
205 for (i = 0; i < 5; i++) {
206 if (*(mac_page + (i * 3) + 2) != ':') {
207 goto error_fail;
208 }
209 }
210
211 for (i = 0; i < 6; i++) {
212 int byte;
213
214 byte = dns323_parse_hex_byte(mac_page + (i * 3));
215 if (byte < 0) {
216 goto error_fail;
217 }
218
219 addr[i] = byte;
220 }
221
222 iounmap(mac_page);
223 printk("DNS323: Found ethernet MAC address: ");
224 for (i = 0; i < 6; i++)
225 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
226
227 memcpy(dns323_eth_data.mac_addr, addr, 6);
228
229 return 0;
230
231error_fail:
232 iounmap(mac_page);
233 return -EINVAL;
234}
235
236/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100237 * GPIO LEDs (simple - doesn't use hardware blinking support)
238 */
239
240static struct gpio_led dns323_leds[] = {
241 {
242 .name = "power:blue",
243 .gpio = DNS323_GPIO_LED_POWER,
Erik Benadacf110522010-01-24 13:43:04 -0800244 .default_state = LEDS_GPIO_DEFSTATE_ON,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100245 }, {
246 .name = "right:amber",
247 .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
248 .active_low = 1,
249 }, {
250 .name = "left:amber",
251 .gpio = DNS323_GPIO_LED_LEFT_AMBER,
252 .active_low = 1,
253 },
254};
255
256static struct gpio_led_platform_data dns323_led_data = {
257 .num_leds = ARRAY_SIZE(dns323_leds),
258 .leds = dns323_leds,
259};
260
261static struct platform_device dns323_gpio_leds = {
262 .name = "leds-gpio",
263 .id = -1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200264 .dev = {
265 .platform_data = &dns323_led_data,
266 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100267};
268
269/****************************************************************************
270 * GPIO Attached Keys
271 */
272
273static struct gpio_keys_button dns323_buttons[] = {
274 {
275 .code = KEY_RESTART,
276 .gpio = DNS323_GPIO_KEY_RESET,
277 .desc = "Reset Button",
278 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200279 }, {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100280 .code = KEY_POWER,
281 .gpio = DNS323_GPIO_KEY_POWER,
282 .desc = "Power Button",
283 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200284 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100285};
286
287static struct gpio_keys_platform_data dns323_button_data = {
288 .buttons = dns323_buttons,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200289 .nbuttons = ARRAY_SIZE(dns323_buttons),
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100290};
291
292static struct platform_device dns323_button_device = {
293 .name = "gpio-keys",
294 .id = -1,
295 .num_resources = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200296 .dev = {
297 .platform_data = &dns323_button_data,
298 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100299};
300
Matt Palmerf93e4152008-10-22 10:16:36 +0200301/*****************************************************************************
302 * SATA
303 */
304static struct mv_sata_platform_data dns323_sata_data = {
305 .n_ports = 2,
306};
307
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100308/****************************************************************************
309 * General Setup
310 */
Matt Palmerf93e4152008-10-22 10:16:36 +0200311static struct orion5x_mpp_mode dns323_mv88f5181_mpp_modes[] __initdata = {
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200312 { 0, MPP_PCIE_RST_OUTn },
313 { 1, MPP_GPIO }, /* right amber LED (sata ch0) */
314 { 2, MPP_GPIO }, /* left amber LED (sata ch1) */
315 { 3, MPP_UNUSED },
316 { 4, MPP_GPIO }, /* power button LED */
317 { 5, MPP_GPIO }, /* power button LED */
318 { 6, MPP_GPIO }, /* GMT G751-2f overtemp */
319 { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */
320 { 8, MPP_GPIO }, /* triggers power off */
321 { 9, MPP_GPIO }, /* power button switch */
322 { 10, MPP_GPIO }, /* reset button switch */
323 { 11, MPP_UNUSED },
324 { 12, MPP_UNUSED },
325 { 13, MPP_UNUSED },
326 { 14, MPP_UNUSED },
327 { 15, MPP_UNUSED },
328 { 16, MPP_UNUSED },
329 { 17, MPP_UNUSED },
330 { 18, MPP_UNUSED },
331 { 19, MPP_UNUSED },
332 { -1 },
333};
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100334
Matt Palmerf93e4152008-10-22 10:16:36 +0200335static struct orion5x_mpp_mode dns323_mv88f5182_mpp_modes[] __initdata = {
336 { 0, MPP_UNUSED },
337 { 1, MPP_GPIO }, /* right amber LED (sata ch0) */
338 { 2, MPP_GPIO }, /* left amber LED (sata ch1) */
Erik Benadacf110522010-01-24 13:43:04 -0800339 { 3, MPP_GPIO }, /* system up flag */
Matt Palmerf93e4152008-10-22 10:16:36 +0200340 { 4, MPP_GPIO }, /* power button LED */
341 { 5, MPP_GPIO }, /* power button LED */
342 { 6, MPP_GPIO }, /* GMT G751-2f overtemp */
343 { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */
344 { 8, MPP_GPIO }, /* triggers power off */
345 { 9, MPP_GPIO }, /* power button switch */
346 { 10, MPP_GPIO }, /* reset button switch */
347 { 11, MPP_UNUSED },
348 { 12, MPP_SATA_LED },
349 { 13, MPP_SATA_LED },
350 { 14, MPP_SATA_LED },
351 { 15, MPP_SATA_LED },
352 { 16, MPP_UNUSED },
353 { 17, MPP_UNUSED },
354 { 18, MPP_UNUSED },
355 { 19, MPP_UNUSED },
356 { -1 },
357};
358
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100359/*
360 * On the DNS-323 the following devices are attached via I2C:
361 *
362 * i2c addr | chip | description
363 * 0x3e | GMT G760Af | fan speed PWM controller
364 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
365 * 0x68 | ST M41T80 | RTC w/ alarm
366 */
367static struct i2c_board_info __initdata dns323_i2c_devices[] = {
368 {
369 I2C_BOARD_INFO("g760a", 0x3e),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200370 }, {
Martin Michlmayrc0fe8192008-08-12 12:50:14 +0300371 I2C_BOARD_INFO("lm75", 0x48),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200372 }, {
Jean Delvare3760f732008-04-29 23:11:40 +0200373 I2C_BOARD_INFO("m41t80", 0x68),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200374 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100375};
376
Erik Benadacf110522010-01-24 13:43:04 -0800377/* DNS-323 rev. A specific power off method */
378static void dns323a_power_off(void)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100379{
380 pr_info("%s: triggering power-off...\n", __func__);
381 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
382}
383
Erik Benadacf110522010-01-24 13:43:04 -0800384/* DNS-323 rev B specific power off method */
385static void dns323b_power_off(void)
386{
387 pr_info("%s: triggering power-off...\n", __func__);
388 /* Pin has to be changed to 1 and back to 0 to do actual power off. */
389 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
390 mdelay(100);
391 gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
392}
393
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100394static void __init dns323_init(void)
395{
396 /* Setup basic Orion functions. Need to be called early. */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400397 orion5x_init();
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100398
Matt Palmerf93e4152008-10-22 10:16:36 +0200399 /* Just to be tricky, the 5182 has a completely different
400 * set of MPP modes to the 5181.
401 */
402 if (dns323_dev_id() == MV88F5182_DEV_ID)
403 orion5x_mpp_conf(dns323_mv88f5182_mpp_modes);
404 else {
405 orion5x_mpp_conf(dns323_mv88f5181_mpp_modes);
406 writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */
407 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100408
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200409 /* setup flash mapping
410 * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
411 */
412 orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE);
413 platform_device_register(&dns323_nor_flash);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100414
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200415 platform_device_register(&dns323_gpio_leds);
416
417 platform_device_register(&dns323_button_device);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100418
419 i2c_register_board_info(0, dns323_i2c_devices,
420 ARRAY_SIZE(dns323_i2c_devices));
421
Matt Palmera93f44c2008-10-19 08:15:09 +1100422 /*
423 * Configure peripherals.
424 */
425 if (dns323_read_mac_addr() < 0)
426 printk("DNS323: Failed to read MAC address\n");
427
428 orion5x_ehci0_init();
429 orion5x_eth_init(&dns323_eth_data);
430 orion5x_i2c_init();
431 orion5x_uart0_init();
432
Martin Michlmayrace14b82009-03-10 08:59:58 +0100433 /* The 5182 has its SATA controller on-chip, and needs its own little
Matt Palmerf93e4152008-10-22 10:16:36 +0200434 * init routine.
435 */
436 if (dns323_dev_id() == MV88F5182_DEV_ID)
437 orion5x_sata_init(&dns323_sata_data);
438
Erik Benadacf110522010-01-24 13:43:04 -0800439 /* The 5182 has flag to indicate the system is up. Without this flag
440 * set, power LED will flash and cannot be controlled via leds-gpio.
441 */
442 if (dns323_dev_id() == MV88F5182_DEV_ID)
443 gpio_set_value(DNS323_GPIO_SYSTEM_UP, 1);
444
445 /* Register dns323 specific power-off method */
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200446 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
447 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
448 pr_err("DNS323: failed to setup power-off GPIO\n");
Erik Benadacf110522010-01-24 13:43:04 -0800449 if (dns323_dev_id() == MV88F5182_DEV_ID)
450 pm_power_off = dns323b_power_off;
451 else
452 pm_power_off = dns323a_power_off;
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100453}
454
455/* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
456MACHINE_START(DNS323, "D-Link DNS-323")
457 /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400458 .phys_io = ORION5X_REGS_PHYS_BASE,
459 .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100460 .boot_params = 0x00000100,
461 .init_machine = dns323_init,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400462 .map_io = orion5x_map_io,
463 .init_irq = orion5x_init_irq,
464 .timer = &orion5x_timer,
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100465 .fixup = tag_fixup_mem32,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100466MACHINE_END