| 1 | /* |
| 2 | * arch/arm/mach-kirkwood/nsa-310-setup.c |
| 3 | * |
| 4 | * ZyXEL NSA-310 Setup |
| 5 | * |
| 6 | * This file is licensed under the terms of the GNU General Public |
| 7 | * License version 2. This program is licensed "as is" without any |
| 8 | * warranty of any kind, whether express or implied. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/ata_platform.h> |
| 15 | #include <linux/i2c.h> |
| 16 | #include <linux/mtd/mtd.h> |
| 17 | #include <linux/mtd/partitions.h> |
| 18 | #include <linux/gpio.h> |
| 19 | #include <linux/gpio_keys.h> |
| 20 | #include <linux/input.h> |
| 21 | #include <linux/leds.h> |
| 22 | #include <linux/delay.h> |
| 23 | |
| 24 | #include <asm/mach-types.h> |
| 25 | #include <asm/mach/arch.h> |
| 26 | #include <mach/kirkwood.h> |
| 27 | #include "common.h" |
| 28 | #include "mpp.h" |
| 29 | |
| 30 | #define NSA310_GPIO_LED_ESATA_GREEN 12 |
| 31 | #define NSA310_GPIO_LED_ESATA_RED 13 |
| 32 | #define NSA310_GPIO_LED_USB_GREEN 15 |
| 33 | #define NSA310_GPIO_LED_USB_RED 16 |
| 34 | #define NSA310_GPIO_USB_POWER_OFF 21 |
| 35 | #define NSA310_GPIO_LED_SYS_GREEN 28 |
| 36 | #define NSA310_GPIO_LED_SYS_RED 29 |
| 37 | #define NSA310_GPIO_KEY_RESTART 36 |
| 38 | #define NSA310_GPIO_KEY_COPY 37 |
| 39 | #define NSA310_GPIO_LED_COPY_GREEN 39 |
| 40 | #define NSA310_GPIO_LED_COPY_RED 40 |
| 41 | #define NSA310_GPIO_LED_HDD_GREEN 41 |
| 42 | #define NSA310_GPIO_LED_HDD_RED 42 |
| 43 | #define NSA310_GPIO_BUZZER 44 |
| 44 | #define NSA310_GPIO_KEY_POWER 46 |
| 45 | #define NSA310_GPIO_POWER_OFF 48 |
| 46 | |
| 47 | |
| 48 | static unsigned int nsa310_mpp_config[] __initdata = { |
| 49 | MPP12_GPIO, |
| 50 | MPP13_GPIO, |
| 51 | MPP15_GPIO, |
| 52 | MPP16_GPIO, |
| 53 | MPP21_GPIO, |
| 54 | MPP28_GPIO, |
| 55 | MPP29_GPIO, |
| 56 | MPP36_GPIO, |
| 57 | MPP37_GPIO, |
| 58 | MPP39_GPIO, |
| 59 | MPP40_GPIO, |
| 60 | MPP41_GPIO, |
| 61 | MPP42_GPIO, |
| 62 | MPP44_GPIO, |
| 63 | MPP46_GPIO, |
| 64 | MPP48_GPIO, |
| 65 | 0 |
| 66 | }; |
| 67 | |
| 68 | static struct mtd_partition nsa310_mtd_parts[] = { |
| 69 | { |
| 70 | .name = "uboot", |
| 71 | .offset = 0, |
| 72 | .size = 0x100000, |
| 73 | .mask_flags = MTD_WRITEABLE, |
| 74 | }, { |
| 75 | .name = "uboot_env", |
| 76 | .offset = MTDPART_OFS_NXTBLK, |
| 77 | .size = 0x80000, |
| 78 | }, { |
| 79 | .name = "key_store", |
| 80 | .offset = MTDPART_OFS_NXTBLK, |
| 81 | .size = 0x80000, |
| 82 | }, { |
| 83 | .name = "info", |
| 84 | .offset = MTDPART_OFS_NXTBLK, |
| 85 | .size = 0x80000, |
| 86 | }, { |
| 87 | .name = "etc", |
| 88 | .offset = MTDPART_OFS_NXTBLK, |
| 89 | .size = 0xa00000, |
| 90 | }, { |
| 91 | .name = "kernel_1", |
| 92 | .offset = MTDPART_OFS_NXTBLK, |
| 93 | .size = 0xa00000, |
| 94 | }, { |
| 95 | .name = "rootfs1", |
| 96 | .offset = MTDPART_OFS_NXTBLK, |
| 97 | .size = 0x2fc0000, |
| 98 | }, { |
| 99 | .name = "kernel_2", |
| 100 | .offset = MTDPART_OFS_NXTBLK, |
| 101 | .size = 0xa00000, |
| 102 | }, { |
| 103 | .name = "rootfs2", |
| 104 | .offset = MTDPART_OFS_NXTBLK, |
| 105 | .size = 0x2fc0000, |
| 106 | }, |
| 107 | }; |
| 108 | |
| 109 | static struct gpio_led nsa310_leds[] = { |
| 110 | { |
| 111 | .name = "nsa310:green:sys", |
| 112 | .gpio = NSA310_GPIO_LED_SYS_GREEN, |
| 113 | }, { |
| 114 | .name = "nsa310:red:sys", |
| 115 | .gpio = NSA310_GPIO_LED_SYS_RED, |
| 116 | }, { |
| 117 | .name = "nsa310:green:hdd", |
| 118 | .gpio = NSA310_GPIO_LED_HDD_GREEN, |
| 119 | }, { |
| 120 | .name = "nsa310:red:hdd", |
| 121 | .gpio = NSA310_GPIO_LED_HDD_RED, |
| 122 | }, { |
| 123 | .name = "nsa310:green:esata", |
| 124 | .gpio = NSA310_GPIO_LED_ESATA_GREEN, |
| 125 | }, { |
| 126 | .name = "nsa310:red:esata", |
| 127 | .gpio = NSA310_GPIO_LED_ESATA_RED, |
| 128 | }, { |
| 129 | .name = "nsa310:green:usb", |
| 130 | .gpio = NSA310_GPIO_LED_USB_GREEN, |
| 131 | }, { |
| 132 | .name = "nsa310:red:usb", |
| 133 | .gpio = NSA310_GPIO_LED_USB_RED, |
| 134 | }, { |
| 135 | .name = "nsa310:green:copy", |
| 136 | .gpio = NSA310_GPIO_LED_COPY_GREEN, |
| 137 | }, { |
| 138 | .name = "nsa310:red:copy", |
| 139 | .gpio = NSA310_GPIO_LED_COPY_RED, |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | static struct gpio_led_platform_data nsa310_leds_data = { |
| 144 | .leds = nsa310_leds, |
| 145 | .num_leds = ARRAY_SIZE(nsa310_leds), |
| 146 | }; |
| 147 | |
| 148 | static struct platform_device nsa310_leds_device = { |
| 149 | .name = "leds-gpio", |
| 150 | .id = -1, |
| 151 | .dev = { |
| 152 | .platform_data = &nsa310_leds_data, |
| 153 | } |
| 154 | }; |
| 155 | |
| 156 | static struct gpio_keys_button nsa310_buttons[] = { |
| 157 | { |
| 158 | .desc = "Power Button", |
| 159 | .code = KEY_POWER, |
| 160 | .type = EV_KEY, |
| 161 | .gpio = NSA310_GPIO_KEY_POWER, |
| 162 | .debounce_interval = 1000, |
| 163 | }, { |
| 164 | .desc = "Copy Button", |
| 165 | .code = KEY_COPY, |
| 166 | .type = EV_KEY, |
| 167 | .gpio = NSA310_GPIO_KEY_COPY, |
| 168 | .active_low = 1, |
| 169 | .debounce_interval = 1000, |
| 170 | }, { |
| 171 | .desc = "Reset Button", |
| 172 | .code = KEY_RESTART, |
| 173 | .type = EV_KEY, |
| 174 | .gpio = NSA310_GPIO_KEY_RESTART, |
| 175 | .active_low = 1, |
| 176 | .debounce_interval = 1000, |
| 177 | }, |
| 178 | }; |
| 179 | |
| 180 | static struct gpio_keys_platform_data nsa310_keys_data = { |
| 181 | .buttons = nsa310_buttons, |
| 182 | .nbuttons = ARRAY_SIZE(nsa310_buttons), |
| 183 | }; |
| 184 | |
| 185 | static struct platform_device nsa310_keys_device = { |
| 186 | .name = "gpio-keys", |
| 187 | .id = -1, |
| 188 | .dev = { |
| 189 | .platform_data = &nsa310_keys_data, |
| 190 | } |
| 191 | }; |
| 192 | |
| 193 | static struct i2c_board_info __initdata nsa310_i2c_info[] = { |
| 194 | { I2C_BOARD_INFO("adt7476", 0x2e) }, |
| 195 | }; |
| 196 | |
| 197 | static struct mv_sata_platform_data nsa310_sata_data = { |
| 198 | .n_ports = 2, |
| 199 | }; |
| 200 | |
| 201 | static void nsa310_power_off(void) |
| 202 | { |
| 203 | gpio_set_value(NSA310_GPIO_POWER_OFF, 1); |
| 204 | } |
| 205 | |
| 206 | static int __init nsa310_gpio_request(unsigned int gpio, unsigned long flags, |
| 207 | const char *label) |
| 208 | { |
| 209 | int err; |
| 210 | |
| 211 | err = gpio_request_one(gpio, flags, label); |
| 212 | if (err) |
| 213 | pr_err("NSA-310: can't setup GPIO%u (%s), err=%d\n", |
| 214 | gpio, label, err); |
| 215 | |
| 216 | return err; |
| 217 | } |
| 218 | |
| 219 | static void __init nsa310_gpio_init(void) |
| 220 | { |
| 221 | int err; |
| 222 | |
| 223 | err = nsa310_gpio_request(NSA310_GPIO_POWER_OFF, GPIOF_OUT_INIT_LOW, |
| 224 | "Power Off"); |
| 225 | if (!err) |
| 226 | pm_power_off = nsa310_power_off; |
| 227 | |
| 228 | nsa310_gpio_request(NSA310_GPIO_USB_POWER_OFF, GPIOF_OUT_INIT_LOW, |
| 229 | "USB Power Off"); |
| 230 | } |
| 231 | |
| 232 | static void __init nsa310_init(void) |
| 233 | { |
| 234 | u32 dev, rev; |
| 235 | |
| 236 | kirkwood_init(); |
| 237 | kirkwood_mpp_conf(nsa310_mpp_config); |
| 238 | |
| 239 | nsa310_gpio_init(); |
| 240 | |
| 241 | kirkwood_nand_init(ARRAY_AND_SIZE(nsa310_mtd_parts), 35); |
| 242 | kirkwood_ehci_init(); |
| 243 | |
| 244 | kirkwood_pcie_id(&dev, &rev); |
| 245 | |
| 246 | kirkwood_sata_init(&nsa310_sata_data); |
| 247 | kirkwood_uart0_init(); |
| 248 | |
| 249 | i2c_register_board_info(0, ARRAY_AND_SIZE(nsa310_i2c_info)); |
| 250 | kirkwood_i2c_init(); |
| 251 | |
| 252 | platform_device_register(&nsa310_leds_device); |
| 253 | platform_device_register(&nsa310_keys_device); |
| 254 | } |
| 255 | |
| 256 | static int __init nsa310_pci_init(void) |
| 257 | { |
| 258 | if (machine_is_nsa310()) |
| 259 | kirkwood_pcie_init(KW_PCIE0); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | subsys_initcall(nsa310_pci_init); |
| 264 | |
| 265 | MACHINE_START(NSA310, "ZyXEL NSA-310") |
| 266 | .atag_offset = 0x100, |
| 267 | .init_machine = nsa310_init, |
| 268 | .map_io = kirkwood_map_io, |
| 269 | .init_early = kirkwood_init_early, |
| 270 | .init_irq = kirkwood_init_irq, |
| 271 | .timer = &kirkwood_timer, |
| 272 | .restart = kirkwood_restart, |
| 273 | MACHINE_END |
| 274 | |