omap3evm: Initialize vmmc and vmmc_aux regulators
[safe/jmp/linux-2.6] / arch / arm / mach-omap2 / board-omap3evm.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3evm.c
3  *
4  * Copyright (C) 2008 Texas Instruments
5  *
6  * Modified from mach-omap2/board-3430sdp.c
7  *
8  * Initial code: Syed Mohammed Khasim
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/gpio.h>
22 #include <linux/input.h>
23 #include <linux/input/matrix_keypad.h>
24 #include <linux/leds.h>
25
26 #include <linux/spi/spi.h>
27 #include <linux/spi/ads7846.h>
28 #include <linux/i2c/twl4030.h>
29 #include <linux/usb/otg.h>
30
31 #include <linux/regulator/machine.h>
32
33 #include <mach/hardware.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37
38 #include <plat/board.h>
39 #include <plat/mux.h>
40 #include <plat/usb.h>
41 #include <plat/common.h>
42 #include <plat/mcspi.h>
43
44 #include "sdram-micron-mt46h32m32lf-6.h"
45 #include "mmc-twl4030.h"
46
47 #define OMAP3_EVM_TS_GPIO       175
48 #define OMAP3_EVM_EHCI_VBUS     22
49 #define OMAP3_EVM_EHCI_SELECT   61
50
51 #define OMAP3EVM_ETHR_START     0x2c000000
52 #define OMAP3EVM_ETHR_SIZE      1024
53 #define OMAP3EVM_ETHR_ID_REV    0x50
54 #define OMAP3EVM_ETHR_GPIO_IRQ  176
55 #define OMAP3EVM_SMC911X_CS     5
56
57 static u8 omap3_evm_version;
58
59 u8 get_omap3_evm_rev(void)
60 {
61         return omap3_evm_version;
62 }
63 EXPORT_SYMBOL(get_omap3_evm_rev);
64
65 static void __init omap3_evm_get_revision(void)
66 {
67         void __iomem *ioaddr;
68         unsigned int smsc_id;
69
70         /* Ethernet PHY ID is stored at ID_REV register */
71         ioaddr = ioremap_nocache(OMAP3EVM_ETHR_START, SZ_1K);
72         if (!ioaddr)
73                 return;
74         smsc_id = readl(ioaddr + OMAP3EVM_ETHR_ID_REV) & 0xFFFF0000;
75         iounmap(ioaddr);
76
77         switch (smsc_id) {
78         /*SMSC9115 chipset*/
79         case 0x01150000:
80                 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
81                 break;
82         /*SMSC 9220 chipset*/
83         case 0x92200000:
84         default:
85                 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
86         }
87 }
88
89 static struct resource omap3evm_smc911x_resources[] = {
90         [0] =   {
91                 .start  = OMAP3EVM_ETHR_START,
92                 .end    = (OMAP3EVM_ETHR_START + OMAP3EVM_ETHR_SIZE - 1),
93                 .flags  = IORESOURCE_MEM,
94         },
95         [1] =   {
96                 .start  = OMAP_GPIO_IRQ(OMAP3EVM_ETHR_GPIO_IRQ),
97                 .end    = OMAP_GPIO_IRQ(OMAP3EVM_ETHR_GPIO_IRQ),
98                 .flags  = IORESOURCE_IRQ,
99         },
100 };
101
102 static struct platform_device omap3evm_smc911x_device = {
103         .name           = "smc911x",
104         .id             = -1,
105         .num_resources  = ARRAY_SIZE(omap3evm_smc911x_resources),
106         .resource       = &omap3evm_smc911x_resources[0],
107 };
108
109 static inline void __init omap3evm_init_smc911x(void)
110 {
111         int eth_cs;
112         struct clk *l3ck;
113         unsigned int rate;
114
115         eth_cs = OMAP3EVM_SMC911X_CS;
116
117         l3ck = clk_get(NULL, "l3_ck");
118         if (IS_ERR(l3ck))
119                 rate = 100000000;
120         else
121                 rate = clk_get_rate(l3ck);
122
123         if (gpio_request(OMAP3EVM_ETHR_GPIO_IRQ, "SMC911x irq") < 0) {
124                 printk(KERN_ERR "Failed to request GPIO%d for smc911x IRQ\n",
125                         OMAP3EVM_ETHR_GPIO_IRQ);
126                 return;
127         }
128
129         gpio_direction_input(OMAP3EVM_ETHR_GPIO_IRQ);
130 }
131
132 static struct regulator_consumer_supply omap3evm_vmmc1_supply = {
133         .supply                 = "vmmc",
134 };
135
136 static struct regulator_consumer_supply omap3evm_vsim_supply = {
137         .supply                 = "vmmc_aux",
138 };
139
140 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
141 static struct regulator_init_data omap3evm_vmmc1 = {
142         .constraints = {
143                 .min_uV                 = 1850000,
144                 .max_uV                 = 3150000,
145                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
146                                         | REGULATOR_MODE_STANDBY,
147                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
148                                         | REGULATOR_CHANGE_MODE
149                                         | REGULATOR_CHANGE_STATUS,
150         },
151         .num_consumer_supplies  = 1,
152         .consumer_supplies      = &omap3evm_vmmc1_supply,
153 };
154
155 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
156 static struct regulator_init_data omap3evm_vsim = {
157         .constraints = {
158                 .min_uV                 = 1800000,
159                 .max_uV                 = 3000000,
160                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
161                                         | REGULATOR_MODE_STANDBY,
162                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
163                                         | REGULATOR_CHANGE_MODE
164                                         | REGULATOR_CHANGE_STATUS,
165         },
166         .num_consumer_supplies  = 1,
167         .consumer_supplies      = &omap3evm_vsim_supply,
168 };
169
170 static struct twl4030_hsmmc_info mmc[] = {
171         {
172                 .mmc            = 1,
173                 .wires          = 4,
174                 .gpio_cd        = -EINVAL,
175                 .gpio_wp        = 63,
176         },
177         {}      /* Terminator */
178 };
179
180 static struct gpio_led gpio_leds[] = {
181         {
182                 .name                   = "omap3evm::ledb",
183                 /* normally not visible (board underside) */
184                 .default_trigger        = "default-on",
185                 .gpio                   = -EINVAL,      /* gets replaced */
186                 .active_low             = true,
187         },
188 };
189
190 static struct gpio_led_platform_data gpio_led_info = {
191         .leds           = gpio_leds,
192         .num_leds       = ARRAY_SIZE(gpio_leds),
193 };
194
195 static struct platform_device leds_gpio = {
196         .name   = "leds-gpio",
197         .id     = -1,
198         .dev    = {
199                 .platform_data  = &gpio_led_info,
200         },
201 };
202
203
204 static int omap3evm_twl_gpio_setup(struct device *dev,
205                 unsigned gpio, unsigned ngpio)
206 {
207         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
208         omap_cfg_reg(L8_34XX_GPIO63);
209         mmc[0].gpio_cd = gpio + 0;
210         twl4030_mmc_init(mmc);
211
212         /* link regulators to MMC adapters */
213         omap3evm_vmmc1_supply.dev = mmc[0].dev;
214         omap3evm_vsim_supply.dev = mmc[0].dev;
215
216         /*
217          * Most GPIOs are for USB OTG.  Some are mostly sent to
218          * the P2 connector; notably LEDA for the LCD backlight.
219          */
220
221         /* TWL4030_GPIO_MAX + 1 == ledB (out, active low LED) */
222         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
223
224         platform_device_register(&leds_gpio);
225
226         return 0;
227 }
228
229 static struct twl4030_gpio_platform_data omap3evm_gpio_data = {
230         .gpio_base      = OMAP_MAX_GPIO_LINES,
231         .irq_base       = TWL4030_GPIO_IRQ_BASE,
232         .irq_end        = TWL4030_GPIO_IRQ_END,
233         .use_leds       = true,
234         .setup          = omap3evm_twl_gpio_setup,
235 };
236
237 static struct twl4030_usb_data omap3evm_usb_data = {
238         .usb_mode       = T2_USB_MODE_ULPI,
239 };
240
241 static int board_keymap[] = {
242         KEY(0, 0, KEY_LEFT),
243         KEY(0, 1, KEY_RIGHT),
244         KEY(0, 2, KEY_A),
245         KEY(0, 3, KEY_B),
246         KEY(1, 0, KEY_DOWN),
247         KEY(1, 1, KEY_UP),
248         KEY(1, 2, KEY_E),
249         KEY(1, 3, KEY_F),
250         KEY(2, 0, KEY_ENTER),
251         KEY(2, 1, KEY_I),
252         KEY(2, 2, KEY_J),
253         KEY(2, 3, KEY_K),
254         KEY(3, 0, KEY_M),
255         KEY(3, 1, KEY_N),
256         KEY(3, 2, KEY_O),
257         KEY(3, 3, KEY_P)
258 };
259
260 static struct matrix_keymap_data board_map_data = {
261         .keymap                 = board_keymap,
262         .keymap_size            = ARRAY_SIZE(board_keymap),
263 };
264
265 static struct twl4030_keypad_data omap3evm_kp_data = {
266         .keymap_data    = &board_map_data,
267         .rows           = 4,
268         .cols           = 4,
269         .rep            = 1,
270 };
271
272 static struct twl4030_madc_platform_data omap3evm_madc_data = {
273         .irq_line       = 1,
274 };
275
276 static struct twl4030_codec_audio_data omap3evm_audio_data = {
277         .audio_mclk = 26000000,
278 };
279
280 static struct twl4030_codec_data omap3evm_codec_data = {
281         .audio_mclk = 26000000,
282         .audio = &omap3evm_audio_data,
283 };
284
285 static struct twl4030_platform_data omap3evm_twldata = {
286         .irq_base       = TWL4030_IRQ_BASE,
287         .irq_end        = TWL4030_IRQ_END,
288
289         /* platform_data for children goes here */
290         .keypad         = &omap3evm_kp_data,
291         .madc           = &omap3evm_madc_data,
292         .usb            = &omap3evm_usb_data,
293         .gpio           = &omap3evm_gpio_data,
294         .codec          = &omap3evm_codec_data,
295 };
296
297 static struct i2c_board_info __initdata omap3evm_i2c_boardinfo[] = {
298         {
299                 I2C_BOARD_INFO("twl4030", 0x48),
300                 .flags = I2C_CLIENT_WAKE,
301                 .irq = INT_34XX_SYS_NIRQ,
302                 .platform_data = &omap3evm_twldata,
303         },
304 };
305
306 static int __init omap3_evm_i2c_init(void)
307 {
308         /*
309          * REVISIT: These entries can be set in omap3evm_twl_data
310          * after a merge with MFD tree
311          */
312         omap3evm_twldata.vmmc1 = &omap3evm_vmmc1;
313         omap3evm_twldata.vsim = &omap3evm_vsim;
314
315         omap_register_i2c_bus(1, 2600, omap3evm_i2c_boardinfo,
316                         ARRAY_SIZE(omap3evm_i2c_boardinfo));
317         omap_register_i2c_bus(2, 400, NULL, 0);
318         omap_register_i2c_bus(3, 400, NULL, 0);
319         return 0;
320 }
321
322 static struct platform_device omap3_evm_lcd_device = {
323         .name           = "omap3evm_lcd",
324         .id             = -1,
325 };
326
327 static struct omap_lcd_config omap3_evm_lcd_config __initdata = {
328         .ctrl_name      = "internal",
329 };
330
331 static void ads7846_dev_init(void)
332 {
333         if (gpio_request(OMAP3_EVM_TS_GPIO, "ADS7846 pendown") < 0)
334                 printk(KERN_ERR "can't get ads7846 pen down GPIO\n");
335
336         gpio_direction_input(OMAP3_EVM_TS_GPIO);
337
338         omap_set_gpio_debounce(OMAP3_EVM_TS_GPIO, 1);
339         omap_set_gpio_debounce_time(OMAP3_EVM_TS_GPIO, 0xa);
340 }
341
342 static int ads7846_get_pendown_state(void)
343 {
344         return !gpio_get_value(OMAP3_EVM_TS_GPIO);
345 }
346
347 struct ads7846_platform_data ads7846_config = {
348         .x_max                  = 0x0fff,
349         .y_max                  = 0x0fff,
350         .x_plate_ohms           = 180,
351         .pressure_max           = 255,
352         .debounce_max           = 10,
353         .debounce_tol           = 3,
354         .debounce_rep           = 1,
355         .get_pendown_state      = ads7846_get_pendown_state,
356         .keep_vref_on           = 1,
357         .settle_delay_usecs     = 150,
358 };
359
360 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
361         .turbo_mode     = 0,
362         .single_channel = 1,    /* 0: slave, 1: master */
363 };
364
365 struct spi_board_info omap3evm_spi_board_info[] = {
366         [0] = {
367                 .modalias               = "ads7846",
368                 .bus_num                = 1,
369                 .chip_select            = 0,
370                 .max_speed_hz           = 1500000,
371                 .controller_data        = &ads7846_mcspi_config,
372                 .irq                    = OMAP_GPIO_IRQ(OMAP3_EVM_TS_GPIO),
373                 .platform_data          = &ads7846_config,
374         },
375 };
376
377 static struct omap_board_config_kernel omap3_evm_config[] __initdata = {
378         { OMAP_TAG_LCD,         &omap3_evm_lcd_config },
379 };
380
381 static void __init omap3_evm_init_irq(void)
382 {
383         omap_board_config = omap3_evm_config;
384         omap_board_config_size = ARRAY_SIZE(omap3_evm_config);
385         omap2_init_common_hw(mt46h32m32lf6_sdrc_params, NULL);
386         omap_init_irq();
387         omap_gpio_init();
388         omap3evm_init_smc911x();
389 }
390
391 static struct platform_device *omap3_evm_devices[] __initdata = {
392         &omap3_evm_lcd_device,
393         &omap3evm_smc911x_device,
394 };
395
396 static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
397
398         .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN,
399         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
400         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
401
402         .phy_reset  = true,
403         /* PHY reset GPIO will be runtime programmed based on EVM version */
404         .reset_gpio_port[0]  = -EINVAL,
405         .reset_gpio_port[1]  = -EINVAL,
406         .reset_gpio_port[2]  = -EINVAL
407 };
408
409 static void __init omap3_evm_init(void)
410 {
411         omap3_evm_get_revision();
412
413         omap3_evm_i2c_init();
414
415         platform_add_devices(omap3_evm_devices, ARRAY_SIZE(omap3_evm_devices));
416
417         spi_register_board_info(omap3evm_spi_board_info,
418                                 ARRAY_SIZE(omap3evm_spi_board_info));
419
420         omap_serial_init();
421 #ifdef CONFIG_NOP_USB_XCEIV
422         /* OMAP3EVM uses ISP1504 phy and so register nop transceiver */
423         usb_nop_xceiv_register();
424 #endif
425         if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2) {
426                 /* enable EHCI VBUS using GPIO22 */
427                 omap_cfg_reg(AF9_34XX_GPIO22);
428                 gpio_request(OMAP3_EVM_EHCI_VBUS, "enable EHCI VBUS");
429                 gpio_direction_output(OMAP3_EVM_EHCI_VBUS, 0);
430                 gpio_set_value(OMAP3_EVM_EHCI_VBUS, 1);
431
432                 /* Select EHCI port on main board */
433                 omap_cfg_reg(U3_34XX_GPIO61);
434                 gpio_request(OMAP3_EVM_EHCI_SELECT, "select EHCI port");
435                 gpio_direction_output(OMAP3_EVM_EHCI_SELECT, 0);
436                 gpio_set_value(OMAP3_EVM_EHCI_SELECT, 0);
437
438                 /* setup EHCI phy reset config */
439                 omap_cfg_reg(AH14_34XX_GPIO21);
440                 ehci_pdata.reset_gpio_port[1] = 21;
441
442         } else {
443                 /* setup EHCI phy reset on MDC */
444                 omap_cfg_reg(AF4_34XX_GPIO135_OUT);
445                 ehci_pdata.reset_gpio_port[1] = 135;
446         }
447         usb_musb_init();
448         usb_ehci_init(&ehci_pdata);
449         ads7846_dev_init();
450 }
451
452 static void __init omap3_evm_map_io(void)
453 {
454         omap2_set_globals_343x();
455         omap2_map_common_io();
456 }
457
458 MACHINE_START(OMAP3EVM, "OMAP3 EVM")
459         /* Maintainer: Syed Mohammed Khasim - Texas Instruments */
460         .phys_io        = 0x48000000,
461         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
462         .boot_params    = 0x80000100,
463         .map_io         = omap3_evm_map_io,
464         .init_irq       = omap3_evm_init_irq,
465         .init_machine   = omap3_evm_init,
466         .timer          = &omap_timer,
467 MACHINE_END