omap: mux: Replace omap_cfg_reg() with new style signal or gpio functions
[safe/jmp/linux-2.6] / arch / arm / mach-omap2 / board-cm-t35.c
1 /*
2  * board-cm-t35.c (CompuLab CM-T35 module)
3  *
4  * Copyright (C) 2009 CompuLab, Ltd.
5  * Author: Mike Rapoport <mike@compulab.co.il>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/platform_device.h>
26 #include <linux/input.h>
27 #include <linux/input/matrix_keypad.h>
28 #include <linux/delay.h>
29 #include <linux/gpio.h>
30
31 #include <linux/i2c/at24.h>
32 #include <linux/i2c/twl4030.h>
33 #include <linux/regulator/machine.h>
34
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/map.h>
38
39 #include <plat/board.h>
40 #include <plat/common.h>
41 #include <plat/mux.h>
42 #include <plat/nand.h>
43 #include <plat/gpmc.h>
44 #include <plat/usb.h>
45
46 #include <mach/hardware.h>
47
48 #include "mux.h"
49 #include "sdram-micron-mt46h32m32lf-6.h"
50 #include "mmc-twl4030.h"
51
52 #define CM_T35_GPIO_PENDOWN     57
53
54 #define CM_T35_SMSC911X_CS      5
55 #define CM_T35_SMSC911X_GPIO    163
56 #define SB_T35_SMSC911X_CS      4
57 #define SB_T35_SMSC911X_GPIO    65
58
59 #define NAND_BLOCK_SIZE         SZ_128K
60 #define GPMC_CS0_BASE           0x60
61 #define GPMC_CS0_BASE_ADDR      (OMAP34XX_GPMC_VIRT + GPMC_CS0_BASE)
62
63 #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
64 #include <linux/smsc911x.h>
65
66 static struct smsc911x_platform_config cm_t35_smsc911x_config = {
67         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
68         .irq_type       = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
69         .flags          = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
70         .phy_interface  = PHY_INTERFACE_MODE_MII,
71 };
72
73 static struct resource cm_t35_smsc911x_resources[] = {
74         {
75                 .flags  = IORESOURCE_MEM,
76         },
77         {
78                 .start  = OMAP_GPIO_IRQ(CM_T35_SMSC911X_GPIO),
79                 .end    = OMAP_GPIO_IRQ(CM_T35_SMSC911X_GPIO),
80                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
81         },
82 };
83
84 static struct platform_device cm_t35_smsc911x_device = {
85         .name           = "smsc911x",
86         .id             = 0,
87         .num_resources  = ARRAY_SIZE(cm_t35_smsc911x_resources),
88         .resource       = cm_t35_smsc911x_resources,
89         .dev            = {
90                 .platform_data = &cm_t35_smsc911x_config,
91         },
92 };
93
94 static struct resource sb_t35_smsc911x_resources[] = {
95         {
96                 .flags  = IORESOURCE_MEM,
97         },
98         {
99                 .start  = OMAP_GPIO_IRQ(SB_T35_SMSC911X_GPIO),
100                 .end    = OMAP_GPIO_IRQ(SB_T35_SMSC911X_GPIO),
101                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
102         },
103 };
104
105 static struct platform_device sb_t35_smsc911x_device = {
106         .name           = "smsc911x",
107         .id             = 1,
108         .num_resources  = ARRAY_SIZE(sb_t35_smsc911x_resources),
109         .resource       = sb_t35_smsc911x_resources,
110         .dev            = {
111                 .platform_data = &cm_t35_smsc911x_config,
112         },
113 };
114
115 static void __init cm_t35_init_smsc911x(struct platform_device *dev,
116                                         int cs, int irq_gpio)
117 {
118         unsigned long cs_mem_base;
119
120         if (gpmc_cs_request(cs, SZ_16M, &cs_mem_base) < 0) {
121                 pr_err("CM-T35: Failed request for GPMC mem for smsc911x\n");
122                 return;
123         }
124
125         dev->resource[0].start = cs_mem_base + 0x0;
126         dev->resource[0].end   = cs_mem_base + 0xff;
127
128         if ((gpio_request(irq_gpio, "ETH IRQ") == 0) &&
129             (gpio_direction_input(irq_gpio) == 0)) {
130                 gpio_export(irq_gpio, 0);
131         } else {
132                 pr_err("CM-T35: could not obtain gpio for SMSC911X IRQ\n");
133                 return;
134         }
135
136         platform_device_register(dev);
137 }
138
139 static void __init cm_t35_init_ethernet(void)
140 {
141         cm_t35_init_smsc911x(&cm_t35_smsc911x_device,
142                              CM_T35_SMSC911X_CS, CM_T35_SMSC911X_GPIO);
143         cm_t35_init_smsc911x(&sb_t35_smsc911x_device,
144                              SB_T35_SMSC911X_CS, SB_T35_SMSC911X_GPIO);
145 }
146 #else
147 static inline void __init cm_t35_init_ethernet(void) { return; }
148 #endif
149
150 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
151 #include <linux/leds.h>
152
153 static struct gpio_led cm_t35_leds[] = {
154         [0] = {
155                 .gpio                   = 186,
156                 .name                   = "cm-t35:green",
157                 .default_trigger        = "heartbeat",
158                 .active_low             = 0,
159         },
160 };
161
162 static struct gpio_led_platform_data cm_t35_led_pdata = {
163         .num_leds       = ARRAY_SIZE(cm_t35_leds),
164         .leds           = cm_t35_leds,
165 };
166
167 static struct platform_device cm_t35_led_device = {
168         .name           = "leds-gpio",
169         .id             = -1,
170         .dev            = {
171                 .platform_data  = &cm_t35_led_pdata,
172         },
173 };
174
175 static void __init cm_t35_init_led(void)
176 {
177         platform_device_register(&cm_t35_led_device);
178 }
179 #else
180 static inline void cm_t35_init_led(void) {}
181 #endif
182
183 #if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE)
184 #include <linux/mtd/mtd.h>
185 #include <linux/mtd/nand.h>
186 #include <linux/mtd/partitions.h>
187
188 static struct mtd_partition cm_t35_nand_partitions[] = {
189         {
190                 .name           = "xloader",
191                 .offset         = 0,                    /* Offset = 0x00000 */
192                 .size           = 4 * NAND_BLOCK_SIZE,
193                 .mask_flags     = MTD_WRITEABLE
194         },
195         {
196                 .name           = "uboot",
197                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
198                 .size           = 15 * NAND_BLOCK_SIZE,
199         },
200         {
201                 .name           = "uboot environment",
202                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x260000 */
203                 .size           = 2 * NAND_BLOCK_SIZE,
204         },
205         {
206                 .name           = "linux",
207                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
208                 .size           = 32 * NAND_BLOCK_SIZE,
209         },
210         {
211                 .name           = "rootfs",
212                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
213                 .size           = MTDPART_SIZ_FULL,
214         },
215 };
216
217 static struct omap_nand_platform_data cm_t35_nand_data = {
218         .parts                  = cm_t35_nand_partitions,
219         .nr_parts               = ARRAY_SIZE(cm_t35_nand_partitions),
220         .dma_channel            = -1,   /* disable DMA in OMAP NAND driver */
221         .cs                     = 0,
222         .gpmc_cs_baseaddr       = (void __iomem *)GPMC_CS0_BASE_ADDR,
223         .gpmc_baseaddr          = (void __iomem *)OMAP34XX_GPMC_VIRT,
224
225 };
226
227 static struct resource cm_t35_nand_resource = {
228         .flags          = IORESOURCE_MEM,
229 };
230
231 static struct platform_device cm_t35_nand_device = {
232         .name           = "omap2-nand",
233         .id             = -1,
234         .num_resources  = 1,
235         .resource       = &cm_t35_nand_resource,
236         .dev            = {
237                 .platform_data  = &cm_t35_nand_data,
238         },
239 };
240
241 static void __init cm_t35_init_nand(void)
242 {
243         if (platform_device_register(&cm_t35_nand_device) < 0)
244                 pr_err("CM-T35: Unable to register NAND device\n");
245 }
246 #else
247 static inline void cm_t35_init_nand(void) {}
248 #endif
249
250 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
251         defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
252 #include <linux/spi/spi.h>
253 #include <linux/spi/ads7846.h>
254
255 #include <plat/mcspi.h>
256
257 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
258         .turbo_mode     = 0,
259         .single_channel = 1,    /* 0: slave, 1: master */
260 };
261
262 static int ads7846_get_pendown_state(void)
263 {
264         return !gpio_get_value(CM_T35_GPIO_PENDOWN);
265 }
266
267 static struct ads7846_platform_data ads7846_config = {
268         .x_max                  = 0x0fff,
269         .y_max                  = 0x0fff,
270         .x_plate_ohms           = 180,
271         .pressure_max           = 255,
272         .debounce_max           = 10,
273         .debounce_tol           = 3,
274         .debounce_rep           = 1,
275         .get_pendown_state      = ads7846_get_pendown_state,
276         .keep_vref_on           = 1,
277 };
278
279 static struct spi_board_info cm_t35_spi_board_info[] __initdata = {
280         {
281                 .modalias               = "ads7846",
282                 .bus_num                = 1,
283                 .chip_select            = 0,
284                 .max_speed_hz           = 1500000,
285                 .controller_data        = &ads7846_mcspi_config,
286                 .irq                    = OMAP_GPIO_IRQ(CM_T35_GPIO_PENDOWN),
287                 .platform_data          = &ads7846_config,
288         },
289 };
290
291 static void __init cm_t35_init_ads7846(void)
292 {
293         if ((gpio_request(CM_T35_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
294             (gpio_direction_input(CM_T35_GPIO_PENDOWN) == 0)) {
295                 gpio_export(CM_T35_GPIO_PENDOWN, 0);
296         } else {
297                 pr_err("CM-T35: could not obtain gpio for ADS7846_PENDOWN\n");
298                 return;
299         }
300
301         spi_register_board_info(cm_t35_spi_board_info,
302                                 ARRAY_SIZE(cm_t35_spi_board_info));
303 }
304 #else
305 static inline void cm_t35_init_ads7846(void) {}
306 #endif
307
308 static struct regulator_consumer_supply cm_t35_vmmc1_supply = {
309         .supply                 = "vmmc",
310 };
311
312 static struct regulator_consumer_supply cm_t35_vsim_supply = {
313         .supply                 = "vmmc_aux",
314 };
315
316 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
317 static struct regulator_init_data cm_t35_vmmc1 = {
318         .constraints = {
319                 .min_uV                 = 1850000,
320                 .max_uV                 = 3150000,
321                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
322                                         | REGULATOR_MODE_STANDBY,
323                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
324                                         | REGULATOR_CHANGE_MODE
325                                         | REGULATOR_CHANGE_STATUS,
326         },
327         .num_consumer_supplies  = 1,
328         .consumer_supplies      = &cm_t35_vmmc1_supply,
329 };
330
331 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
332 static struct regulator_init_data cm_t35_vsim = {
333         .constraints = {
334                 .min_uV                 = 1800000,
335                 .max_uV                 = 3000000,
336                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
337                                         | REGULATOR_MODE_STANDBY,
338                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
339                                         | REGULATOR_CHANGE_MODE
340                                         | REGULATOR_CHANGE_STATUS,
341         },
342         .num_consumer_supplies  = 1,
343         .consumer_supplies      = &cm_t35_vsim_supply,
344 };
345
346 static struct twl4030_usb_data cm_t35_usb_data = {
347         .usb_mode       = T2_USB_MODE_ULPI,
348 };
349
350 static int cm_t35_keymap[] = {
351         KEY(0, 0, KEY_A),       KEY(0, 1, KEY_B),       KEY(0, 2, KEY_LEFT),
352         KEY(1, 0, KEY_UP),      KEY(1, 1, KEY_ENTER),   KEY(1, 2, KEY_DOWN),
353         KEY(2, 0, KEY_RIGHT),   KEY(2, 1, KEY_C),       KEY(2, 2, KEY_D),
354 };
355
356 static struct matrix_keymap_data cm_t35_keymap_data = {
357         .keymap                 = cm_t35_keymap,
358         .keymap_size            = ARRAY_SIZE(cm_t35_keymap),
359 };
360
361 static struct twl4030_keypad_data cm_t35_kp_data = {
362         .keymap_data    = &cm_t35_keymap_data,
363         .rows           = 3,
364         .cols           = 3,
365         .rep            = 1,
366 };
367
368 static struct twl4030_hsmmc_info mmc[] = {
369         {
370                 .mmc            = 1,
371                 .wires          = 4,
372                 .gpio_cd        = -EINVAL,
373                 .gpio_wp        = -EINVAL,
374
375         },
376         {
377                 .mmc            = 2,
378                 .wires          = 4,
379                 .transceiver    = 1,
380                 .gpio_cd        = -EINVAL,
381                 .gpio_wp        = -EINVAL,
382                 .ocr_mask       = 0x00100000,   /* 3.3V */
383         },
384         {}      /* Terminator */
385 };
386
387 static struct ehci_hcd_omap_platform_data ehci_pdata = {
388         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
389         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
390         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
391
392         .phy_reset  = true,
393         .reset_gpio_port[0]  = -EINVAL,
394         .reset_gpio_port[1]  = -EINVAL,
395         .reset_gpio_port[2]  = -EINVAL
396 };
397
398 static int cm_t35_twl_gpio_setup(struct device *dev, unsigned gpio,
399                                  unsigned ngpio)
400 {
401         int wlan_rst = gpio + 2;
402
403         if ((gpio_request(wlan_rst, "WLAN RST") == 0) &&
404             (gpio_direction_output(wlan_rst, 1) == 0)) {
405                 gpio_export(wlan_rst, 0);
406
407                 udelay(10);
408                 gpio_set_value(wlan_rst, 0);
409                 udelay(10);
410                 gpio_set_value(wlan_rst, 1);
411         } else {
412                 pr_err("CM-T35: could not obtain gpio for WiFi reset\n");
413         }
414
415         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
416         mmc[0].gpio_cd = gpio + 0;
417         twl4030_mmc_init(mmc);
418
419         /* link regulators to MMC adapters */
420         cm_t35_vmmc1_supply.dev = mmc[0].dev;
421         cm_t35_vsim_supply.dev = mmc[0].dev;
422
423         /* setup USB with proper PHY reset GPIOs */
424         ehci_pdata.reset_gpio_port[0] = gpio + 6;
425         ehci_pdata.reset_gpio_port[1] = gpio + 7;
426
427         usb_ehci_init(&ehci_pdata);
428
429         return 0;
430 }
431
432 static struct twl4030_gpio_platform_data cm_t35_gpio_data = {
433         .gpio_base      = OMAP_MAX_GPIO_LINES,
434         .irq_base       = TWL4030_GPIO_IRQ_BASE,
435         .irq_end        = TWL4030_GPIO_IRQ_END,
436         .setup          = cm_t35_twl_gpio_setup,
437 };
438
439 static struct twl4030_platform_data cm_t35_twldata = {
440         .irq_base       = TWL4030_IRQ_BASE,
441         .irq_end        = TWL4030_IRQ_END,
442
443         /* platform_data for children goes here */
444         .keypad         = &cm_t35_kp_data,
445         .usb            = &cm_t35_usb_data,
446         .gpio           = &cm_t35_gpio_data,
447         .vmmc1          = &cm_t35_vmmc1,
448         .vsim           = &cm_t35_vsim,
449 };
450
451 static struct i2c_board_info __initdata cm_t35_i2c_boardinfo[] = {
452         {
453                 I2C_BOARD_INFO("tps65930", 0x48),
454                 .flags          = I2C_CLIENT_WAKE,
455                 .irq            = INT_34XX_SYS_NIRQ,
456                 .platform_data  = &cm_t35_twldata,
457         },
458 };
459
460 static void __init cm_t35_init_i2c(void)
461 {
462         omap_register_i2c_bus(1, 2600, cm_t35_i2c_boardinfo,
463                               ARRAY_SIZE(cm_t35_i2c_boardinfo));
464 }
465
466 static struct omap_board_config_kernel cm_t35_config[] __initdata = {
467 };
468
469 static void __init cm_t35_init_irq(void)
470 {
471         omap_board_config = cm_t35_config;
472         omap_board_config_size = ARRAY_SIZE(cm_t35_config);
473
474         omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
475                              mt46h32m32lf6_sdrc_params);
476         omap_init_irq();
477         omap_gpio_init();
478 }
479
480 static void __init cm_t35_map_io(void)
481 {
482         omap2_set_globals_343x();
483         omap2_map_common_io();
484 }
485
486 #ifdef CONFIG_OMAP_MUX
487 static struct omap_board_mux board_mux[] __initdata = {
488         { .reg_offset = OMAP_MUX_TERMINATOR },
489 };
490 #else
491 #define board_mux       NULL
492 #endif
493
494 static void __init cm_t35_init(void)
495 {
496         omap3_mux_init(board_mux, OMAP_PACKAGE_CUS);
497         omap_serial_init();
498         cm_t35_init_i2c();
499         cm_t35_init_nand();
500         cm_t35_init_ads7846();
501         cm_t35_init_ethernet();
502         cm_t35_init_led();
503
504         usb_musb_init();
505
506         omap_mux_init_signal("sys_nirq",
507                 OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP);
508 }
509
510 MACHINE_START(CM_T35, "Compulab CM-T35")
511         .phys_io        = 0x48000000,
512         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
513         .boot_params    = 0x80000100,
514         .map_io         = cm_t35_map_io,
515         .init_irq       = cm_t35_init_irq,
516         .init_machine   = cm_t35_init,
517         .timer          = &omap_timer,
518 MACHINE_END