ARM: OMAP2+: Remove hardcoded twl4030 gpio_base, irq_base and irq_end
[cascardo/linux.git] / arch / arm / mach-omap2 / board-overo.c
1 /*
2  * board-overo.c (Gumstix Overo)
3  *
4  * Initial code: Steve Sakoman <steve@sakoman.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21
22 #include <linux/clk.h>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/init.h>
26 #include <linux/io.h>
27 #include <linux/gpio.h>
28 #include <linux/kernel.h>
29 #include <linux/platform_device.h>
30 #include <linux/i2c/twl.h>
31 #include <linux/regulator/machine.h>
32 #include <linux/regulator/fixed.h>
33 #include <linux/spi/spi.h>
34
35 #include <linux/mtd/mtd.h>
36 #include <linux/mtd/nand.h>
37 #include <linux/mtd/partitions.h>
38 #include <linux/mmc/host.h>
39
40 #include <asm/mach-types.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/flash.h>
43 #include <asm/mach/map.h>
44
45 #include "common.h"
46 #include <video/omapdss.h>
47 #include <video/omap-panel-generic-dpi.h>
48 #include <video/omap-panel-tfp410.h>
49 #include <plat/gpmc.h>
50 #include <mach/hardware.h>
51 #include <plat/nand.h>
52 #include <plat/mcspi.h>
53 #include <plat/mux.h>
54 #include <plat/usb.h>
55
56 #include "mux.h"
57 #include "sdram-micron-mt46h32m32lf-6.h"
58 #include "hsmmc.h"
59 #include "common-board-devices.h"
60
61 #define OVERO_GPIO_BT_XGATE     15
62 #define OVERO_GPIO_W2W_NRESET   16
63 #define OVERO_GPIO_PENDOWN      114
64 #define OVERO_GPIO_BT_NRESET    164
65 #define OVERO_GPIO_USBH_CPEN    168
66 #define OVERO_GPIO_USBH_NRESET  183
67
68 #define OVERO_SMSC911X_CS      5
69 #define OVERO_SMSC911X_GPIO    176
70 #define OVERO_SMSC911X2_CS     4
71 #define OVERO_SMSC911X2_GPIO   65
72
73 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
74         defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
75
76 /* fixed regulator for ads7846 */
77 static struct regulator_consumer_supply ads7846_supply[] = {
78         REGULATOR_SUPPLY("vcc", "spi1.0"),
79 };
80
81 static struct regulator_init_data vads7846_regulator = {
82         .constraints = {
83                 .valid_ops_mask         = REGULATOR_CHANGE_STATUS,
84         },
85         .num_consumer_supplies  = ARRAY_SIZE(ads7846_supply),
86         .consumer_supplies      = ads7846_supply,
87 };
88
89 static struct fixed_voltage_config vads7846 = {
90         .supply_name            = "vads7846",
91         .microvolts             = 3300000, /* 3.3V */
92         .gpio                   = -EINVAL,
93         .startup_delay          = 0,
94         .init_data              = &vads7846_regulator,
95 };
96
97 static struct platform_device vads7846_device = {
98         .name           = "reg-fixed-voltage",
99         .id             = 1,
100         .dev = {
101                 .platform_data = &vads7846,
102         },
103 };
104
105 static void __init overo_ads7846_init(void)
106 {
107         omap_ads7846_init(1, OVERO_GPIO_PENDOWN, 0, NULL);
108         platform_device_register(&vads7846_device);
109 }
110
111 #else
112 static inline void __init overo_ads7846_init(void) { return; }
113 #endif
114
115 #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
116
117 #include <linux/smsc911x.h>
118 #include <plat/gpmc-smsc911x.h>
119
120 static struct omap_smsc911x_platform_data smsc911x_cfg = {
121         .id             = 0,
122         .cs             = OVERO_SMSC911X_CS,
123         .gpio_irq       = OVERO_SMSC911X_GPIO,
124         .gpio_reset     = -EINVAL,
125         .flags          = SMSC911X_USE_32BIT,
126 };
127
128 static struct omap_smsc911x_platform_data smsc911x2_cfg = {
129         .id             = 1,
130         .cs             = OVERO_SMSC911X2_CS,
131         .gpio_irq       = OVERO_SMSC911X2_GPIO,
132         .gpio_reset     = -EINVAL,
133         .flags          = SMSC911X_USE_32BIT,
134 };
135
136 static void __init overo_init_smsc911x(void)
137 {
138         gpmc_smsc911x_init(&smsc911x_cfg);
139         gpmc_smsc911x_init(&smsc911x2_cfg);
140 }
141
142 #else
143 static inline void __init overo_init_smsc911x(void) { return; }
144 #endif
145
146 /* DSS */
147 static int lcd_enabled;
148 static int dvi_enabled;
149
150 #define OVERO_GPIO_LCD_EN 144
151 #define OVERO_GPIO_LCD_BL 145
152
153 static struct gpio overo_dss_gpios[] __initdata = {
154         { OVERO_GPIO_LCD_EN, GPIOF_OUT_INIT_HIGH, "OVERO_GPIO_LCD_EN" },
155         { OVERO_GPIO_LCD_BL, GPIOF_OUT_INIT_HIGH, "OVERO_GPIO_LCD_BL" },
156 };
157
158 static void __init overo_display_init(void)
159 {
160         if (gpio_request_array(overo_dss_gpios, ARRAY_SIZE(overo_dss_gpios))) {
161                 printk(KERN_ERR "could not obtain DSS control GPIOs\n");
162                 return;
163         }
164
165         gpio_export(OVERO_GPIO_LCD_EN, 0);
166         gpio_export(OVERO_GPIO_LCD_BL, 0);
167 }
168
169 static struct tfp410_platform_data dvi_panel = {
170         .i2c_bus_num            = 3,
171         .power_down_gpio        = -1,
172 };
173
174 static struct omap_dss_device overo_dvi_device = {
175         .name                   = "dvi",
176         .type                   = OMAP_DISPLAY_TYPE_DPI,
177         .driver_name            = "tfp410",
178         .data                   = &dvi_panel,
179         .phy.dpi.data_lines     = 24,
180 };
181
182 static struct omap_dss_device overo_tv_device = {
183         .name = "tv",
184         .driver_name = "venc",
185         .type = OMAP_DISPLAY_TYPE_VENC,
186         .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
187 };
188
189 static int overo_panel_enable_lcd(struct omap_dss_device *dssdev)
190 {
191         if (dvi_enabled) {
192                 printk(KERN_ERR "cannot enable LCD, DVI is enabled\n");
193                 return -EINVAL;
194         }
195
196         gpio_set_value(OVERO_GPIO_LCD_EN, 1);
197         gpio_set_value(OVERO_GPIO_LCD_BL, 1);
198         lcd_enabled = 1;
199         return 0;
200 }
201
202 static void overo_panel_disable_lcd(struct omap_dss_device *dssdev)
203 {
204         gpio_set_value(OVERO_GPIO_LCD_EN, 0);
205         gpio_set_value(OVERO_GPIO_LCD_BL, 0);
206         lcd_enabled = 0;
207 }
208
209 static struct panel_generic_dpi_data lcd43_panel = {
210         .name                   = "samsung_lte430wq_f0c",
211         .platform_enable        = overo_panel_enable_lcd,
212         .platform_disable       = overo_panel_disable_lcd,
213 };
214
215 static struct omap_dss_device overo_lcd43_device = {
216         .name                   = "lcd43",
217         .type                   = OMAP_DISPLAY_TYPE_DPI,
218         .driver_name            = "generic_dpi_panel",
219         .data                   = &lcd43_panel,
220         .phy.dpi.data_lines     = 24,
221 };
222
223 #if defined(CONFIG_PANEL_LGPHILIPS_LB035Q02) || \
224         defined(CONFIG_PANEL_LGPHILIPS_LB035Q02_MODULE)
225 static struct omap_dss_device overo_lcd35_device = {
226         .type                   = OMAP_DISPLAY_TYPE_DPI,
227         .name                   = "lcd35",
228         .driver_name            = "lgphilips_lb035q02_panel",
229         .phy.dpi.data_lines     = 24,
230         .platform_enable        = overo_panel_enable_lcd,
231         .platform_disable       = overo_panel_disable_lcd,
232 };
233 #endif
234
235 static struct omap_dss_device *overo_dss_devices[] = {
236         &overo_dvi_device,
237         &overo_tv_device,
238 #if defined(CONFIG_PANEL_LGPHILIPS_LB035Q02) || \
239         defined(CONFIG_PANEL_LGPHILIPS_LB035Q02_MODULE)
240         &overo_lcd35_device,
241 #endif
242         &overo_lcd43_device,
243 };
244
245 static struct omap_dss_board_info overo_dss_data = {
246         .num_devices    = ARRAY_SIZE(overo_dss_devices),
247         .devices        = overo_dss_devices,
248         .default_device = &overo_dvi_device,
249 };
250
251 static struct mtd_partition overo_nand_partitions[] = {
252         {
253                 .name           = "xloader",
254                 .offset         = 0,                    /* Offset = 0x00000 */
255                 .size           = 4 * NAND_BLOCK_SIZE,
256                 .mask_flags     = MTD_WRITEABLE
257         },
258         {
259                 .name           = "uboot",
260                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
261                 .size           = 14 * NAND_BLOCK_SIZE,
262         },
263         {
264                 .name           = "uboot environment",
265                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x240000 */
266                 .size           = 2 * NAND_BLOCK_SIZE,
267         },
268         {
269                 .name           = "linux",
270                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
271                 .size           = 32 * NAND_BLOCK_SIZE,
272         },
273         {
274                 .name           = "rootfs",
275                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
276                 .size           = MTDPART_SIZ_FULL,
277         },
278 };
279
280 static struct omap2_hsmmc_info mmc[] = {
281         {
282                 .mmc            = 1,
283                 .caps           = MMC_CAP_4_BIT_DATA,
284                 .gpio_cd        = -EINVAL,
285                 .gpio_wp        = -EINVAL,
286         },
287         {
288                 .mmc            = 2,
289                 .caps           = MMC_CAP_4_BIT_DATA,
290                 .gpio_cd        = -EINVAL,
291                 .gpio_wp        = -EINVAL,
292                 .transceiver    = true,
293                 .ocr_mask       = 0x00100000,   /* 3.3V */
294         },
295         {}      /* Terminator */
296 };
297
298 static struct regulator_consumer_supply overo_vmmc1_supply[] = {
299         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
300 };
301
302 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
303 #include <linux/leds.h>
304
305 static struct gpio_led gpio_leds[] = {
306         {
307                 .name                   = "overo:red:gpio21",
308                 .default_trigger        = "heartbeat",
309                 .gpio                   = 21,
310                 .active_low             = true,
311         },
312         {
313                 .name                   = "overo:blue:gpio22",
314                 .default_trigger        = "none",
315                 .gpio                   = 22,
316                 .active_low             = true,
317         },
318         {
319                 .name                   = "overo:blue:COM",
320                 .default_trigger        = "mmc0",
321                 .gpio                   = -EINVAL,      /* gets replaced */
322                 .active_low             = true,
323         },
324 };
325
326 static struct gpio_led_platform_data gpio_leds_pdata = {
327         .leds           = gpio_leds,
328         .num_leds       = ARRAY_SIZE(gpio_leds),
329 };
330
331 static struct platform_device gpio_leds_device = {
332         .name   = "leds-gpio",
333         .id     = -1,
334         .dev    = {
335                 .platform_data  = &gpio_leds_pdata,
336         },
337 };
338
339 static void __init overo_init_led(void)
340 {
341         platform_device_register(&gpio_leds_device);
342 }
343
344 #else
345 static inline void __init overo_init_led(void) { return; }
346 #endif
347
348 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
349 #include <linux/input.h>
350 #include <linux/gpio_keys.h>
351
352 static struct gpio_keys_button gpio_buttons[] = {
353         {
354                 .code                   = BTN_0,
355                 .gpio                   = 23,
356                 .desc                   = "button0",
357                 .wakeup                 = 1,
358         },
359         {
360                 .code                   = BTN_1,
361                 .gpio                   = 14,
362                 .desc                   = "button1",
363                 .wakeup                 = 1,
364         },
365 };
366
367 static struct gpio_keys_platform_data gpio_keys_pdata = {
368         .buttons        = gpio_buttons,
369         .nbuttons       = ARRAY_SIZE(gpio_buttons),
370 };
371
372 static struct platform_device gpio_keys_device = {
373         .name   = "gpio-keys",
374         .id     = -1,
375         .dev    = {
376                 .platform_data  = &gpio_keys_pdata,
377         },
378 };
379
380 static void __init overo_init_keys(void)
381 {
382         platform_device_register(&gpio_keys_device);
383 }
384
385 #else
386 static inline void __init overo_init_keys(void) { return; }
387 #endif
388
389 static int overo_twl_gpio_setup(struct device *dev,
390                 unsigned gpio, unsigned ngpio)
391 {
392 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
393         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
394         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
395 #endif
396
397         return 0;
398 }
399
400 static struct twl4030_gpio_platform_data overo_gpio_data = {
401         .use_leds       = true,
402         .setup          = overo_twl_gpio_setup,
403 };
404
405 static struct regulator_init_data overo_vmmc1 = {
406         .constraints = {
407                 .min_uV                 = 1850000,
408                 .max_uV                 = 3150000,
409                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
410                                         | REGULATOR_MODE_STANDBY,
411                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
412                                         | REGULATOR_CHANGE_MODE
413                                         | REGULATOR_CHANGE_STATUS,
414         },
415         .num_consumer_supplies  = ARRAY_SIZE(overo_vmmc1_supply),
416         .consumer_supplies      = overo_vmmc1_supply,
417 };
418
419 static struct twl4030_platform_data overo_twldata = {
420         .gpio           = &overo_gpio_data,
421         .vmmc1          = &overo_vmmc1,
422 };
423
424 static int __init overo_i2c_init(void)
425 {
426         omap3_pmic_get_config(&overo_twldata,
427                         TWL_COMMON_PDATA_USB | TWL_COMMON_PDATA_AUDIO,
428                         TWL_COMMON_REGULATOR_VDAC | TWL_COMMON_REGULATOR_VPLL2);
429
430         overo_twldata.vpll2->constraints.name = "VDVI";
431
432         omap3_pmic_init("tps65950", &overo_twldata);
433         /* i2c2 pins are used for gpio */
434         omap_register_i2c_bus(3, 400, NULL, 0);
435         return 0;
436 }
437
438 static struct spi_board_info overo_spi_board_info[] __initdata = {
439 #if defined(CONFIG_PANEL_LGPHILIPS_LB035Q02) || \
440         defined(CONFIG_PANEL_LGPHILIPS_LB035Q02_MODULE)
441         {
442                 .modalias               = "lgphilips_lb035q02_panel-spi",
443                 .bus_num                = 1,
444                 .chip_select            = 1,
445                 .max_speed_hz           = 500000,
446                 .mode                   = SPI_MODE_3,
447         },
448 #endif
449 };
450
451 static int __init overo_spi_init(void)
452 {
453         overo_ads7846_init();
454         spi_register_board_info(overo_spi_board_info,
455                         ARRAY_SIZE(overo_spi_board_info));
456         return 0;
457 }
458
459 static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
460         .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
461         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
462         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
463         .phy_reset  = true,
464         .reset_gpio_port[0]  = -EINVAL,
465         .reset_gpio_port[1]  = OVERO_GPIO_USBH_NRESET,
466         .reset_gpio_port[2]  = -EINVAL
467 };
468
469 #ifdef CONFIG_OMAP_MUX
470 static struct omap_board_mux board_mux[] __initdata = {
471         { .reg_offset = OMAP_MUX_TERMINATOR },
472 };
473 #endif
474
475 static struct gpio overo_bt_gpios[] __initdata = {
476         { OVERO_GPIO_BT_XGATE,  GPIOF_OUT_INIT_LOW,     "lcd enable"    },
477         { OVERO_GPIO_BT_NRESET, GPIOF_OUT_INIT_HIGH,    "lcd bl enable" },
478 };
479
480 static struct regulator_consumer_supply dummy_supplies[] = {
481         REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
482         REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
483         REGULATOR_SUPPLY("vddvario", "smsc911x.1"),
484         REGULATOR_SUPPLY("vdd33a", "smsc911x.1"),
485 };
486
487 static void __init overo_init(void)
488 {
489         int ret;
490
491         regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
492         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
493         overo_i2c_init();
494         omap_hsmmc_init(mmc);
495         omap_display_init(&overo_dss_data);
496         omap_serial_init();
497         omap_sdrc_init(mt46h32m32lf6_sdrc_params,
498                                   mt46h32m32lf6_sdrc_params);
499         omap_nand_flash_init(0, overo_nand_partitions,
500                              ARRAY_SIZE(overo_nand_partitions));
501         usb_musb_init(NULL);
502         usbhs_init(&usbhs_bdata);
503         overo_spi_init();
504         overo_init_smsc911x();
505         overo_display_init();
506         overo_init_led();
507         overo_init_keys();
508
509         /* Ensure SDRC pins are mux'd for self-refresh */
510         omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
511         omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
512
513         ret = gpio_request_one(OVERO_GPIO_W2W_NRESET, GPIOF_OUT_INIT_HIGH,
514                                "OVERO_GPIO_W2W_NRESET");
515         if (ret == 0) {
516                 gpio_export(OVERO_GPIO_W2W_NRESET, 0);
517                 gpio_set_value(OVERO_GPIO_W2W_NRESET, 0);
518                 udelay(10);
519                 gpio_set_value(OVERO_GPIO_W2W_NRESET, 1);
520         } else {
521                 printk(KERN_ERR "could not obtain gpio for "
522                                         "OVERO_GPIO_W2W_NRESET\n");
523         }
524
525         ret = gpio_request_array(overo_bt_gpios, ARRAY_SIZE(overo_bt_gpios));
526         if (ret) {
527                 pr_err("%s: could not obtain BT gpios\n", __func__);
528         } else {
529                 gpio_export(OVERO_GPIO_BT_XGATE, 0);
530                 gpio_export(OVERO_GPIO_BT_NRESET, 0);
531                 gpio_set_value(OVERO_GPIO_BT_NRESET, 0);
532                 mdelay(6);
533                 gpio_set_value(OVERO_GPIO_BT_NRESET, 1);
534         }
535
536         ret = gpio_request_one(OVERO_GPIO_USBH_CPEN, GPIOF_OUT_INIT_HIGH,
537                                "OVERO_GPIO_USBH_CPEN");
538         if (ret == 0)
539                 gpio_export(OVERO_GPIO_USBH_CPEN, 0);
540         else
541                 printk(KERN_ERR "could not obtain gpio for "
542                                         "OVERO_GPIO_USBH_CPEN\n");
543 }
544
545 MACHINE_START(OVERO, "Gumstix Overo")
546         .atag_offset    = 0x100,
547         .reserve        = omap_reserve,
548         .map_io         = omap3_map_io,
549         .init_early     = omap35xx_init_early,
550         .init_irq       = omap3_init_irq,
551         .handle_irq     = omap3_intc_handle_irq,
552         .init_machine   = overo_init,
553         .init_late      = omap35xx_init_late,
554         .timer          = &omap3_timer,
555         .restart        = omap_prcm_restart,
556 MACHINE_END