Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / arch / arm / mach-omap1 / board-sx1.c
1 /*
2 * linux/arch/arm/mach-omap1/board-sx1.c
3 *
4 * Modified from board-generic.c
5 *
6 * Support for the Siemens SX1 mobile phone.
7 *
8 * Original version : Vladimir Ananiev (Vovan888-at-gmail com)
9 *
10 * Maintainters : Vladimir Ananiev (aka Vovan888), Sergge
11 *               oslik.ru
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/input.h>
21 #include <linux/platform_device.h>
22 #include <linux/notifier.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/partitions.h>
25 #include <linux/types.h>
26 #include <linux/i2c.h>
27 #include <linux/errno.h>
28
29 #include <mach/hardware.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/flash.h>
33 #include <asm/mach/map.h>
34
35 #include <mach/gpio.h>
36 #include <mach/gpio-switch.h>
37 #include <mach/mux.h>
38 #include <mach/irda.h>
39 #include <mach/usb.h>
40 #include <mach/tc.h>
41 #include <mach/board.h>
42 #include <mach/common.h>
43 #include <mach/mcbsp.h>
44 #include <mach/omap-alsa.h>
45 #include <mach/keypad.h>
46
47 /* Write to I2C device */
48 int sx1_i2c_write_byte(u8 devaddr, u8 regoffset, u8 value)
49 {
50         struct i2c_adapter *adap;
51         int err;
52         struct i2c_msg msg[1];
53         unsigned char data[2];
54
55         adap = i2c_get_adapter(0);
56         if (!adap)
57                 return -ENODEV;
58         msg->addr = devaddr;    /* I2C address of chip */
59         msg->flags = 0;
60         msg->len = 2;
61         msg->buf = data;
62         data[0] = regoffset;    /* register num */
63         data[1] = value;                /* register data */
64         err = i2c_transfer(adap, msg, 1);
65         i2c_put_adapter(adap);
66         if (err >= 0)
67                 return 0;
68         return err;
69 }
70
71 /* Read from I2C device */
72 int sx1_i2c_read_byte(u8 devaddr, u8 regoffset, u8 *value)
73 {
74         struct i2c_adapter *adap;
75         int err;
76         struct i2c_msg msg[1];
77         unsigned char data[2];
78
79         adap = i2c_get_adapter(0);
80         if (!adap)
81                 return -ENODEV;
82
83         msg->addr = devaddr;    /* I2C address of chip */
84         msg->flags = 0;
85         msg->len = 1;
86         msg->buf = data;
87         data[0] = regoffset;    /* register num */
88         err = i2c_transfer(adap, msg, 1);
89
90         msg->addr = devaddr;    /* I2C address */
91         msg->flags = I2C_M_RD;
92         msg->len = 1;
93         msg->buf = data;
94         err = i2c_transfer(adap, msg, 1);
95         *value = data[0];
96         i2c_put_adapter(adap);
97
98         if (err >= 0)
99                 return 0;
100         return err;
101 }
102 /* set keyboard backlight intensity */
103 int sx1_setkeylight(u8 keylight)
104 {
105         if (keylight > SOFIA_MAX_LIGHT_VAL)
106                 keylight = SOFIA_MAX_LIGHT_VAL;
107         return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
108 }
109 /* get current keylight intensity */
110 int sx1_getkeylight(u8 * keylight)
111 {
112         return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
113 }
114 /* set LCD backlight intensity */
115 int sx1_setbacklight(u8 backlight)
116 {
117         if (backlight > SOFIA_MAX_LIGHT_VAL)
118                 backlight = SOFIA_MAX_LIGHT_VAL;
119         return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
120                                   backlight);
121 }
122 /* get current LCD backlight intensity */
123 int sx1_getbacklight (u8 * backlight)
124 {
125         return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
126                                  backlight);
127 }
128 /* set LCD backlight power on/off */
129 int sx1_setmmipower(u8 onoff)
130 {
131         int err;
132         u8 dat = 0;
133         err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
134         if (err < 0)
135                 return err;
136         if (onoff)
137                 dat |= SOFIA_MMILIGHT_POWER;
138         else
139                 dat &= ~SOFIA_MMILIGHT_POWER;
140         return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
141 }
142
143 /* set USB power on/off */
144 int sx1_setusbpower(u8 onoff)
145 {
146         int err;
147         u8 dat = 0;
148         err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
149         if (err < 0)
150                 return err;
151         if (onoff)
152                 dat |= SOFIA_USB_POWER;
153         else
154                 dat &= ~SOFIA_USB_POWER;
155         return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
156 }
157
158 EXPORT_SYMBOL(sx1_setkeylight);
159 EXPORT_SYMBOL(sx1_getkeylight);
160 EXPORT_SYMBOL(sx1_setbacklight);
161 EXPORT_SYMBOL(sx1_getbacklight);
162 EXPORT_SYMBOL(sx1_setmmipower);
163 EXPORT_SYMBOL(sx1_setusbpower);
164
165 /*----------- Keypad -------------------------*/
166
167 static int sx1_keymap[] = {
168         KEY(5, 3, GROUP_0 | 117), /* camera Qt::Key_F17 */
169         KEY(0, 4, GROUP_0 | 114), /* voice memo Qt::Key_F14 */
170         KEY(1, 4, GROUP_2 | 114), /* voice memo */
171         KEY(2, 4, GROUP_3 | 114), /* voice memo */
172         KEY(0, 0, GROUP_1 | KEY_F12),   /* red button Qt::Key_Hangup */
173         KEY(4, 3, GROUP_1 | KEY_LEFT),
174         KEY(2, 3, GROUP_1 | KEY_DOWN),
175         KEY(1, 3, GROUP_1 | KEY_RIGHT),
176         KEY(0, 3, GROUP_1 | KEY_UP),
177         KEY(3, 3, GROUP_1 | KEY_POWER), /* joystick press or Qt::Key_Select */
178         KEY(5, 0, GROUP_1 | KEY_1),
179         KEY(4, 0, GROUP_1 | KEY_2),
180         KEY(3, 0, GROUP_1 | KEY_3),
181         KEY(3, 4, GROUP_1 | KEY_4),
182         KEY(4, 4, GROUP_1 | KEY_5),
183         KEY(5, 4, GROUP_1 | KEY_KPASTERISK),/* "*" */
184         KEY(4, 1, GROUP_1 | KEY_6),
185         KEY(5, 1, GROUP_1 | KEY_7),
186         KEY(3, 1, GROUP_1 | KEY_8),
187         KEY(3, 2, GROUP_1 | KEY_9),
188         KEY(5, 2, GROUP_1 | KEY_0),
189         KEY(4, 2, GROUP_1 | 113),       /* # F13 Toggle input method Qt::Key_F13 */
190         KEY(0, 1, GROUP_1 | KEY_F11),   /* green button Qt::Key_Call */
191         KEY(1, 2, GROUP_1 | KEY_YEN),   /* left soft Qt::Key_Context1 */
192         KEY(2, 2, GROUP_1 | KEY_F8),    /* right soft Qt::Key_Back */
193         KEY(2, 1, GROUP_1 | KEY_LEFTSHIFT), /* shift */
194         KEY(1, 1, GROUP_1 | KEY_BACKSPACE), /* C (clear) */
195         KEY(0, 2, GROUP_1 | KEY_F7),    /* menu Qt::Key_Menu */
196         0
197 };
198
199 static struct resource sx1_kp_resources[] = {
200         [0] = {
201                 .start  = INT_KEYBOARD,
202                 .end    = INT_KEYBOARD,
203                 .flags  = IORESOURCE_IRQ,
204         },
205 };
206
207 static struct omap_kp_platform_data sx1_kp_data = {
208         .rows           = 6,
209         .cols           = 6,
210         .keymap = sx1_keymap,
211         .keymapsize = ARRAY_SIZE(sx1_keymap),
212         .delay  = 80,
213 };
214
215 static struct platform_device sx1_kp_device = {
216         .name           = "omap-keypad",
217         .id             = -1,
218         .dev            = {
219                 .platform_data = &sx1_kp_data,
220         },
221         .num_resources  = ARRAY_SIZE(sx1_kp_resources),
222         .resource       = sx1_kp_resources,
223 };
224
225 /*----------- IRDA -------------------------*/
226
227 static struct omap_irda_config sx1_irda_data = {
228         .transceiver_cap        = IR_SIRMODE,
229         .rx_channel             = OMAP_DMA_UART3_RX,
230         .tx_channel             = OMAP_DMA_UART3_TX,
231         .dest_start             = UART3_THR,
232         .src_start              = UART3_RHR,
233         .tx_trigger             = 0,
234         .rx_trigger             = 0,
235 };
236
237 static struct resource sx1_irda_resources[] = {
238         [0] = {
239                 .start  = INT_UART3,
240                 .end    = INT_UART3,
241                 .flags  = IORESOURCE_IRQ,
242         },
243 };
244
245 static u64 irda_dmamask = 0xffffffff;
246
247 static struct platform_device sx1_irda_device = {
248         .name           = "omapirda",
249         .id             = 0,
250         .dev            = {
251                 .platform_data  = &sx1_irda_data,
252                 .dma_mask       = &irda_dmamask,
253         },
254         .num_resources  = ARRAY_SIZE(sx1_irda_resources),
255         .resource       = sx1_irda_resources,
256 };
257
258 /*----------- McBSP & Sound -------------------------*/
259
260 /* Playback interface - McBSP1 */
261 static struct omap_mcbsp_reg_cfg mcbsp1_regs = {
262         .spcr2  = XINTM(3),     /* SPCR2=30 */
263         .spcr1  = RINTM(3),     /* SPCR1=30 */
264         .rcr2   = 0,    /* RCR2 =00 */
265         .rcr1   = RFRLEN1(1) | RWDLEN1(OMAP_MCBSP_WORD_16),     /* RCR1=140 */
266         .xcr2   = 0,    /* XCR2 = 0 */
267         .xcr1   = XFRLEN1(1) | XWDLEN1(OMAP_MCBSP_WORD_16),     /* XCR1 = 140 */
268         .srgr1  = FWID(15) | CLKGDV(12),        /* SRGR1=0f0c */
269         .srgr2  = FSGM | FPER(31),      /* SRGR2=101f */
270         .pcr0   = FSXM | FSRM | CLKXM | CLKRM | FSXP | FSRP | CLKXP | CLKRP,
271                                                 /* PCR0 =0f0f */
272 };
273
274 static struct omap_alsa_codec_config sx1_alsa_config = {
275         .name                   = "SX1 EGold",
276         .mcbsp_regs_alsa        = &mcbsp1_regs,
277 };
278
279 static struct platform_device sx1_mcbsp1_device = {
280         .name   = "omap_alsa_mcbsp",
281         .id     = 1,
282         .dev = {
283                 .platform_data  = &sx1_alsa_config,
284         },
285 };
286
287 /*----------- MTD -------------------------*/
288
289 static struct mtd_partition sx1_partitions[] = {
290         /* bootloader (U-Boot, etc) in first sector */
291         {
292                 .name           = "bootloader",
293                 .offset         = 0x01800000,
294                 .size           = SZ_128K,
295                 .mask_flags     = MTD_WRITEABLE, /* force read-only */
296         },
297         /* bootloader params in the next sector */
298         {
299                 .name           = "params",
300                 .offset         = MTDPART_OFS_APPEND,
301                 .size           = SZ_128K,
302                 .mask_flags     = 0,
303         },
304         /* kernel */
305         {
306                 .name           = "kernel",
307                 .offset         = MTDPART_OFS_APPEND,
308                 .size           = SZ_2M - 2 * SZ_128K,
309                 .mask_flags     = 0
310         },
311         /* file system */
312         {
313                 .name           = "filesystem",
314                 .offset         = MTDPART_OFS_APPEND,
315                 .size           = MTDPART_SIZ_FULL,
316                 .mask_flags     = 0
317         }
318 };
319
320 static struct flash_platform_data sx1_flash_data = {
321         .map_name       = "cfi_probe",
322         .width          = 2,
323         .parts          = sx1_partitions,
324         .nr_parts       = ARRAY_SIZE(sx1_partitions),
325 };
326
327 #ifdef CONFIG_SX1_OLD_FLASH
328 /* MTD Intel StrataFlash - old flashes */
329 static struct resource sx1_old_flash_resource[] = {
330         [0] = {
331                 .start  = OMAP_CS0_PHYS,        /* Physical */
332                 .end    = OMAP_CS0_PHYS + SZ_16M - 1,,
333                 .flags  = IORESOURCE_MEM,
334         },
335         [1] = {
336                 .start  = OMAP_CS1_PHYS,
337                 .end    = OMAP_CS1_PHYS + SZ_8M - 1,
338                 .flags  = IORESOURCE_MEM,
339         },
340 };
341
342 static struct platform_device sx1_flash_device = {
343         .name           = "omapflash",
344         .id             = 0,
345         .dev            = {
346                 .platform_data  = &sx1_flash_data,
347         },
348         .num_resources  = 2,
349         .resource       = &sx1_old_flash_resource,
350 };
351 #else
352 /* MTD Intel 4000 flash - new flashes */
353 static struct resource sx1_new_flash_resource = {
354         .start          = OMAP_CS0_PHYS,
355         .end            = OMAP_CS0_PHYS + SZ_32M - 1,
356         .flags          = IORESOURCE_MEM,
357 };
358
359 static struct platform_device sx1_flash_device = {
360         .name           = "omapflash",
361         .id             = 0,
362         .dev            = {
363                 .platform_data  = &sx1_flash_data,
364         },
365         .num_resources  = 1,
366         .resource       = &sx1_new_flash_resource,
367 };
368 #endif
369
370 /*----------- USB -------------------------*/
371
372 static struct omap_usb_config sx1_usb_config __initdata = {
373         .otg            = 0,
374         .register_dev   = 1,
375         .register_host  = 0,
376         .hmc_mode       = 0,
377         .pins[0]        = 2,
378         .pins[1]        = 0,
379         .pins[2]        = 0,
380 };
381
382 /*----------- LCD -------------------------*/
383
384 static struct platform_device sx1_lcd_device = {
385         .name           = "lcd_sx1",
386         .id             = -1,
387 };
388
389 static struct omap_lcd_config sx1_lcd_config __initdata = {
390         .ctrl_name      = "internal",
391 };
392
393 /*-----------------------------------------*/
394 static struct platform_device *sx1_devices[] __initdata = {
395         &sx1_flash_device,
396         &sx1_kp_device,
397         &sx1_lcd_device,
398         &sx1_mcbsp1_device,
399         &sx1_irda_device,
400 };
401 /*-----------------------------------------*/
402
403 static struct omap_uart_config sx1_uart_config __initdata = {
404         .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
405 };
406
407 static struct omap_board_config_kernel sx1_config[] __initdata = {
408         { OMAP_TAG_USB, &sx1_usb_config },
409         { OMAP_TAG_LCD, &sx1_lcd_config },
410         { OMAP_TAG_UART,        &sx1_uart_config },
411 };
412
413 /*-----------------------------------------*/
414
415 static void __init omap_sx1_init(void)
416 {
417         platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
418
419         omap_board_config = sx1_config;
420         omap_board_config_size = ARRAY_SIZE(sx1_config);
421         omap_serial_init();
422         omap_register_i2c_bus(1, 100, NULL, 0);
423         sx1_mmc_init();
424
425         /* turn on USB power */
426         /* sx1_setusbpower(1); cant do it here because i2c is not ready */
427         omap_request_gpio(1);   /* A_IRDA_OFF */
428         omap_request_gpio(11);  /* A_SWITCH */
429         omap_request_gpio(15);  /* A_USB_ON */
430         omap_set_gpio_direction(1, 0);/* gpio1 -> output */
431         omap_set_gpio_direction(11, 0);/* gpio11 -> output */
432         omap_set_gpio_direction(15, 0);/* gpio15 -> output */
433         /* set GPIO data */
434         omap_set_gpio_dataout(1, 1);/*A_IRDA_OFF = 1 */
435         omap_set_gpio_dataout(11, 0);/*A_SWITCH = 0 */
436         omap_set_gpio_dataout(15, 0);/*A_USB_ON = 0 */
437 }
438 /*----------------------------------------*/
439 static void __init omap_sx1_init_irq(void)
440 {
441         omap1_init_common_hw();
442         omap_init_irq();
443         omap_gpio_init();
444 }
445 /*----------------------------------------*/
446
447 static void __init omap_sx1_map_io(void)
448 {
449         omap1_map_common_io();
450 }
451
452 MACHINE_START(SX1, "OMAP310 based Siemens SX1")
453         .phys_io        = 0xfff00000,
454         .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
455         .boot_params    = 0x10000100,
456         .map_io         = omap_sx1_map_io,
457         .init_irq               = omap_sx1_init_irq,
458         .init_machine   = omap_sx1_init,
459         .timer          = &omap_timer,
460 MACHINE_END