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