blob: 2fb1e5f8e2ec5c637a992007123842bf7e48d2f3 [file] [log] [blame]
Vladimir Ananievc79ed192006-12-06 17:14:08 -08001/*
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>
Ladislav Michl561b0362010-02-15 10:03:32 -080025#include <linux/mtd/physmap.h>
Vladimir Ananievc79ed192006-12-06 17:14:08 -080026#include <linux/types.h>
27#include <linux/i2c.h>
28#include <linux/errno.h>
29
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/hardware.h>
Vladimir Ananievc79ed192006-12-06 17:14:08 -080031#include <asm/mach-types.h>
32#include <asm/mach/arch.h>
Vladimir Ananievc79ed192006-12-06 17:14:08 -080033#include <asm/mach/map.h>
34
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/gpio.h>
Ladislav Michl561b0362010-02-15 10:03:32 -080036#include <plat/flash.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070037#include <plat/mux.h>
38#include <plat/dma.h>
39#include <plat/irda.h>
40#include <plat/usb.h>
41#include <plat/tc.h>
42#include <plat/board.h>
43#include <plat/common.h>
44#include <plat/keypad.h>
45#include <plat/board-sx1.h>
Vladimir Ananievc79ed192006-12-06 17:14:08 -080046
47/* Write to I2C device */
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -040048int sx1_i2c_write_byte(u8 devaddr, u8 regoffset, u8 value)
Vladimir Ananievc79ed192006-12-06 17:14:08 -080049{
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);
Jean Delvarec9a2c462008-02-24 20:03:41 +010065 i2c_put_adapter(adap);
Vladimir Ananievc79ed192006-12-06 17:14:08 -080066 if (err >= 0)
67 return 0;
68 return err;
69}
70
71/* Read from I2C device */
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -040072int sx1_i2c_read_byte(u8 devaddr, u8 regoffset, u8 *value)
Vladimir Ananievc79ed192006-12-06 17:14:08 -080073{
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];
Jean Delvarec9a2c462008-02-24 20:03:41 +010096 i2c_put_adapter(adap);
Vladimir Ananievc79ed192006-12-06 17:14:08 -080097
98 if (err >= 0)
99 return 0;
100 return err;
101}
102/* set keyboard backlight intensity */
103int sx1_setkeylight(u8 keylight)
104{
105 if (keylight > SOFIA_MAX_LIGHT_VAL)
106 keylight = SOFIA_MAX_LIGHT_VAL;
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400107 return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800108}
109/* get current keylight intensity */
110int sx1_getkeylight(u8 * keylight)
111{
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400112 return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800113}
114/* set LCD backlight intensity */
115int sx1_setbacklight(u8 backlight)
116{
117 if (backlight > SOFIA_MAX_LIGHT_VAL)
118 backlight = SOFIA_MAX_LIGHT_VAL;
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400119 return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
120 backlight);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800121}
122/* get current LCD backlight intensity */
123int sx1_getbacklight (u8 * backlight)
124{
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400125 return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
126 backlight);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800127}
128/* set LCD backlight power on/off */
129int sx1_setmmipower(u8 onoff)
130{
131 int err;
132 u8 dat = 0;
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400133 err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800134 if (err < 0)
135 return err;
136 if (onoff)
137 dat |= SOFIA_MMILIGHT_POWER;
138 else
139 dat &= ~SOFIA_MMILIGHT_POWER;
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400140 return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800141}
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400142
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800143/* set USB power on/off */
144int sx1_setusbpower(u8 onoff)
145{
146 int err;
147 u8 dat = 0;
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400148 err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800149 if (err < 0)
150 return err;
151 if (onoff)
152 dat |= SOFIA_USB_POWER;
153 else
154 dat &= ~SOFIA_USB_POWER;
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400155 return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800156}
157
158EXPORT_SYMBOL(sx1_setkeylight);
159EXPORT_SYMBOL(sx1_getkeylight);
160EXPORT_SYMBOL(sx1_setbacklight);
161EXPORT_SYMBOL(sx1_getbacklight);
162EXPORT_SYMBOL(sx1_setmmipower);
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800163EXPORT_SYMBOL(sx1_setusbpower);
164
165/*----------- Keypad -------------------------*/
166
167static 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
199static struct resource sx1_kp_resources[] = {
200 [0] = {
201 .start = INT_KEYBOARD,
202 .end = INT_KEYBOARD,
203 .flags = IORESOURCE_IRQ,
204 },
205};
206
207static 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
215static 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
227static 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
237static struct resource sx1_irda_resources[] = {
238 [0] = {
239 .start = INT_UART3,
240 .end = INT_UART3,
241 .flags = IORESOURCE_IRQ,
242 },
243};
244
245static u64 irda_dmamask = 0xffffffff;
246
247static 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
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800258/*----------- MTD -------------------------*/
259
260static struct mtd_partition sx1_partitions[] = {
261 /* bootloader (U-Boot, etc) in first sector */
262 {
263 .name = "bootloader",
264 .offset = 0x01800000,
265 .size = SZ_128K,
266 .mask_flags = MTD_WRITEABLE, /* force read-only */
267 },
268 /* bootloader params in the next sector */
269 {
270 .name = "params",
271 .offset = MTDPART_OFS_APPEND,
272 .size = SZ_128K,
273 .mask_flags = 0,
274 },
275 /* kernel */
276 {
277 .name = "kernel",
278 .offset = MTDPART_OFS_APPEND,
279 .size = SZ_2M - 2 * SZ_128K,
280 .mask_flags = 0
281 },
282 /* file system */
283 {
284 .name = "filesystem",
285 .offset = MTDPART_OFS_APPEND,
286 .size = MTDPART_SIZ_FULL,
287 .mask_flags = 0
288 }
289};
290
Ladislav Michl561b0362010-02-15 10:03:32 -0800291static struct physmap_flash_data sx1_flash_data = {
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800292 .width = 2,
Ladislav Michl561b0362010-02-15 10:03:32 -0800293 .set_vpp = omap1_set_vpp,
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800294 .parts = sx1_partitions,
295 .nr_parts = ARRAY_SIZE(sx1_partitions),
296};
297
298#ifdef CONFIG_SX1_OLD_FLASH
299/* MTD Intel StrataFlash - old flashes */
300static struct resource sx1_old_flash_resource[] = {
301 [0] = {
302 .start = OMAP_CS0_PHYS, /* Physical */
303 .end = OMAP_CS0_PHYS + SZ_16M - 1,,
304 .flags = IORESOURCE_MEM,
305 },
306 [1] = {
307 .start = OMAP_CS1_PHYS,
308 .end = OMAP_CS1_PHYS + SZ_8M - 1,
309 .flags = IORESOURCE_MEM,
310 },
311};
312
313static struct platform_device sx1_flash_device = {
Ladislav Michl561b0362010-02-15 10:03:32 -0800314 .name = "physmap-flash",
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800315 .id = 0,
316 .dev = {
317 .platform_data = &sx1_flash_data,
318 },
319 .num_resources = 2,
320 .resource = &sx1_old_flash_resource,
321};
322#else
323/* MTD Intel 4000 flash - new flashes */
324static struct resource sx1_new_flash_resource = {
325 .start = OMAP_CS0_PHYS,
326 .end = OMAP_CS0_PHYS + SZ_32M - 1,
327 .flags = IORESOURCE_MEM,
328};
329
330static struct platform_device sx1_flash_device = {
Ladislav Michl561b0362010-02-15 10:03:32 -0800331 .name = "physmap-flash",
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800332 .id = 0,
333 .dev = {
334 .platform_data = &sx1_flash_data,
335 },
336 .num_resources = 1,
337 .resource = &sx1_new_flash_resource,
338};
339#endif
340
341/*----------- USB -------------------------*/
342
343static struct omap_usb_config sx1_usb_config __initdata = {
344 .otg = 0,
345 .register_dev = 1,
346 .register_host = 0,
347 .hmc_mode = 0,
348 .pins[0] = 2,
349 .pins[1] = 0,
350 .pins[2] = 0,
351};
352
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800353/*----------- LCD -------------------------*/
354
355static struct platform_device sx1_lcd_device = {
356 .name = "lcd_sx1",
357 .id = -1,
358};
359
360static struct omap_lcd_config sx1_lcd_config __initdata = {
361 .ctrl_name = "internal",
362};
363
364/*-----------------------------------------*/
365static struct platform_device *sx1_devices[] __initdata = {
366 &sx1_flash_device,
367 &sx1_kp_device,
368 &sx1_lcd_device,
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800369 &sx1_irda_device,
370};
371/*-----------------------------------------*/
372
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800373static struct omap_board_config_kernel sx1_config[] __initdata = {
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800374 { OMAP_TAG_LCD, &sx1_lcd_config },
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800375};
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800376
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800377/*-----------------------------------------*/
Tony Lindgrene27a93a2007-12-18 20:58:32 -0800378
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800379static void __init omap_sx1_init(void)
380{
Janusz Krzysztofikc33da3a2009-10-22 14:47:42 -0700381 /* mux pins for uarts */
382 omap_cfg_reg(UART1_TX);
383 omap_cfg_reg(UART1_RTS);
384 omap_cfg_reg(UART2_TX);
385 omap_cfg_reg(UART2_RTS);
386 omap_cfg_reg(UART3_TX);
387 omap_cfg_reg(UART3_RX);
388
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800389 platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
390
391 omap_board_config = sx1_config;
392 omap_board_config_size = ARRAY_SIZE(sx1_config);
393 omap_serial_init();
Jarkko Nikula1ed16a82007-11-07 06:54:32 +0200394 omap_register_i2c_bus(1, 100, NULL, 0);
Felipe Balbib0b5aa32009-03-23 18:07:49 -0700395 omap_usb_init(&sx1_usb_config);
Carlos Eduardo Aguiar087c5032007-11-30 01:52:53 -0400396 sx1_mmc_init();
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800397
398 /* turn on USB power */
399 /* sx1_setusbpower(1); cant do it here because i2c is not ready */
Jarkko Nikula73069e32009-01-15 13:09:52 +0200400 gpio_request(1, "A_IRDA_OFF");
401 gpio_request(11, "A_SWITCH");
402 gpio_request(15, "A_USB_ON");
David Brownelle918edf2008-12-10 17:35:26 -0800403 gpio_direction_output(1, 1); /*A_IRDA_OFF = 1 */
404 gpio_direction_output(11, 0); /*A_SWITCH = 0 */
405 gpio_direction_output(15, 0); /*A_USB_ON = 0 */
Vladimir Ananievc79ed192006-12-06 17:14:08 -0800406}
407/*----------------------------------------*/
408static void __init omap_sx1_init_irq(void)
409{
410 omap1_init_common_hw();
411 omap_init_irq();
412 omap_gpio_init();
413}
414/*----------------------------------------*/
415
416static void __init omap_sx1_map_io(void)
417{
418 omap1_map_common_io();
419}
420
421MACHINE_START(SX1, "OMAP310 based Siemens SX1")
422 .phys_io = 0xfff00000,
423 .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
424 .boot_params = 0x10000100,
425 .map_io = omap_sx1_map_io,
426 .init_irq = omap_sx1_init_irq,
427 .init_machine = omap_sx1_init,
428 .timer = &omap_timer,
429MACHINE_END