Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 1 | /* |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 2 | * arch/arm/mach-orion5x/dns323-setup.c |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org> |
| 5 | * |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 6 | * Support for HW Rev C1: |
| 7 | * |
| 8 | * Copyright (C) 2010 Benjamin Herrenschmidt <benh@kernel.crashing.org> |
| 9 | * |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 10 | * 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 King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 16 | #include <linux/gpio.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 19 | #include <linux/delay.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 20 | #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 Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 29 | #include <linux/ata_platform.h> |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 30 | #include <linux/phy.h> |
| 31 | #include <linux/marvell_phy.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 32 | #include <asm/mach-types.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 33 | #include <asm/mach/arch.h> |
| 34 | #include <asm/mach/pci.h> |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 35 | #include <asm/system_info.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 36 | #include <mach/orion5x.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 37 | #include "common.h" |
Lennert Buytenhek | 19cfd5c | 2008-05-10 23:25:46 +0200 | [diff] [blame] | 38 | #include "mpp.h" |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 39 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 40 | /* Rev A1 and B1 */ |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 41 | #define DNS323_GPIO_LED_RIGHT_AMBER 1 |
| 42 | #define DNS323_GPIO_LED_LEFT_AMBER 2 |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 43 | #define DNS323_GPIO_SYSTEM_UP 3 |
Laurie Bradshaw | b2a731a | 2010-02-10 16:10:43 +0000 | [diff] [blame] | 44 | #define DNS323_GPIO_LED_POWER1 4 |
| 45 | #define DNS323_GPIO_LED_POWER2 5 |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 46 | #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 Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 52 | /* 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 */ |
| 62 | enum { |
| 63 | DNS323_REV_A1, /* 0 */ |
| 64 | DNS323_REV_B1, /* 1 */ |
| 65 | DNS323_REV_C1, /* 2 */ |
| 66 | }; |
| 67 | |
| 68 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 69 | /**************************************************************************** |
| 70 | * PCI setup |
| 71 | */ |
| 72 | |
Ralf Baechle | d534194 | 2011-06-10 15:30:21 +0100 | [diff] [blame] | 73 | static int __init dns323_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 74 | { |
Lennert Buytenhek | 92b913b | 2008-04-25 16:28:33 -0400 | [diff] [blame] | 75 | int irq; |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 76 | |
Lennert Buytenhek | 92b913b | 2008-04-25 16:28:33 -0400 | [diff] [blame] | 77 | /* |
| 78 | * Check for devices with hard-wired IRQs. |
| 79 | */ |
Paul Gortmaker | 5166793 | 2011-08-01 12:42:14 -0400 | [diff] [blame] | 80 | irq = orion5x_pci_map_irq(dev, slot, pin); |
Lennert Buytenhek | 92b913b | 2008-04-25 16:28:33 -0400 | [diff] [blame] | 81 | if (irq != -1) |
| 82 | return irq; |
| 83 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 84 | return -1; |
| 85 | } |
| 86 | |
| 87 | static struct hw_pci dns323_pci __initdata = { |
Lennert Buytenhek | bbdf1c1 | 2008-05-15 10:31:14 +0100 | [diff] [blame] | 88 | .nr_controllers = 2, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 89 | .swizzle = pci_std_swizzle, |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 90 | .setup = orion5x_pci_sys_setup, |
| 91 | .scan = orion5x_pci_sys_scan_bus, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 92 | .map_irq = dns323_pci_map_irq, |
| 93 | }; |
| 94 | |
| 95 | static int __init dns323_pci_init(void) |
| 96 | { |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 97 | /* Rev B1 and C1 doesn't really use its PCI bus, and initialising PCI |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 98 | * gets in the way of initialising the SATA controller. |
| 99 | */ |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 100 | if (machine_is_dns323() && system_rev == DNS323_REV_A1) |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 101 | pci_common_init(&dns323_pci); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | subsys_initcall(dns323_pci_init); |
| 107 | |
| 108 | /**************************************************************************** |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 109 | * 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 | |
| 122 | static 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 Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 143 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | static struct physmap_flash_data dns323_nor_flash_data = { |
| 147 | .width = 1, |
| 148 | .parts = dns323_partitions, |
| 149 | .nr_parts = ARRAY_SIZE(dns323_partitions) |
| 150 | }; |
| 151 | |
| 152 | static 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 | |
| 158 | static struct platform_device dns323_nor_flash = { |
| 159 | .name = "physmap-flash", |
| 160 | .id = 0, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 161 | .dev = { |
| 162 | .platform_data = &dns323_nor_flash_data, |
| 163 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 164 | .resource = &dns323_nor_flash_resource, |
| 165 | .num_resources = 1, |
| 166 | }; |
| 167 | |
| 168 | /**************************************************************************** |
Matt Palmer | a93f44c | 2008-10-19 08:15:09 +1100 | [diff] [blame] | 169 | * Ethernet |
| 170 | */ |
| 171 | |
| 172 | static 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 | */ |
| 179 | static 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 | |
| 193 | static 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 | |
| 207 | static 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 Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 239 | printk("DNS-323: Found ethernet MAC address: "); |
Matt Palmer | a93f44c | 2008-10-19 08:15:09 +1100 | [diff] [blame] | 240 | 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 | |
| 247 | error_fail: |
| 248 | iounmap(mac_page); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |
| 252 | /**************************************************************************** |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 253 | * GPIO LEDs (simple - doesn't use hardware blinking support) |
| 254 | */ |
| 255 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 256 | static struct gpio_led dns323ab_leds[] = { |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 257 | { |
| 258 | .name = "power:blue", |
Laurie Bradshaw | b2a731a | 2010-02-10 16:10:43 +0000 | [diff] [blame] | 259 | .gpio = DNS323_GPIO_LED_POWER2, |
Martin Michlmayr | f8e0053 | 2010-03-26 11:20:00 +0100 | [diff] [blame] | 260 | .default_trigger = "default-on", |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 261 | }, { |
| 262 | .name = "right:amber", |
| 263 | .gpio = DNS323_GPIO_LED_RIGHT_AMBER, |
| 264 | .active_low = 1, |
| 265 | }, { |
| 266 | .name = "left:amber", |
| 267 | .gpio = DNS323_GPIO_LED_LEFT_AMBER, |
| 268 | .active_low = 1, |
| 269 | }, |
| 270 | }; |
| 271 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 272 | |
| 273 | static struct gpio_led dns323c_leds[] = { |
| 274 | { |
| 275 | .name = "power:blue", |
| 276 | .gpio = DNS323C_GPIO_LED_POWER, |
| 277 | .default_trigger = "timer", |
| 278 | .active_low = 1, |
| 279 | }, { |
| 280 | .name = "right:amber", |
| 281 | .gpio = DNS323C_GPIO_LED_RIGHT_AMBER, |
| 282 | .active_low = 1, |
| 283 | }, { |
| 284 | .name = "left:amber", |
| 285 | .gpio = DNS323C_GPIO_LED_LEFT_AMBER, |
| 286 | .active_low = 1, |
| 287 | }, |
| 288 | }; |
| 289 | |
| 290 | |
| 291 | static struct gpio_led_platform_data dns323ab_led_data = { |
| 292 | .num_leds = ARRAY_SIZE(dns323ab_leds), |
| 293 | .leds = dns323ab_leds, |
Arnaud Patard (Rtp) | ff3e660 | 2012-04-18 23:16:40 +0200 | [diff] [blame^] | 294 | .gpio_blink_set = orion_gpio_led_blink_set, |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | static struct gpio_led_platform_data dns323c_led_data = { |
| 298 | .num_leds = ARRAY_SIZE(dns323c_leds), |
| 299 | .leds = dns323c_leds, |
Arnaud Patard (Rtp) | ff3e660 | 2012-04-18 23:16:40 +0200 | [diff] [blame^] | 300 | .gpio_blink_set = orion_gpio_led_blink_set, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | static struct platform_device dns323_gpio_leds = { |
| 304 | .name = "leds-gpio", |
| 305 | .id = -1, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 306 | .dev = { |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 307 | .platform_data = &dns323ab_led_data, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 308 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | /**************************************************************************** |
| 312 | * GPIO Attached Keys |
| 313 | */ |
| 314 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 315 | static struct gpio_keys_button dns323ab_buttons[] = { |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 316 | { |
| 317 | .code = KEY_RESTART, |
| 318 | .gpio = DNS323_GPIO_KEY_RESET, |
| 319 | .desc = "Reset Button", |
| 320 | .active_low = 1, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 321 | }, { |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 322 | .code = KEY_POWER, |
| 323 | .gpio = DNS323_GPIO_KEY_POWER, |
| 324 | .desc = "Power Button", |
| 325 | .active_low = 1, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 326 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 327 | }; |
| 328 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 329 | static struct gpio_keys_platform_data dns323ab_button_data = { |
| 330 | .buttons = dns323ab_buttons, |
| 331 | .nbuttons = ARRAY_SIZE(dns323ab_buttons), |
| 332 | }; |
| 333 | |
| 334 | static struct gpio_keys_button dns323c_buttons[] = { |
| 335 | { |
| 336 | .code = KEY_POWER, |
| 337 | .gpio = DNS323C_GPIO_KEY_POWER, |
| 338 | .desc = "Power Button", |
| 339 | .active_low = 1, |
| 340 | }, |
| 341 | }; |
| 342 | |
| 343 | static struct gpio_keys_platform_data dns323c_button_data = { |
| 344 | .buttons = dns323c_buttons, |
| 345 | .nbuttons = ARRAY_SIZE(dns323c_buttons), |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 346 | }; |
| 347 | |
| 348 | static struct platform_device dns323_button_device = { |
| 349 | .name = "gpio-keys", |
| 350 | .id = -1, |
| 351 | .num_resources = 0, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 352 | .dev = { |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 353 | .platform_data = &dns323ab_button_data, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 354 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 355 | }; |
| 356 | |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 357 | /***************************************************************************** |
| 358 | * SATA |
| 359 | */ |
| 360 | static struct mv_sata_platform_data dns323_sata_data = { |
| 361 | .n_ports = 2, |
| 362 | }; |
| 363 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 364 | /**************************************************************************** |
| 365 | * General Setup |
| 366 | */ |
Andrew Lunn | 554cdae | 2011-05-15 13:32:53 +0200 | [diff] [blame] | 367 | static unsigned int dns323a_mpp_modes[] __initdata = { |
| 368 | MPP0_PCIE_RST_OUTn, |
| 369 | MPP1_GPIO, /* right amber LED (sata ch0) */ |
| 370 | MPP2_GPIO, /* left amber LED (sata ch1) */ |
| 371 | MPP3_UNUSED, |
| 372 | MPP4_GPIO, /* power button LED */ |
| 373 | MPP5_GPIO, /* power button LED */ |
| 374 | MPP6_GPIO, /* GMT G751-2f overtemp */ |
| 375 | MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */ |
| 376 | MPP8_GPIO, /* triggers power off */ |
| 377 | MPP9_GPIO, /* power button switch */ |
| 378 | MPP10_GPIO, /* reset button switch */ |
| 379 | MPP11_UNUSED, |
| 380 | MPP12_UNUSED, |
| 381 | MPP13_UNUSED, |
| 382 | MPP14_UNUSED, |
| 383 | MPP15_UNUSED, |
| 384 | MPP16_UNUSED, |
| 385 | MPP17_UNUSED, |
| 386 | MPP18_UNUSED, |
| 387 | MPP19_UNUSED, |
| 388 | 0, |
Lennert Buytenhek | 19cfd5c | 2008-05-10 23:25:46 +0200 | [diff] [blame] | 389 | }; |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 390 | |
Andrew Lunn | 554cdae | 2011-05-15 13:32:53 +0200 | [diff] [blame] | 391 | static unsigned int dns323b_mpp_modes[] __initdata = { |
| 392 | MPP0_UNUSED, |
| 393 | MPP1_GPIO, /* right amber LED (sata ch0) */ |
| 394 | MPP2_GPIO, /* left amber LED (sata ch1) */ |
| 395 | MPP3_GPIO, /* system up flag */ |
| 396 | MPP4_GPIO, /* power button LED */ |
| 397 | MPP5_GPIO, /* power button LED */ |
| 398 | MPP6_GPIO, /* GMT G751-2f overtemp */ |
| 399 | MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */ |
| 400 | MPP8_GPIO, /* triggers power off */ |
| 401 | MPP9_GPIO, /* power button switch */ |
| 402 | MPP10_GPIO, /* reset button switch */ |
| 403 | MPP11_UNUSED, |
| 404 | MPP12_SATA_LED, |
| 405 | MPP13_SATA_LED, |
| 406 | MPP14_SATA_LED, |
| 407 | MPP15_SATA_LED, |
| 408 | MPP16_UNUSED, |
| 409 | MPP17_UNUSED, |
| 410 | MPP18_UNUSED, |
| 411 | MPP19_UNUSED, |
| 412 | 0, |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 413 | }; |
| 414 | |
Andrew Lunn | 554cdae | 2011-05-15 13:32:53 +0200 | [diff] [blame] | 415 | static unsigned int dns323c_mpp_modes[] __initdata = { |
| 416 | MPP0_GPIO, /* ? input */ |
| 417 | MPP1_GPIO, /* input power switch (0 = pressed) */ |
| 418 | MPP2_GPIO, /* output power off */ |
| 419 | MPP3_UNUSED, /* ? output */ |
| 420 | MPP4_UNUSED, /* ? output */ |
| 421 | MPP5_UNUSED, /* ? output */ |
| 422 | MPP6_UNUSED, /* ? output */ |
| 423 | MPP7_UNUSED, /* ? output */ |
| 424 | MPP8_GPIO, /* i/o right amber LED */ |
| 425 | MPP9_GPIO, /* i/o left amber LED */ |
| 426 | MPP10_GPIO, /* input */ |
| 427 | MPP11_UNUSED, |
| 428 | MPP12_SATA_LED, |
| 429 | MPP13_SATA_LED, |
| 430 | MPP14_SATA_LED, |
| 431 | MPP15_SATA_LED, |
| 432 | MPP16_UNUSED, |
| 433 | MPP17_GPIO, /* power button LED */ |
| 434 | MPP18_GPIO, /* fan speed bit 0 */ |
| 435 | MPP19_GPIO, /* fan speed bit 1 */ |
| 436 | 0, |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | /* Rev C1 Fan speed notes: |
| 440 | * |
| 441 | * The fan is controlled by 2 GPIOs on this board. The settings |
| 442 | * of the bits is as follow: |
| 443 | * |
| 444 | * GPIO 18 GPIO 19 Fan |
| 445 | * |
| 446 | * 0 0 stopped |
| 447 | * 0 1 low speed |
| 448 | * 1 0 high speed |
| 449 | * 1 1 don't do that (*) |
| 450 | * |
| 451 | * (*) I think the two bits control two feed-in resistors into a fixed |
| 452 | * PWN circuit, setting both bits will basically go a 'bit' faster |
| 453 | * than high speed, but d-link doesn't do it and you may get out of |
| 454 | * HW spec so don't do it. |
| 455 | */ |
| 456 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 457 | /* |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 458 | * On the DNS-323 A1 and B1 the following devices are attached via I2C: |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 459 | * |
| 460 | * i2c addr | chip | description |
| 461 | * 0x3e | GMT G760Af | fan speed PWM controller |
| 462 | * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible) |
| 463 | * 0x68 | ST M41T80 | RTC w/ alarm |
| 464 | */ |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 465 | static struct i2c_board_info __initdata dns323ab_i2c_devices[] = { |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 466 | { |
| 467 | I2C_BOARD_INFO("g760a", 0x3e), |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 468 | }, { |
Martin Michlmayr | c0fe819 | 2008-08-12 12:50:14 +0300 | [diff] [blame] | 469 | I2C_BOARD_INFO("lm75", 0x48), |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 470 | }, { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 471 | I2C_BOARD_INFO("m41t80", 0x68), |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 472 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 473 | }; |
| 474 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 475 | /* |
| 476 | * On the DNS-323 C1 the following devices are attached via I2C: |
| 477 | * |
| 478 | * i2c addr | chip | description |
| 479 | * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible) |
| 480 | * 0x68 | ST M41T80 | RTC w/ alarm |
| 481 | */ |
| 482 | static struct i2c_board_info __initdata dns323c_i2c_devices[] = { |
| 483 | { |
| 484 | I2C_BOARD_INFO("lm75", 0x48), |
| 485 | }, { |
| 486 | I2C_BOARD_INFO("m41t80", 0x68), |
| 487 | }, |
| 488 | }; |
| 489 | |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 490 | /* DNS-323 rev. A specific power off method */ |
| 491 | static void dns323a_power_off(void) |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 492 | { |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 493 | pr_info("DNS-323: Triggering power-off...\n"); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 494 | gpio_set_value(DNS323_GPIO_POWER_OFF, 1); |
| 495 | } |
| 496 | |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 497 | /* DNS-323 rev B specific power off method */ |
| 498 | static void dns323b_power_off(void) |
| 499 | { |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 500 | pr_info("DNS-323: Triggering power-off...\n"); |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 501 | /* Pin has to be changed to 1 and back to 0 to do actual power off. */ |
| 502 | gpio_set_value(DNS323_GPIO_POWER_OFF, 1); |
| 503 | mdelay(100); |
| 504 | gpio_set_value(DNS323_GPIO_POWER_OFF, 0); |
| 505 | } |
| 506 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 507 | /* DNS-323 rev. C specific power off method */ |
| 508 | static void dns323c_power_off(void) |
| 509 | { |
| 510 | pr_info("DNS-323: Triggering power-off...\n"); |
| 511 | gpio_set_value(DNS323C_GPIO_POWER_OFF, 1); |
| 512 | } |
| 513 | |
| 514 | static int dns323c_phy_fixup(struct phy_device *phy) |
| 515 | { |
| 516 | phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS; |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | static int __init dns323_identify_rev(void) |
| 522 | { |
| 523 | u32 dev, rev, i, reg; |
| 524 | |
| 525 | pr_debug("DNS-323: Identifying board ... \n"); |
| 526 | |
| 527 | /* Rev A1 has a 5181 */ |
| 528 | orion5x_pcie_id(&dev, &rev); |
| 529 | if (dev == MV88F5181_DEV_ID) { |
| 530 | pr_debug("DNS-323: 5181 found, board is A1\n"); |
| 531 | return DNS323_REV_A1; |
| 532 | } |
| 533 | pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n"); |
| 534 | |
| 535 | /* Rev B1 and C1 both have 5182, let's poke at the eth PHY. This is |
| 536 | * a bit gross but we want to do that without links into the eth |
| 537 | * driver so let's poke at it directly. We default to rev B1 in |
| 538 | * case the accesses fail |
| 539 | */ |
| 540 | |
| 541 | #define ETH_SMI_REG (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004) |
| 542 | #define SMI_BUSY 0x10000000 |
| 543 | #define SMI_READ_VALID 0x08000000 |
| 544 | #define SMI_OPCODE_READ 0x04000000 |
| 545 | #define SMI_OPCODE_WRITE 0x00000000 |
| 546 | |
| 547 | for (i = 0; i < 1000; i++) { |
| 548 | reg = readl(ETH_SMI_REG); |
| 549 | if (!(reg & SMI_BUSY)) |
| 550 | break; |
| 551 | } |
| 552 | if (i >= 1000) { |
| 553 | pr_warning("DNS-323: Timeout accessing PHY, assuming rev B1\n"); |
| 554 | return DNS323_REV_B1; |
| 555 | } |
| 556 | writel((3 << 21) /* phy ID reg */ | |
| 557 | (8 << 16) /* phy addr */ | |
| 558 | SMI_OPCODE_READ, ETH_SMI_REG); |
| 559 | for (i = 0; i < 1000; i++) { |
| 560 | reg = readl(ETH_SMI_REG); |
| 561 | if (reg & SMI_READ_VALID) |
| 562 | break; |
| 563 | } |
| 564 | if (i >= 1000) { |
| 565 | pr_warning("DNS-323: Timeout reading PHY, assuming rev B1\n"); |
| 566 | return DNS323_REV_B1; |
| 567 | } |
| 568 | pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff); |
| 569 | |
| 570 | /* Note: the Marvell tools mask the ID with 0x3f0 before comparison |
| 571 | * but I don't see that making a difference here, at least with |
| 572 | * any known Marvell PHY ID |
| 573 | */ |
| 574 | switch(reg & 0xfff0) { |
| 575 | case 0x0cc0: /* MV88E1111 */ |
| 576 | return DNS323_REV_B1; |
| 577 | case 0x0e10: /* MV88E1118 */ |
| 578 | return DNS323_REV_C1; |
| 579 | default: |
| 580 | pr_warning("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n", |
| 581 | reg & 0xffff); |
| 582 | } |
| 583 | return DNS323_REV_B1; |
| 584 | } |
| 585 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 586 | static void __init dns323_init(void) |
| 587 | { |
| 588 | /* Setup basic Orion functions. Need to be called early. */ |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 589 | orion5x_init(); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 590 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 591 | /* Identify revision */ |
| 592 | system_rev = dns323_identify_rev(); |
| 593 | pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev); |
| 594 | |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 595 | /* Just to be tricky, the 5182 has a completely different |
| 596 | * set of MPP modes to the 5181. |
| 597 | */ |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 598 | switch(system_rev) { |
| 599 | case DNS323_REV_A1: |
| 600 | orion5x_mpp_conf(dns323a_mpp_modes); |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 601 | writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */ |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 602 | break; |
| 603 | case DNS323_REV_B1: |
| 604 | orion5x_mpp_conf(dns323b_mpp_modes); |
| 605 | break; |
| 606 | case DNS323_REV_C1: |
| 607 | orion5x_mpp_conf(dns323c_mpp_modes); |
| 608 | break; |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 609 | } |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 610 | |
Lennert Buytenhek | 044f6c7 | 2008-04-22 05:37:12 +0200 | [diff] [blame] | 611 | /* setup flash mapping |
| 612 | * CS3 holds a 8 MB Spansion S29GL064M90TFIR4 |
| 613 | */ |
| 614 | orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE); |
| 615 | platform_device_register(&dns323_nor_flash); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 616 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 617 | /* Sort out LEDs, Buttons and i2c devices */ |
| 618 | switch(system_rev) { |
| 619 | case DNS323_REV_A1: |
| 620 | /* The 5181 power LED is active low and requires |
| 621 | * DNS323_GPIO_LED_POWER1 to also be low. |
| 622 | */ |
| 623 | dns323ab_leds[0].active_low = 1; |
| 624 | gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable"); |
| 625 | gpio_direction_output(DNS323_GPIO_LED_POWER1, 0); |
| 626 | /* Fall through */ |
| 627 | case DNS323_REV_B1: |
| 628 | i2c_register_board_info(0, dns323ab_i2c_devices, |
| 629 | ARRAY_SIZE(dns323ab_i2c_devices)); |
| 630 | break; |
| 631 | case DNS323_REV_C1: |
| 632 | /* Hookup LEDs & Buttons */ |
| 633 | dns323_gpio_leds.dev.platform_data = &dns323c_led_data; |
| 634 | dns323_button_device.dev.platform_data = &dns323c_button_data; |
| 635 | |
| 636 | /* Hookup i2c devices and fan driver */ |
| 637 | i2c_register_board_info(0, dns323c_i2c_devices, |
| 638 | ARRAY_SIZE(dns323c_i2c_devices)); |
| 639 | platform_device_register_simple("dns323c-fan", 0, NULL, 0); |
| 640 | |
| 641 | /* Register fixup for the PHY LEDs */ |
| 642 | phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118, |
| 643 | MARVELL_PHY_ID_MASK, |
| 644 | dns323c_phy_fixup); |
Laurie Bradshaw | b2a731a | 2010-02-10 16:10:43 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Lennert Buytenhek | 044f6c7 | 2008-04-22 05:37:12 +0200 | [diff] [blame] | 647 | platform_device_register(&dns323_gpio_leds); |
Lennert Buytenhek | 044f6c7 | 2008-04-22 05:37:12 +0200 | [diff] [blame] | 648 | platform_device_register(&dns323_button_device); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 649 | |
Matt Palmer | a93f44c | 2008-10-19 08:15:09 +1100 | [diff] [blame] | 650 | /* |
| 651 | * Configure peripherals. |
| 652 | */ |
| 653 | if (dns323_read_mac_addr() < 0) |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 654 | printk("DNS-323: Failed to read MAC address\n"); |
Matt Palmer | a93f44c | 2008-10-19 08:15:09 +1100 | [diff] [blame] | 655 | orion5x_ehci0_init(); |
| 656 | orion5x_eth_init(&dns323_eth_data); |
| 657 | orion5x_i2c_init(); |
| 658 | orion5x_uart0_init(); |
| 659 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 660 | /* Remaining GPIOs */ |
| 661 | switch(system_rev) { |
| 662 | case DNS323_REV_A1: |
| 663 | /* Poweroff GPIO */ |
| 664 | if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 || |
| 665 | gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0) |
| 666 | pr_err("DNS-323: failed to setup power-off GPIO\n"); |
| 667 | pm_power_off = dns323a_power_off; |
| 668 | break; |
| 669 | case DNS323_REV_B1: |
| 670 | /* 5182 built-in SATA init */ |
Matt Palmer | f93e415 | 2008-10-22 10:16:36 +0200 | [diff] [blame] | 671 | orion5x_sata_init(&dns323_sata_data); |
| 672 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 673 | /* The DNS323 rev B1 has flag to indicate the system is up. |
| 674 | * Without this flag set, power LED will flash and cannot be |
| 675 | * controlled via leds-gpio. |
| 676 | */ |
| 677 | if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0) |
| 678 | gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1); |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 679 | |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 680 | /* Poweroff GPIO */ |
| 681 | if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 || |
| 682 | gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0) |
| 683 | pr_err("DNS-323: failed to setup power-off GPIO\n"); |
Erik Benada | cf11052 | 2010-01-24 13:43:04 -0800 | [diff] [blame] | 684 | pm_power_off = dns323b_power_off; |
Benjamin Herrenschmidt | 6e2daa4 | 2010-06-21 13:21:53 +1000 | [diff] [blame] | 685 | break; |
| 686 | case DNS323_REV_C1: |
| 687 | /* 5182 built-in SATA init */ |
| 688 | orion5x_sata_init(&dns323_sata_data); |
| 689 | |
| 690 | /* Poweroff GPIO */ |
| 691 | if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 || |
| 692 | gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0) |
| 693 | pr_err("DNS-323: failed to setup power-off GPIO\n"); |
| 694 | pm_power_off = dns323c_power_off; |
| 695 | |
| 696 | /* Now, -this- should theorically be done by the sata_mv driver |
| 697 | * once I figure out what's going on there. Maybe the behaviour |
| 698 | * of the LEDs should be somewhat passed via the platform_data. |
| 699 | * for now, just whack the register and make the LEDs happy |
| 700 | * |
| 701 | * Note: AFAIK, rev B1 needs the same treatement but I'll let |
| 702 | * somebody else test it. |
| 703 | */ |
| 704 | writel(0x5, ORION5X_SATA_VIRT_BASE | 0x2c); |
| 705 | break; |
| 706 | } |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */ |
| 710 | MACHINE_START(DNS323, "D-Link DNS-323") |
| 711 | /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */ |
Nicolas Pitre | 65aa1b1 | 2011-07-05 22:38:15 -0400 | [diff] [blame] | 712 | .atag_offset = 0x100, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 713 | .init_machine = dns323_init, |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 714 | .map_io = orion5x_map_io, |
Lennert Buytenhek | 4ee1f6b | 2010-10-15 16:50:26 +0200 | [diff] [blame] | 715 | .init_early = orion5x_init_early, |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 716 | .init_irq = orion5x_init_irq, |
| 717 | .timer = &orion5x_timer, |
Guennadi Liakhovetski | be73a34 | 2008-02-29 21:12:57 +0100 | [diff] [blame] | 718 | .fixup = tag_fixup_mem32, |
Russell King | 764cbcc2 | 2011-11-05 10:13:41 +0000 | [diff] [blame] | 719 | .restart = orion5x_restart, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 720 | MACHINE_END |