board-sx1.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. #include <linux/gpio.h>
  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/mtd/physmap.h>
  26. #include <linux/types.h>
  27. #include <linux/i2c.h>
  28. #include <linux/errno.h>
  29. #include <linux/export.h>
  30. #include <mach/hardware.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/map.h>
  34. #include <plat/flash.h>
  35. #include <plat/mux.h>
  36. #include <plat/dma.h>
  37. #include <plat/irda.h>
  38. #include <plat/usb.h>
  39. #include <plat/tc.h>
  40. #include <plat/board.h>
  41. #include "common.h"
  42. #include <plat/keypad.h>
  43. #include <plat/board-sx1.h>
  44. /* Write to I2C device */
  45. int sx1_i2c_write_byte(u8 devaddr, u8 regoffset, u8 value)
  46. {
  47. struct i2c_adapter *adap;
  48. int err;
  49. struct i2c_msg msg[1];
  50. unsigned char data[2];
  51. adap = i2c_get_adapter(0);
  52. if (!adap)
  53. return -ENODEV;
  54. msg->addr = devaddr; /* I2C address of chip */
  55. msg->flags = 0;
  56. msg->len = 2;
  57. msg->buf = data;
  58. data[0] = regoffset; /* register num */
  59. data[1] = value; /* register data */
  60. err = i2c_transfer(adap, msg, 1);
  61. i2c_put_adapter(adap);
  62. if (err >= 0)
  63. return 0;
  64. return err;
  65. }
  66. /* Read from I2C device */
  67. int sx1_i2c_read_byte(u8 devaddr, u8 regoffset, u8 *value)
  68. {
  69. struct i2c_adapter *adap;
  70. int err;
  71. struct i2c_msg msg[1];
  72. unsigned char data[2];
  73. adap = i2c_get_adapter(0);
  74. if (!adap)
  75. return -ENODEV;
  76. msg->addr = devaddr; /* I2C address of chip */
  77. msg->flags = 0;
  78. msg->len = 1;
  79. msg->buf = data;
  80. data[0] = regoffset; /* register num */
  81. err = i2c_transfer(adap, msg, 1);
  82. msg->addr = devaddr; /* I2C address */
  83. msg->flags = I2C_M_RD;
  84. msg->len = 1;
  85. msg->buf = data;
  86. err = i2c_transfer(adap, msg, 1);
  87. *value = data[0];
  88. i2c_put_adapter(adap);
  89. if (err >= 0)
  90. return 0;
  91. return err;
  92. }
  93. /* set keyboard backlight intensity */
  94. int sx1_setkeylight(u8 keylight)
  95. {
  96. if (keylight > SOFIA_MAX_LIGHT_VAL)
  97. keylight = SOFIA_MAX_LIGHT_VAL;
  98. return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
  99. }
  100. /* get current keylight intensity */
  101. int sx1_getkeylight(u8 * keylight)
  102. {
  103. return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
  104. }
  105. /* set LCD backlight intensity */
  106. int sx1_setbacklight(u8 backlight)
  107. {
  108. if (backlight > SOFIA_MAX_LIGHT_VAL)
  109. backlight = SOFIA_MAX_LIGHT_VAL;
  110. return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
  111. backlight);
  112. }
  113. /* get current LCD backlight intensity */
  114. int sx1_getbacklight (u8 * backlight)
  115. {
  116. return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
  117. backlight);
  118. }
  119. /* set LCD backlight power on/off */
  120. int sx1_setmmipower(u8 onoff)
  121. {
  122. int err;
  123. u8 dat = 0;
  124. err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
  125. if (err < 0)
  126. return err;
  127. if (onoff)
  128. dat |= SOFIA_MMILIGHT_POWER;
  129. else
  130. dat &= ~SOFIA_MMILIGHT_POWER;
  131. return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
  132. }
  133. /* set USB power on/off */
  134. int sx1_setusbpower(u8 onoff)
  135. {
  136. int err;
  137. u8 dat = 0;
  138. err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
  139. if (err < 0)
  140. return err;
  141. if (onoff)
  142. dat |= SOFIA_USB_POWER;
  143. else
  144. dat &= ~SOFIA_USB_POWER;
  145. return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
  146. }
  147. EXPORT_SYMBOL(sx1_setkeylight);
  148. EXPORT_SYMBOL(sx1_getkeylight);
  149. EXPORT_SYMBOL(sx1_setbacklight);
  150. EXPORT_SYMBOL(sx1_getbacklight);
  151. EXPORT_SYMBOL(sx1_setmmipower);
  152. EXPORT_SYMBOL(sx1_setusbpower);
  153. /*----------- Keypad -------------------------*/
  154. static const unsigned int sx1_keymap[] = {
  155. KEY(3, 5, GROUP_0 | 117), /* camera Qt::Key_F17 */
  156. KEY(4, 0, GROUP_0 | 114), /* voice memo Qt::Key_F14 */
  157. KEY(4, 1, GROUP_2 | 114), /* voice memo */
  158. KEY(4, 2, GROUP_3 | 114), /* voice memo */
  159. KEY(0, 0, GROUP_1 | KEY_F12), /* red button Qt::Key_Hangup */
  160. KEY(3, 4, GROUP_1 | KEY_LEFT),
  161. KEY(3, 2, GROUP_1 | KEY_DOWN),
  162. KEY(3, 1, GROUP_1 | KEY_RIGHT),
  163. KEY(3, 0, GROUP_1 | KEY_UP),
  164. KEY(3, 3, GROUP_1 | KEY_POWER), /* joystick press or Qt::Key_Select */
  165. KEY(0, 5, GROUP_1 | KEY_1),
  166. KEY(0, 4, GROUP_1 | KEY_2),
  167. KEY(0, 3, GROUP_1 | KEY_3),
  168. KEY(4, 3, GROUP_1 | KEY_4),
  169. KEY(4, 4, GROUP_1 | KEY_5),
  170. KEY(4, 5, GROUP_1 | KEY_KPASTERISK),/* "*" */
  171. KEY(1, 4, GROUP_1 | KEY_6),
  172. KEY(1, 5, GROUP_1 | KEY_7),
  173. KEY(1, 3, GROUP_1 | KEY_8),
  174. KEY(2, 3, GROUP_1 | KEY_9),
  175. KEY(2, 5, GROUP_1 | KEY_0),
  176. KEY(2, 4, GROUP_1 | 113), /* # F13 Toggle input method Qt::Key_F13 */
  177. KEY(1, 0, GROUP_1 | KEY_F11), /* green button Qt::Key_Call */
  178. KEY(2, 1, GROUP_1 | KEY_YEN), /* left soft Qt::Key_Context1 */
  179. KEY(2, 2, GROUP_1 | KEY_F8), /* right soft Qt::Key_Back */
  180. KEY(1, 2, GROUP_1 | KEY_LEFTSHIFT), /* shift */
  181. KEY(1, 1, GROUP_1 | KEY_BACKSPACE), /* C (clear) */
  182. KEY(2, 0, GROUP_1 | KEY_F7), /* menu Qt::Key_Menu */
  183. };
  184. static struct resource sx1_kp_resources[] = {
  185. [0] = {
  186. .start = INT_KEYBOARD,
  187. .end = INT_KEYBOARD,
  188. .flags = IORESOURCE_IRQ,
  189. },
  190. };
  191. static const struct matrix_keymap_data sx1_keymap_data = {
  192. .keymap = sx1_keymap,
  193. .keymap_size = ARRAY_SIZE(sx1_keymap),
  194. };
  195. static struct omap_kp_platform_data sx1_kp_data = {
  196. .rows = 6,
  197. .cols = 6,
  198. .keymap_data = &sx1_keymap_data,
  199. .delay = 80,
  200. };
  201. static struct platform_device sx1_kp_device = {
  202. .name = "omap-keypad",
  203. .id = -1,
  204. .dev = {
  205. .platform_data = &sx1_kp_data,
  206. },
  207. .num_resources = ARRAY_SIZE(sx1_kp_resources),
  208. .resource = sx1_kp_resources,
  209. };
  210. /*----------- IRDA -------------------------*/
  211. static struct omap_irda_config sx1_irda_data = {
  212. .transceiver_cap = IR_SIRMODE,
  213. .rx_channel = OMAP_DMA_UART3_RX,
  214. .tx_channel = OMAP_DMA_UART3_TX,
  215. .dest_start = UART3_THR,
  216. .src_start = UART3_RHR,
  217. .tx_trigger = 0,
  218. .rx_trigger = 0,
  219. };
  220. static struct resource sx1_irda_resources[] = {
  221. [0] = {
  222. .start = INT_UART3,
  223. .end = INT_UART3,
  224. .flags = IORESOURCE_IRQ,
  225. },
  226. };
  227. static u64 irda_dmamask = 0xffffffff;
  228. static struct platform_device sx1_irda_device = {
  229. .name = "omapirda",
  230. .id = 0,
  231. .dev = {
  232. .platform_data = &sx1_irda_data,
  233. .dma_mask = &irda_dmamask,
  234. },
  235. .num_resources = ARRAY_SIZE(sx1_irda_resources),
  236. .resource = sx1_irda_resources,
  237. };
  238. /*----------- MTD -------------------------*/
  239. static struct mtd_partition sx1_partitions[] = {
  240. /* bootloader (U-Boot, etc) in first sector */
  241. {
  242. .name = "bootloader",
  243. .offset = 0x01800000,
  244. .size = SZ_128K,
  245. .mask_flags = MTD_WRITEABLE, /* force read-only */
  246. },
  247. /* bootloader params in the next sector */
  248. {
  249. .name = "params",
  250. .offset = MTDPART_OFS_APPEND,
  251. .size = SZ_128K,
  252. .mask_flags = 0,
  253. },
  254. /* kernel */
  255. {
  256. .name = "kernel",
  257. .offset = MTDPART_OFS_APPEND,
  258. .size = SZ_2M - 2 * SZ_128K,
  259. .mask_flags = 0
  260. },
  261. /* file system */
  262. {
  263. .name = "filesystem",
  264. .offset = MTDPART_OFS_APPEND,
  265. .size = MTDPART_SIZ_FULL,
  266. .mask_flags = 0
  267. }
  268. };
  269. static struct physmap_flash_data sx1_flash_data = {
  270. .width = 2,
  271. .set_vpp = omap1_set_vpp,
  272. .parts = sx1_partitions,
  273. .nr_parts = ARRAY_SIZE(sx1_partitions),
  274. };
  275. #ifdef CONFIG_SX1_OLD_FLASH
  276. /* MTD Intel StrataFlash - old flashes */
  277. static struct resource sx1_old_flash_resource[] = {
  278. [0] = {
  279. .start = OMAP_CS0_PHYS, /* Physical */
  280. .end = OMAP_CS0_PHYS + SZ_16M - 1,,
  281. .flags = IORESOURCE_MEM,
  282. },
  283. [1] = {
  284. .start = OMAP_CS1_PHYS,
  285. .end = OMAP_CS1_PHYS + SZ_8M - 1,
  286. .flags = IORESOURCE_MEM,
  287. },
  288. };
  289. static struct platform_device sx1_flash_device = {
  290. .name = "physmap-flash",
  291. .id = 0,
  292. .dev = {
  293. .platform_data = &sx1_flash_data,
  294. },
  295. .num_resources = 2,
  296. .resource = &sx1_old_flash_resource,
  297. };
  298. #else
  299. /* MTD Intel 4000 flash - new flashes */
  300. static struct resource sx1_new_flash_resource = {
  301. .start = OMAP_CS0_PHYS,
  302. .end = OMAP_CS0_PHYS + SZ_32M - 1,
  303. .flags = IORESOURCE_MEM,
  304. };
  305. static struct platform_device sx1_flash_device = {
  306. .name = "physmap-flash",
  307. .id = 0,
  308. .dev = {
  309. .platform_data = &sx1_flash_data,
  310. },
  311. .num_resources = 1,
  312. .resource = &sx1_new_flash_resource,
  313. };
  314. #endif
  315. /*----------- USB -------------------------*/
  316. static struct omap_usb_config sx1_usb_config __initdata = {
  317. .otg = 0,
  318. .register_dev = 1,
  319. .register_host = 0,
  320. .hmc_mode = 0,
  321. .pins[0] = 2,
  322. .pins[1] = 0,
  323. .pins[2] = 0,
  324. };
  325. /*----------- LCD -------------------------*/
  326. static struct platform_device sx1_lcd_device = {
  327. .name = "lcd_sx1",
  328. .id = -1,
  329. };
  330. static struct omap_lcd_config sx1_lcd_config __initdata = {
  331. .ctrl_name = "internal",
  332. };
  333. /*-----------------------------------------*/
  334. static struct platform_device *sx1_devices[] __initdata = {
  335. &sx1_flash_device,
  336. &sx1_kp_device,
  337. &sx1_lcd_device,
  338. &sx1_irda_device,
  339. };
  340. /*-----------------------------------------*/
  341. static struct omap_board_config_kernel sx1_config[] __initdata = {
  342. { OMAP_TAG_LCD, &sx1_lcd_config },
  343. };
  344. /*-----------------------------------------*/
  345. static void __init omap_sx1_init(void)
  346. {
  347. /* mux pins for uarts */
  348. omap_cfg_reg(UART1_TX);
  349. omap_cfg_reg(UART1_RTS);
  350. omap_cfg_reg(UART2_TX);
  351. omap_cfg_reg(UART2_RTS);
  352. omap_cfg_reg(UART3_TX);
  353. omap_cfg_reg(UART3_RX);
  354. platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
  355. omap_board_config = sx1_config;
  356. omap_board_config_size = ARRAY_SIZE(sx1_config);
  357. omap_serial_init();
  358. omap_register_i2c_bus(1, 100, NULL, 0);
  359. omap1_usb_init(&sx1_usb_config);
  360. sx1_mmc_init();
  361. /* turn on USB power */
  362. /* sx1_setusbpower(1); can't do it here because i2c is not ready */
  363. gpio_request(1, "A_IRDA_OFF");
  364. gpio_request(11, "A_SWITCH");
  365. gpio_request(15, "A_USB_ON");
  366. gpio_direction_output(1, 1); /*A_IRDA_OFF = 1 */
  367. gpio_direction_output(11, 0); /*A_SWITCH = 0 */
  368. gpio_direction_output(15, 0); /*A_USB_ON = 0 */
  369. }
  370. MACHINE_START(SX1, "OMAP310 based Siemens SX1")
  371. .atag_offset = 0x100,
  372. .map_io = omap15xx_map_io,
  373. .init_early = omap1_init_early,
  374. .reserve = omap_reserve,
  375. .init_irq = omap1_init_irq,
  376. .init_machine = omap_sx1_init,
  377. .timer = &omap1_timer,
  378. .restart = omap1_restart,
  379. MACHINE_END