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