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 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Lesser General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/pci.h> |
| 17 | #include <linux/irq.h> |
| 18 | #include <linux/mtd/physmap.h> |
| 19 | #include <linux/mv643xx_eth.h> |
| 20 | #include <linux/leds.h> |
| 21 | #include <linux/gpio_keys.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <linux/i2c.h> |
| 24 | #include <asm/mach-types.h> |
| 25 | #include <asm/gpio.h> |
| 26 | #include <asm/mach/arch.h> |
| 27 | #include <asm/mach/pci.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/orion5x.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 29 | #include "common.h" |
Lennert Buytenhek | 19cfd5c | 2008-05-10 23:25:46 +0200 | [diff] [blame] | 30 | #include "mpp.h" |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 31 | |
| 32 | #define DNS323_GPIO_LED_RIGHT_AMBER 1 |
| 33 | #define DNS323_GPIO_LED_LEFT_AMBER 2 |
| 34 | #define DNS323_GPIO_LED_POWER 5 |
| 35 | #define DNS323_GPIO_OVERTEMP 6 |
| 36 | #define DNS323_GPIO_RTC 7 |
| 37 | #define DNS323_GPIO_POWER_OFF 8 |
| 38 | #define DNS323_GPIO_KEY_POWER 9 |
| 39 | #define DNS323_GPIO_KEY_RESET 10 |
| 40 | |
| 41 | /**************************************************************************** |
| 42 | * PCI setup |
| 43 | */ |
| 44 | |
| 45 | static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin) |
| 46 | { |
Lennert Buytenhek | 92b913b | 2008-04-25 16:28:33 -0400 | [diff] [blame] | 47 | int irq; |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 48 | |
Lennert Buytenhek | 92b913b | 2008-04-25 16:28:33 -0400 | [diff] [blame] | 49 | /* |
| 50 | * Check for devices with hard-wired IRQs. |
| 51 | */ |
| 52 | irq = orion5x_pci_map_irq(dev, slot, pin); |
| 53 | if (irq != -1) |
| 54 | return irq; |
| 55 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | static struct hw_pci dns323_pci __initdata = { |
Lennert Buytenhek | bbdf1c1 | 2008-05-15 10:31:14 +0100 | [diff] [blame] | 60 | .nr_controllers = 2, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 61 | .swizzle = pci_std_swizzle, |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 62 | .setup = orion5x_pci_sys_setup, |
| 63 | .scan = orion5x_pci_sys_scan_bus, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 64 | .map_irq = dns323_pci_map_irq, |
| 65 | }; |
| 66 | |
| 67 | static int __init dns323_pci_init(void) |
| 68 | { |
| 69 | if (machine_is_dns323()) |
| 70 | pci_common_init(&dns323_pci); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | subsys_initcall(dns323_pci_init); |
| 76 | |
| 77 | /**************************************************************************** |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 78 | * 8MiB NOR flash (Spansion S29GL064M90TFIR4) |
| 79 | * |
| 80 | * Layout as used by D-Link: |
| 81 | * 0x00000000-0x00010000 : "MTD1" |
| 82 | * 0x00010000-0x00020000 : "MTD2" |
| 83 | * 0x00020000-0x001a0000 : "Linux Kernel" |
| 84 | * 0x001a0000-0x007d0000 : "File System" |
| 85 | * 0x007d0000-0x00800000 : "u-boot" |
| 86 | */ |
| 87 | |
| 88 | #define DNS323_NOR_BOOT_BASE 0xf4000000 |
| 89 | #define DNS323_NOR_BOOT_SIZE SZ_8M |
| 90 | |
| 91 | static struct mtd_partition dns323_partitions[] = { |
| 92 | { |
| 93 | .name = "MTD1", |
| 94 | .size = 0x00010000, |
| 95 | .offset = 0, |
| 96 | }, { |
| 97 | .name = "MTD2", |
| 98 | .size = 0x00010000, |
| 99 | .offset = 0x00010000, |
| 100 | }, { |
| 101 | .name = "Linux Kernel", |
| 102 | .size = 0x00180000, |
| 103 | .offset = 0x00020000, |
| 104 | }, { |
| 105 | .name = "File System", |
| 106 | .size = 0x00630000, |
| 107 | .offset = 0x001A0000, |
| 108 | }, { |
| 109 | .name = "u-boot", |
| 110 | .size = 0x00030000, |
| 111 | .offset = 0x007d0000, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 112 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | static struct physmap_flash_data dns323_nor_flash_data = { |
| 116 | .width = 1, |
| 117 | .parts = dns323_partitions, |
| 118 | .nr_parts = ARRAY_SIZE(dns323_partitions) |
| 119 | }; |
| 120 | |
| 121 | static struct resource dns323_nor_flash_resource = { |
| 122 | .flags = IORESOURCE_MEM, |
| 123 | .start = DNS323_NOR_BOOT_BASE, |
| 124 | .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1, |
| 125 | }; |
| 126 | |
| 127 | static struct platform_device dns323_nor_flash = { |
| 128 | .name = "physmap-flash", |
| 129 | .id = 0, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 130 | .dev = { |
| 131 | .platform_data = &dns323_nor_flash_data, |
| 132 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 133 | .resource = &dns323_nor_flash_resource, |
| 134 | .num_resources = 1, |
| 135 | }; |
| 136 | |
| 137 | /**************************************************************************** |
Matt Palmer | a93f44c | 2008-10-19 08:15:09 +1100 | [diff] [blame^] | 138 | * Ethernet |
| 139 | */ |
| 140 | |
| 141 | static struct mv643xx_eth_platform_data dns323_eth_data = { |
| 142 | .phy_addr = MV643XX_ETH_PHY_ADDR(8), |
| 143 | }; |
| 144 | |
| 145 | /* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these |
| 146 | * functions be kept somewhere? |
| 147 | */ |
| 148 | static int __init dns323_parse_hex_nibble(char n) |
| 149 | { |
| 150 | if (n >= '0' && n <= '9') |
| 151 | return n - '0'; |
| 152 | |
| 153 | if (n >= 'A' && n <= 'F') |
| 154 | return n - 'A' + 10; |
| 155 | |
| 156 | if (n >= 'a' && n <= 'f') |
| 157 | return n - 'a' + 10; |
| 158 | |
| 159 | return -1; |
| 160 | } |
| 161 | |
| 162 | static int __init dns323_parse_hex_byte(const char *b) |
| 163 | { |
| 164 | int hi; |
| 165 | int lo; |
| 166 | |
| 167 | hi = dns323_parse_hex_nibble(b[0]); |
| 168 | lo = dns323_parse_hex_nibble(b[1]); |
| 169 | |
| 170 | if (hi < 0 || lo < 0) |
| 171 | return -1; |
| 172 | |
| 173 | return (hi << 4) | lo; |
| 174 | } |
| 175 | |
| 176 | static int __init dns323_read_mac_addr(void) |
| 177 | { |
| 178 | u_int8_t addr[6]; |
| 179 | int i; |
| 180 | char *mac_page; |
| 181 | |
| 182 | /* MAC address is stored as a regular ol' string in /dev/mtdblock4 |
| 183 | * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80). |
| 184 | */ |
| 185 | mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024); |
| 186 | if (!mac_page) |
| 187 | return -ENOMEM; |
| 188 | |
| 189 | /* Sanity check the string we're looking at */ |
| 190 | for (i = 0; i < 5; i++) { |
| 191 | if (*(mac_page + (i * 3) + 2) != ':') { |
| 192 | goto error_fail; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | for (i = 0; i < 6; i++) { |
| 197 | int byte; |
| 198 | |
| 199 | byte = dns323_parse_hex_byte(mac_page + (i * 3)); |
| 200 | if (byte < 0) { |
| 201 | goto error_fail; |
| 202 | } |
| 203 | |
| 204 | addr[i] = byte; |
| 205 | } |
| 206 | |
| 207 | iounmap(mac_page); |
| 208 | printk("DNS323: Found ethernet MAC address: "); |
| 209 | for (i = 0; i < 6; i++) |
| 210 | printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n"); |
| 211 | |
| 212 | memcpy(dns323_eth_data.mac_addr, addr, 6); |
| 213 | |
| 214 | return 0; |
| 215 | |
| 216 | error_fail: |
| 217 | iounmap(mac_page); |
| 218 | return -EINVAL; |
| 219 | } |
| 220 | |
| 221 | /**************************************************************************** |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 222 | * GPIO LEDs (simple - doesn't use hardware blinking support) |
| 223 | */ |
| 224 | |
| 225 | static struct gpio_led dns323_leds[] = { |
| 226 | { |
| 227 | .name = "power:blue", |
| 228 | .gpio = DNS323_GPIO_LED_POWER, |
| 229 | .active_low = 1, |
| 230 | }, { |
| 231 | .name = "right:amber", |
| 232 | .gpio = DNS323_GPIO_LED_RIGHT_AMBER, |
| 233 | .active_low = 1, |
| 234 | }, { |
| 235 | .name = "left:amber", |
| 236 | .gpio = DNS323_GPIO_LED_LEFT_AMBER, |
| 237 | .active_low = 1, |
| 238 | }, |
| 239 | }; |
| 240 | |
| 241 | static struct gpio_led_platform_data dns323_led_data = { |
| 242 | .num_leds = ARRAY_SIZE(dns323_leds), |
| 243 | .leds = dns323_leds, |
| 244 | }; |
| 245 | |
| 246 | static struct platform_device dns323_gpio_leds = { |
| 247 | .name = "leds-gpio", |
| 248 | .id = -1, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 249 | .dev = { |
| 250 | .platform_data = &dns323_led_data, |
| 251 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | /**************************************************************************** |
| 255 | * GPIO Attached Keys |
| 256 | */ |
| 257 | |
| 258 | static struct gpio_keys_button dns323_buttons[] = { |
| 259 | { |
| 260 | .code = KEY_RESTART, |
| 261 | .gpio = DNS323_GPIO_KEY_RESET, |
| 262 | .desc = "Reset Button", |
| 263 | .active_low = 1, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 264 | }, { |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 265 | .code = KEY_POWER, |
| 266 | .gpio = DNS323_GPIO_KEY_POWER, |
| 267 | .desc = "Power Button", |
| 268 | .active_low = 1, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 269 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | static struct gpio_keys_platform_data dns323_button_data = { |
| 273 | .buttons = dns323_buttons, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 274 | .nbuttons = ARRAY_SIZE(dns323_buttons), |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | static struct platform_device dns323_button_device = { |
| 278 | .name = "gpio-keys", |
| 279 | .id = -1, |
| 280 | .num_resources = 0, |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 281 | .dev = { |
| 282 | .platform_data = &dns323_button_data, |
| 283 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | /**************************************************************************** |
| 287 | * General Setup |
| 288 | */ |
Lennert Buytenhek | 19cfd5c | 2008-05-10 23:25:46 +0200 | [diff] [blame] | 289 | static struct orion5x_mpp_mode dns323_mpp_modes[] __initdata = { |
| 290 | { 0, MPP_PCIE_RST_OUTn }, |
| 291 | { 1, MPP_GPIO }, /* right amber LED (sata ch0) */ |
| 292 | { 2, MPP_GPIO }, /* left amber LED (sata ch1) */ |
| 293 | { 3, MPP_UNUSED }, |
| 294 | { 4, MPP_GPIO }, /* power button LED */ |
| 295 | { 5, MPP_GPIO }, /* power button LED */ |
| 296 | { 6, MPP_GPIO }, /* GMT G751-2f overtemp */ |
| 297 | { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */ |
| 298 | { 8, MPP_GPIO }, /* triggers power off */ |
| 299 | { 9, MPP_GPIO }, /* power button switch */ |
| 300 | { 10, MPP_GPIO }, /* reset button switch */ |
| 301 | { 11, MPP_UNUSED }, |
| 302 | { 12, MPP_UNUSED }, |
| 303 | { 13, MPP_UNUSED }, |
| 304 | { 14, MPP_UNUSED }, |
| 305 | { 15, MPP_UNUSED }, |
| 306 | { 16, MPP_UNUSED }, |
| 307 | { 17, MPP_UNUSED }, |
| 308 | { 18, MPP_UNUSED }, |
| 309 | { 19, MPP_UNUSED }, |
| 310 | { -1 }, |
| 311 | }; |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 312 | |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 313 | /* |
| 314 | * On the DNS-323 the following devices are attached via I2C: |
| 315 | * |
| 316 | * i2c addr | chip | description |
| 317 | * 0x3e | GMT G760Af | fan speed PWM controller |
| 318 | * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible) |
| 319 | * 0x68 | ST M41T80 | RTC w/ alarm |
| 320 | */ |
| 321 | static struct i2c_board_info __initdata dns323_i2c_devices[] = { |
| 322 | { |
| 323 | I2C_BOARD_INFO("g760a", 0x3e), |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 324 | }, { |
Martin Michlmayr | c0fe819 | 2008-08-12 12:50:14 +0300 | [diff] [blame] | 325 | I2C_BOARD_INFO("lm75", 0x48), |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 326 | }, { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 327 | I2C_BOARD_INFO("m41t80", 0x68), |
Lennert Buytenhek | e7068ad | 2008-05-10 16:30:01 +0200 | [diff] [blame] | 328 | }, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | /* DNS-323 specific power off method */ |
| 332 | static void dns323_power_off(void) |
| 333 | { |
| 334 | pr_info("%s: triggering power-off...\n", __func__); |
| 335 | gpio_set_value(DNS323_GPIO_POWER_OFF, 1); |
| 336 | } |
| 337 | |
| 338 | static void __init dns323_init(void) |
| 339 | { |
| 340 | /* Setup basic Orion functions. Need to be called early. */ |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 341 | orion5x_init(); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 342 | |
Lennert Buytenhek | 19cfd5c | 2008-05-10 23:25:46 +0200 | [diff] [blame] | 343 | orion5x_mpp_conf(dns323_mpp_modes); |
Lennert Buytenhek | 79e90dd | 2008-05-28 16:43:48 +0200 | [diff] [blame] | 344 | writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */ |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 345 | |
Lennert Buytenhek | 044f6c7 | 2008-04-22 05:37:12 +0200 | [diff] [blame] | 346 | /* setup flash mapping |
| 347 | * CS3 holds a 8 MB Spansion S29GL064M90TFIR4 |
| 348 | */ |
| 349 | orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE); |
| 350 | platform_device_register(&dns323_nor_flash); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 351 | |
Lennert Buytenhek | 044f6c7 | 2008-04-22 05:37:12 +0200 | [diff] [blame] | 352 | platform_device_register(&dns323_gpio_leds); |
| 353 | |
| 354 | platform_device_register(&dns323_button_device); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 355 | |
| 356 | i2c_register_board_info(0, dns323_i2c_devices, |
| 357 | ARRAY_SIZE(dns323_i2c_devices)); |
| 358 | |
Matt Palmer | a93f44c | 2008-10-19 08:15:09 +1100 | [diff] [blame^] | 359 | /* |
| 360 | * Configure peripherals. |
| 361 | */ |
| 362 | if (dns323_read_mac_addr() < 0) |
| 363 | printk("DNS323: Failed to read MAC address\n"); |
| 364 | |
| 365 | orion5x_ehci0_init(); |
| 366 | orion5x_eth_init(&dns323_eth_data); |
| 367 | orion5x_i2c_init(); |
| 368 | orion5x_uart0_init(); |
| 369 | |
Lennert Buytenhek | 044f6c7 | 2008-04-22 05:37:12 +0200 | [diff] [blame] | 370 | /* register dns323 specific power-off method */ |
| 371 | if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 || |
| 372 | gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0) |
| 373 | pr_err("DNS323: failed to setup power-off GPIO\n"); |
| 374 | pm_power_off = dns323_power_off; |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */ |
| 378 | MACHINE_START(DNS323, "D-Link DNS-323") |
| 379 | /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */ |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 380 | .phys_io = ORION5X_REGS_PHYS_BASE, |
| 381 | .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 382 | .boot_params = 0x00000100, |
| 383 | .init_machine = dns323_init, |
Lennert Buytenhek | 9dd0b19 | 2008-03-27 14:51:41 -0400 | [diff] [blame] | 384 | .map_io = orion5x_map_io, |
| 385 | .init_irq = orion5x_init_irq, |
| 386 | .timer = &orion5x_timer, |
Guennadi Liakhovetski | be73a34 | 2008-02-29 21:12:57 +0100 | [diff] [blame] | 387 | .fixup = tag_fixup_mem32, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 388 | MACHINE_END |