Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-orion/dns323-setup.c |
| 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> |
| 28 | #include <asm/arch/orion.h> |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 29 | #include "common.h" |
| 30 | |
| 31 | #define DNS323_GPIO_LED_RIGHT_AMBER 1 |
| 32 | #define DNS323_GPIO_LED_LEFT_AMBER 2 |
| 33 | #define DNS323_GPIO_LED_POWER 5 |
| 34 | #define DNS323_GPIO_OVERTEMP 6 |
| 35 | #define DNS323_GPIO_RTC 7 |
| 36 | #define DNS323_GPIO_POWER_OFF 8 |
| 37 | #define DNS323_GPIO_KEY_POWER 9 |
| 38 | #define DNS323_GPIO_KEY_RESET 10 |
| 39 | |
| 40 | /**************************************************************************** |
| 41 | * PCI setup |
| 42 | */ |
| 43 | |
| 44 | static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin) |
| 45 | { |
| 46 | /* PCI-E */ |
| 47 | if (dev->bus->number == orion_pcie_local_bus_nr()) |
| 48 | return IRQ_ORION_PCIE0_INT; |
| 49 | |
| 50 | pr_err("%s: requested mapping for unknown bus\n", __func__); |
| 51 | |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | static struct hw_pci dns323_pci __initdata = { |
| 56 | .nr_controllers = 1, |
| 57 | .swizzle = pci_std_swizzle, |
| 58 | .setup = orion_pci_sys_setup, |
| 59 | .scan = orion_pci_sys_scan_bus, |
| 60 | .map_irq = dns323_pci_map_irq, |
| 61 | }; |
| 62 | |
| 63 | static int __init dns323_pci_init(void) |
| 64 | { |
| 65 | if (machine_is_dns323()) |
| 66 | pci_common_init(&dns323_pci); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | subsys_initcall(dns323_pci_init); |
| 72 | |
| 73 | /**************************************************************************** |
| 74 | * Ethernet |
| 75 | */ |
| 76 | |
| 77 | static struct mv643xx_eth_platform_data dns323_eth_data = { |
| 78 | .phy_addr = 8, |
| 79 | .force_phy_addr = 1, |
| 80 | }; |
| 81 | |
| 82 | /**************************************************************************** |
| 83 | * 8MiB NOR flash (Spansion S29GL064M90TFIR4) |
| 84 | * |
| 85 | * Layout as used by D-Link: |
| 86 | * 0x00000000-0x00010000 : "MTD1" |
| 87 | * 0x00010000-0x00020000 : "MTD2" |
| 88 | * 0x00020000-0x001a0000 : "Linux Kernel" |
| 89 | * 0x001a0000-0x007d0000 : "File System" |
| 90 | * 0x007d0000-0x00800000 : "u-boot" |
| 91 | */ |
| 92 | |
| 93 | #define DNS323_NOR_BOOT_BASE 0xf4000000 |
| 94 | #define DNS323_NOR_BOOT_SIZE SZ_8M |
| 95 | |
| 96 | static struct mtd_partition dns323_partitions[] = { |
| 97 | { |
| 98 | .name = "MTD1", |
| 99 | .size = 0x00010000, |
| 100 | .offset = 0, |
| 101 | }, { |
| 102 | .name = "MTD2", |
| 103 | .size = 0x00010000, |
| 104 | .offset = 0x00010000, |
| 105 | }, { |
| 106 | .name = "Linux Kernel", |
| 107 | .size = 0x00180000, |
| 108 | .offset = 0x00020000, |
| 109 | }, { |
| 110 | .name = "File System", |
| 111 | .size = 0x00630000, |
| 112 | .offset = 0x001A0000, |
| 113 | }, { |
| 114 | .name = "u-boot", |
| 115 | .size = 0x00030000, |
| 116 | .offset = 0x007d0000, |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | static struct physmap_flash_data dns323_nor_flash_data = { |
| 121 | .width = 1, |
| 122 | .parts = dns323_partitions, |
| 123 | .nr_parts = ARRAY_SIZE(dns323_partitions) |
| 124 | }; |
| 125 | |
| 126 | static struct resource dns323_nor_flash_resource = { |
| 127 | .flags = IORESOURCE_MEM, |
| 128 | .start = DNS323_NOR_BOOT_BASE, |
| 129 | .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1, |
| 130 | }; |
| 131 | |
| 132 | static struct platform_device dns323_nor_flash = { |
| 133 | .name = "physmap-flash", |
| 134 | .id = 0, |
| 135 | .dev = { .platform_data = &dns323_nor_flash_data, }, |
| 136 | .resource = &dns323_nor_flash_resource, |
| 137 | .num_resources = 1, |
| 138 | }; |
| 139 | |
| 140 | /**************************************************************************** |
| 141 | * GPIO LEDs (simple - doesn't use hardware blinking support) |
| 142 | */ |
| 143 | |
| 144 | static struct gpio_led dns323_leds[] = { |
| 145 | { |
| 146 | .name = "power:blue", |
| 147 | .gpio = DNS323_GPIO_LED_POWER, |
| 148 | .active_low = 1, |
| 149 | }, { |
| 150 | .name = "right:amber", |
| 151 | .gpio = DNS323_GPIO_LED_RIGHT_AMBER, |
| 152 | .active_low = 1, |
| 153 | }, { |
| 154 | .name = "left:amber", |
| 155 | .gpio = DNS323_GPIO_LED_LEFT_AMBER, |
| 156 | .active_low = 1, |
| 157 | }, |
| 158 | }; |
| 159 | |
| 160 | static struct gpio_led_platform_data dns323_led_data = { |
| 161 | .num_leds = ARRAY_SIZE(dns323_leds), |
| 162 | .leds = dns323_leds, |
| 163 | }; |
| 164 | |
| 165 | static struct platform_device dns323_gpio_leds = { |
| 166 | .name = "leds-gpio", |
| 167 | .id = -1, |
| 168 | .dev = { .platform_data = &dns323_led_data, }, |
| 169 | }; |
| 170 | |
| 171 | /**************************************************************************** |
| 172 | * GPIO Attached Keys |
| 173 | */ |
| 174 | |
| 175 | static struct gpio_keys_button dns323_buttons[] = { |
| 176 | { |
| 177 | .code = KEY_RESTART, |
| 178 | .gpio = DNS323_GPIO_KEY_RESET, |
| 179 | .desc = "Reset Button", |
| 180 | .active_low = 1, |
| 181 | }, |
| 182 | { |
| 183 | .code = KEY_POWER, |
| 184 | .gpio = DNS323_GPIO_KEY_POWER, |
| 185 | .desc = "Power Button", |
| 186 | .active_low = 1, |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | static struct gpio_keys_platform_data dns323_button_data = { |
| 191 | .buttons = dns323_buttons, |
| 192 | .nbuttons = ARRAY_SIZE(dns323_buttons), |
| 193 | }; |
| 194 | |
| 195 | static struct platform_device dns323_button_device = { |
| 196 | .name = "gpio-keys", |
| 197 | .id = -1, |
| 198 | .num_resources = 0, |
| 199 | .dev = { .platform_data = &dns323_button_data, }, |
| 200 | }; |
| 201 | |
| 202 | /**************************************************************************** |
| 203 | * General Setup |
| 204 | */ |
| 205 | |
| 206 | static struct platform_device *dns323_plat_devices[] __initdata = { |
| 207 | &dns323_nor_flash, |
| 208 | &dns323_gpio_leds, |
| 209 | &dns323_button_device, |
| 210 | }; |
| 211 | |
| 212 | /* |
| 213 | * On the DNS-323 the following devices are attached via I2C: |
| 214 | * |
| 215 | * i2c addr | chip | description |
| 216 | * 0x3e | GMT G760Af | fan speed PWM controller |
| 217 | * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible) |
| 218 | * 0x68 | ST M41T80 | RTC w/ alarm |
| 219 | */ |
| 220 | static struct i2c_board_info __initdata dns323_i2c_devices[] = { |
| 221 | { |
| 222 | I2C_BOARD_INFO("g760a", 0x3e), |
| 223 | .type = "g760a", |
| 224 | }, |
| 225 | #if 0 |
| 226 | /* this entry requires the new-style driver model lm75 driver, |
| 227 | * for the meantime "insmod lm75.ko force_lm75=0,0x48" is needed */ |
| 228 | { |
| 229 | I2C_BOARD_INFO("lm75", 0x48), |
| 230 | .type = "g751", |
| 231 | }, |
| 232 | #endif |
| 233 | { |
| 234 | I2C_BOARD_INFO("rtc-m41t80", 0x68), |
| 235 | .type = "m41t80", |
| 236 | } |
| 237 | }; |
| 238 | |
| 239 | /* DNS-323 specific power off method */ |
| 240 | static void dns323_power_off(void) |
| 241 | { |
| 242 | pr_info("%s: triggering power-off...\n", __func__); |
| 243 | gpio_set_value(DNS323_GPIO_POWER_OFF, 1); |
| 244 | } |
| 245 | |
| 246 | static void __init dns323_init(void) |
| 247 | { |
| 248 | /* Setup basic Orion functions. Need to be called early. */ |
| 249 | orion_init(); |
| 250 | |
| 251 | /* setup flash mapping |
| 252 | * CS3 holds a 8 MB Spansion S29GL064M90TFIR4 |
| 253 | */ |
Lennert Buytenhek | 98f79d1 | 2008-03-27 14:51:40 -0400 | [diff] [blame^] | 254 | orion_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 255 | |
| 256 | /* DNS-323 has a Marvell 88X7042 SATA controller attached via PCIE |
| 257 | * |
| 258 | * Open a special address decode windows for the PCIE WA. |
| 259 | */ |
Lennert Buytenhek | 98f79d1 | 2008-03-27 14:51:40 -0400 | [diff] [blame^] | 260 | orion_setup_pcie_wa_win(ORION_PCIE_WA_PHYS_BASE, ORION_PCIE_WA_SIZE); |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 261 | |
| 262 | /* set MPP to 0 as D-Link's 2.6.12.6 kernel did */ |
| 263 | orion_write(MPP_0_7_CTRL, 0); |
| 264 | orion_write(MPP_8_15_CTRL, 0); |
| 265 | orion_write(MPP_16_19_CTRL, 0); |
| 266 | orion_write(MPP_DEV_CTRL, 0); |
| 267 | |
| 268 | /* Define used GPIO pins |
| 269 | |
| 270 | GPIO Map: |
| 271 | |
| 272 | | 0 | | PEX_RST_OUT (not controlled by GPIO) |
| 273 | | 1 | Out | right amber LED (= sata ch0 LED) (low-active) |
| 274 | | 2 | Out | left amber LED (= sata ch1 LED) (low-active) |
| 275 | | 3 | Out | //unknown// |
| 276 | | 4 | Out | power button LED (low-active, together with pin #5) |
| 277 | | 5 | Out | power button LED (low-active, together with pin #4) |
| 278 | | 6 | In | GMT G751-2f overtemp. shutdown signal (low-active) |
| 279 | | 7 | In | M41T80 nIRQ/OUT/SQW signal |
| 280 | | 8 | Out | triggers power off (high-active) |
| 281 | | 9 | In | power button switch (low-active) |
| 282 | | 10 | In | reset button switch (low-active) |
| 283 | | 11 | Out | //unknown// |
| 284 | | 12 | Out | //unknown// |
| 285 | | 13 | Out | //unknown// |
| 286 | | 14 | Out | //unknown// |
| 287 | | 15 | Out | //unknown// |
| 288 | */ |
| 289 | orion_gpio_set_valid_pins(0x07f6); |
| 290 | |
| 291 | /* register dns323 specific power-off method */ |
| 292 | if ((gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0) |
| 293 | || (gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)) |
| 294 | pr_err("DNS323: failed to setup power-off GPIO\n"); |
| 295 | |
| 296 | pm_power_off = dns323_power_off; |
| 297 | |
| 298 | /* register flash and other platform devices */ |
| 299 | platform_add_devices(dns323_plat_devices, |
| 300 | ARRAY_SIZE(dns323_plat_devices)); |
| 301 | |
| 302 | i2c_register_board_info(0, dns323_i2c_devices, |
| 303 | ARRAY_SIZE(dns323_i2c_devices)); |
| 304 | |
| 305 | orion_eth_init(&dns323_eth_data); |
| 306 | } |
| 307 | |
| 308 | /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */ |
| 309 | MACHINE_START(DNS323, "D-Link DNS-323") |
| 310 | /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */ |
Lennert Buytenhek | 7f74c2c | 2008-02-07 21:55:17 +0100 | [diff] [blame] | 311 | .phys_io = ORION_REGS_PHYS_BASE, |
| 312 | .io_pg_offst = ((ORION_REGS_VIRT_BASE) >> 18) & 0xFFFC, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 313 | .boot_params = 0x00000100, |
| 314 | .init_machine = dns323_init, |
| 315 | .map_io = orion_map_io, |
| 316 | .init_irq = orion_init_irq, |
| 317 | .timer = &orion_timer, |
Guennadi Liakhovetski | be73a34 | 2008-02-29 21:12:57 +0100 | [diff] [blame] | 318 | .fixup = tag_fixup_mem32, |
Herbert Valerio Riedel | 555a365 | 2007-11-12 09:05:55 +0100 | [diff] [blame] | 319 | MACHINE_END |