board-sx1.c 10 KB

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