board-sx1.c 10 KB

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