]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-n800.c
I2C: LM8323: Introduce lm8323 keypad driver
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-n800.c
1 /*
2  * linux/arch/arm/mach-omap2/board-n800.c
3  *
4  * Copyright (C) 2005-2007 Nokia Corporation
5  * Author: Juha Yrjola <juha.yrjola@nokia.com>
6  *
7  * Modified from mach-omap2/board-generic.c
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/clk.h>
17 #include <linux/device.h>
18 #include <linux/platform_device.h>
19 #include <linux/spi/spi.h>
20 #include <linux/spi/tsc2301.h>
21 #include <linux/input.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c/lm8323.h>
27 #include <asm/hardware.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
31 #include <asm/arch/gpio.h>
32 #include <asm/arch/usb.h>
33 #include <asm/arch/board.h>
34 #include <asm/arch/common.h>
35 #include <asm/arch/mcspi.h>
36 #include <asm/arch/menelaus.h>
37 #include <asm/arch/lcd_mipid.h>
38 #include <asm/arch/clock.h>
39 #include <asm/arch/gpio-switch.h>
40 #include <asm/arch/omapfb.h>
41 #include <asm/arch/blizzard.h>
42
43 #include <../drivers/cbus/tahvo.h>
44 #include <../drivers/media/video/tcm825x.h>
45
46 #define N800_BLIZZARD_POWERDOWN_GPIO    15
47 #define N800_STI_GPIO                   62
48 #define N800_KEYB_IRQ_GPIO              109
49 #define N800_DAV_IRQ_GPIO               103
50 #define N800_TSC2301_RESET_GPIO         118
51
52 #ifdef CONFIG_MACH_NOKIA_N810
53 static s16 rx44_keymap[LM8323_KEYMAP_SIZE] = {
54         [0x01] = KEY_Q,
55         [0x02] = KEY_K,
56         [0x03] = KEY_O,
57         [0x04] = KEY_P,
58         [0x05] = KEY_BACKSPACE,
59         [0x06] = KEY_A,
60         [0x07] = KEY_S,
61         [0x08] = KEY_D,
62         [0x09] = KEY_F,
63         [0x0a] = KEY_G,
64         [0x0b] = KEY_H,
65         [0x0c] = KEY_J,
66
67         [0x11] = KEY_W,
68         [0x12] = KEY_F4,
69         [0x13] = KEY_L,
70         [0x14] = KEY_APOSTROPHE,
71         [0x16] = KEY_Z,
72         [0x17] = KEY_X,
73         [0x18] = KEY_C,
74         [0x19] = KEY_V,
75         [0x1a] = KEY_B,
76         [0x1b] = KEY_N,
77         [0x1c] = KEY_LEFTSHIFT, /* Actually, this is both shift keys */
78         [0x1f] = KEY_F7,
79
80         [0x21] = KEY_E,
81         [0x22] = KEY_SEMICOLON,
82         [0x23] = KEY_MINUS,
83         [0x24] = KEY_EQUAL,
84         [0x2b] = KEY_FN,
85         [0x2c] = KEY_M,
86         [0x2f] = KEY_F8,
87
88         [0x31] = KEY_R,
89         [0x32] = KEY_RIGHTCTRL,
90         [0x34] = KEY_SPACE,
91         [0x35] = KEY_COMMA,
92         [0x37] = KEY_UP,
93         [0x3c] = KEY_COMPOSE,
94         [0x3f] = KEY_F6,
95
96         [0x41] = KEY_T,
97         [0x44] = KEY_DOT,
98         [0x46] = KEY_RIGHT,
99         [0x4f] = KEY_F5,
100         [0x51] = KEY_Y,
101         [0x53] = KEY_DOWN,
102         [0x55] = KEY_ENTER,
103         [0x5f] = KEY_ESC,
104
105         [0x61] = KEY_U,
106         [0x64] = KEY_LEFT,
107
108         [0x71] = KEY_I,
109         [0x75] = KEY_KPENTER,
110 };
111
112 static struct lm8323_platform_data lm8323_pdata = {
113         .repeat = 0, /* Repeat is handled in userspace for now. */
114         .keymap = rx44_keymap,
115
116         .name = "Internal keyboard",
117         .pwm1_name = "keyboard",
118         .pwm2_name = "cover",
119 };
120 #endif
121
122 void __init nokia_n800_init_irq(void)
123 {
124         omap2_init_common_hw();
125         omap_init_irq();
126         omap_gpio_init();
127
128 #ifdef CONFIG_OMAP_STI
129         if (omap_request_gpio(N800_STI_GPIO) < 0) {
130                 printk(KERN_ERR "Failed to request GPIO %d for STI\n",
131                        N800_STI_GPIO);
132                 return;
133         }
134
135         omap_set_gpio_direction(N800_STI_GPIO, 0);
136         omap_set_gpio_dataout(N800_STI_GPIO, 0);
137 #endif
138 }
139
140 #if defined(CONFIG_MENELAUS) && defined(CONFIG_SENSORS_TMP105)
141
142 static int n800_tmp105_set_power(int enable)
143 {
144         return menelaus_set_vaux(enable ? 2800 : 0);
145 }
146
147 #else
148
149 #define n800_tmp105_set_power NULL
150
151 #endif
152
153 static struct omap_uart_config n800_uart_config __initdata = {
154         .enabled_uarts = (1 << 0) | (1 << 2),
155 };
156
157 #include "../../../drivers/cbus/retu.h"
158
159 static struct omap_fbmem_config n800_fbmem0_config __initdata = {
160         .size = 752 * 1024,
161 };
162
163 static struct omap_fbmem_config n800_fbmem1_config __initdata = {
164         .size = 752 * 1024,
165 };
166
167 static struct omap_fbmem_config n800_fbmem2_config __initdata = {
168         .size = 752 * 1024,
169 };
170
171 static struct omap_tmp105_config n800_tmp105_config __initdata = {
172         .tmp105_irq_pin = 125,
173         .set_power = n800_tmp105_set_power,
174 };
175
176 static void mipid_shutdown(struct mipid_platform_data *pdata)
177 {
178         if (pdata->nreset_gpio != -1) {
179                 pr_info("shutdown LCD\n");
180                 omap_set_gpio_dataout(pdata->nreset_gpio, 0);
181                 msleep(120);
182         }
183 }
184
185 static struct mipid_platform_data n800_mipid_platform_data = {
186         .shutdown = mipid_shutdown,
187 };
188
189 static void __init mipid_dev_init(void)
190 {
191         const struct omap_lcd_config *conf;
192
193         conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
194         if (conf != NULL) {
195                 n800_mipid_platform_data.nreset_gpio = conf->nreset_gpio;
196                 n800_mipid_platform_data.data_lines = conf->data_lines;
197         }
198 }
199
200 static struct {
201         struct clk *sys_ck;
202 } blizzard;
203
204 static int blizzard_get_clocks(void)
205 {
206         blizzard.sys_ck = clk_get(0, "osc_ck");
207         if (IS_ERR(blizzard.sys_ck)) {
208                 printk(KERN_ERR "can't get Blizzard clock\n");
209                 return PTR_ERR(blizzard.sys_ck);
210         }
211         return 0;
212 }
213
214 static unsigned long blizzard_get_clock_rate(struct device *dev)
215 {
216         return clk_get_rate(blizzard.sys_ck);
217 }
218
219 static void blizzard_enable_clocks(int enable)
220 {
221         if (enable)
222                 clk_enable(blizzard.sys_ck);
223         else
224                 clk_disable(blizzard.sys_ck);
225 }
226
227 static void blizzard_power_up(struct device *dev)
228 {
229         /* Vcore to 1.475V */
230         tahvo_set_clear_reg_bits(0x07, 0, 0xf);
231         msleep(10);
232
233         blizzard_enable_clocks(1);
234         omap_set_gpio_dataout(N800_BLIZZARD_POWERDOWN_GPIO, 1);
235 }
236
237 static void blizzard_power_down(struct device *dev)
238 {
239         omap_set_gpio_dataout(N800_BLIZZARD_POWERDOWN_GPIO, 0);
240         blizzard_enable_clocks(0);
241
242         /* Vcore to 1.005V */
243         tahvo_set_clear_reg_bits(0x07, 0xf, 0);
244 }
245
246 static struct blizzard_platform_data n800_blizzard_data = {
247         .power_up       = blizzard_power_up,
248         .power_down     = blizzard_power_down,
249         .get_clock_rate = blizzard_get_clock_rate,
250         .te_connected   = 1,
251 };
252
253 static void __init blizzard_dev_init(void)
254 {
255         int r;
256
257         r = omap_request_gpio(N800_BLIZZARD_POWERDOWN_GPIO);
258         if (r < 0)
259                 return;
260         omap_set_gpio_direction(N800_BLIZZARD_POWERDOWN_GPIO, 0);
261         omap_set_gpio_dataout(N800_BLIZZARD_POWERDOWN_GPIO, 1);
262
263         blizzard_get_clocks();
264         omapfb_set_ctrl_platform_data(&n800_blizzard_data);
265 }
266
267 static struct omap_mmc_config n800_mmc_config __initdata = {
268         .mmc [0] = {
269                 .enabled                = 1,
270                 .wire4                  = 1,
271         },
272 };
273
274 extern struct omap_mmc_platform_data n800_mmc_data;
275
276 static struct omap_board_config_kernel n800_config[] __initdata = {
277         { OMAP_TAG_UART,                        &n800_uart_config },
278         { OMAP_TAG_FBMEM,                       &n800_fbmem0_config },
279         { OMAP_TAG_FBMEM,                       &n800_fbmem1_config },
280         { OMAP_TAG_FBMEM,                       &n800_fbmem2_config },
281         { OMAP_TAG_TMP105,                      &n800_tmp105_config },
282         { OMAP_TAG_MMC,                         &n800_mmc_config },
283 };
284
285 static struct tsc2301_platform_data tsc2301_config = {
286         .reset_gpio     = N800_TSC2301_RESET_GPIO,
287         .keymap = {
288                 -1,             /* Event for bit 0 */
289                 KEY_UP,         /* Event for bit 1 (up) */
290                 KEY_F5,         /* Event for bit 2 (home) */
291                 -1,             /* Event for bit 3 */
292                 KEY_LEFT,       /* Event for bit 4 (left) */
293                 KEY_ENTER,      /* Event for bit 5 (enter) */
294                 KEY_RIGHT,      /* Event for bit 6 (right) */
295                 -1,             /* Event for bit 7 */
296                 KEY_ESC,        /* Event for bit 8 (cycle) */
297                 KEY_DOWN,       /* Event for bit 9 (down) */
298                 KEY_F4,         /* Event for bit 10 (menu) */
299                 -1,             /* Event for bit 11 */
300                 KEY_F8,         /* Event for bit 12 (Zoom-) */
301                 KEY_F6,         /* Event for bit 13 (FS) */
302                 KEY_F7,         /* Event for bit 14 (Zoom+) */
303                 -1,             /* Event for bit 15 */
304         },
305         .kp_rep         = 0,
306         .keyb_name      = "Internal keypad",
307 };
308
309 static void tsc2301_dev_init(void)
310 {
311         int r;
312         int gpio = N800_KEYB_IRQ_GPIO;
313
314         r = gpio_request(gpio, "tsc2301 KBD IRQ");
315         if (r >= 0) {
316                 gpio_direction_input(gpio);
317                 tsc2301_config.keyb_int = OMAP_GPIO_IRQ(gpio);
318         } else {
319                 printk(KERN_ERR "unable to get KBD GPIO");
320         }
321
322         gpio = N800_DAV_IRQ_GPIO;
323         r = gpio_request(gpio, "tsc2301 DAV IRQ");
324         if (r >= 0) {
325                 gpio_direction_input(gpio);
326                 tsc2301_config.dav_int = OMAP_GPIO_IRQ(gpio);
327         } else {
328                 printk(KERN_ERR "unable to get DAV GPIO");
329         }
330 }
331
332 static int __init tea5761_dev_init(void)
333 {
334         const struct omap_tea5761_config *info;
335         int enable_gpio = 0;
336
337         info = omap_get_config(OMAP_TAG_TEA5761, struct omap_tea5761_config);
338         if (info)
339                 enable_gpio = info->enable_gpio;
340
341         if (enable_gpio) {
342                 pr_debug("Enabling tea5761 at GPIO %d\n",
343                          enable_gpio);
344
345                 if (omap_request_gpio(enable_gpio) < 0) {
346                         printk(KERN_ERR "Can't request GPIO %d\n",
347                                enable_gpio);
348                         return -ENODEV;
349                 }
350
351                 omap_set_gpio_direction(enable_gpio, 0);
352                 udelay(50);
353                 omap_set_gpio_dataout(enable_gpio, 1);
354         }
355
356         return 0;
357 }
358
359 static struct omap2_mcspi_device_config tsc2301_mcspi_config = {
360         .turbo_mode     = 0,
361         .single_channel = 1,
362 };
363
364 static struct omap2_mcspi_device_config mipid_mcspi_config = {
365         .turbo_mode     = 0,
366         .single_channel = 1,
367 };
368
369 static struct omap2_mcspi_device_config cx3110x_mcspi_config = {
370         .turbo_mode     = 0,
371         .single_channel = 1,
372 };
373
374 static struct spi_board_info n800_spi_board_info[] __initdata = {
375         [0] = {
376                 .modalias       = "lcd_mipid",
377                 .bus_num        = 1,
378                 .chip_select    = 1,
379                 .max_speed_hz   = 4000000,
380                 .controller_data= &mipid_mcspi_config,
381                 .platform_data  = &n800_mipid_platform_data,
382         }, [1] = {
383                 .modalias       = "cx3110x",
384                 .bus_num        = 2,
385                 .chip_select    = 0,
386                 .max_speed_hz   = 48000000,
387                 .controller_data= &cx3110x_mcspi_config,
388         }, [2] = {
389                 .modalias       = "tsc2301",
390                 .bus_num        = 1,
391                 .chip_select    = 0,
392                 .max_speed_hz   = 6000000,
393                 .controller_data= &tsc2301_mcspi_config,
394                 .platform_data  = &tsc2301_config,
395         },
396 };
397
398 #if defined(CONFIG_CBUS_RETU) && defined(CONFIG_LEDS_OMAP_PWM)
399
400 void retu_keypad_led_set_power(struct omap_pwm_led_platform_data *self,
401                                int on_off)
402 {
403         if (on_off) {
404                 retu_write_reg(RETU_REG_CTRL_SET, 1 << 6);
405                 msleep(2);
406                 retu_write_reg(RETU_REG_CTRL_SET, 1 << 3);
407         } else {
408                 retu_write_reg(RETU_REG_CTRL_CLR, (1 << 6) | (1 << 3));
409         }
410 }
411
412 static struct omap_pwm_led_platform_data n800_keypad_led_data = {
413         .name = "keypad",
414         .intensity_timer = 10,
415         .blink_timer = 9,
416         .set_power = retu_keypad_led_set_power,
417 };
418
419 static struct platform_device n800_keypad_led_device = {
420         .name           = "omap_pwm_led",
421         .id             = -1,
422         .dev            = {
423                 .platform_data = &n800_keypad_led_data,
424         },
425 };
426 #endif
427
428 #if defined(CONFIG_TOUCHSCREEN_TSC2301)
429 static void __init n800_ts_set_config(void)
430 {
431         const struct omap_lcd_config *conf;
432
433         conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
434         if (conf != NULL) {
435                 if (strcmp(conf->panel_name, "lph8923") == 0) {
436                         tsc2301_config.ts_x_plate_ohm   = 180;
437                         tsc2301_config.ts_hw_avg        = 8;
438                         tsc2301_config.ts_max_pressure  = 2048;
439                         tsc2301_config.ts_touch_pressure = 400;
440                         tsc2301_config.ts_stab_time     = 100;
441                         tsc2301_config.ts_pressure_fudge = 2;
442                         tsc2301_config.ts_x_max         = 4096;
443                         tsc2301_config.ts_x_fudge       = 4;
444                         tsc2301_config.ts_y_max         = 4096;
445                         tsc2301_config.ts_y_fudge       = 7;
446                 } else if (strcmp(conf->panel_name, "ls041y3") == 0) {
447                         tsc2301_config.ts_x_plate_ohm   = 280;
448                         tsc2301_config.ts_hw_avg        = 8;
449                         tsc2301_config.ts_touch_pressure = 400;
450                         tsc2301_config.ts_max_pressure  = 2048;
451                         tsc2301_config.ts_stab_time     = 1000;
452                         tsc2301_config.ts_pressure_fudge = 2;
453                         tsc2301_config.ts_x_max         = 4096;
454                         tsc2301_config.ts_x_fudge       = 4;
455                         tsc2301_config.ts_y_max         = 4096;
456                         tsc2301_config.ts_y_fudge       = 7;
457                 } else {
458                         printk(KERN_ERR "Unknown panel type, set default "
459                                "touchscreen configuration\n");
460                         tsc2301_config.ts_x_plate_ohm   = 200;
461                         tsc2301_config.ts_stab_time     = 100;
462                 }
463         }
464 }
465 #else
466 static inline void n800_ts_set_config(void)
467 {
468 }
469 #endif
470
471 static struct omap_gpio_switch n800_gpio_switches[] __initdata = {
472         {
473                 .name                   = "bat_cover",
474                 .gpio                   = -1,
475                 .debounce_rising        = 100,
476                 .debounce_falling       = 0,
477                 .notify                 = n800_mmc_slot1_cover_handler,
478                 .notify_data            = NULL,
479         }, {
480                 .name                   = "headphone",
481                 .gpio                   = -1,
482                 .debounce_rising        = 200,
483                 .debounce_falling       = 200,
484         }, {
485                 .name                   = "cam_act",
486                 .gpio                   = -1,
487                 .debounce_rising        = 200,
488                 .debounce_falling       = 200,
489         }, {
490                 .name                   = "cam_turn",
491                 .gpio                   = -1,
492                 .debounce_rising        = 100,
493                 .debounce_falling       = 100,
494         },
495 };
496
497 static struct platform_device *n800_devices[] __initdata = {
498 #if defined(CONFIG_CBUS_RETU) && defined(CONFIG_LEDS_OMAP_PWM)
499         &n800_keypad_led_device,
500 #endif
501 };
502
503 #ifdef CONFIG_MENELAUS
504 static int n800_auto_sleep_regulators(void)
505 {
506         u32 val;
507         int ret;
508
509         val = EN_VPLL_SLEEP | EN_VMMC_SLEEP    \
510                 | EN_VAUX_SLEEP | EN_VIO_SLEEP \
511                 | EN_VMEM_SLEEP | EN_DC3_SLEEP \
512                 | EN_VC_SLEEP | EN_DC2_SLEEP;
513
514         ret = menelaus_set_regulator_sleep(1, val);
515         if (ret < 0) {
516                 printk(KERN_ERR "Could not set regulators to sleep on "
517                         "menelaus: %u\n", ret);
518                 return ret;
519         }
520         return 0;
521 }
522
523 static int n800_auto_voltage_scale(void)
524 {
525         int ret;
526
527         ret = menelaus_set_vcore_hw(1400, 1050);
528         if (ret < 0) {
529                 printk(KERN_ERR "Could not set VCORE voltage on "
530                         "menelaus: %u\n", ret);
531                 return ret;
532         }
533         return 0;
534 }
535
536 static int n800_menelaus_init(struct device *dev)
537 {
538         int ret;
539
540         ret = n800_auto_voltage_scale();
541         if (ret < 0)
542                 return ret;
543         ret = n800_auto_sleep_regulators();
544         if (ret < 0)
545                 return ret;
546         return 0;
547 }
548
549 static struct menelaus_platform_data n800_menelaus_platform_data = {
550         .late_init = n800_menelaus_init,
551 };
552 #endif
553
554 static struct i2c_board_info __initdata n800_i2c_board_info_1[] = {
555         {
556                 I2C_BOARD_INFO("menelaus", 0x72),
557                 .irq = INT_24XX_SYS_NIRQ,
558                 .platform_data = &n800_menelaus_platform_data,
559         },
560 };
561
562 extern struct tcm825x_platform_data n800_tcm825x_platform_data;
563
564 static struct i2c_board_info __initdata n800_i2c_board_info_2[] = {
565 #if defined (CONFIG_VIDEO_TCM825X) || defined (CONFIG_VIDEO_TCM825X_MODULE)
566         {
567                 I2C_BOARD_INFO(TCM825X_NAME, TCM825X_I2C_ADDR),
568                 .platform_data = &n800_tcm825x_platform_data,
569         },
570 #endif
571 #if defined(CONFIG_RADIO_TEA5761) || defined(CONFIG_RADIO_TEA5761_MODULE)
572         {
573                 I2C_BOARD_INFO("tea5761", 0x10),
574         },
575 #endif
576         {
577                 I2C_BOARD_INFO("lm8323", 0x45),
578                 .type           = "lm8323",
579                 .irq            = OMAP_GPIO_IRQ(109),
580                 .platform_data  = &lm8323_pdata,
581         },
582 };
583
584 void __init nokia_n800_common_init(void)
585 {
586         platform_add_devices(n800_devices, ARRAY_SIZE(n800_devices));
587
588         n800_flash_init();
589         n800_mmc_init();
590         n800_bt_init();
591         n800_dsp_init();
592         n800_usb_init();
593         n800_cam_init();
594         spi_register_board_info(n800_spi_board_info,
595                                 ARRAY_SIZE(n800_spi_board_info));
596         omap_serial_init();
597         omap_register_i2c_bus(1, 400, n800_i2c_board_info_1,
598                               ARRAY_SIZE(n800_i2c_board_info_1));
599         omap_register_i2c_bus(2, 400, n800_i2c_board_info_2,
600                               ARRAY_SIZE(n800_i2c_board_info_2));
601         mipid_dev_init();
602         blizzard_dev_init();
603 }
604
605 static void __init nokia_n800_init(void)
606 {
607         nokia_n800_common_init();
608
609         n800_audio_init(&tsc2301_config);
610         n800_ts_set_config();
611         tsc2301_dev_init();
612         tea5761_dev_init();
613         omap_register_gpio_switches(n800_gpio_switches,
614                                     ARRAY_SIZE(n800_gpio_switches));
615 }
616
617 void __init nokia_n800_map_io(void)
618 {
619         omap_board_config = n800_config;
620         omap_board_config_size = ARRAY_SIZE(n800_config);
621
622         omap2_set_globals_242x();
623         omap2_map_common_io();
624 }
625
626 MACHINE_START(NOKIA_N800, "Nokia N800")
627         .phys_io        = 0x48000000,
628         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
629         .boot_params    = 0x80000100,
630         .map_io         = nokia_n800_map_io,
631         .init_irq       = nokia_n800_init_irq,
632         .init_machine   = nokia_n800_init,
633         .timer          = &omap_timer,
634 MACHINE_END