| 1 | /* |
| 2 | * arch/ubicom32/mach-ip7k/board-ip7160rgw.c |
| 3 | * Platform initialization for ip7160rgw board. |
| 4 | * |
| 5 | * (C) Copyright 2009, Ubicom, Inc. |
| 6 | * |
| 7 | * This file is part of the Ubicom32 Linux Kernel Port. |
| 8 | * |
| 9 | * The Ubicom32 Linux Kernel Port is free software: you can redistribute |
| 10 | * it and/or modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation, either version 2 of the |
| 12 | * License, or (at your option) any later version. |
| 13 | * |
| 14 | * The Ubicom32 Linux Kernel Port is distributed in the hope that it |
| 15 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 16 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with the Ubicom32 Linux Kernel Port. If not, |
| 21 | * see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | * Ubicom32 implementation derived from (with many thanks): |
| 24 | * arch/m68knommu |
| 25 | * arch/blackfin |
| 26 | * arch/parisc |
| 27 | */ |
| 28 | #include <linux/device.h> |
| 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/gpio.h> |
| 31 | #include <linux/leds.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/input.h> |
| 34 | #include <linux/spi/spi.h> |
| 35 | |
| 36 | #include <asm/board.h> |
| 37 | #include <asm/machdep.h> |
| 38 | #include <asm/ubicom32input.h> |
| 39 | |
| 40 | #ifdef CONFIG_SERIAL_UBI32_SERDES |
| 41 | #include <asm/ubicom32suart.h> |
| 42 | #endif |
| 43 | |
| 44 | #include <asm/ubicom32-spi-gpio.h> |
| 45 | #include <asm/switch-dev.h> |
| 46 | |
| 47 | #ifdef CONFIG_IP7160RGWLCD |
| 48 | #include <linux/i2c.h> |
| 49 | #include <linux/i2c-gpio.h> |
| 50 | /* |
| 51 | * LCD Adapter board 8007-092x support |
| 52 | * |
| 53 | * Touch controller |
| 54 | * |
| 55 | * Connected via I2C bus, interrupt on PA6 |
| 56 | */ |
| 57 | #include <linux/i2c/tsc2007.h> |
| 58 | |
| 59 | /* |
| 60 | * ip7160rgwlcd_tsc2007_exit_platform_hw |
| 61 | */ |
| 62 | static void ip7160rgwlcd_tsc2007_exit_platform_hw(void) |
| 63 | { |
| 64 | UBICOM32_IO_PORT(RA)->ctl0 &= ~(0x03 << 17); |
| 65 | gpio_free(GPIO_RA_5); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * ip7160rgwlcd_tsc2007_init_platform_hw |
| 70 | */ |
| 71 | static int ip7160rgwlcd_tsc2007_init_platform_hw(void) |
| 72 | { |
| 73 | int res = gpio_request(GPIO_RA_5, "TSC2007_IRQ"); |
| 74 | if (res) { |
| 75 | return res; |
| 76 | } |
| 77 | |
| 78 | UBICOM32_IO_PORT(RA)->ctl0 &= ~(0x03 << 17); |
| 79 | UBICOM32_IO_PORT(RA)->ctl0 |= (0x02 << 17); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * ip7160rgwlcd_tsc2007_get_pendown_state |
| 85 | */ |
| 86 | static int ip7160rgwlcd_tsc2007_get_pendown_state(void) |
| 87 | { |
| 88 | return !gpio_get_value(GPIO_RA_5); |
| 89 | } |
| 90 | |
| 91 | static struct tsc2007_platform_data ip7160rgwlcd_tsc2007_data = { |
| 92 | .model = 2007, |
| 93 | .x_plate_ohms = 350, |
| 94 | .get_pendown_state = ip7160rgwlcd_tsc2007_get_pendown_state, |
| 95 | .init_platform_hw = ip7160rgwlcd_tsc2007_init_platform_hw, |
| 96 | .exit_platform_hw = ip7160rgwlcd_tsc2007_exit_platform_hw, |
| 97 | }; |
| 98 | |
| 99 | /****************************************************************************** |
| 100 | * I2C bus on the board, SDA PI14, SCL PI13 |
| 101 | */ |
| 102 | static struct i2c_gpio_platform_data ip7160rgwlcd_i2c_data = { |
| 103 | .sda_pin = GPIO_RI_14, |
| 104 | .scl_pin = GPIO_RI_13, |
| 105 | .sda_is_open_drain = 0, |
| 106 | .scl_is_open_drain = 0, |
| 107 | .udelay = 50, |
| 108 | }; |
| 109 | |
| 110 | static struct platform_device ip7160rgwlcd_i2c_device = { |
| 111 | .name = "i2c-gpio", |
| 112 | .id = 0, |
| 113 | .dev = { |
| 114 | .platform_data = &ip7160rgwlcd_i2c_data, |
| 115 | }, |
| 116 | }; |
| 117 | |
| 118 | static struct i2c_board_info __initdata ip7160rgwlcd_i2c_board_info[] = { |
| 119 | { |
| 120 | .type = "tsc2007", |
| 121 | .addr = 0x48, |
| 122 | .irq = 45, // RA5 |
| 123 | .platform_data = &ip7160rgwlcd_tsc2007_data, |
| 124 | }, |
| 125 | }; |
| 126 | |
| 127 | #endif |
| 128 | |
| 129 | /* |
| 130 | * SPI bus over GPIO for Gigabit Ethernet Switch |
| 131 | * U58: |
| 132 | * MOSI PE0 |
| 133 | * MISO PE1 |
| 134 | * CLK PE3 |
| 135 | * CS PE2 |
| 136 | */ |
| 137 | static struct ubicom32_spi_gpio_platform_data ip7160rgw_spi_gpio_data = { |
| 138 | .pin_mosi = GPIO_RE_0, |
| 139 | .pin_miso = GPIO_RE_1, |
| 140 | .pin_clk = GPIO_RE_3, |
| 141 | .bus_num = 0, // We'll call this SPI bus 0 |
| 142 | .num_chipselect = 1, // only one device on this SPI bus |
| 143 | .clk_default = 1, |
| 144 | }; |
| 145 | |
| 146 | static struct platform_device ip7160rgw_spi_gpio_device = { |
| 147 | .name = "ubicom32-spi-gpio", |
| 148 | .id = 0, |
| 149 | .dev = { |
| 150 | .platform_data = &ip7160rgw_spi_gpio_data, |
| 151 | }, |
| 152 | }; |
| 153 | |
| 154 | static struct ubicom32_spi_gpio_controller_data ip7160rgw_bcm539x_controller_data = { |
| 155 | .pin_cs = GPIO_RE_2, |
| 156 | }; |
| 157 | |
| 158 | static struct switch_core_platform_data ip7160rgw_bcm539x_platform_data = { |
| 159 | .flags = SWITCH_DEV_FLAG_HW_RESET, |
| 160 | .pin_reset = GPIO_RE_4, |
| 161 | .name = "bcm539x", |
| 162 | }; |
| 163 | |
| 164 | static struct spi_board_info ip7160rgw_spi_board_info[] = { |
| 165 | { |
| 166 | .modalias = "bcm539x-spi", |
| 167 | .bus_num = 0, |
| 168 | .chip_select = 0, |
| 169 | .max_speed_hz = 2000000, |
| 170 | .platform_data = &ip7160rgw_bcm539x_platform_data, |
| 171 | .controller_data = &ip7160rgw_bcm539x_controller_data, |
| 172 | .mode = SPI_MODE_3, |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | /* |
| 177 | * LEDs |
| 178 | * |
| 179 | * WLAN1 PD0 (PWM capable) |
| 180 | * WLAN2 PD1 |
| 181 | * USB2.0 PD2 |
| 182 | * Status PD3 |
| 183 | * WPS PD4 |
| 184 | * |
| 185 | * TODO: check triggers, are they generic? |
| 186 | */ |
| 187 | static struct gpio_led ip7160rgw_gpio_leds[] = { |
| 188 | { |
| 189 | .name = "d53:green:WLAN1", |
| 190 | .default_trigger = "WLAN1", |
| 191 | .gpio = GPIO_RD_0, |
| 192 | .active_low = 1, |
| 193 | }, |
| 194 | { |
| 195 | .name = "d54:green:WLAN2", |
| 196 | .default_trigger = "WLAN2", |
| 197 | .gpio = GPIO_RD_1, |
| 198 | .active_low = 1, |
| 199 | }, |
| 200 | { |
| 201 | .name = "d55:green:USB", |
| 202 | .default_trigger = "USB", |
| 203 | .gpio = GPIO_RD_2, |
| 204 | .active_low = 1, |
| 205 | }, |
| 206 | { |
| 207 | .name = "d56:green:Status", |
| 208 | .default_trigger = "Status", |
| 209 | .gpio = GPIO_RD_3, |
| 210 | .active_low = 1, |
| 211 | }, |
| 212 | { |
| 213 | .name = "d57:green:WPS", |
| 214 | .default_trigger = "WPS", |
| 215 | .gpio = GPIO_RD_4, |
| 216 | .active_low = 1, |
| 217 | }, |
| 218 | }; |
| 219 | |
| 220 | static struct gpio_led_platform_data ip7160rgw_gpio_led_platform_data = { |
| 221 | .num_leds = 5, |
| 222 | .leds = ip7160rgw_gpio_leds, |
| 223 | }; |
| 224 | |
| 225 | static struct platform_device ip7160rgw_gpio_leds_device = { |
| 226 | .name = "leds-gpio", |
| 227 | .id = -1, |
| 228 | .dev = { |
| 229 | .platform_data = &ip7160rgw_gpio_led_platform_data, |
| 230 | }, |
| 231 | }; |
| 232 | |
| 233 | /* |
| 234 | * Use ubicom32input driver to monitor the various pushbuttons on this board. |
| 235 | * |
| 236 | * WPS PD5 |
| 237 | * FACT_DEFAULT PD6 |
| 238 | * |
| 239 | * TODO: pick some ubicom understood EV_xxx define for WPS and Fact Default |
| 240 | */ |
| 241 | static struct ubicom32input_button ip7160rgw_ubicom32input_buttons[] = { |
| 242 | { |
| 243 | .type = EV_KEY, |
| 244 | .code = KEY_FN_F1, |
| 245 | .gpio = GPIO_RD_5, |
| 246 | .desc = "WPS", |
| 247 | .active_low = 1, |
| 248 | }, |
| 249 | { |
| 250 | .type = EV_KEY, |
| 251 | .code = KEY_FN_F2, |
| 252 | .gpio = GPIO_RD_6, |
| 253 | .desc = "Factory Default", |
| 254 | .active_low = 1, |
| 255 | }, |
| 256 | }; |
| 257 | |
| 258 | static struct ubicom32input_platform_data ip7160rgw_ubicom32input_data = { |
| 259 | .buttons = ip7160rgw_ubicom32input_buttons, |
| 260 | .nbuttons = ARRAY_SIZE(ip7160rgw_ubicom32input_buttons), |
| 261 | }; |
| 262 | |
| 263 | static struct platform_device ip7160rgw_ubicom32input_device = { |
| 264 | .name = "ubicom32input", |
| 265 | .id = -1, |
| 266 | .dev = { |
| 267 | .platform_data = &ip7160rgw_ubicom32input_data, |
| 268 | }, |
| 269 | }; |
| 270 | |
| 271 | #ifdef CONFIG_SERIAL_UBI32_SERDES |
| 272 | static struct resource ip7160rgw_ubicom32_suart_resources[] = { |
| 273 | { |
| 274 | .start = RE, |
| 275 | .end = RE, |
| 276 | .flags = IORESOURCE_MEM, |
| 277 | }, |
| 278 | { |
| 279 | .start = PORT_OTHER_INT(RE), |
| 280 | .end = PORT_OTHER_INT(RE), |
| 281 | .flags = IORESOURCE_IRQ, |
| 282 | }, |
| 283 | { |
| 284 | .start = 250000000, |
| 285 | .end = 250000000, |
| 286 | .flags = UBICOM32_SUART_IORESOURCE_CLOCK, |
| 287 | }, |
| 288 | }; |
| 289 | |
| 290 | static struct platform_device ip7160rgw_ubicom32_suart_device = { |
| 291 | .name = "ubicom32suart", |
| 292 | .id = -1, |
| 293 | .num_resources = ARRAY_SIZE(ip7160rgw_ubicom32_suart_resources), |
| 294 | .resource = ip7160rgw_ubicom32_suart_resources, |
| 295 | }; |
| 296 | #endif |
| 297 | |
| 298 | /* |
| 299 | * List of all devices in our system |
| 300 | */ |
| 301 | static struct platform_device *ip7160rgw_devices[] __initdata = { |
| 302 | #ifdef CONFIG_SERIAL_UBI32_SERDES |
| 303 | &ip7160rgw_ubicom32_suart_device, |
| 304 | #endif |
| 305 | &ip7160rgw_ubicom32input_device, |
| 306 | &ip7160rgw_gpio_leds_device, |
| 307 | &ip7160rgw_spi_gpio_device, |
| 308 | #ifdef CONFIG_IP7160RGWLCD |
| 309 | &ip7160rgwlcd_i2c_device, |
| 310 | #endif |
| 311 | }; |
| 312 | |
| 313 | /* |
| 314 | * ip7160rgw_init |
| 315 | * Called to add the devices which we have on this board |
| 316 | */ |
| 317 | static int __init ip7160rgw_init(void) |
| 318 | { |
| 319 | board_init(); |
| 320 | |
| 321 | /* |
| 322 | * Rev 1.2 boards have spi in a different place than 1.1/1.0 |
| 323 | */ |
| 324 | if (strcmp(board_get_revision(), "1.2") == 0) { |
| 325 | ip7160rgw_spi_gpio_data.pin_mosi = GPIO_RD_7; |
| 326 | } |
| 327 | |
| 328 | ubi_gpio_init(); |
| 329 | |
| 330 | /* |
| 331 | * Reserve switch SPI CS on behalf on switch driver |
| 332 | */ |
| 333 | if (gpio_request(ip7160rgw_bcm539x_controller_data.pin_cs, "switch-bcm539x-cs")) { |
| 334 | printk(KERN_WARNING "Could not request cs of switch SPI I/F\n"); |
| 335 | return -EIO; |
| 336 | } |
| 337 | gpio_direction_output(ip7160rgw_bcm539x_controller_data.pin_cs, 1); |
| 338 | |
| 339 | printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__); |
| 340 | platform_add_devices(ip7160rgw_devices, ARRAY_SIZE(ip7160rgw_devices)); |
| 341 | |
| 342 | printk(KERN_INFO "%s: registering SPI resources\n", __FUNCTION__); |
| 343 | spi_register_board_info(ip7160rgw_spi_board_info, ARRAY_SIZE(ip7160rgw_spi_board_info)); |
| 344 | |
| 345 | #ifdef CONFIG_IP7160RGWLCD |
| 346 | printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__); |
| 347 | i2c_register_board_info(0, ip7160rgwlcd_i2c_board_info, ARRAY_SIZE(ip7160rgwlcd_i2c_board_info)); |
| 348 | printk(KERN_INFO "IP7160 RGW + LCD\n"); |
| 349 | #else |
| 350 | printk(KERN_INFO "IP7160 RGW\n"); |
| 351 | #endif |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | arch_initcall(ip7160rgw_init); |
| 356 | |