board-sx1.c 8.5 KB

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