46669fda33ed32b9d7e8cca4f0c70b642739dfbc
[openembedded.git] /
1 From d732dfd967b870ea5effa599d501996b620a1f60 Mon Sep 17 00:00:00 2001
2 From: Gregoire Gentil <gregoire@gentil.com>
3 Date: Fri, 12 Mar 2010 11:49:16 +0100
4 Subject: [PATCH 06/14] ARM: OMAP: omap3-touchbook: update boardfile
5
6 ---
7  arch/arm/mach-omap2/board-omap3touchbook.c |  390 +++++++++++++++++++++-------
8  1 files changed, 301 insertions(+), 89 deletions(-)
9
10 diff --git a/arch/arm/mach-omap2/board-omap3touchbook.c b/arch/arm/mach-omap2/board-omap3touchbook.c
11 index fc3e03c..4f89cf3 100644
12 --- a/arch/arm/mach-omap2/board-omap3touchbook.c
13 +++ b/arch/arm/mach-omap2/board-omap3touchbook.c
14 @@ -33,6 +33,7 @@
15  #include <linux/spi/spi.h>
16  
17  #include <linux/spi/ads7846.h>
18 +#include <linux/mma7455l.h>
19  
20  #include <linux/regulator/machine.h>
21  #include <linux/i2c/twl.h>
22 @@ -45,6 +46,7 @@
23  
24  #include <plat/board.h>
25  #include <plat/common.h>
26 +#include <plat/display.h>
27  #include <plat/gpmc.h>
28  #include <plat/nand.h>
29  #include <plat/usb.h>
30 @@ -60,6 +62,8 @@
31  
32  #include <asm/setup.h>
33  
34 +#include <plat/dmtimer.h>
35 +#include <linux/backlight.h>
36  
37  #define GPMC_CS0_BASE  0x60
38  #define GPMC_CS_SIZE   0x30
39 @@ -68,10 +72,11 @@
40  
41  #define OMAP3_AC_GPIO          136
42  #define OMAP3_TS_GPIO          162
43 +#define OMAP3_CHACHA_GPIO      154
44  #define TB_BL_PWM_TIMER                9
45  #define TB_KILL_POWER_GPIO     168
46  
47 -unsigned long touchbook_revision;
48 +unsigned long ai_revision = 2;
49  
50  static struct mtd_partition omap3touchbook_nand_partitions[] = {
51         /* All the partition sizes are listed in terms of NAND block size */
52 @@ -126,6 +131,103 @@ static struct platform_device omap3touchbook_nand_device = {
53         .resource       = &omap3touchbook_nand_resource,
54  };
55  
56 +static int touchbook_enable_dvi(struct omap_dss_device *dssdev)
57 +{
58 +       if (dssdev->reset_gpio != -1)
59 +               gpio_set_value(dssdev->reset_gpio, 1);
60 +
61 +       return 0;
62 +}
63 +
64 +static void touchbook_disable_dvi(struct omap_dss_device *dssdev)
65 +{
66 +       if (dssdev->reset_gpio != -1)
67 +               gpio_set_value(dssdev->reset_gpio, 0);
68 +}
69 +
70 +static struct omap_dss_device touchbook_dvi_device = {
71 +       .type = OMAP_DISPLAY_TYPE_DPI,
72 +       .name = "dvi",
73 +       .driver_name = "generic_panel",
74 +       .phy.dpi.data_lines = 24,
75 +       .reset_gpio = 176,
76 +       .platform_enable = touchbook_enable_dvi,
77 +       .platform_disable = touchbook_disable_dvi,
78 +};
79 +
80 +static int touchbook_panel_enable_tv(struct omap_dss_device *dssdev)
81 +{
82 +#define ENABLE_VDAC_DEDICATED           0x03
83 +#define ENABLE_VDAC_DEV_GRP             0x20
84 +
85 +       twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
86 +                       ENABLE_VDAC_DEDICATED,
87 +                       TWL4030_VDAC_DEDICATED);
88 +       twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
89 +                       ENABLE_VDAC_DEV_GRP, TWL4030_VDAC_DEV_GRP);
90 +
91 +       return 0;
92 +}
93 +
94 +static void touchbook_panel_disable_tv(struct omap_dss_device *dssdev)
95 +{
96 +       twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
97 +                       TWL4030_VDAC_DEDICATED);
98 +       twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
99 +                       TWL4030_VDAC_DEV_GRP);
100 +}
101 +
102 +static struct omap_dss_device touchbook_tv_device = {
103 +       .name = "tv",
104 +       .driver_name = "venc",
105 +       .type = OMAP_DISPLAY_TYPE_VENC,
106 +       .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
107 +       .platform_enable = touchbook_panel_enable_tv,
108 +       .platform_disable = touchbook_panel_disable_tv,
109 +};
110 +
111 +static struct omap_dss_device *touchbook_dss_devices[] = {
112 +       &touchbook_dvi_device,
113 +       &touchbook_tv_device,
114 +};
115 +
116 +static struct omap_dss_board_info touchbook_dss_data = {
117 +       .num_devices = ARRAY_SIZE(touchbook_dss_devices),
118 +       .devices = touchbook_dss_devices,
119 +       .default_device = &touchbook_dvi_device,
120 +};
121 +
122 +static struct platform_device touchbook_dss_device = {
123 +       .name           = "omapdss",
124 +       .id             = -1,
125 +       .dev            = {
126 +               .platform_data = &touchbook_dss_data,
127 +       },
128 +};
129 +
130 +static struct regulator_consumer_supply touchbook_vdac_supply = {
131 +       .supply         = "vdda_dac",
132 +       .dev            = &touchbook_dss_device.dev,
133 +};
134 +
135 +static struct regulator_consumer_supply touchbook_vdvi_supply = {
136 +       .supply         = "vdds_dsi",
137 +       .dev            = &touchbook_dss_device.dev,
138 +};
139 +
140 +static void __init touchbook_display_init(void)
141 +{
142 +       int r;
143 +
144 +       r = gpio_request(touchbook_dvi_device.reset_gpio, "DVI reset");
145 +       if (r < 0) {
146 +               printk(KERN_ERR "Unable to get DVI reset GPIO\n");
147 +               return;
148 +       }
149 +
150 +       gpio_direction_output(touchbook_dvi_device.reset_gpio, 0);
151 +}
152 +
153  #include "sdram-micron-mt46h32m32lf-6.h"
154  
155  static struct twl4030_hsmmc_info mmc[] = {
156 @@ -137,15 +239,6 @@ static struct twl4030_hsmmc_info mmc[] = {
157         {}      /* Terminator */
158  };
159  
160 -static struct platform_device omap3_touchbook_lcd_device = {
161 -       .name           = "omap3touchbook_lcd",
162 -       .id             = -1,
163 -};
164 -
165 -static struct omap_lcd_config omap3_touchbook_lcd_config __initdata = {
166 -       .ctrl_name      = "internal",
167 -};
168 -
169  static struct regulator_consumer_supply touchbook_vmmc1_supply = {
170         .supply                 = "vmmc",
171  };
172 @@ -177,6 +270,7 @@ static int touchbook_twl_gpio_setup(struct device *dev,
173          * power switch and overcurrent detect
174          */
175  
176 +#if 0
177         gpio_request(gpio + 1, "EHCI_nOC");
178         gpio_direction_input(gpio + 1);
179  
180 @@ -187,6 +281,7 @@ static int touchbook_twl_gpio_setup(struct device *dev,
181         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
182         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
183  
184 +#endif
185         return 0;
186  }
187  
188 @@ -201,16 +296,6 @@ static struct twl4030_gpio_platform_data touchbook_gpio_data = {
189         .setup          = touchbook_twl_gpio_setup,
190  };
191  
192 -static struct regulator_consumer_supply touchbook_vdac_supply = {
193 -       .supply         = "vdac",
194 -       .dev            = &omap3_touchbook_lcd_device.dev,
195 -};
196 -
197 -static struct regulator_consumer_supply touchbook_vdvi_supply = {
198 -       .supply         = "vdvi",
199 -       .dev            = &omap3_touchbook_lcd_device.dev,
200 -};
201 -
202  /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
203  static struct regulator_init_data touchbook_vmmc1 = {
204         .constraints = {
205 @@ -283,6 +368,10 @@ static struct twl4030_codec_data touchbook_codec_data = {
206         .audio = &touchbook_audio_data,
207  };
208  
209 +static struct twl4030_madc_platform_data touchbook_madc_data = {
210 +       .irq_line       = 1,
211 +};
212 +
213  static struct twl4030_platform_data touchbook_twldata = {
214         .irq_base       = TWL4030_IRQ_BASE,
215         .irq_end        = TWL4030_IRQ_END,
216 @@ -291,6 +380,7 @@ static struct twl4030_platform_data touchbook_twldata = {
217         .usb            = &touchbook_usb_data,
218         .gpio           = &touchbook_gpio_data,
219         .codec          = &touchbook_codec_data,
220 +       .madc           = &touchbook_madc_data,
221         .vmmc1          = &touchbook_vmmc1,
222         .vsim           = &touchbook_vsim,
223         .vdac           = &touchbook_vdac,
224 @@ -310,10 +400,18 @@ static struct i2c_board_info __initdata touchBook_i2c_boardinfo[] = {
225         {
226                 I2C_BOARD_INFO("bq27200", 0x55),
227         },
228 +       {
229 +               I2C_BOARD_INFO("chacha", 0x40),
230 +               .irq = OMAP_GPIO_IRQ(OMAP3_CHACHA_GPIO),
231 +       },
232 +       {
233 +               I2C_BOARD_INFO("ds1307", 0x68),
234 +       },
235  };
236  
237  static int __init omap3_touchbook_i2c_init(void)
238  {
239 +       int ret;
240         /* Standard TouchBook bus */
241         omap_register_i2c_bus(1, 2600, touchbook_i2c_boardinfo,
242                         ARRAY_SIZE(touchbook_i2c_boardinfo));
243 @@ -322,53 +420,16 @@ static int __init omap3_touchbook_i2c_init(void)
244         omap_register_i2c_bus(3, 100, touchBook_i2c_boardinfo,
245                         ARRAY_SIZE(touchBook_i2c_boardinfo));
246  
247 -       return 0;
248 -}
249 -
250 -static void __init omap3_ads7846_init(void)
251 -{
252 -       if (gpio_request(OMAP3_TS_GPIO, "ads7846_pen_down")) {
253 -               printk(KERN_ERR "Failed to request GPIO %d for "
254 -                               "ads7846 pen down IRQ\n", OMAP3_TS_GPIO);
255 -               return;
256 +       ret = gpio_request(OMAP3_CHACHA_GPIO, "chacha");
257 +       if (ret < 0) {
258 +               printk(KERN_ERR "Failed to request GPIO %d for chacha IRQ\n", OMAP3_CHACHA_GPIO);
259 +               return 0;
260         }
261 +       gpio_direction_input(OMAP3_CHACHA_GPIO);
262  
263 -       gpio_direction_input(OMAP3_TS_GPIO);
264 -       omap_set_gpio_debounce(OMAP3_TS_GPIO, 1);
265 -       omap_set_gpio_debounce_time(OMAP3_TS_GPIO, 0xa);
266 +       return 0;
267  }
268  
269 -static struct ads7846_platform_data ads7846_config = {
270 -       .x_min                  = 100,
271 -       .y_min                  = 265,
272 -       .x_max                  = 3950,
273 -       .y_max                  = 3750,
274 -       .x_plate_ohms           = 40,
275 -       .pressure_max           = 255,
276 -       .debounce_max           = 10,
277 -       .debounce_tol           = 5,
278 -       .debounce_rep           = 1,
279 -       .gpio_pendown           = OMAP3_TS_GPIO,
280 -       .keep_vref_on           = 1,
281 -};
282 -
283 -static struct omap2_mcspi_device_config ads7846_mcspi_config = {
284 -       .turbo_mode     = 0,
285 -       .single_channel = 1,    /* 0: slave, 1: master */
286 -};
287 -
288 -static struct spi_board_info omap3_ads7846_spi_board_info[] __initdata = {
289 -       {
290 -               .modalias               = "ads7846",
291 -               .bus_num                = 4,
292 -               .chip_select            = 0,
293 -               .max_speed_hz           = 1500000,
294 -               .controller_data        = &ads7846_mcspi_config,
295 -               .irq                    = OMAP_GPIO_IRQ(OMAP3_TS_GPIO),
296 -               .platform_data          = &ads7846_config,
297 -       }
298 -};
299 -
300  static struct gpio_led gpio_leds[] = {
301         {
302                 .name                   = "touchbook::usr0",
303 @@ -412,6 +473,7 @@ static struct gpio_keys_button gpio_buttons[] = {
304                 .gpio                   = 183,
305                 .desc                   = "power",
306                 .wakeup                 = 1,
307 +               .active_low             = 1,
308         },
309  };
310  
311 @@ -428,23 +490,8 @@ static struct platform_device keys_gpio = {
312         },
313  };
314  
315 -static struct omap_board_config_kernel omap3_touchbook_config[] __initdata = {
316 -       { OMAP_TAG_LCD,         &omap3_touchbook_lcd_config },
317 -};
318 -
319 -#ifdef CONFIG_OMAP_MUX
320 -static struct omap_board_mux board_mux[] __initdata = {
321 -       { .reg_offset = OMAP_MUX_TERMINATOR },
322 -};
323 -#else
324 -#define board_mux      NULL
325 -#endif
326 -
327  static void __init omap3_touchbook_init_irq(void)
328  {
329 -       omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
330 -       omap_board_config = omap3_touchbook_config;
331 -       omap_board_config_size = ARRAY_SIZE(omap3_touchbook_config);
332         omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
333                              mt46h32m32lf6_sdrc_params, omap35x_mpu_rate_table,
334                              omap35x_dsp_rate_table, omap35x_l3_rate_table);
335 @@ -456,9 +503,9 @@ static void __init omap3_touchbook_init_irq(void)
336  }
337  
338  static struct platform_device *omap3_touchbook_devices[] __initdata = {
339 -       &omap3_touchbook_lcd_device,
340         &leds_gpio,
341         &keys_gpio,
342 +       &touchbook_dss_device,
343  };
344  
345  static void __init omap3touchbook_flash_init(void)
346 @@ -512,6 +559,166 @@ static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
347         .reset_gpio_port[2]  = -EINVAL
348  };
349  
350 +#ifdef CONFIG_OMAP_MUX
351 +static struct omap_board_mux board_mux[] __initdata = {
352 +       { .reg_offset = OMAP_MUX_TERMINATOR },
353 +};
354 +#else
355 +#define board_mux      NULL
356 +#endif
357 +
358 +static struct ads7846_platform_data ads7846_config = {
359 +       .x_min                  = 100,
360 +       .y_min                  = 265,
361 +       .x_max                  = 3950,
362 +       .y_max                  = 3750,
363 +       .x_plate_ohms           = 40,
364 +       .pressure_max           = 255,
365 +       .debounce_max           = 10,
366 +       .debounce_tol           = 5,
367 +       .debounce_rep           = 1,
368 +       .gpio_pendown           = OMAP3_TS_GPIO,
369 +       .keep_vref_on           = 1,
370 +};
371 +
372 +static struct omap2_mcspi_device_config ads7846_mcspi_config = {
373 +       .turbo_mode     = 0,
374 +       .single_channel = 1,    /* 0: slave, 1: master */
375 +};
376 +
377 +static struct spi_board_info omap3_ads7846_spi_board_info[] __initdata = {
378 +       {
379 +               .modalias               = "ads7846",
380 +               .bus_num                = 4,
381 +               .chip_select            = 0,
382 +               .max_speed_hz           = 1500000,
383 +               .controller_data        = &ads7846_mcspi_config,
384 +               .irq                    = OMAP_GPIO_IRQ(OMAP3_TS_GPIO),
385 +               .platform_data          = &ads7846_config,
386 +       }
387 +};
388 +
389 +static void __init omap3_ads7846_init(void)
390 +{
391 +       if (gpio_request(OMAP3_TS_GPIO, "ads7846_pen_down")) {
392 +               printk(KERN_ERR "Failed to request GPIO %d for "
393 +                               "ads7846 pen down IRQ\n", OMAP3_TS_GPIO);
394 +               return;
395 +       }
396 +
397 +       gpio_direction_input(OMAP3_TS_GPIO);
398 +       omap_set_gpio_debounce(OMAP3_TS_GPIO, 1);
399 +       omap_set_gpio_debounce_time(OMAP3_TS_GPIO, 0xa);
400 +}
401 +
402 +static struct mma7455l_platform_data mma7455l_config = {
403 +       .calibration_x = -4,
404 +       .calibration_y = 28,
405 +       .calibration_z = -28,
406 +};
407 +
408 +static struct omap2_mcspi_device_config mma7455l_mcspi_config = {
409 +       .turbo_mode     = 0,
410 +       .single_channel = 1,    /* 0: slave, 1: master */
411 +};
412 +
413 +static struct spi_board_info omap3_mma7455l_spi_board_info[] __initdata = {
414 +       {
415 +               .modalias               = "mma7455l",
416 +               .bus_num                = 3,
417 +               .chip_select            = 0,
418 +               .max_speed_hz           = 200000,
419 +               .irq                    = OMAP_GPIO_IRQ(OMAP3_AC_GPIO),
420 +               .controller_data        = &mma7455l_mcspi_config, //(void *) 135,
421 +               .platform_data          = &mma7455l_config,
422 +       }
423 +};
424 +
425 +static void __init omap3_mma7455l_init(void)
426 +{
427 +       int ret;
428 +
429 +       ret = gpio_request(OMAP3_AC_GPIO, "mma7455l");
430 +       if (ret < 0) {
431 +               printk(KERN_ERR "Failed to request GPIO %d for mma7455l IRQ\n", OMAP3_AC_GPIO);
432 +               return;
433 +       }
434 +
435 +       gpio_direction_input(OMAP3_AC_GPIO);
436 +}
437 +
438 +static int touchbook_backlight_brightness = 50;
439 +static struct omap_dm_timer *touchbook_backlight_pwm;
440 +
441 +static int touchbook_backlight_read(struct backlight_device *bd)
442 +{
443 +       return touchbook_backlight_brightness;
444 +}
445 +
446 +static int touchbook_backlight_update(struct backlight_device *bd)
447 +{
448 +       int value = bd->props.brightness;
449 +       touchbook_backlight_brightness = value;
450 +
451 +       /* Frequency calculation:
452 +          - For 200Hz PWM, you want to load -164 (=> -32768Hz / 200Hz).
453 +          - Minimum duty cycle for the backlight is 15%.
454 +          - You have (164*0.85) => ~140 levels of brightness.
455 +       */
456 +
457 +       /* Halve input brightness */
458 +       value /= 2;
459 +
460 +       /* For maximum brightness, just stop the timer... */
461 +       if(value != bd->props.max_brightness)
462 +       {
463 +               /* Load the appropriate value for 200Hz PWM */
464 +               u32 period = clk_get_rate(omap_dm_timer_get_fclk(touchbook_backlight_pwm)) / 200;
465 +
466 +               /* Minimum duty cycle is 15% */
467 +               u32 minimum = (period * 3) / 20;
468 +               u32 maximum = (period * 17) / 20;
469 +
470 +               /* Work out match value */
471 +               u32 match = (maximum * value) / 100;
472 +
473 +               /* Start... */
474 +               omap_dm_timer_set_load(touchbook_backlight_pwm, 1, 0xFFFFFFFF - period - 1);
475 +               omap_dm_timer_set_match(touchbook_backlight_pwm, 1, 0xFFFFFFFF - minimum - match);
476 +               omap_dm_timer_write_counter(touchbook_backlight_pwm, -1);
477 +               omap_dm_timer_start(touchbook_backlight_pwm);
478 +       }
479 +       else
480 +               omap_dm_timer_stop(touchbook_backlight_pwm);
481 +
482 +
483 +       return 0;
484 +}
485 +
486 +static struct backlight_ops touchbook_backlight_properties = {
487 +       .get_brightness = touchbook_backlight_read,
488 +       .update_status = touchbook_backlight_update,
489 +};
490 +
491 +static void __init omap3_touchbook_backlight_init(void)
492 +{
493 +       static struct backlight_device *bd;
494 +       bd = backlight_device_register("touchbook", NULL, NULL, &touchbook_backlight_properties);
495 +
496 +       if(bd)
497 +       {
498 +               touchbook_backlight_pwm = omap_dm_timer_request_specific(TB_BL_PWM_TIMER);
499 +               omap_dm_timer_enable(touchbook_backlight_pwm);
500 +               omap_dm_timer_set_source(touchbook_backlight_pwm, OMAP_TIMER_SRC_SYS_CLK);
501 +               omap_dm_timer_set_pwm(touchbook_backlight_pwm, 1, 1, OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE);
502 +
503 +               bd->props.max_brightness = 100;
504 +               bd->props.brightness = touchbook_backlight_brightness;
505 +       }
506 +
507 +       touchbook_backlight_update(bd);
508 +}
509 +
510  static void omap3_touchbook_poweroff(void)
511  {
512         int r;
513 @@ -525,33 +732,27 @@ static void omap3_touchbook_poweroff(void)
514         gpio_direction_output(TB_KILL_POWER_GPIO, 0);
515  }
516  
517 -static void __init early_touchbook_revision(char **p)
518 +static void __init early_ai_revision(char **p)
519  {
520         if (!*p)
521                 return;
522  
523 -       strict_strtoul(*p, 10, &touchbook_revision);
524 +       strict_strtoul(*p, 10, &ai_revision);
525  }
526 -__early_param("tbr=", early_touchbook_revision);
527 +__early_param("air=", early_ai_revision);
528  
529  static void __init omap3_touchbook_init(void)
530  {
531         pm_power_off = omap3_touchbook_poweroff;
532  
533 +       omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
534         omap3_touchbook_i2c_init();
535         platform_add_devices(omap3_touchbook_devices,
536                         ARRAY_SIZE(omap3_touchbook_devices));
537         omap_serial_init();
538  
539 -       omap_mux_init_gpio(170, OMAP_PIN_INPUT);
540         gpio_request(176, "DVI_nPD");
541 -       /* REVISIT leave DVI powered down until it's needed ... */
542 -       gpio_direction_output(176, true);
543  
544 -       /* Touchscreen and accelerometer */
545 -       spi_register_board_info(omap3_ads7846_spi_board_info,
546 -                               ARRAY_SIZE(omap3_ads7846_spi_board_info));
547 -       omap3_ads7846_init();
548         usb_musb_init();
549         usb_ehci_init(&ehci_pdata);
550         omap3touchbook_flash_init();
551 @@ -559,6 +760,17 @@ static void __init omap3_touchbook_init(void)
552         /* Ensure SDRC pins are mux'd for self-refresh */
553         omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
554         omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
555 +
556 +       touchbook_display_init();
557 +       omap3_touchbook_backlight_init();
558 +
559 +       /* Touchscreen and accelerometer */
560 +       spi_register_board_info(omap3_ads7846_spi_board_info,
561 +                               ARRAY_SIZE(omap3_ads7846_spi_board_info));
562 +       spi_register_board_info(omap3_mma7455l_spi_board_info,
563 +                               ARRAY_SIZE(omap3_mma7455l_spi_board_info));
564 +       omap3_ads7846_init();
565 +       omap3_mma7455l_init();
566  }
567  
568  static void __init omap3_touchbook_map_io(void)
569 -- 
570 1.6.6.1
571