]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-rx51-peripherals.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-rx51-peripherals.c
1 /*
2  * linux/arch/arm/mach-omap2/board-rx51-flash.c
3  *
4  * Copyright (C) 2008-2009 Nokia
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/input.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/tsc2005.h>
17 #include <linux/i2c.h>
18 #include <linux/i2c/twl4030.h>
19 #include <linux/clk.h>
20 #include <linux/delay.h>
21 #include <linux/regulator/machine.h>
22
23 #include <mach/mcspi.h>
24 #include <mach/gpio.h>
25 #include <mach/mux.h>
26 #include <mach/board.h>
27 #include <mach/common.h>
28 #include <mach/dma.h>
29 #include <mach/gpmc.h>
30
31 #include "mmc-twl4030.h"
32
33 #define SYSTEM_REV_B_USES_VAUX3 0x1699
34 #define SYSTEM_REV_S_USES_VAUX3 0x8
35
36 #define SMC91X_CS                       1
37 #define SMC91X_GPIO_IRQ                 54
38 #define SMC91X_GPIO_RESET               164
39 #define SMC91X_GPIO_PWRDWN              86
40
41 #define RX51_TSC2005_RESET_GPIO         104
42 #define RX51_TSC2005_IRQ_GPIO           100
43
44 static struct resource rx51_smc91x_resources[] = {
45         [0] = {
46                 .flags          = IORESOURCE_MEM,
47         },
48         [1] = {
49                 .flags          = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
50         },
51 };
52
53 static struct platform_device rx51_smc91x_device = {
54         .name           = "smc91x",
55         .id             = -1,
56         .num_resources  = ARRAY_SIZE(rx51_smc91x_resources),
57         .resource       = rx51_smc91x_resources,
58 };
59
60 static struct tsc2005_platform_data tsc2005_config = {
61         .reset_gpio             = RX51_TSC2005_RESET_GPIO, /* not used */
62
63         .ts_x_plate_ohm         = 280,
64         .ts_hw_avg              = 0,
65         .ts_touch_pressure      = 1500,
66         .ts_stab_time           = 1000,
67         .ts_pressure_max        = 2048,
68         .ts_pressure_fudge      = 2,
69         .ts_x_max               = 4096,
70         .ts_x_fudge             = 4,
71         .ts_y_max               = 4096,
72         .ts_y_fudge             = 7,
73 };
74
75 static struct omap2_mcspi_device_config tsc2005_mcspi_config = {
76         .turbo_mode     = 0,
77         .single_channel = 1,
78 };
79
80 static struct spi_board_info rx51_peripherals_spi_board_info[] = {
81         [0] = {
82                 .modalias               = "tsc2005",
83                 .bus_num                = 1,
84                 .chip_select            = 0,
85                 .irq                    = OMAP_GPIO_IRQ(RX51_TSC2005_IRQ_GPIO),
86                 .max_speed_hz           = 6000000,
87                 .controller_data        = &tsc2005_mcspi_config,
88                 .platform_data          = &tsc2005_config,
89         },
90 };
91
92 static int rx51_keymap[] = {
93         KEY(0, 0, KEY_Q),
94         KEY(0, 1, KEY_W),
95         KEY(0, 2, KEY_E),
96         KEY(0, 3, KEY_R),
97         KEY(0, 4, KEY_T),
98         KEY(0, 5, KEY_Y),
99         KEY(0, 6, KEY_U),
100         KEY(0, 7, KEY_I),
101         KEY(1, 0, KEY_O),
102         KEY(1, 1, KEY_D),
103         KEY(1, 2, KEY_DOT),
104         KEY(1, 3, KEY_V),
105         KEY(1, 4, KEY_DOWN),
106         KEY(2, 0, KEY_P),
107         KEY(2, 1, KEY_F),
108         KEY(2, 2, KEY_UP),
109         KEY(2, 3, KEY_B),
110         KEY(2, 4, KEY_RIGHT),
111         KEY(3, 0, KEY_COMMA),
112         KEY(3, 1, KEY_G),
113         KEY(3, 2, KEY_ENTER),
114         KEY(3, 3, KEY_N),
115         KEY(4, 0, KEY_BACKSPACE),
116         KEY(4, 1, KEY_H),
117         KEY(4, 3, KEY_M),
118         KEY(4, 4, KEY_LEFTCTRL),
119         KEY(5, 1, KEY_J),
120         KEY(5, 2, KEY_Z),
121         KEY(5, 3, KEY_SPACE),
122         KEY(5, 4, KEY_LEFTSHIFT),
123         KEY(6, 0, KEY_A),
124         KEY(6, 1, KEY_K),
125         KEY(6, 2, KEY_X),
126         KEY(6, 3, KEY_SPACE),
127         KEY(6, 4, KEY_FN),
128         KEY(7, 0, KEY_S),
129         KEY(7, 1, KEY_L),
130         KEY(7, 2, KEY_C),
131         KEY(7, 3, KEY_LEFT),
132         KEY(0xff, 0, KEY_F6),
133         KEY(0xff, 1, KEY_F7),
134         KEY(0xff, 2, KEY_F8),
135         KEY(0xff, 4, KEY_F9),
136         KEY(0xff, 5, KEY_F10),
137 };
138
139 static struct twl4030_keypad_data rx51_kp_data = {
140         .rows           = 8,
141         .cols           = 8,
142         .keymap         = rx51_keymap,
143         .keymapsize     = ARRAY_SIZE(rx51_keymap),
144         .rep            = 1,
145 };
146
147 static struct platform_device *rx51_peripherals_devices[] = {
148         &rx51_smc91x_device,
149 };
150
151 /*
152  * Timings are taken from smsc-lan91c96-ms.pdf
153  */
154 static int smc91x_init_gpmc(int cs)
155 {
156         struct gpmc_timings t;
157         const int t2_r = 45;            /* t2 in Figure 12.10 */
158         const int t2_w = 30;            /* t2 in Figure 12.11 */
159         const int t3 = 15;              /* t3 in Figure 12.10 */
160         const int t5_r = 0;             /* t5 in Figure 12.10 */
161         const int t6_r = 45;            /* t6 in Figure 12.10 */
162         const int t6_w = 0;             /* t6 in Figure 12.11 */
163         const int t7_w = 15;            /* t7 in Figure 12.11 */
164         const int t15 = 12;             /* t15 in Figure 12.2 */
165         const int t20 = 185;            /* t20 in Figure 12.2 */
166
167         memset(&t, 0, sizeof(t));
168
169         t.cs_on = t15;
170         t.cs_rd_off = t3 + t2_r + t5_r; /* Figure 12.10 */
171         t.cs_wr_off = t3 + t2_w + t6_w; /* Figure 12.11 */
172         t.adv_on = t3;                  /* Figure 12.10 */
173         t.adv_rd_off = t3 + t2_r;       /* Figure 12.10 */
174         t.adv_wr_off = t3 + t2_w;       /* Figure 12.11 */
175         t.oe_off = t3 + t2_r + t5_r;    /* Figure 12.10 */
176         t.oe_on = t.oe_off - t6_r;      /* Figure 12.10 */
177         t.we_off = t3 + t2_w + t6_w;    /* Figure 12.11 */
178         t.we_on = t.we_off - t7_w;      /* Figure 12.11 */
179         t.rd_cycle = t20;               /* Figure 12.2 */
180         t.wr_cycle = t20;               /* Figure 12.4 */
181         t.access = t3 + t2_r + t5_r;    /* Figure 12.10 */
182         t.wr_access = t3 + t2_w + t6_w; /* Figure 12.11 */
183
184         gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, GPMC_CONFIG1_DEVICESIZE_16);
185
186         return gpmc_cs_set_timings(cs, &t);
187 }
188
189 static void __init rx51_init_smc91x(void)
190 {
191         unsigned long cs_mem_base;
192         int ret;
193
194         omap_cfg_reg(U8_34XX_GPIO54_DOWN);
195         omap_cfg_reg(G25_34XX_GPIO86_OUT);
196         omap_cfg_reg(H19_34XX_GPIO164_OUT);
197
198         if (gpmc_cs_request(SMC91X_CS, SZ_16M, &cs_mem_base) < 0) {
199                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
200                 return;
201         }
202
203         rx51_smc91x_resources[0].start = cs_mem_base + 0x300;
204         rx51_smc91x_resources[0].end = cs_mem_base + 0x30f;
205
206         smc91x_init_gpmc(SMC91X_CS);
207
208         if (gpio_request(SMC91X_GPIO_IRQ, "SMC91X irq") < 0)
209                 goto free1;
210
211         gpio_direction_input(SMC91X_GPIO_IRQ);
212         rx51_smc91x_resources[1].start = gpio_to_irq(SMC91X_GPIO_IRQ);
213
214         ret = gpio_request(SMC91X_GPIO_PWRDWN, "SMC91X powerdown");
215         if (ret)
216                 goto free2;
217         gpio_direction_output(SMC91X_GPIO_PWRDWN, 0);
218
219         ret = gpio_request(SMC91X_GPIO_RESET, "SMC91X reset");
220         if (ret)
221                 goto free3;
222         gpio_direction_output(SMC91X_GPIO_RESET, 0);
223         gpio_set_value(SMC91X_GPIO_RESET, 1);
224         msleep(100);
225         gpio_set_value(SMC91X_GPIO_RESET, 0);
226
227         return;
228
229 free3:
230         gpio_free(SMC91X_GPIO_PWRDWN);
231 free2:
232         gpio_free(SMC91X_GPIO_IRQ);
233 free1:
234         gpmc_cs_free(SMC91X_CS);
235
236         printk(KERN_ERR "Could not initialize smc91x\n");
237 }
238
239 static void __init rx51_init_tsc2005(void)
240 {
241         int r;
242
243         r = gpio_request(RX51_TSC2005_IRQ_GPIO, "tsc2005 DAV IRQ");
244         if (r >= 0) {
245                 gpio_direction_input(RX51_TSC2005_IRQ_GPIO);
246         } else {
247                 printk(KERN_ERR "unable to get DAV GPIO");
248         }
249 }
250
251 static struct twl4030_madc_platform_data rx51_madc_data = {
252         .irq_line               = 1,
253 };
254
255 static struct twl4030_hsmmc_info mmc[] = {
256         {
257                 .name           = "external",
258                 .mmc            = 1,
259                 .wires          = 4,
260                 .cover_only     = true,
261                 .gpio_cd        = 160,
262                 .gpio_wp        = -EINVAL,
263         },
264         {
265                 .name           = "internal",
266                 .mmc            = 2,
267                 .wires          = 8,
268                 .gpio_cd        = -EINVAL,
269                 .gpio_wp        = -EINVAL,
270         },
271         {}      /* Terminator */
272 };
273
274 static struct regulator_consumer_supply rx51_vmmc1_supply = {
275         .supply                 = "vmmc",
276 };
277
278 static struct regulator_consumer_supply rx51_vmmc2_supply = {
279         .supply                 = "vmmc",
280 };
281
282 static struct regulator_consumer_supply rx51_vsim_supply = {
283         .supply                 = "vmmc_aux",
284 };
285
286 static struct regulator_init_data rx51_vaux1 = {
287         .constraints = {
288                 .name                   = "V28",
289                 .min_uV                 = 2800000,
290                 .max_uV                 = 2800000,
291                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
292                                         | REGULATOR_MODE_STANDBY,
293                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
294                                         | REGULATOR_CHANGE_STATUS,
295         },
296 };
297
298 static struct regulator_init_data rx51_vaux2 = {
299         .constraints = {
300                 .name                   = "VCSI",
301                 .min_uV                 = 1800000,
302                 .max_uV                 = 1800000,
303                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
304                                         | REGULATOR_MODE_STANDBY,
305                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
306                                         | REGULATOR_CHANGE_STATUS,
307         },
308 };
309
310 /* VAUX3 - adds more power to VIO_18 rail */
311 static struct regulator_init_data rx51_vaux3_cam = {
312         .constraints = {
313                 .name                   = "VCAM_DIG_18",
314                 .min_uV                 = 1800000,
315                 .max_uV                 = 1800000,
316                 .apply_uV               = true,
317                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
318                                         | REGULATOR_MODE_STANDBY,
319                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
320                                         | REGULATOR_CHANGE_STATUS,
321         },
322 };
323
324 static struct regulator_init_data rx51_vaux3_mmc = {
325         .constraints = {
326                 .name                   = "VMMC2_30",
327                 .min_uV                 = 2800000,
328                 .max_uV                 = 3000000,
329                 .apply_uV               = true,
330                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
331                                         | REGULATOR_MODE_STANDBY,
332                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
333                                         | REGULATOR_CHANGE_MODE
334                                         | REGULATOR_CHANGE_STATUS,
335         },
336         .num_consumer_supplies  = 1,
337         .consumer_supplies      = &rx51_vmmc2_supply,
338 };
339
340 static struct regulator_init_data rx51_vaux4 = {
341         .constraints = {
342                 .name                   = "VCAM_ANA_28",
343                 .min_uV                 = 2800000,
344                 .max_uV                 = 2800000,
345                 .apply_uV               = true,
346                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
347                                         | REGULATOR_MODE_STANDBY,
348                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
349                                         | REGULATOR_CHANGE_STATUS,
350         },
351 };
352
353 static struct regulator_init_data rx51_vmmc1 = {
354         .constraints = {
355                 .min_uV                 = 1850000,
356                 .max_uV                 = 3150000,
357                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
358                                         | REGULATOR_MODE_STANDBY,
359                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
360                                         | REGULATOR_CHANGE_MODE
361                                         | REGULATOR_CHANGE_STATUS,
362         },
363         .num_consumer_supplies  = 1,
364         .consumer_supplies      = &rx51_vmmc1_supply,
365 };
366
367 static struct regulator_init_data rx51_vmmc2 = {
368         .constraints = {
369                 .name                   = "VMMC2_30",
370                 .min_uV                 = 1850000,
371                 .max_uV                 = 3150000,
372                 .apply_uV               = true,
373                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
374                                         | REGULATOR_MODE_STANDBY,
375                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
376                                         | REGULATOR_CHANGE_MODE
377                                         | REGULATOR_CHANGE_STATUS,
378         },
379         .num_consumer_supplies  = 1,
380         .consumer_supplies      = &rx51_vmmc2_supply,
381 };
382
383 static struct regulator_init_data rx51_vsim = {
384         .constraints = {
385                 .name                   = "VMMC2_IO_18",
386                 .min_uV                 = 1800000,
387                 .max_uV                 = 1800000,
388                 .apply_uV               = true,
389                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
390                                         | REGULATOR_MODE_STANDBY,
391                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
392                                         | REGULATOR_CHANGE_STATUS,
393         },
394         .num_consumer_supplies  = 1,
395         .consumer_supplies      = &rx51_vsim_supply,
396 };
397
398 static struct regulator_init_data rx51_vdac = {
399         .constraints = {
400                 .min_uV                 = 1800000,
401                 .max_uV                 = 1800000,
402                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
403                                         | REGULATOR_MODE_STANDBY,
404                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
405                                         | REGULATOR_CHANGE_MODE
406                                         | REGULATOR_CHANGE_STATUS,
407         },
408 };
409
410 static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
411 {
412         /* FIXME this gpio setup is just a placeholder for now */
413         gpio_request(gpio + 6, "backlight_pwm");
414         gpio_direction_output(gpio + 6, 0);
415         gpio_request(gpio + 7, "speaker_en");
416         gpio_direction_output(gpio + 7, 1);
417
418         /* set up MMC adapters, linking their regulators to them */
419         twl4030_mmc_init(mmc);
420         rx51_vmmc1_supply.dev = mmc[0].dev;
421         rx51_vmmc2_supply.dev = mmc[1].dev;
422         rx51_vsim_supply.dev = mmc[1].dev;
423
424         return 0;
425 }
426
427 static struct twl4030_gpio_platform_data rx51_gpio_data = {
428         .gpio_base              = OMAP_MAX_GPIO_LINES,
429         .irq_base               = TWL4030_GPIO_IRQ_BASE,
430         .irq_end                = TWL4030_GPIO_IRQ_END,
431         .pulldowns              = BIT(0) | BIT(1) | BIT(2) | BIT(3)
432                                 | BIT(4) | BIT(5)
433                                 | BIT(8) | BIT(9) | BIT(10) | BIT(11)
434                                 | BIT(12) | BIT(13) | BIT(14) | BIT(15)
435                                 | BIT(16) | BIT(17) ,
436         .setup                  = rx51_twlgpio_setup,
437 };
438
439 static struct twl4030_platform_data rx51_twldata = {
440         .irq_base               = TWL4030_IRQ_BASE,
441         .irq_end                = TWL4030_IRQ_END,
442
443         /* platform_data for children goes here */
444         .gpio                   = &rx51_gpio_data,
445         .keypad                 = &rx51_kp_data,
446         .madc                   = &rx51_madc_data,
447
448         .vaux1                  = &rx51_vaux1,
449         .vaux2                  = &rx51_vaux2,
450         .vaux4                  = &rx51_vaux4,
451         .vmmc1                  = &rx51_vmmc1,
452         .vsim                   = &rx51_vsim,
453         .vdac                   = &rx51_vdac,
454 };
455
456 static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
457         {
458                 I2C_BOARD_INFO("twl5030", 0x48),
459                 .flags = I2C_CLIENT_WAKE,
460                 .irq = INT_34XX_SYS_NIRQ,
461                 .platform_data = &rx51_twldata,
462         },
463 };
464
465 static int __init rx51_i2c_init(void)
466 {
467         if ((system_rev >= SYSTEM_REV_S_USES_VAUX3 && system_rev < 0x100) ||
468             system_rev >= SYSTEM_REV_B_USES_VAUX3)
469                 rx51_twldata.vaux3 = &rx51_vaux3_mmc;
470         else {
471                 rx51_twldata.vaux3 = &rx51_vaux3_cam;
472                 rx51_twldata.vmmc2 = &rx51_vmmc2;
473         }
474         omap_register_i2c_bus(1, 2600, rx51_peripherals_i2c_board_info_1,
475                         ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
476         omap_register_i2c_bus(2, 100, NULL, 0);
477         omap_register_i2c_bus(3, 400, NULL, 0);
478         return 0;
479 }
480
481
482 void __init rx51_peripherals_init(void)
483 {
484         platform_add_devices(rx51_peripherals_devices,
485                                 ARRAY_SIZE(rx51_peripherals_devices));
486         spi_register_board_info(rx51_peripherals_spi_board_info,
487                                 ARRAY_SIZE(rx51_peripherals_spi_board_info));
488         rx51_i2c_init();
489         rx51_init_smc91x();
490         rx51_init_tsc2005();
491 }
492