board-sx1.c 9.7 KB

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