]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-n800.c
i2c: tea5761: New-style i2c 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 <asm/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/arch/gpio.h>
31 #include <asm/arch/usb.h>
32 #include <asm/arch/board.h>
33 #include <asm/arch/common.h>
34 #include <asm/arch/mcspi.h>
35 #include <asm/arch/menelaus.h>
36 #include <asm/arch/lcd_mipid.h>
37 #include <asm/arch/clock.h>
38 #include <asm/arch/gpio-switch.h>
39 #include <asm/arch/omapfb.h>
40 #include <asm/arch/blizzard.h>
41
42 #include <../drivers/cbus/tahvo.h>
43 #include <../drivers/media/video/tcm825x.h>
44
45 #define N800_BLIZZARD_POWERDOWN_GPIO    15
46 #define N800_STI_GPIO                   62
47 #define N800_KEYB_IRQ_GPIO              109
48 #define N800_DAV_IRQ_GPIO               103
49 #define N800_TSC2301_RESET_GPIO         118
50
51 void __init nokia_n800_init_irq(void)
52 {
53         omap2_init_common_hw();
54         omap_init_irq();
55         omap_gpio_init();
56
57 #ifdef CONFIG_OMAP_STI
58         if (omap_request_gpio(N800_STI_GPIO) < 0) {
59                 printk(KERN_ERR "Failed to request GPIO %d for STI\n",
60                        N800_STI_GPIO);
61                 return;
62         }
63
64         omap_set_gpio_direction(N800_STI_GPIO, 0);
65         omap_set_gpio_dataout(N800_STI_GPIO, 0);
66 #endif
67 }
68
69 #if defined(CONFIG_MENELAUS) && defined(CONFIG_SENSORS_TMP105)
70
71 static int n800_tmp105_set_power(int enable)
72 {
73         return menelaus_set_vaux(enable ? 2800 : 0);
74 }
75
76 #else
77
78 #define n800_tmp105_set_power NULL
79
80 #endif
81
82 static struct omap_uart_config n800_uart_config __initdata = {
83         .enabled_uarts = (1 << 0) | (1 << 2),
84 };
85
86 #include "../../../drivers/cbus/retu.h"
87
88 static struct omap_fbmem_config n800_fbmem0_config __initdata = {
89         .size = 752 * 1024,
90 };
91
92 static struct omap_fbmem_config n800_fbmem1_config __initdata = {
93         .size = 752 * 1024,
94 };
95
96 static struct omap_fbmem_config n800_fbmem2_config __initdata = {
97         .size = 752 * 1024,
98 };
99
100 static struct omap_tmp105_config n800_tmp105_config __initdata = {
101         .tmp105_irq_pin = 125,
102         .set_power = n800_tmp105_set_power,
103 };
104
105 static void mipid_shutdown(struct mipid_platform_data *pdata)
106 {
107         if (pdata->nreset_gpio != -1) {
108                 pr_info("shutdown LCD\n");
109                 omap_set_gpio_dataout(pdata->nreset_gpio, 0);
110                 msleep(120);
111         }
112 }
113
114 static struct mipid_platform_data n800_mipid_platform_data = {
115         .shutdown = mipid_shutdown,
116 };
117
118 static void __init mipid_dev_init(void)
119 {
120         const struct omap_lcd_config *conf;
121
122         conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
123         if (conf != NULL) {
124                 n800_mipid_platform_data.nreset_gpio = conf->nreset_gpio;
125                 n800_mipid_platform_data.data_lines = conf->data_lines;
126         }
127 }
128
129 static struct {
130         struct clk *sys_ck;
131 } blizzard;
132
133 static int blizzard_get_clocks(void)
134 {
135         blizzard.sys_ck = clk_get(0, "osc_ck");
136         if (IS_ERR(blizzard.sys_ck)) {
137                 printk(KERN_ERR "can't get Blizzard clock\n");
138                 return PTR_ERR(blizzard.sys_ck);
139         }
140         return 0;
141 }
142
143 static unsigned long blizzard_get_clock_rate(struct device *dev)
144 {
145         return clk_get_rate(blizzard.sys_ck);
146 }
147
148 static void blizzard_enable_clocks(int enable)
149 {
150         if (enable)
151                 clk_enable(blizzard.sys_ck);
152         else
153                 clk_disable(blizzard.sys_ck);
154 }
155
156 static void blizzard_power_up(struct device *dev)
157 {
158         /* Vcore to 1.475V */
159         tahvo_set_clear_reg_bits(0x07, 0, 0xf);
160         msleep(10);
161
162         blizzard_enable_clocks(1);
163         omap_set_gpio_dataout(N800_BLIZZARD_POWERDOWN_GPIO, 1);
164 }
165
166 static void blizzard_power_down(struct device *dev)
167 {
168         omap_set_gpio_dataout(N800_BLIZZARD_POWERDOWN_GPIO, 0);
169         blizzard_enable_clocks(0);
170
171         /* Vcore to 1.005V */
172         tahvo_set_clear_reg_bits(0x07, 0xf, 0);
173 }
174
175 static struct blizzard_platform_data n800_blizzard_data = {
176         .power_up       = blizzard_power_up,
177         .power_down     = blizzard_power_down,
178         .get_clock_rate = blizzard_get_clock_rate,
179         .te_connected   = 1,
180 };
181
182 static void __init blizzard_dev_init(void)
183 {
184         int r;
185
186         r = omap_request_gpio(N800_BLIZZARD_POWERDOWN_GPIO);
187         if (r < 0)
188                 return;
189         omap_set_gpio_direction(N800_BLIZZARD_POWERDOWN_GPIO, 0);
190         omap_set_gpio_dataout(N800_BLIZZARD_POWERDOWN_GPIO, 1);
191
192         blizzard_get_clocks();
193         omapfb_set_ctrl_platform_data(&n800_blizzard_data);
194 }
195
196 static struct omap_mmc_config n800_mmc_config __initdata = {
197         .mmc [0] = {
198                 .enabled                = 1,
199                 .wire4                  = 1,
200         },
201 };
202
203 extern struct omap_mmc_platform_data n800_mmc_data;
204
205 static struct omap_board_config_kernel n800_config[] __initdata = {
206         { OMAP_TAG_UART,                        &n800_uart_config },
207         { OMAP_TAG_FBMEM,                       &n800_fbmem0_config },
208         { OMAP_TAG_FBMEM,                       &n800_fbmem1_config },
209         { OMAP_TAG_FBMEM,                       &n800_fbmem2_config },
210         { OMAP_TAG_TMP105,                      &n800_tmp105_config },
211         { OMAP_TAG_MMC,                         &n800_mmc_config },
212 };
213
214 static struct tsc2301_platform_data tsc2301_config = {
215         .reset_gpio     = N800_TSC2301_RESET_GPIO,
216         .keymap = {
217                 -1,             /* Event for bit 0 */
218                 KEY_UP,         /* Event for bit 1 (up) */
219                 KEY_F5,         /* Event for bit 2 (home) */
220                 -1,             /* Event for bit 3 */
221                 KEY_LEFT,       /* Event for bit 4 (left) */
222                 KEY_ENTER,      /* Event for bit 5 (enter) */
223                 KEY_RIGHT,      /* Event for bit 6 (right) */
224                 -1,             /* Event for bit 7 */
225                 KEY_ESC,        /* Event for bit 8 (cycle) */
226                 KEY_DOWN,       /* Event for bit 9 (down) */
227                 KEY_F4,         /* Event for bit 10 (menu) */
228                 -1,             /* Event for bit 11 */
229                 KEY_F8,         /* Event for bit 12 (Zoom-) */
230                 KEY_F6,         /* Event for bit 13 (FS) */
231                 KEY_F7,         /* Event for bit 14 (Zoom+) */
232                 -1,             /* Event for bit 15 */
233         },
234         .kp_rep         = 0,
235         .keyb_name      = "Internal keypad",
236 };
237
238 static void tsc2301_dev_init(void)
239 {
240         int r;
241         int gpio = N800_KEYB_IRQ_GPIO;
242
243         r = gpio_request(gpio, "tsc2301 KBD IRQ");
244         if (r >= 0) {
245                 gpio_direction_input(gpio);
246                 tsc2301_config.keyb_int = OMAP_GPIO_IRQ(gpio);
247         } else {
248                 printk(KERN_ERR "unable to get KBD GPIO");
249         }
250
251         gpio = N800_DAV_IRQ_GPIO;
252         r = gpio_request(gpio, "tsc2301 DAV IRQ");
253         if (r >= 0) {
254                 gpio_direction_input(gpio);
255                 tsc2301_config.dav_int = OMAP_GPIO_IRQ(gpio);
256         } else {
257                 printk(KERN_ERR "unable to get DAV GPIO");
258         }
259 }
260
261 static int __init tea5761_dev_init(void)
262 {
263         const struct omap_tea5761_config *info;
264         int enable_gpio = 0;
265
266         info = omap_get_config(OMAP_TAG_TEA5761, struct omap_tea5761_config);
267         if (info)
268                 enable_gpio = info->enable_gpio;
269
270         if (enable_gpio) {
271                 pr_debug("Enabling tea5761 at GPIO %d\n",
272                          enable_gpio);
273
274                 if (omap_request_gpio(enable_gpio) < 0) {
275                         printk(KERN_ERR "Can't request GPIO %d\n",
276                                enable_gpio);
277                         return -ENODEV;
278                 }
279
280                 omap_set_gpio_direction(enable_gpio, 0);
281                 udelay(50);
282                 omap_set_gpio_dataout(enable_gpio, 1);
283         }
284
285         return 0;
286 }
287
288 static struct omap2_mcspi_device_config tsc2301_mcspi_config = {
289         .turbo_mode     = 0,
290         .single_channel = 1,
291 };
292
293 static struct omap2_mcspi_device_config mipid_mcspi_config = {
294         .turbo_mode     = 0,
295         .single_channel = 1,
296 };
297
298 static struct omap2_mcspi_device_config cx3110x_mcspi_config = {
299         .turbo_mode     = 0,
300         .single_channel = 1,
301 };
302
303 static struct spi_board_info n800_spi_board_info[] __initdata = {
304         [0] = {
305                 .modalias       = "lcd_mipid",
306                 .bus_num        = 1,
307                 .chip_select    = 1,
308                 .max_speed_hz   = 4000000,
309                 .controller_data= &mipid_mcspi_config,
310                 .platform_data  = &n800_mipid_platform_data,
311         }, [1] = {
312                 .modalias       = "cx3110x",
313                 .bus_num        = 2,
314                 .chip_select    = 0,
315                 .max_speed_hz   = 48000000,
316                 .controller_data= &cx3110x_mcspi_config,
317         }, [2] = {
318                 .modalias       = "tsc2301",
319                 .bus_num        = 1,
320                 .chip_select    = 0,
321                 .max_speed_hz   = 6000000,
322                 .controller_data= &tsc2301_mcspi_config,
323                 .platform_data  = &tsc2301_config,
324         },
325 };
326
327 #if defined(CONFIG_CBUS_RETU) && defined(CONFIG_LEDS_OMAP_PWM)
328
329 void retu_keypad_led_set_power(struct omap_pwm_led_platform_data *self,
330                                int on_off)
331 {
332         if (on_off) {
333                 retu_write_reg(RETU_REG_CTRL_SET, 1 << 6);
334                 msleep(2);
335                 retu_write_reg(RETU_REG_CTRL_SET, 1 << 3);
336         } else {
337                 retu_write_reg(RETU_REG_CTRL_CLR, (1 << 6) | (1 << 3));
338         }
339 }
340
341 static struct omap_pwm_led_platform_data n800_keypad_led_data = {
342         .name = "keypad",
343         .intensity_timer = 10,
344         .blink_timer = 9,
345         .set_power = retu_keypad_led_set_power,
346 };
347
348 static struct platform_device n800_keypad_led_device = {
349         .name           = "omap_pwm_led",
350         .id             = -1,
351         .dev            = {
352                 .platform_data = &n800_keypad_led_data,
353         },
354 };
355 #endif
356
357 #if defined(CONFIG_TOUCHSCREEN_TSC2301)
358 static void __init n800_ts_set_config(void)
359 {
360         const struct omap_lcd_config *conf;
361
362         conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
363         if (conf != NULL) {
364                 if (strcmp(conf->panel_name, "lph8923") == 0) {
365                         tsc2301_config.ts_x_plate_ohm   = 180;
366                         tsc2301_config.ts_hw_avg        = 8;
367                         tsc2301_config.ts_max_pressure  = 2048;
368                         tsc2301_config.ts_touch_pressure = 400;
369                         tsc2301_config.ts_stab_time     = 100;
370                         tsc2301_config.ts_pressure_fudge = 2;
371                         tsc2301_config.ts_x_max         = 4096;
372                         tsc2301_config.ts_x_fudge       = 4;
373                         tsc2301_config.ts_y_max         = 4096;
374                         tsc2301_config.ts_y_fudge       = 7;
375                 } else if (strcmp(conf->panel_name, "ls041y3") == 0) {
376                         tsc2301_config.ts_x_plate_ohm   = 280;
377                         tsc2301_config.ts_hw_avg        = 8;
378                         tsc2301_config.ts_touch_pressure = 400;
379                         tsc2301_config.ts_max_pressure  = 2048;
380                         tsc2301_config.ts_stab_time     = 1000;
381                         tsc2301_config.ts_pressure_fudge = 2;
382                         tsc2301_config.ts_x_max         = 4096;
383                         tsc2301_config.ts_x_fudge       = 4;
384                         tsc2301_config.ts_y_max         = 4096;
385                         tsc2301_config.ts_y_fudge       = 7;
386                 } else {
387                         printk(KERN_ERR "Unknown panel type, set default "
388                                "touchscreen configuration\n");
389                         tsc2301_config.ts_x_plate_ohm   = 200;
390                         tsc2301_config.ts_stab_time     = 100;
391                 }
392         }
393 }
394 #else
395 static inline void n800_ts_set_config(void)
396 {
397 }
398 #endif
399
400 static struct omap_gpio_switch n800_gpio_switches[] __initdata = {
401         {
402                 .name                   = "bat_cover",
403                 .gpio                   = -1,
404                 .debounce_rising        = 100,
405                 .debounce_falling       = 0,
406                 .notify                 = n800_mmc_slot1_cover_handler,
407                 .notify_data            = NULL,
408         }, {
409                 .name                   = "headphone",
410                 .gpio                   = -1,
411                 .debounce_rising        = 200,
412                 .debounce_falling       = 200,
413         }, {
414                 .name                   = "cam_act",
415                 .gpio                   = -1,
416                 .debounce_rising        = 200,
417                 .debounce_falling       = 200,
418         }, {
419                 .name                   = "cam_turn",
420                 .gpio                   = -1,
421                 .debounce_rising        = 100,
422                 .debounce_falling       = 100,
423         },
424 };
425
426 static struct platform_device *n800_devices[] __initdata = {
427 #if defined(CONFIG_CBUS_RETU) && defined(CONFIG_LEDS_OMAP_PWM)
428         &n800_keypad_led_device,
429 #endif
430 };
431
432 #ifdef CONFIG_MENELAUS
433 static int n800_auto_sleep_regulators(void)
434 {
435         u32 val;
436         int ret;
437
438         val = EN_VPLL_SLEEP | EN_VMMC_SLEEP    \
439                 | EN_VAUX_SLEEP | EN_VIO_SLEEP \
440                 | EN_VMEM_SLEEP | EN_DC3_SLEEP \
441                 | EN_VC_SLEEP | EN_DC2_SLEEP;
442
443         ret = menelaus_set_regulator_sleep(1, val);
444         if (ret < 0) {
445                 printk(KERN_ERR "Could not set regulators to sleep on "
446                         "menelaus: %u\n", ret);
447                 return ret;
448         }
449         return 0;
450 }
451
452 static int n800_auto_voltage_scale(void)
453 {
454         int ret;
455
456         ret = menelaus_set_vcore_hw(1400, 1050);
457         if (ret < 0) {
458                 printk(KERN_ERR "Could not set VCORE voltage on "
459                         "menelaus: %u\n", ret);
460                 return ret;
461         }
462         return 0;
463 }
464
465 static int n800_menelaus_init(struct device *dev)
466 {
467         int ret;
468
469         ret = n800_auto_voltage_scale();
470         if (ret < 0)
471                 return ret;
472         ret = n800_auto_sleep_regulators();
473         if (ret < 0)
474                 return ret;
475         return 0;
476 }
477
478 static struct menelaus_platform_data n800_menelaus_platform_data = {
479         .late_init = n800_menelaus_init,
480 };
481 #endif
482
483 static struct i2c_board_info __initdata n800_i2c_board_info_1[] = {
484         {
485                 I2C_BOARD_INFO("menelaus", 0x72),
486                 .irq = INT_24XX_SYS_NIRQ,
487                 .platform_data = &n800_menelaus_platform_data,
488         },
489 };
490
491 extern struct tcm825x_platform_data n800_tcm825x_platform_data;
492
493 static struct i2c_board_info __initdata n800_i2c_board_info_2[] = {
494 #if defined (CONFIG_VIDEO_TCM825X) || defined (CONFIG_VIDEO_TCM825X_MODULE)
495         {
496                 I2C_BOARD_INFO(TCM825X_NAME, TCM825X_I2C_ADDR),
497                 .platform_data = &n800_tcm825x_platform_data,
498         },
499 #endif
500 #if defined(CONFIG_RADIO_TEA5761) || defined(CONFIG_RADIO_TEA5761_MODULE)
501         {
502                 I2C_BOARD_INFO("tea5761", 0x10),
503         },
504 #endif
505 };
506
507 void __init nokia_n800_common_init(void)
508 {
509         platform_add_devices(n800_devices, ARRAY_SIZE(n800_devices));
510
511         n800_flash_init();
512         n800_mmc_init();
513         n800_bt_init();
514         n800_dsp_init();
515         n800_usb_init();
516         n800_cam_init();
517         spi_register_board_info(n800_spi_board_info,
518                                 ARRAY_SIZE(n800_spi_board_info));
519         omap_serial_init();
520         omap_register_i2c_bus(1, 400, n800_i2c_board_info_1,
521                               ARRAY_SIZE(n800_i2c_board_info_1));
522         omap_register_i2c_bus(2, 400, n800_i2c_board_info_2,
523                               ARRAY_SIZE(n800_i2c_board_info_2));
524         mipid_dev_init();
525         blizzard_dev_init();
526 }
527
528 static void __init nokia_n800_init(void)
529 {
530         nokia_n800_common_init();
531
532         n800_audio_init(&tsc2301_config);
533         n800_ts_set_config();
534         tsc2301_dev_init();
535         tea5761_dev_init();
536         omap_register_gpio_switches(n800_gpio_switches,
537                                     ARRAY_SIZE(n800_gpio_switches));
538 }
539
540 void __init nokia_n800_map_io(void)
541 {
542         omap_board_config = n800_config;
543         omap_board_config_size = ARRAY_SIZE(n800_config);
544
545         omap2_set_globals_242x();
546         omap2_map_common_io();
547 }
548
549 MACHINE_START(NOKIA_N800, "Nokia N800")
550         .phys_io        = 0x48000000,
551         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
552         .boot_params    = 0x80000100,
553         .map_io         = nokia_n800_map_io,
554         .init_irq       = nokia_n800_init_irq,
555         .init_machine   = nokia_n800_init,
556         .timer          = &omap_timer,
557 MACHINE_END