blob: d13344b2ddcd4ef0ad6c8b8554733a0fc6063610 [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>
David Howells9f97da72012-03-28 18:30:01 +010035#include <asm/system_info.h>
Rob Herringce915742012-08-29 10:16:55 -050036#include <plat/orion-gpio.h>
Arnd Bergmannc22c2c62015-12-02 22:27:08 +010037#include "orion5x.h"
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010038#include "common.h"
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +020039#include "mpp.h"
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010040
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100041/* Rev A1 and B1 */
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010042#define DNS323_GPIO_LED_RIGHT_AMBER 1
43#define DNS323_GPIO_LED_LEFT_AMBER 2
Erik Benadacf110522010-01-24 13:43:04 -080044#define DNS323_GPIO_SYSTEM_UP 3
Laurie Bradshawb2a731a2010-02-10 16:10:43 +000045#define DNS323_GPIO_LED_POWER1 4
46#define DNS323_GPIO_LED_POWER2 5
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010047#define DNS323_GPIO_OVERTEMP 6
48#define DNS323_GPIO_RTC 7
49#define DNS323_GPIO_POWER_OFF 8
50#define DNS323_GPIO_KEY_POWER 9
51#define DNS323_GPIO_KEY_RESET 10
52
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +100053/* Rev C1 */
54#define DNS323C_GPIO_KEY_POWER 1
55#define DNS323C_GPIO_POWER_OFF 2
56#define DNS323C_GPIO_LED_RIGHT_AMBER 8
57#define DNS323C_GPIO_LED_LEFT_AMBER 9
58#define DNS323C_GPIO_LED_POWER 17
59#define DNS323C_GPIO_FAN_BIT1 18
60#define DNS323C_GPIO_FAN_BIT0 19
61
62/* Exposed to userspace, do not change */
63enum {
64 DNS323_REV_A1, /* 0 */
65 DNS323_REV_B1, /* 1 */
66 DNS323_REV_C1, /* 2 */
67};
68
69
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010070/****************************************************************************
71 * PCI setup
72 */
73
Ralf Baechled5341942011-06-10 15:30:21 +010074static int __init dns323_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010075{
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040076 int irq;
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010077
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040078 /*
79 * Check for devices with hard-wired IRQs.
80 */
Paul Gortmaker51667932011-08-01 12:42:14 -040081 irq = orion5x_pci_map_irq(dev, slot, pin);
Lennert Buytenhek92b913b2008-04-25 16:28:33 -040082 if (irq != -1)
83 return irq;
84
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +010085 return -1;
86}
87
88static struct hw_pci dns323_pci __initdata = {
Lennert Buytenhekbbdf1c12008-05-15 10:31:14 +010089 .nr_controllers = 2,
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
David S. Miller13a55372018-02-26 13:41:47 -0500176/* 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
Matt Palmera93f44c2008-10-19 08:15:09 +1100207static int __init dns323_read_mac_addr(void)
208{
209 u_int8_t addr[6];
David S. Miller13a55372018-02-26 13:41:47 -0500210 int i;
211 char *mac_page;
Matt Palmera93f44c2008-10-19 08:15:09 +1100212
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
David S. Miller13a55372018-02-26 13:41:47 -0500220 /* 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 }
Matt Palmera93f44c2008-10-19 08:15:09 +1100237
238 iounmap(mac_page);
Joe Perches7a1436d2015-06-14 19:01:30 -0700239 printk("DNS-323: Found ethernet MAC address: %pM\n", addr);
Matt Palmera93f44c2008-10-19 08:15:09 +1100240
241 memcpy(dns323_eth_data.mac_addr, addr, 6);
242
243 return 0;
244
245error_fail:
246 iounmap(mac_page);
247 return -EINVAL;
248}
249
250/****************************************************************************
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100251 * GPIO LEDs (simple - doesn't use hardware blinking support)
252 */
253
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000254static struct gpio_led dns323ab_leds[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100255 {
256 .name = "power:blue",
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000257 .gpio = DNS323_GPIO_LED_POWER2,
Martin Michlmayrf8e00532010-03-26 11:20:00 +0100258 .default_trigger = "default-on",
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100259 }, {
260 .name = "right:amber",
261 .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
262 .active_low = 1,
263 }, {
264 .name = "left:amber",
265 .gpio = DNS323_GPIO_LED_LEFT_AMBER,
266 .active_low = 1,
267 },
268};
269
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000270
271static struct gpio_led dns323c_leds[] = {
272 {
273 .name = "power:blue",
274 .gpio = DNS323C_GPIO_LED_POWER,
275 .default_trigger = "timer",
276 .active_low = 1,
277 }, {
278 .name = "right:amber",
279 .gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
280 .active_low = 1,
281 }, {
282 .name = "left:amber",
283 .gpio = DNS323C_GPIO_LED_LEFT_AMBER,
284 .active_low = 1,
285 },
286};
287
288
289static struct gpio_led_platform_data dns323ab_led_data = {
290 .num_leds = ARRAY_SIZE(dns323ab_leds),
291 .leds = dns323ab_leds,
Arnaud Patard (Rtp)ff3e6602012-04-18 23:16:40 +0200292 .gpio_blink_set = orion_gpio_led_blink_set,
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000293};
294
295static struct gpio_led_platform_data dns323c_led_data = {
296 .num_leds = ARRAY_SIZE(dns323c_leds),
297 .leds = dns323c_leds,
Arnaud Patard (Rtp)ff3e6602012-04-18 23:16:40 +0200298 .gpio_blink_set = orion_gpio_led_blink_set,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100299};
300
301static struct platform_device dns323_gpio_leds = {
302 .name = "leds-gpio",
303 .id = -1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200304 .dev = {
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000305 .platform_data = &dns323ab_led_data,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200306 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100307};
308
309/****************************************************************************
310 * GPIO Attached Keys
311 */
312
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000313static struct gpio_keys_button dns323ab_buttons[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100314 {
315 .code = KEY_RESTART,
316 .gpio = DNS323_GPIO_KEY_RESET,
317 .desc = "Reset Button",
318 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200319 }, {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100320 .code = KEY_POWER,
321 .gpio = DNS323_GPIO_KEY_POWER,
322 .desc = "Power Button",
323 .active_low = 1,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200324 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100325};
326
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000327static struct gpio_keys_platform_data dns323ab_button_data = {
328 .buttons = dns323ab_buttons,
329 .nbuttons = ARRAY_SIZE(dns323ab_buttons),
330};
331
332static struct gpio_keys_button dns323c_buttons[] = {
333 {
334 .code = KEY_POWER,
335 .gpio = DNS323C_GPIO_KEY_POWER,
336 .desc = "Power Button",
337 .active_low = 1,
338 },
339};
340
341static struct gpio_keys_platform_data dns323c_button_data = {
342 .buttons = dns323c_buttons,
343 .nbuttons = ARRAY_SIZE(dns323c_buttons),
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100344};
345
346static struct platform_device dns323_button_device = {
347 .name = "gpio-keys",
348 .id = -1,
349 .num_resources = 0,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200350 .dev = {
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000351 .platform_data = &dns323ab_button_data,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200352 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100353};
354
Matt Palmerf93e4152008-10-22 10:16:36 +0200355/*****************************************************************************
356 * SATA
357 */
358static struct mv_sata_platform_data dns323_sata_data = {
359 .n_ports = 2,
360};
361
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100362/****************************************************************************
363 * General Setup
364 */
Andrew Lunn554cdae2011-05-15 13:32:53 +0200365static unsigned int dns323a_mpp_modes[] __initdata = {
366 MPP0_PCIE_RST_OUTn,
367 MPP1_GPIO, /* right amber LED (sata ch0) */
368 MPP2_GPIO, /* left amber LED (sata ch1) */
369 MPP3_UNUSED,
370 MPP4_GPIO, /* power button LED */
371 MPP5_GPIO, /* power button LED */
372 MPP6_GPIO, /* GMT G751-2f overtemp */
373 MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */
374 MPP8_GPIO, /* triggers power off */
375 MPP9_GPIO, /* power button switch */
376 MPP10_GPIO, /* reset button switch */
377 MPP11_UNUSED,
378 MPP12_UNUSED,
379 MPP13_UNUSED,
380 MPP14_UNUSED,
381 MPP15_UNUSED,
382 MPP16_UNUSED,
383 MPP17_UNUSED,
384 MPP18_UNUSED,
385 MPP19_UNUSED,
386 0,
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200387};
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100388
Andrew Lunn554cdae2011-05-15 13:32:53 +0200389static unsigned int dns323b_mpp_modes[] __initdata = {
390 MPP0_UNUSED,
391 MPP1_GPIO, /* right amber LED (sata ch0) */
392 MPP2_GPIO, /* left amber LED (sata ch1) */
393 MPP3_GPIO, /* system up flag */
394 MPP4_GPIO, /* power button LED */
395 MPP5_GPIO, /* power button LED */
396 MPP6_GPIO, /* GMT G751-2f overtemp */
397 MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */
398 MPP8_GPIO, /* triggers power off */
399 MPP9_GPIO, /* power button switch */
400 MPP10_GPIO, /* reset button switch */
401 MPP11_UNUSED,
402 MPP12_SATA_LED,
403 MPP13_SATA_LED,
404 MPP14_SATA_LED,
405 MPP15_SATA_LED,
406 MPP16_UNUSED,
407 MPP17_UNUSED,
408 MPP18_UNUSED,
409 MPP19_UNUSED,
410 0,
Matt Palmerf93e4152008-10-22 10:16:36 +0200411};
412
Andrew Lunn554cdae2011-05-15 13:32:53 +0200413static unsigned int dns323c_mpp_modes[] __initdata = {
414 MPP0_GPIO, /* ? input */
415 MPP1_GPIO, /* input power switch (0 = pressed) */
416 MPP2_GPIO, /* output power off */
417 MPP3_UNUSED, /* ? output */
418 MPP4_UNUSED, /* ? output */
419 MPP5_UNUSED, /* ? output */
420 MPP6_UNUSED, /* ? output */
421 MPP7_UNUSED, /* ? output */
422 MPP8_GPIO, /* i/o right amber LED */
423 MPP9_GPIO, /* i/o left amber LED */
424 MPP10_GPIO, /* input */
425 MPP11_UNUSED,
426 MPP12_SATA_LED,
427 MPP13_SATA_LED,
428 MPP14_SATA_LED,
429 MPP15_SATA_LED,
430 MPP16_UNUSED,
431 MPP17_GPIO, /* power button LED */
432 MPP18_GPIO, /* fan speed bit 0 */
433 MPP19_GPIO, /* fan speed bit 1 */
434 0,
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000435};
436
437/* Rev C1 Fan speed notes:
438 *
439 * The fan is controlled by 2 GPIOs on this board. The settings
440 * of the bits is as follow:
441 *
442 * GPIO 18 GPIO 19 Fan
443 *
444 * 0 0 stopped
445 * 0 1 low speed
446 * 1 0 high speed
447 * 1 1 don't do that (*)
448 *
449 * (*) I think the two bits control two feed-in resistors into a fixed
450 * PWN circuit, setting both bits will basically go a 'bit' faster
451 * than high speed, but d-link doesn't do it and you may get out of
452 * HW spec so don't do it.
453 */
454
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100455/*
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000456 * On the DNS-323 A1 and B1 the following devices are attached via I2C:
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100457 *
458 * i2c addr | chip | description
459 * 0x3e | GMT G760Af | fan speed PWM controller
460 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
461 * 0x68 | ST M41T80 | RTC w/ alarm
462 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000463static struct i2c_board_info __initdata dns323ab_i2c_devices[] = {
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100464 {
465 I2C_BOARD_INFO("g760a", 0x3e),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200466 }, {
Martin Michlmayrc0fe8192008-08-12 12:50:14 +0300467 I2C_BOARD_INFO("lm75", 0x48),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200468 }, {
Jean Delvare3760f732008-04-29 23:11:40 +0200469 I2C_BOARD_INFO("m41t80", 0x68),
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200470 },
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100471};
472
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000473/*
474 * On the DNS-323 C1 the following devices are attached via I2C:
475 *
476 * i2c addr | chip | description
477 * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
478 * 0x68 | ST M41T80 | RTC w/ alarm
479 */
480static struct i2c_board_info __initdata dns323c_i2c_devices[] = {
481 {
482 I2C_BOARD_INFO("lm75", 0x48),
483 }, {
484 I2C_BOARD_INFO("m41t80", 0x68),
485 },
486};
487
Erik Benadacf110522010-01-24 13:43:04 -0800488/* DNS-323 rev. A specific power off method */
489static void dns323a_power_off(void)
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100490{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000491 pr_info("DNS-323: Triggering power-off...\n");
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100492 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
493}
494
Erik Benadacf110522010-01-24 13:43:04 -0800495/* DNS-323 rev B specific power off method */
496static void dns323b_power_off(void)
497{
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000498 pr_info("DNS-323: Triggering power-off...\n");
Erik Benadacf110522010-01-24 13:43:04 -0800499 /* Pin has to be changed to 1 and back to 0 to do actual power off. */
500 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
501 mdelay(100);
502 gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
503}
504
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000505/* DNS-323 rev. C specific power off method */
506static void dns323c_power_off(void)
507{
508 pr_info("DNS-323: Triggering power-off...\n");
509 gpio_set_value(DNS323C_GPIO_POWER_OFF, 1);
510}
511
512static int dns323c_phy_fixup(struct phy_device *phy)
513{
514 phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS;
515
516 return 0;
517}
518
519static int __init dns323_identify_rev(void)
520{
521 u32 dev, rev, i, reg;
522
523 pr_debug("DNS-323: Identifying board ... \n");
524
525 /* Rev A1 has a 5181 */
526 orion5x_pcie_id(&dev, &rev);
527 if (dev == MV88F5181_DEV_ID) {
528 pr_debug("DNS-323: 5181 found, board is A1\n");
529 return DNS323_REV_A1;
530 }
531 pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n");
532
533 /* Rev B1 and C1 both have 5182, let's poke at the eth PHY. This is
534 * a bit gross but we want to do that without links into the eth
535 * driver so let's poke at it directly. We default to rev B1 in
536 * case the accesses fail
537 */
538
539#define ETH_SMI_REG (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004)
540#define SMI_BUSY 0x10000000
541#define SMI_READ_VALID 0x08000000
542#define SMI_OPCODE_READ 0x04000000
543#define SMI_OPCODE_WRITE 0x00000000
544
545 for (i = 0; i < 1000; i++) {
546 reg = readl(ETH_SMI_REG);
547 if (!(reg & SMI_BUSY))
548 break;
549 }
550 if (i >= 1000) {
Joe Perches9d06d342014-09-13 11:31:17 -0700551 pr_warn("DNS-323: Timeout accessing PHY, assuming rev B1\n");
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000552 return DNS323_REV_B1;
553 }
554 writel((3 << 21) /* phy ID reg */ |
555 (8 << 16) /* phy addr */ |
556 SMI_OPCODE_READ, ETH_SMI_REG);
557 for (i = 0; i < 1000; i++) {
558 reg = readl(ETH_SMI_REG);
559 if (reg & SMI_READ_VALID)
560 break;
561 }
562 if (i >= 1000) {
Joe Perches9d06d342014-09-13 11:31:17 -0700563 pr_warn("DNS-323: Timeout reading PHY, assuming rev B1\n");
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000564 return DNS323_REV_B1;
565 }
566 pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff);
567
568 /* Note: the Marvell tools mask the ID with 0x3f0 before comparison
569 * but I don't see that making a difference here, at least with
570 * any known Marvell PHY ID
571 */
572 switch(reg & 0xfff0) {
573 case 0x0cc0: /* MV88E1111 */
574 return DNS323_REV_B1;
575 case 0x0e10: /* MV88E1118 */
576 return DNS323_REV_C1;
577 default:
Joe Perches9d06d342014-09-13 11:31:17 -0700578 pr_warn("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n",
579 reg & 0xffff);
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000580 }
581 return DNS323_REV_B1;
582}
583
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100584static void __init dns323_init(void)
585{
586 /* Setup basic Orion functions. Need to be called early. */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400587 orion5x_init();
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100588
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000589 /* Identify revision */
590 system_rev = dns323_identify_rev();
591 pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev);
592
Matt Palmerf93e4152008-10-22 10:16:36 +0200593 /* Just to be tricky, the 5182 has a completely different
594 * set of MPP modes to the 5181.
595 */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000596 switch(system_rev) {
597 case DNS323_REV_A1:
598 orion5x_mpp_conf(dns323a_mpp_modes);
Matt Palmerf93e4152008-10-22 10:16:36 +0200599 writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000600 break;
601 case DNS323_REV_B1:
602 orion5x_mpp_conf(dns323b_mpp_modes);
603 break;
604 case DNS323_REV_C1:
605 orion5x_mpp_conf(dns323c_mpp_modes);
606 break;
Matt Palmerf93e4152008-10-22 10:16:36 +0200607 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100608
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200609 /* setup flash mapping
610 * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
611 */
Thomas Petazzoni4ca2c042013-07-26 10:17:42 -0300612 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
613 ORION_MBUS_DEVBUS_BOOT_ATTR,
614 DNS323_NOR_BOOT_BASE,
615 DNS323_NOR_BOOT_SIZE);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200616 platform_device_register(&dns323_nor_flash);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100617
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000618 /* Sort out LEDs, Buttons and i2c devices */
619 switch(system_rev) {
620 case DNS323_REV_A1:
621 /* The 5181 power LED is active low and requires
622 * DNS323_GPIO_LED_POWER1 to also be low.
623 */
624 dns323ab_leds[0].active_low = 1;
625 gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
626 gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
627 /* Fall through */
628 case DNS323_REV_B1:
629 i2c_register_board_info(0, dns323ab_i2c_devices,
630 ARRAY_SIZE(dns323ab_i2c_devices));
631 break;
632 case DNS323_REV_C1:
633 /* Hookup LEDs & Buttons */
634 dns323_gpio_leds.dev.platform_data = &dns323c_led_data;
635 dns323_button_device.dev.platform_data = &dns323c_button_data;
636
637 /* Hookup i2c devices and fan driver */
638 i2c_register_board_info(0, dns323c_i2c_devices,
639 ARRAY_SIZE(dns323c_i2c_devices));
640 platform_device_register_simple("dns323c-fan", 0, NULL, 0);
641
642 /* Register fixup for the PHY LEDs */
Arnd Bergmann32ff4972014-03-13 15:31:44 +0100643 if (!IS_BUILTIN(CONFIG_PHYLIB))
644 break;
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000645 phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118,
646 MARVELL_PHY_ID_MASK,
647 dns323c_phy_fixup);
Laurie Bradshawb2a731a2010-02-10 16:10:43 +0000648 }
649
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200650 platform_device_register(&dns323_gpio_leds);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200651 platform_device_register(&dns323_button_device);
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100652
Matt Palmera93f44c2008-10-19 08:15:09 +1100653 /*
654 * Configure peripherals.
655 */
656 if (dns323_read_mac_addr() < 0)
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000657 printk("DNS-323: Failed to read MAC address\n");
Matt Palmera93f44c2008-10-19 08:15:09 +1100658 orion5x_ehci0_init();
659 orion5x_eth_init(&dns323_eth_data);
660 orion5x_i2c_init();
661 orion5x_uart0_init();
662
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000663 /* Remaining GPIOs */
664 switch(system_rev) {
665 case DNS323_REV_A1:
666 /* Poweroff GPIO */
667 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
668 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
669 pr_err("DNS-323: failed to setup power-off GPIO\n");
670 pm_power_off = dns323a_power_off;
671 break;
672 case DNS323_REV_B1:
673 /* 5182 built-in SATA init */
Matt Palmerf93e4152008-10-22 10:16:36 +0200674 orion5x_sata_init(&dns323_sata_data);
675
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000676 /* The DNS323 rev B1 has flag to indicate the system is up.
677 * Without this flag set, power LED will flash and cannot be
678 * controlled via leds-gpio.
679 */
680 if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0)
681 gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1);
Erik Benadacf110522010-01-24 13:43:04 -0800682
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000683 /* 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");
Erik Benadacf110522010-01-24 13:43:04 -0800687 pm_power_off = dns323b_power_off;
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000688 break;
689 case DNS323_REV_C1:
690 /* 5182 built-in SATA init */
691 orion5x_sata_init(&dns323_sata_data);
692
693 /* Poweroff GPIO */
694 if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
695 gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
696 pr_err("DNS-323: failed to setup power-off GPIO\n");
697 pm_power_off = dns323c_power_off;
698
699 /* Now, -this- should theorically be done by the sata_mv driver
700 * once I figure out what's going on there. Maybe the behaviour
701 * of the LEDs should be somewhat passed via the platform_data.
702 * for now, just whack the register and make the LEDs happy
703 *
704 * Note: AFAIK, rev B1 needs the same treatement but I'll let
705 * somebody else test it.
706 */
Thomas Petazzoni3904a392012-09-11 14:27:21 +0200707 writel(0x5, ORION5X_SATA_VIRT_BASE + 0x2c);
Benjamin Herrenschmidt6e2daa42010-06-21 13:21:53 +1000708 break;
709 }
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100710}
711
712/* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
713MACHINE_START(DNS323, "D-Link DNS-323")
714 /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */
Nicolas Pitre65aa1b12011-07-05 22:38:15 -0400715 .atag_offset = 0x100,
Arnd Bergmann5cdbe5d2015-12-02 22:27:05 +0100716 .nr_irqs = ORION5X_NR_IRQS,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100717 .init_machine = dns323_init,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400718 .map_io = orion5x_map_io,
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200719 .init_early = orion5x_init_early,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400720 .init_irq = orion5x_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700721 .init_time = orion5x_timer_init,
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100722 .fixup = tag_fixup_mem32,
Russell King764cbcc22011-11-05 10:13:41 +0000723 .restart = orion5x_restart,
Herbert Valerio Riedel555a3652007-11-12 09:05:55 +0100724MACHINE_END