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