blob: 3a7bc0e36982bff6e9e73863960277ac01249cdb [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 */
16
17#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>
33#include <asm/gpio.h>
34#include <asm/mach/arch.h>
35#include <asm/mach/pci.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/orion5x.h>
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010037#include "common.h"
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +020038#include "mpp.h"
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010039
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100040/* Rev A1 and B1 */
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010041#define DNS323_GPIO_LED_RIGHT_AMBER 1
42#define DNS323_GPIO_LED_LEFT_AMBER 2
Erik Benadacf110522010-01-24 13:43:04 -080043#define DNS323_GPIO_SYSTEM_UP 3
Laurie Bradshawb2a731a2010-02-10 16:10:43 +000044#define DNS323_GPIO_LED_POWER1 4
45#define DNS323_GPIO_LED_POWER2 5
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010046#define DNS323_GPIO_OVERTEMP 6
47#define DNS323_GPIO_RTC 7
48#define DNS323_GPIO_POWER_OFF 8
49#define DNS323_GPIO_KEY_POWER 9
50#define DNS323_GPIO_KEY_RESET 10
51
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100052/* Rev C1 */
53#define DNS323C_GPIO_KEY_POWER 1
54#define DNS323C_GPIO_POWER_OFF 2
55#define DNS323C_GPIO_LED_RIGHT_AMBER 8
56#define DNS323C_GPIO_LED_LEFT_AMBER 9
57#define DNS323C_GPIO_LED_POWER 17
58#define DNS323C_GPIO_FAN_BIT1 18
59#define DNS323C_GPIO_FAN_BIT0 19
60
61/* Exposed to userspace, do not change */
62enum {
63 DNS323_REV_A1, /* 0 */
64 DNS323_REV_B1, /* 1 */
65 DNS323_REV_C1, /* 2 */
66};
67
68
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010069/****************************************************************************
70 * PCI setup
71 */
72
73static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
74{
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040075 int irq;
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010076
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040077 /*
78 * Check for devices with hard-wired IRQs.
79 */
80 irq = orion5x_pci_map_irq(dev, slot, pin);
81 if (irq != -1)
82 return irq;
83
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010084 return -1;
85}
86
87static struct hw_pci dns323_pci __initdata = {
Lennert Buytenhekbbdf1c12008-05-15 10:31:14 +010088 .nr_controllers = 2,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010089 .swizzle = pci_std_swizzle,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -040090 .setup = orion5x_pci_sys_setup,
91 .scan = orion5x_pci_sys_scan_bus,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010092 .map_irq = dns323_pci_map_irq,
93};
94
95static int __init dns323_pci_init(void)
96{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100097 /* Rev B1 and C1 doesn't really use its PCI bus, and initialising PCI
Matt Palmerf93e4152008-10-22 10:16:36 +020098 * gets in the way of initialising the SATA controller.
99 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000100 if (machine_is_dns323() && system_rev == DNS323_REV_A1)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100101 pci_common_init(&dns323_pci);
102
103 return 0;
104}
105
106subsys_initcall(dns323_pci_init);
107
108/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100109 * 8MiB NOR flash (Spansion S29GL064M90TFIR4)
110 *
111 * Layout as used by D-Link:
112 * 0x00000000-0x00010000 : "MTD1"
113 * 0x00010000-0x00020000 : "MTD2"
114 * 0x00020000-0x001a0000 : "Linux Kernel"
115 * 0x001a0000-0x007d0000 : "File System"
116 * 0x007d0000-0x00800000 : "u-boot"
117 */
118
119#define DNS323_NOR_BOOT_BASE 0xf4000000
120#define DNS323_NOR_BOOT_SIZE SZ_8M
121
122static struct mtd_partition dns323_partitions[] = {
123 {
124 .name = "MTD1",
125 .size = 0x00010000,
126 .offset = 0,
127 }, {
128 .name = "MTD2",
129 .size = 0x00010000,
130 .offset = 0x00010000,
131 }, {
132 .name = "Linux Kernel",
133 .size = 0x00180000,
134 .offset = 0x00020000,
135 }, {
136 .name = "File System",
137 .size = 0x00630000,
138 .offset = 0x001A0000,
139 }, {
140 .name = "u-boot",
141 .size = 0x00030000,
142 .offset = 0x007d0000,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200143 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100144};
145
146static struct physmap_flash_data dns323_nor_flash_data = {
147 .width = 1,
148 .parts = dns323_partitions,
149 .nr_parts = ARRAY_SIZE(dns323_partitions)
150};
151
152static struct resource dns323_nor_flash_resource = {
153 .flags = IORESOURCE_MEM,
154 .start = DNS323_NOR_BOOT_BASE,
155 .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1,
156};
157
158static struct platform_device dns323_nor_flash = {
159 .name = "physmap-flash",
160 .id = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200161 .dev = {
162 .platform_data = &dns323_nor_flash_data,
163 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100164 .resource = &dns323_nor_flash_resource,
165 .num_resources = 1,
166};
167
168/****************************************************************************
Matt Palmera93f44c2008-10-19 08:15:09 +1100169 * Ethernet
170 */
171
172static struct mv643xx_eth_platform_data dns323_eth_data = {
173 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
174};
175
176/* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these
177 * functions be kept somewhere?
178 */
179static int __init dns323_parse_hex_nibble(char n)
180{
181 if (n >= '0' && n <= '9')
182 return n - '0';
183
184 if (n >= 'A' && n <= 'F')
185 return n - 'A' + 10;
186
187 if (n >= 'a' && n <= 'f')
188 return n - 'a' + 10;
189
190 return -1;
191}
192
193static int __init dns323_parse_hex_byte(const char *b)
194{
195 int hi;
196 int lo;
197
198 hi = dns323_parse_hex_nibble(b[0]);
199 lo = dns323_parse_hex_nibble(b[1]);
200
201 if (hi < 0 || lo < 0)
202 return -1;
203
204 return (hi << 4) | lo;
205}
206
207static int __init dns323_read_mac_addr(void)
208{
209 u_int8_t addr[6];
210 int i;
211 char *mac_page;
212
213 /* MAC address is stored as a regular ol' string in /dev/mtdblock4
214 * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80).
215 */
216 mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024);
217 if (!mac_page)
218 return -ENOMEM;
219
220 /* Sanity check the string we're looking at */
221 for (i = 0; i < 5; i++) {
222 if (*(mac_page + (i * 3) + 2) != ':') {
223 goto error_fail;
224 }
225 }
226
227 for (i = 0; i < 6; i++) {
228 int byte;
229
230 byte = dns323_parse_hex_byte(mac_page + (i * 3));
231 if (byte < 0) {
232 goto error_fail;
233 }
234
235 addr[i] = byte;
236 }
237
238 iounmap(mac_page);
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000239 printk("DNS-323: Found ethernet MAC address: ");
Matt Palmera93f44c2008-10-19 08:15:09 +1100240 for (i = 0; i < 6; i++)
241 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
242
243 memcpy(dns323_eth_data.mac_addr, addr, 6);
244
245 return 0;
246
247error_fail:
248 iounmap(mac_page);
249 return -EINVAL;
250}
251
252/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100253 * GPIO LEDs (simple - doesn't use hardware blinking support)
254 */
255
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000256#define ORION_BLINK_HALF_PERIOD 100 /* ms */
257
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000258static int dns323_gpio_blink_set(unsigned gpio, int state,
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000259 unsigned long *delay_on, unsigned long *delay_off)
260{
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000261
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000262 if (delay_on && delay_off && !*delay_on && !*delay_off)
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000263 *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD;
264
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000265 switch(state) {
266 case GPIO_LED_NO_BLINK_LOW:
267 case GPIO_LED_NO_BLINK_HIGH:
268 orion_gpio_set_blink(gpio, 0);
269 gpio_set_value(gpio, state);
270 break;
271 case GPIO_LED_BLINK:
272 orion_gpio_set_blink(gpio, 1);
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000273 }
Benjamin Herrenschmidt21463252010-05-22 20:54:55 +1000274 return 0;
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000275}
276
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000277static struct gpio_led dns323ab_leds[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100278 {
279 .name = "power:blue",
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000280 .gpio = DNS323_GPIO_LED_POWER2,
Martin Michlmayrf8e00532010-03-26 11:20:00 +0100281 .default_trigger = "default-on",
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100282 }, {
283 .name = "right:amber",
284 .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
285 .active_low = 1,
286 }, {
287 .name = "left:amber",
288 .gpio = DNS323_GPIO_LED_LEFT_AMBER,
289 .active_low = 1,
290 },
291};
292
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000293
294static struct gpio_led dns323c_leds[] = {
295 {
296 .name = "power:blue",
297 .gpio = DNS323C_GPIO_LED_POWER,
298 .default_trigger = "timer",
299 .active_low = 1,
300 }, {
301 .name = "right:amber",
302 .gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
303 .active_low = 1,
304 }, {
305 .name = "left:amber",
306 .gpio = DNS323C_GPIO_LED_LEFT_AMBER,
307 .active_low = 1,
308 },
309};
310
311
312static struct gpio_led_platform_data dns323ab_led_data = {
313 .num_leds = ARRAY_SIZE(dns323ab_leds),
314 .leds = dns323ab_leds,
315 .gpio_blink_set = dns323_gpio_blink_set,
316};
317
318static struct gpio_led_platform_data dns323c_led_data = {
319 .num_leds = ARRAY_SIZE(dns323c_leds),
320 .leds = dns323c_leds,
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000321 .gpio_blink_set = dns323_gpio_blink_set,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100322};
323
324static struct platform_device dns323_gpio_leds = {
325 .name = "leds-gpio",
326 .id = -1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200327 .dev = {
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000328 .platform_data = &dns323ab_led_data,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200329 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100330};
331
332/****************************************************************************
333 * GPIO Attached Keys
334 */
335
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000336static struct gpio_keys_button dns323ab_buttons[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100337 {
338 .code = KEY_RESTART,
339 .gpio = DNS323_GPIO_KEY_RESET,
340 .desc = "Reset Button",
341 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200342 }, {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100343 .code = KEY_POWER,
344 .gpio = DNS323_GPIO_KEY_POWER,
345 .desc = "Power Button",
346 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200347 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100348};
349
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000350static struct gpio_keys_platform_data dns323ab_button_data = {
351 .buttons = dns323ab_buttons,
352 .nbuttons = ARRAY_SIZE(dns323ab_buttons),
353};
354
355static struct gpio_keys_button dns323c_buttons[] = {
356 {
357 .code = KEY_POWER,
358 .gpio = DNS323C_GPIO_KEY_POWER,
359 .desc = "Power Button",
360 .active_low = 1,
361 },
362};
363
364static struct gpio_keys_platform_data dns323c_button_data = {
365 .buttons = dns323c_buttons,
366 .nbuttons = ARRAY_SIZE(dns323c_buttons),
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100367};
368
369static struct platform_device dns323_button_device = {
370 .name = "gpio-keys",
371 .id = -1,
372 .num_resources = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200373 .dev = {
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000374 .platform_data = &dns323ab_button_data,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200375 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100376};
377
Matt Palmerf93e4152008-10-22 10:16:36 +0200378/*****************************************************************************
379 * SATA
380 */
381static struct mv_sata_platform_data dns323_sata_data = {
382 .n_ports = 2,
383};
384
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100385/****************************************************************************
386 * General Setup
387 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000388static struct orion5x_mpp_mode dns323a_mpp_modes[] __initdata = {
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200389 { 0, MPP_PCIE_RST_OUTn },
390 { 1, MPP_GPIO }, /* right amber LED (sata ch0) */
391 { 2, MPP_GPIO }, /* left amber LED (sata ch1) */
392 { 3, MPP_UNUSED },
393 { 4, MPP_GPIO }, /* power button LED */
394 { 5, MPP_GPIO }, /* power button LED */
395 { 6, MPP_GPIO }, /* GMT G751-2f overtemp */
396 { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */
397 { 8, MPP_GPIO }, /* triggers power off */
398 { 9, MPP_GPIO }, /* power button switch */
399 { 10, MPP_GPIO }, /* reset button switch */
400 { 11, MPP_UNUSED },
401 { 12, MPP_UNUSED },
402 { 13, MPP_UNUSED },
403 { 14, MPP_UNUSED },
404 { 15, MPP_UNUSED },
405 { 16, MPP_UNUSED },
406 { 17, MPP_UNUSED },
407 { 18, MPP_UNUSED },
408 { 19, MPP_UNUSED },
409 { -1 },
410};
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100411
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000412static struct orion5x_mpp_mode dns323b_mpp_modes[] __initdata = {
Matt Palmerf93e4152008-10-22 10:16:36 +0200413 { 0, MPP_UNUSED },
414 { 1, MPP_GPIO }, /* right amber LED (sata ch0) */
415 { 2, MPP_GPIO }, /* left amber LED (sata ch1) */
Erik Benadacf110522010-01-24 13:43:04 -0800416 { 3, MPP_GPIO }, /* system up flag */
Matt Palmerf93e4152008-10-22 10:16:36 +0200417 { 4, MPP_GPIO }, /* power button LED */
418 { 5, MPP_GPIO }, /* power button LED */
419 { 6, MPP_GPIO }, /* GMT G751-2f overtemp */
420 { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */
421 { 8, MPP_GPIO }, /* triggers power off */
422 { 9, MPP_GPIO }, /* power button switch */
423 { 10, MPP_GPIO }, /* reset button switch */
424 { 11, MPP_UNUSED },
425 { 12, MPP_SATA_LED },
426 { 13, MPP_SATA_LED },
427 { 14, MPP_SATA_LED },
428 { 15, MPP_SATA_LED },
429 { 16, MPP_UNUSED },
430 { 17, MPP_UNUSED },
431 { 18, MPP_UNUSED },
432 { 19, MPP_UNUSED },
433 { -1 },
434};
435
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000436static struct orion5x_mpp_mode dns323c_mpp_modes[] __initdata = {
437 { 0, MPP_GPIO }, /* ? input */
438 { 1, MPP_GPIO }, /* input power switch (0 = pressed) */
439 { 2, MPP_GPIO }, /* output power off */
440 { 3, MPP_UNUSED }, /* ? output */
441 { 4, MPP_UNUSED }, /* ? output */
442 { 5, MPP_UNUSED }, /* ? output */
443 { 6, MPP_UNUSED }, /* ? output */
444 { 7, MPP_UNUSED }, /* ? output */
445 { 8, MPP_GPIO }, /* i/o right amber LED */
446 { 9, MPP_GPIO }, /* i/o left amber LED */
447 { 10, MPP_GPIO }, /* input */
448 { 11, MPP_UNUSED },
449 { 12, MPP_SATA_LED },
450 { 13, MPP_SATA_LED },
451 { 14, MPP_SATA_LED },
452 { 15, MPP_SATA_LED },
453 { 16, MPP_UNUSED },
454 { 17, MPP_GPIO }, /* power button LED */
455 { 18, MPP_GPIO }, /* fan speed bit 0 */
456 { 19, MPP_GPIO }, /* fan speed bit 1 */
457 { -1 },
458};
459
460/* Rev C1 Fan speed notes:
461 *
462 * The fan is controlled by 2 GPIOs on this board. The settings
463 * of the bits is as follow:
464 *
465 * GPIO 18 GPIO 19 Fan
466 *
467 * 0 0 stopped
468 * 0 1 low speed
469 * 1 0 high speed
470 * 1 1 don't do that (*)
471 *
472 * (*) I think the two bits control two feed-in resistors into a fixed
473 * PWN circuit, setting both bits will basically go a 'bit' faster
474 * than high speed, but d-link doesn't do it and you may get out of
475 * HW spec so don't do it.
476 */
477
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100478/*
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000479 * On the DNS-323 A1 and B1 the following devices are attached via I2C:
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100480 *
481 * i2c addr | chip | description
482 * 0x3e | GMT G760Af | fan speed PWM controller
483 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
484 * 0x68 | ST M41T80 | RTC w/ alarm
485 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000486static struct i2c_board_info __initdata dns323ab_i2c_devices[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100487 {
488 I2C_BOARD_INFO("g760a", 0x3e),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200489 }, {
Martin Michlmayrc0fe8192008-08-12 12:50:14 +0300490 I2C_BOARD_INFO("lm75", 0x48),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200491 }, {
Jean Delvare3760f732008-04-29 23:11:40 +0200492 I2C_BOARD_INFO("m41t80", 0x68),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200493 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100494};
495
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000496/*
497 * On the DNS-323 C1 the following devices are attached via I2C:
498 *
499 * i2c addr | chip | description
500 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
501 * 0x68 | ST M41T80 | RTC w/ alarm
502 */
503static struct i2c_board_info __initdata dns323c_i2c_devices[] = {
504 {
505 I2C_BOARD_INFO("lm75", 0x48),
506 }, {
507 I2C_BOARD_INFO("m41t80", 0x68),
508 },
509};
510
Erik Benadacf110522010-01-24 13:43:04 -0800511/* DNS-323 rev. A specific power off method */
512static void dns323a_power_off(void)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100513{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000514 pr_info("DNS-323: Triggering power-off...\n");
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100515 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
516}
517
Erik Benadacf110522010-01-24 13:43:04 -0800518/* DNS-323 rev B specific power off method */
519static void dns323b_power_off(void)
520{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000521 pr_info("DNS-323: Triggering power-off...\n");
Erik Benadacf110522010-01-24 13:43:04 -0800522 /* Pin has to be changed to 1 and back to 0 to do actual power off. */
523 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
524 mdelay(100);
525 gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
526}
527
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000528/* DNS-323 rev. C specific power off method */
529static void dns323c_power_off(void)
530{
531 pr_info("DNS-323: Triggering power-off...\n");
532 gpio_set_value(DNS323C_GPIO_POWER_OFF, 1);
533}
534
535static int dns323c_phy_fixup(struct phy_device *phy)
536{
537 phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS;
538
539 return 0;
540}
541
542static int __init dns323_identify_rev(void)
543{
544 u32 dev, rev, i, reg;
545
546 pr_debug("DNS-323: Identifying board ... \n");
547
548 /* Rev A1 has a 5181 */
549 orion5x_pcie_id(&dev, &rev);
550 if (dev == MV88F5181_DEV_ID) {
551 pr_debug("DNS-323: 5181 found, board is A1\n");
552 return DNS323_REV_A1;
553 }
554 pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n");
555
556 /* Rev B1 and C1 both have 5182, let's poke at the eth PHY. This is
557 * a bit gross but we want to do that without links into the eth
558 * driver so let's poke at it directly. We default to rev B1 in
559 * case the accesses fail
560 */
561
562#define ETH_SMI_REG (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004)
563#define SMI_BUSY 0x10000000
564#define SMI_READ_VALID 0x08000000
565#define SMI_OPCODE_READ 0x04000000
566#define SMI_OPCODE_WRITE 0x00000000
567
568 for (i = 0; i < 1000; i++) {
569 reg = readl(ETH_SMI_REG);
570 if (!(reg & SMI_BUSY))
571 break;
572 }
573 if (i >= 1000) {
574 pr_warning("DNS-323: Timeout accessing PHY, assuming rev B1\n");
575 return DNS323_REV_B1;
576 }
577 writel((3 << 21) /* phy ID reg */ |
578 (8 << 16) /* phy addr */ |
579 SMI_OPCODE_READ, ETH_SMI_REG);
580 for (i = 0; i < 1000; i++) {
581 reg = readl(ETH_SMI_REG);
582 if (reg & SMI_READ_VALID)
583 break;
584 }
585 if (i >= 1000) {
586 pr_warning("DNS-323: Timeout reading PHY, assuming rev B1\n");
587 return DNS323_REV_B1;
588 }
589 pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff);
590
591 /* Note: the Marvell tools mask the ID with 0x3f0 before comparison
592 * but I don't see that making a difference here, at least with
593 * any known Marvell PHY ID
594 */
595 switch(reg & 0xfff0) {
596 case 0x0cc0: /* MV88E1111 */
597 return DNS323_REV_B1;
598 case 0x0e10: /* MV88E1118 */
599 return DNS323_REV_C1;
600 default:
601 pr_warning("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n",
602 reg & 0xffff);
603 }
604 return DNS323_REV_B1;
605}
606
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100607static void __init dns323_init(void)
608{
609 /* Setup basic Orion functions. Need to be called early. */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400610 orion5x_init();
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100611
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000612 /* Identify revision */
613 system_rev = dns323_identify_rev();
614 pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev);
615
Matt Palmerf93e4152008-10-22 10:16:36 +0200616 /* Just to be tricky, the 5182 has a completely different
617 * set of MPP modes to the 5181.
618 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000619 switch(system_rev) {
620 case DNS323_REV_A1:
621 orion5x_mpp_conf(dns323a_mpp_modes);
Matt Palmerf93e4152008-10-22 10:16:36 +0200622 writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000623 break;
624 case DNS323_REV_B1:
625 orion5x_mpp_conf(dns323b_mpp_modes);
626 break;
627 case DNS323_REV_C1:
628 orion5x_mpp_conf(dns323c_mpp_modes);
629 break;
Matt Palmerf93e4152008-10-22 10:16:36 +0200630 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100631
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200632 /* setup flash mapping
633 * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
634 */
635 orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE);
636 platform_device_register(&dns323_nor_flash);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100637
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000638 /* Sort out LEDs, Buttons and i2c devices */
639 switch(system_rev) {
640 case DNS323_REV_A1:
641 /* The 5181 power LED is active low and requires
642 * DNS323_GPIO_LED_POWER1 to also be low.
643 */
644 dns323ab_leds[0].active_low = 1;
645 gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
646 gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
647 /* Fall through */
648 case DNS323_REV_B1:
649 i2c_register_board_info(0, dns323ab_i2c_devices,
650 ARRAY_SIZE(dns323ab_i2c_devices));
651 break;
652 case DNS323_REV_C1:
653 /* Hookup LEDs & Buttons */
654 dns323_gpio_leds.dev.platform_data = &dns323c_led_data;
655 dns323_button_device.dev.platform_data = &dns323c_button_data;
656
657 /* Hookup i2c devices and fan driver */
658 i2c_register_board_info(0, dns323c_i2c_devices,
659 ARRAY_SIZE(dns323c_i2c_devices));
660 platform_device_register_simple("dns323c-fan", 0, NULL, 0);
661
662 /* Register fixup for the PHY LEDs */
663 phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118,
664 MARVELL_PHY_ID_MASK,
665 dns323c_phy_fixup);
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000666 }
667
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200668 platform_device_register(&dns323_gpio_leds);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200669 platform_device_register(&dns323_button_device);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100670
Matt Palmera93f44c2008-10-19 08:15:09 +1100671 /*
672 * Configure peripherals.
673 */
674 if (dns323_read_mac_addr() < 0)
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000675 printk("DNS-323: Failed to read MAC address\n");
Matt Palmera93f44c2008-10-19 08:15:09 +1100676 orion5x_ehci0_init();
677 orion5x_eth_init(&dns323_eth_data);
678 orion5x_i2c_init();
679 orion5x_uart0_init();
680
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000681 /* Remaining GPIOs */
682 switch(system_rev) {
683 case DNS323_REV_A1:
684 /* Poweroff GPIO */
685 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
686 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
687 pr_err("DNS-323: failed to setup power-off GPIO\n");
688 pm_power_off = dns323a_power_off;
689 break;
690 case DNS323_REV_B1:
691 /* 5182 built-in SATA init */
Matt Palmerf93e4152008-10-22 10:16:36 +0200692 orion5x_sata_init(&dns323_sata_data);
693
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000694 /* The DNS323 rev B1 has flag to indicate the system is up.
695 * Without this flag set, power LED will flash and cannot be
696 * controlled via leds-gpio.
697 */
698 if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0)
699 gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1);
Erik Benadacf110522010-01-24 13:43:04 -0800700
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000701 /* Poweroff GPIO */
702 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
703 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
704 pr_err("DNS-323: failed to setup power-off GPIO\n");
Erik Benadacf110522010-01-24 13:43:04 -0800705 pm_power_off = dns323b_power_off;
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000706 break;
707 case DNS323_REV_C1:
708 /* 5182 built-in SATA init */
709 orion5x_sata_init(&dns323_sata_data);
710
711 /* Poweroff GPIO */
712 if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
713 gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
714 pr_err("DNS-323: failed to setup power-off GPIO\n");
715 pm_power_off = dns323c_power_off;
716
717 /* Now, -this- should theorically be done by the sata_mv driver
718 * once I figure out what's going on there. Maybe the behaviour
719 * of the LEDs should be somewhat passed via the platform_data.
720 * for now, just whack the register and make the LEDs happy
721 *
722 * Note: AFAIK, rev B1 needs the same treatement but I'll let
723 * somebody else test it.
724 */
725 writel(0x5, ORION5X_SATA_VIRT_BASE | 0x2c);
726 break;
727 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100728}
729
730/* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
731MACHINE_START(DNS323, "D-Link DNS-323")
732 /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100733 .boot_params = 0x00000100,
734 .init_machine = dns323_init,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400735 .map_io = orion5x_map_io,
736 .init_irq = orion5x_init_irq,
737 .timer = &orion5x_timer,
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100738 .fixup = tag_fixup_mem32,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100739MACHINE_END