blob: 91b0f47885977e80ba5109f6b4205ce4b30de3b8 [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 *
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +10006 * Support for HW Rev C1:
7 *
8 * Copyright (C) 2010 Benjamin Herrenschmidt <benh@kernel.crashing.org>
9 *
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
14 *
15 */
Russell King2f8163b2011-07-26 10:53:52 +010016#include <linux/gpio.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010017#include <linux/kernel.h>
18#include <linux/init.h>
Erik Benadacf110522010-01-24 13:43:04 -080019#include <linux/delay.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010020#include <linux/platform_device.h>
21#include <linux/pci.h>
22#include <linux/irq.h>
23#include <linux/mtd/physmap.h>
24#include <linux/mv643xx_eth.h>
25#include <linux/leds.h>
26#include <linux/gpio_keys.h>
27#include <linux/input.h>
28#include <linux/i2c.h>
Matt Palmerf93e4152008-10-22 10:16:36 +020029#include <linux/ata_platform.h>
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100030#include <linux/phy.h>
31#include <linux/marvell_phy.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010032#include <asm/mach-types.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010033#include <asm/mach/arch.h>
34#include <asm/mach/pci.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/orion5x.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010036#include "common.h"
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +020037#include "mpp.h"
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010038
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100039/* Rev A1 and B1 */
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010040#define DNS323_GPIO_LED_RIGHT_AMBER 1
41#define DNS323_GPIO_LED_LEFT_AMBER 2
Erik Benadacf110522010-01-24 13:43:04 -080042#define DNS323_GPIO_SYSTEM_UP 3
Laurie Bradshawb2a731a2010-02-10 16:10:43 +000043#define DNS323_GPIO_LED_POWER1 4
44#define DNS323_GPIO_LED_POWER2 5
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010045#define DNS323_GPIO_OVERTEMP 6
46#define DNS323_GPIO_RTC 7
47#define DNS323_GPIO_POWER_OFF 8
48#define DNS323_GPIO_KEY_POWER 9
49#define DNS323_GPIO_KEY_RESET 10
50
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100051/* Rev C1 */
52#define DNS323C_GPIO_KEY_POWER 1
53#define DNS323C_GPIO_POWER_OFF 2
54#define DNS323C_GPIO_LED_RIGHT_AMBER 8
55#define DNS323C_GPIO_LED_LEFT_AMBER 9
56#define DNS323C_GPIO_LED_POWER 17
57#define DNS323C_GPIO_FAN_BIT1 18
58#define DNS323C_GPIO_FAN_BIT0 19
59
60/* Exposed to userspace, do not change */
61enum {
62 DNS323_REV_A1, /* 0 */
63 DNS323_REV_B1, /* 1 */
64 DNS323_REV_C1, /* 2 */
65};
66
67
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010068/****************************************************************************
69 * PCI setup
70 */
71
Ralf Baechled5341942011-06-10 15:30:21 +010072static int __init dns323_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010073{
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040074 int irq;
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010075
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040076 /*
77 * Check for devices with hard-wired IRQs.
78 */
Paul Gortmaker51667932011-08-01 12:42:14 -040079 irq = orion5x_pci_map_irq(dev, slot, pin);
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040080 if (irq != -1)
81 return irq;
82
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010083 return -1;
84}
85
86static struct hw_pci dns323_pci __initdata = {
Lennert Buytenhekbbdf1c12008-05-15 10:31:14 +010087 .nr_controllers = 2,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010088 .swizzle = pci_std_swizzle,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -040089 .setup = orion5x_pci_sys_setup,
90 .scan = orion5x_pci_sys_scan_bus,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010091 .map_irq = dns323_pci_map_irq,
92};
93
94static int __init dns323_pci_init(void)
95{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100096 /* Rev B1 and C1 doesn't really use its PCI bus, and initialising PCI
Matt Palmerf93e4152008-10-22 10:16:36 +020097 * gets in the way of initialising the SATA controller.
98 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100099 if (machine_is_dns323() && system_rev == DNS323_REV_A1)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100100 pci_common_init(&dns323_pci);
101
102 return 0;
103}
104
105subsys_initcall(dns323_pci_init);
106
107/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100108 * 8MiB NOR flash (Spansion S29GL064M90TFIR4)
109 *
110 * Layout as used by D-Link:
111 * 0x00000000-0x00010000 : "MTD1"
112 * 0x00010000-0x00020000 : "MTD2"
113 * 0x00020000-0x001a0000 : "Linux Kernel"
114 * 0x001a0000-0x007d0000 : "File System"
115 * 0x007d0000-0x00800000 : "u-boot"
116 */
117
118#define DNS323_NOR_BOOT_BASE 0xf4000000
119#define DNS323_NOR_BOOT_SIZE SZ_8M
120
121static struct mtd_partition dns323_partitions[] = {
122 {
123 .name = "MTD1",
124 .size = 0x00010000,
125 .offset = 0,
126 }, {
127 .name = "MTD2",
128 .size = 0x00010000,
129 .offset = 0x00010000,
130 }, {
131 .name = "Linux Kernel",
132 .size = 0x00180000,
133 .offset = 0x00020000,
134 }, {
135 .name = "File System",
136 .size = 0x00630000,
137 .offset = 0x001A0000,
138 }, {
139 .name = "u-boot",
140 .size = 0x00030000,
141 .offset = 0x007d0000,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200142 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100143};
144
145static struct physmap_flash_data dns323_nor_flash_data = {
146 .width = 1,
147 .parts = dns323_partitions,
148 .nr_parts = ARRAY_SIZE(dns323_partitions)
149};
150
151static struct resource dns323_nor_flash_resource = {
152 .flags = IORESOURCE_MEM,
153 .start = DNS323_NOR_BOOT_BASE,
154 .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1,
155};
156
157static struct platform_device dns323_nor_flash = {
158 .name = "physmap-flash",
159 .id = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200160 .dev = {
161 .platform_data = &dns323_nor_flash_data,
162 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100163 .resource = &dns323_nor_flash_resource,
164 .num_resources = 1,
165};
166
167/****************************************************************************
Matt Palmera93f44c2008-10-19 08:15:09 +1100168 * Ethernet
169 */
170
171static struct mv643xx_eth_platform_data dns323_eth_data = {
172 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
173};
174
175/* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these
176 * functions be kept somewhere?
177 */
178static int __init dns323_parse_hex_nibble(char n)
179{
180 if (n >= '0' && n <= '9')
181 return n - '0';
182
183 if (n >= 'A' && n <= 'F')
184 return n - 'A' + 10;
185
186 if (n >= 'a' && n <= 'f')
187 return n - 'a' + 10;
188
189 return -1;
190}
191
192static int __init dns323_parse_hex_byte(const char *b)
193{
194 int hi;
195 int lo;
196
197 hi = dns323_parse_hex_nibble(b[0]);
198 lo = dns323_parse_hex_nibble(b[1]);
199
200 if (hi < 0 || lo < 0)
201 return -1;
202
203 return (hi << 4) | lo;
204}
205
206static int __init dns323_read_mac_addr(void)
207{
208 u_int8_t addr[6];
209 int i;
210 char *mac_page;
211
212 /* MAC address is stored as a regular ol' string in /dev/mtdblock4
213 * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80).
214 */
215 mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024);
216 if (!mac_page)
217 return -ENOMEM;
218
219 /* Sanity check the string we're looking at */
220 for (i = 0; i < 5; i++) {
221 if (*(mac_page + (i * 3) + 2) != ':') {
222 goto error_fail;
223 }
224 }
225
226 for (i = 0; i < 6; i++) {
227 int byte;
228
229 byte = dns323_parse_hex_byte(mac_page + (i * 3));
230 if (byte < 0) {
231 goto error_fail;
232 }
233
234 addr[i] = byte;
235 }
236
237 iounmap(mac_page);
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000238 printk("DNS-323: Found ethernet MAC address: ");
Matt Palmera93f44c2008-10-19 08:15:09 +1100239 for (i = 0; i < 6; i++)
240 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
241
242 memcpy(dns323_eth_data.mac_addr, addr, 6);
243
244 return 0;
245
246error_fail:
247 iounmap(mac_page);
248 return -EINVAL;
249}
250
251/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100252 * GPIO LEDs (simple - doesn't use hardware blinking support)
253 */
254
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000255#define ORION_BLINK_HALF_PERIOD 100 /* ms */
256
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000257static int dns323_gpio_blink_set(unsigned gpio, int state,
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000258 unsigned long *delay_on, unsigned long *delay_off)
259{
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000260
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000261 if (delay_on && delay_off && !*delay_on && !*delay_off)
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000262 *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD;
263
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000264 switch(state) {
265 case GPIO_LED_NO_BLINK_LOW:
266 case GPIO_LED_NO_BLINK_HIGH:
267 orion_gpio_set_blink(gpio, 0);
268 gpio_set_value(gpio, state);
269 break;
270 case GPIO_LED_BLINK:
271 orion_gpio_set_blink(gpio, 1);
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000272 }
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000273 return 0;
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000274}
275
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000276static struct gpio_led dns323ab_leds[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100277 {
278 .name = "power:blue",
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000279 .gpio = DNS323_GPIO_LED_POWER2,
Martin Michlmayrf8e00532010-03-26 11:20:00 +0100280 .default_trigger = "default-on",
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100281 }, {
282 .name = "right:amber",
283 .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
284 .active_low = 1,
285 }, {
286 .name = "left:amber",
287 .gpio = DNS323_GPIO_LED_LEFT_AMBER,
288 .active_low = 1,
289 },
290};
291
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000292
293static struct gpio_led dns323c_leds[] = {
294 {
295 .name = "power:blue",
296 .gpio = DNS323C_GPIO_LED_POWER,
297 .default_trigger = "timer",
298 .active_low = 1,
299 }, {
300 .name = "right:amber",
301 .gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
302 .active_low = 1,
303 }, {
304 .name = "left:amber",
305 .gpio = DNS323C_GPIO_LED_LEFT_AMBER,
306 .active_low = 1,
307 },
308};
309
310
311static struct gpio_led_platform_data dns323ab_led_data = {
312 .num_leds = ARRAY_SIZE(dns323ab_leds),
313 .leds = dns323ab_leds,
314 .gpio_blink_set = dns323_gpio_blink_set,
315};
316
317static struct gpio_led_platform_data dns323c_led_data = {
318 .num_leds = ARRAY_SIZE(dns323c_leds),
319 .leds = dns323c_leds,
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000320 .gpio_blink_set = dns323_gpio_blink_set,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100321};
322
323static struct platform_device dns323_gpio_leds = {
324 .name = "leds-gpio",
325 .id = -1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200326 .dev = {
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000327 .platform_data = &dns323ab_led_data,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200328 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100329};
330
331/****************************************************************************
332 * GPIO Attached Keys
333 */
334
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000335static struct gpio_keys_button dns323ab_buttons[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100336 {
337 .code = KEY_RESTART,
338 .gpio = DNS323_GPIO_KEY_RESET,
339 .desc = "Reset Button",
340 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200341 }, {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100342 .code = KEY_POWER,
343 .gpio = DNS323_GPIO_KEY_POWER,
344 .desc = "Power Button",
345 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200346 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100347};
348
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000349static struct gpio_keys_platform_data dns323ab_button_data = {
350 .buttons = dns323ab_buttons,
351 .nbuttons = ARRAY_SIZE(dns323ab_buttons),
352};
353
354static struct gpio_keys_button dns323c_buttons[] = {
355 {
356 .code = KEY_POWER,
357 .gpio = DNS323C_GPIO_KEY_POWER,
358 .desc = "Power Button",
359 .active_low = 1,
360 },
361};
362
363static struct gpio_keys_platform_data dns323c_button_data = {
364 .buttons = dns323c_buttons,
365 .nbuttons = ARRAY_SIZE(dns323c_buttons),
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100366};
367
368static struct platform_device dns323_button_device = {
369 .name = "gpio-keys",
370 .id = -1,
371 .num_resources = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200372 .dev = {
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000373 .platform_data = &dns323ab_button_data,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200374 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100375};
376
Matt Palmerf93e4152008-10-22 10:16:36 +0200377/*****************************************************************************
378 * SATA
379 */
380static struct mv_sata_platform_data dns323_sata_data = {
381 .n_ports = 2,
382};
383
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100384/****************************************************************************
385 * General Setup
386 */
Andrew Lunn554cdae2011-05-15 13:32:53 +0200387static unsigned int dns323a_mpp_modes[] __initdata = {
388 MPP0_PCIE_RST_OUTn,
389 MPP1_GPIO, /* right amber LED (sata ch0) */
390 MPP2_GPIO, /* left amber LED (sata ch1) */
391 MPP3_UNUSED,
392 MPP4_GPIO, /* power button LED */
393 MPP5_GPIO, /* power button LED */
394 MPP6_GPIO, /* GMT G751-2f overtemp */
395 MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */
396 MPP8_GPIO, /* triggers power off */
397 MPP9_GPIO, /* power button switch */
398 MPP10_GPIO, /* reset button switch */
399 MPP11_UNUSED,
400 MPP12_UNUSED,
401 MPP13_UNUSED,
402 MPP14_UNUSED,
403 MPP15_UNUSED,
404 MPP16_UNUSED,
405 MPP17_UNUSED,
406 MPP18_UNUSED,
407 MPP19_UNUSED,
408 0,
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200409};
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100410
Andrew Lunn554cdae2011-05-15 13:32:53 +0200411static unsigned int dns323b_mpp_modes[] __initdata = {
412 MPP0_UNUSED,
413 MPP1_GPIO, /* right amber LED (sata ch0) */
414 MPP2_GPIO, /* left amber LED (sata ch1) */
415 MPP3_GPIO, /* system up flag */
416 MPP4_GPIO, /* power button LED */
417 MPP5_GPIO, /* power button LED */
418 MPP6_GPIO, /* GMT G751-2f overtemp */
419 MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */
420 MPP8_GPIO, /* triggers power off */
421 MPP9_GPIO, /* power button switch */
422 MPP10_GPIO, /* reset button switch */
423 MPP11_UNUSED,
424 MPP12_SATA_LED,
425 MPP13_SATA_LED,
426 MPP14_SATA_LED,
427 MPP15_SATA_LED,
428 MPP16_UNUSED,
429 MPP17_UNUSED,
430 MPP18_UNUSED,
431 MPP19_UNUSED,
432 0,
Matt Palmerf93e4152008-10-22 10:16:36 +0200433};
434
Andrew Lunn554cdae2011-05-15 13:32:53 +0200435static unsigned int dns323c_mpp_modes[] __initdata = {
436 MPP0_GPIO, /* ? input */
437 MPP1_GPIO, /* input power switch (0 = pressed) */
438 MPP2_GPIO, /* output power off */
439 MPP3_UNUSED, /* ? output */
440 MPP4_UNUSED, /* ? output */
441 MPP5_UNUSED, /* ? output */
442 MPP6_UNUSED, /* ? output */
443 MPP7_UNUSED, /* ? output */
444 MPP8_GPIO, /* i/o right amber LED */
445 MPP9_GPIO, /* i/o left amber LED */
446 MPP10_GPIO, /* input */
447 MPP11_UNUSED,
448 MPP12_SATA_LED,
449 MPP13_SATA_LED,
450 MPP14_SATA_LED,
451 MPP15_SATA_LED,
452 MPP16_UNUSED,
453 MPP17_GPIO, /* power button LED */
454 MPP18_GPIO, /* fan speed bit 0 */
455 MPP19_GPIO, /* fan speed bit 1 */
456 0,
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000457};
458
459/* Rev C1 Fan speed notes:
460 *
461 * The fan is controlled by 2 GPIOs on this board. The settings
462 * of the bits is as follow:
463 *
464 * GPIO 18 GPIO 19 Fan
465 *
466 * 0 0 stopped
467 * 0 1 low speed
468 * 1 0 high speed
469 * 1 1 don't do that (*)
470 *
471 * (*) I think the two bits control two feed-in resistors into a fixed
472 * PWN circuit, setting both bits will basically go a 'bit' faster
473 * than high speed, but d-link doesn't do it and you may get out of
474 * HW spec so don't do it.
475 */
476
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100477/*
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000478 * On the DNS-323 A1 and B1 the following devices are attached via I2C:
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100479 *
480 * i2c addr | chip | description
481 * 0x3e | GMT G760Af | fan speed PWM controller
482 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
483 * 0x68 | ST M41T80 | RTC w/ alarm
484 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000485static struct i2c_board_info __initdata dns323ab_i2c_devices[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100486 {
487 I2C_BOARD_INFO("g760a", 0x3e),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200488 }, {
Martin Michlmayrc0fe8192008-08-12 12:50:14 +0300489 I2C_BOARD_INFO("lm75", 0x48),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200490 }, {
Jean Delvare3760f732008-04-29 23:11:40 +0200491 I2C_BOARD_INFO("m41t80", 0x68),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200492 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100493};
494
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000495/*
496 * On the DNS-323 C1 the following devices are attached via I2C:
497 *
498 * i2c addr | chip | description
499 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
500 * 0x68 | ST M41T80 | RTC w/ alarm
501 */
502static struct i2c_board_info __initdata dns323c_i2c_devices[] = {
503 {
504 I2C_BOARD_INFO("lm75", 0x48),
505 }, {
506 I2C_BOARD_INFO("m41t80", 0x68),
507 },
508};
509
Erik Benadacf110522010-01-24 13:43:04 -0800510/* DNS-323 rev. A specific power off method */
511static void dns323a_power_off(void)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100512{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000513 pr_info("DNS-323: Triggering power-off...\n");
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100514 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
515}
516
Erik Benadacf110522010-01-24 13:43:04 -0800517/* DNS-323 rev B specific power off method */
518static void dns323b_power_off(void)
519{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000520 pr_info("DNS-323: Triggering power-off...\n");
Erik Benadacf110522010-01-24 13:43:04 -0800521 /* Pin has to be changed to 1 and back to 0 to do actual power off. */
522 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
523 mdelay(100);
524 gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
525}
526
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000527/* DNS-323 rev. C specific power off method */
528static void dns323c_power_off(void)
529{
530 pr_info("DNS-323: Triggering power-off...\n");
531 gpio_set_value(DNS323C_GPIO_POWER_OFF, 1);
532}
533
534static int dns323c_phy_fixup(struct phy_device *phy)
535{
536 phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS;
537
538 return 0;
539}
540
541static int __init dns323_identify_rev(void)
542{
543 u32 dev, rev, i, reg;
544
545 pr_debug("DNS-323: Identifying board ... \n");
546
547 /* Rev A1 has a 5181 */
548 orion5x_pcie_id(&dev, &rev);
549 if (dev == MV88F5181_DEV_ID) {
550 pr_debug("DNS-323: 5181 found, board is A1\n");
551 return DNS323_REV_A1;
552 }
553 pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n");
554
555 /* Rev B1 and C1 both have 5182, let's poke at the eth PHY. This is
556 * a bit gross but we want to do that without links into the eth
557 * driver so let's poke at it directly. We default to rev B1 in
558 * case the accesses fail
559 */
560
561#define ETH_SMI_REG (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004)
562#define SMI_BUSY 0x10000000
563#define SMI_READ_VALID 0x08000000
564#define SMI_OPCODE_READ 0x04000000
565#define SMI_OPCODE_WRITE 0x00000000
566
567 for (i = 0; i < 1000; i++) {
568 reg = readl(ETH_SMI_REG);
569 if (!(reg & SMI_BUSY))
570 break;
571 }
572 if (i >= 1000) {
573 pr_warning("DNS-323: Timeout accessing PHY, assuming rev B1\n");
574 return DNS323_REV_B1;
575 }
576 writel((3 << 21) /* phy ID reg */ |
577 (8 << 16) /* phy addr */ |
578 SMI_OPCODE_READ, ETH_SMI_REG);
579 for (i = 0; i < 1000; i++) {
580 reg = readl(ETH_SMI_REG);
581 if (reg & SMI_READ_VALID)
582 break;
583 }
584 if (i >= 1000) {
585 pr_warning("DNS-323: Timeout reading PHY, assuming rev B1\n");
586 return DNS323_REV_B1;
587 }
588 pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff);
589
590 /* Note: the Marvell tools mask the ID with 0x3f0 before comparison
591 * but I don't see that making a difference here, at least with
592 * any known Marvell PHY ID
593 */
594 switch(reg & 0xfff0) {
595 case 0x0cc0: /* MV88E1111 */
596 return DNS323_REV_B1;
597 case 0x0e10: /* MV88E1118 */
598 return DNS323_REV_C1;
599 default:
600 pr_warning("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n",
601 reg & 0xffff);
602 }
603 return DNS323_REV_B1;
604}
605
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100606static void __init dns323_init(void)
607{
608 /* Setup basic Orion functions. Need to be called early. */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400609 orion5x_init();
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100610
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000611 /* Identify revision */
612 system_rev = dns323_identify_rev();
613 pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev);
614
Matt Palmerf93e4152008-10-22 10:16:36 +0200615 /* Just to be tricky, the 5182 has a completely different
616 * set of MPP modes to the 5181.
617 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000618 switch(system_rev) {
619 case DNS323_REV_A1:
620 orion5x_mpp_conf(dns323a_mpp_modes);
Matt Palmerf93e4152008-10-22 10:16:36 +0200621 writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000622 break;
623 case DNS323_REV_B1:
624 orion5x_mpp_conf(dns323b_mpp_modes);
625 break;
626 case DNS323_REV_C1:
627 orion5x_mpp_conf(dns323c_mpp_modes);
628 break;
Matt Palmerf93e4152008-10-22 10:16:36 +0200629 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100630
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200631 /* setup flash mapping
632 * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
633 */
634 orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE);
635 platform_device_register(&dns323_nor_flash);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100636
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000637 /* Sort out LEDs, Buttons and i2c devices */
638 switch(system_rev) {
639 case DNS323_REV_A1:
640 /* The 5181 power LED is active low and requires
641 * DNS323_GPIO_LED_POWER1 to also be low.
642 */
643 dns323ab_leds[0].active_low = 1;
644 gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
645 gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
646 /* Fall through */
647 case DNS323_REV_B1:
648 i2c_register_board_info(0, dns323ab_i2c_devices,
649 ARRAY_SIZE(dns323ab_i2c_devices));
650 break;
651 case DNS323_REV_C1:
652 /* Hookup LEDs & Buttons */
653 dns323_gpio_leds.dev.platform_data = &dns323c_led_data;
654 dns323_button_device.dev.platform_data = &dns323c_button_data;
655
656 /* Hookup i2c devices and fan driver */
657 i2c_register_board_info(0, dns323c_i2c_devices,
658 ARRAY_SIZE(dns323c_i2c_devices));
659 platform_device_register_simple("dns323c-fan", 0, NULL, 0);
660
661 /* Register fixup for the PHY LEDs */
662 phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118,
663 MARVELL_PHY_ID_MASK,
664 dns323c_phy_fixup);
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000665 }
666
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200667 platform_device_register(&dns323_gpio_leds);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200668 platform_device_register(&dns323_button_device);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100669
Matt Palmera93f44c2008-10-19 08:15:09 +1100670 /*
671 * Configure peripherals.
672 */
673 if (dns323_read_mac_addr() < 0)
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000674 printk("DNS-323: Failed to read MAC address\n");
Matt Palmera93f44c2008-10-19 08:15:09 +1100675 orion5x_ehci0_init();
676 orion5x_eth_init(&dns323_eth_data);
677 orion5x_i2c_init();
678 orion5x_uart0_init();
679
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000680 /* Remaining GPIOs */
681 switch(system_rev) {
682 case DNS323_REV_A1:
683 /* Poweroff GPIO */
684 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
685 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
686 pr_err("DNS-323: failed to setup power-off GPIO\n");
687 pm_power_off = dns323a_power_off;
688 break;
689 case DNS323_REV_B1:
690 /* 5182 built-in SATA init */
Matt Palmerf93e4152008-10-22 10:16:36 +0200691 orion5x_sata_init(&dns323_sata_data);
692
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000693 /* The DNS323 rev B1 has flag to indicate the system is up.
694 * Without this flag set, power LED will flash and cannot be
695 * controlled via leds-gpio.
696 */
697 if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0)
698 gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1);
Erik Benadacf110522010-01-24 13:43:04 -0800699
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000700 /* Poweroff GPIO */
701 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
702 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
703 pr_err("DNS-323: failed to setup power-off GPIO\n");
Erik Benadacf110522010-01-24 13:43:04 -0800704 pm_power_off = dns323b_power_off;
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000705 break;
706 case DNS323_REV_C1:
707 /* 5182 built-in SATA init */
708 orion5x_sata_init(&dns323_sata_data);
709
710 /* Poweroff GPIO */
711 if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
712 gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
713 pr_err("DNS-323: failed to setup power-off GPIO\n");
714 pm_power_off = dns323c_power_off;
715
716 /* Now, -this- should theorically be done by the sata_mv driver
717 * once I figure out what's going on there. Maybe the behaviour
718 * of the LEDs should be somewhat passed via the platform_data.
719 * for now, just whack the register and make the LEDs happy
720 *
721 * Note: AFAIK, rev B1 needs the same treatement but I'll let
722 * somebody else test it.
723 */
724 writel(0x5, ORION5X_SATA_VIRT_BASE | 0x2c);
725 break;
726 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100727}
728
729/* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
730MACHINE_START(DNS323, "D-Link DNS-323")
731 /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */
Nicolas Pitre65aa1b12011-07-05 22:38:15 -0400732 .atag_offset = 0x100,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100733 .init_machine = dns323_init,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400734 .map_io = orion5x_map_io,
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200735 .init_early = orion5x_init_early,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400736 .init_irq = orion5x_init_irq,
737 .timer = &orion5x_timer,
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100738 .fixup = tag_fixup_mem32,
Russell King764cbcc22011-11-05 10:13:41 +0000739 .restart = orion5x_restart,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100740MACHINE_END