board-sx1.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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/irda.h>
  35. #include <mach/usb.h>
  36. #include <mach/tc.h>
  37. #include <mach/board.h>
  38. #include <mach/common.h>
  39. #include <mach/mcbsp.h>
  40. #include <mach/omap-alsa.h>
  41. #include <mach/keypad.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. /*----------- McBSP & Sound -------------------------*/
  235. /* Playback interface - McBSP1 */
  236. static struct omap_mcbsp_reg_cfg mcbsp1_regs = {
  237. .spcr2 = XINTM(3), /* SPCR2=30 */
  238. .spcr1 = RINTM(3), /* SPCR1=30 */
  239. .rcr2 = 0, /* RCR2 =00 */
  240. .rcr1 = RFRLEN1(1) | RWDLEN1(OMAP_MCBSP_WORD_16), /* RCR1=140 */
  241. .xcr2 = 0, /* XCR2 = 0 */
  242. .xcr1 = XFRLEN1(1) | XWDLEN1(OMAP_MCBSP_WORD_16), /* XCR1 = 140 */
  243. .srgr1 = FWID(15) | CLKGDV(12), /* SRGR1=0f0c */
  244. .srgr2 = FSGM | FPER(31), /* SRGR2=101f */
  245. .pcr0 = FSXM | FSRM | CLKXM | CLKRM | FSXP | FSRP | CLKXP | CLKRP,
  246. /* PCR0 =0f0f */
  247. };
  248. static struct omap_alsa_codec_config sx1_alsa_config = {
  249. .name = "SX1 EGold",
  250. .mcbsp_regs_alsa = &mcbsp1_regs,
  251. };
  252. static struct platform_device sx1_mcbsp1_device = {
  253. .name = "omap_alsa_mcbsp",
  254. .id = 1,
  255. .dev = {
  256. .platform_data = &sx1_alsa_config,
  257. },
  258. };
  259. /*----------- MTD -------------------------*/
  260. static struct mtd_partition sx1_partitions[] = {
  261. /* bootloader (U-Boot, etc) in first sector */
  262. {
  263. .name = "bootloader",
  264. .offset = 0x01800000,
  265. .size = SZ_128K,
  266. .mask_flags = MTD_WRITEABLE, /* force read-only */
  267. },
  268. /* bootloader params in the next sector */
  269. {
  270. .name = "params",
  271. .offset = MTDPART_OFS_APPEND,
  272. .size = SZ_128K,
  273. .mask_flags = 0,
  274. },
  275. /* kernel */
  276. {
  277. .name = "kernel",
  278. .offset = MTDPART_OFS_APPEND,
  279. .size = SZ_2M - 2 * SZ_128K,
  280. .mask_flags = 0
  281. },
  282. /* file system */
  283. {
  284. .name = "filesystem",
  285. .offset = MTDPART_OFS_APPEND,
  286. .size = MTDPART_SIZ_FULL,
  287. .mask_flags = 0
  288. }
  289. };
  290. static struct flash_platform_data sx1_flash_data = {
  291. .map_name = "cfi_probe",
  292. .width = 2,
  293. .parts = sx1_partitions,
  294. .nr_parts = ARRAY_SIZE(sx1_partitions),
  295. };
  296. #ifdef CONFIG_SX1_OLD_FLASH
  297. /* MTD Intel StrataFlash - old flashes */
  298. static struct resource sx1_old_flash_resource[] = {
  299. [0] = {
  300. .start = OMAP_CS0_PHYS, /* Physical */
  301. .end = OMAP_CS0_PHYS + SZ_16M - 1,,
  302. .flags = IORESOURCE_MEM,
  303. },
  304. [1] = {
  305. .start = OMAP_CS1_PHYS,
  306. .end = OMAP_CS1_PHYS + SZ_8M - 1,
  307. .flags = IORESOURCE_MEM,
  308. },
  309. };
  310. static struct platform_device sx1_flash_device = {
  311. .name = "omapflash",
  312. .id = 0,
  313. .dev = {
  314. .platform_data = &sx1_flash_data,
  315. },
  316. .num_resources = 2,
  317. .resource = &sx1_old_flash_resource,
  318. };
  319. #else
  320. /* MTD Intel 4000 flash - new flashes */
  321. static struct resource sx1_new_flash_resource = {
  322. .start = OMAP_CS0_PHYS,
  323. .end = OMAP_CS0_PHYS + SZ_32M - 1,
  324. .flags = IORESOURCE_MEM,
  325. };
  326. static struct platform_device sx1_flash_device = {
  327. .name = "omapflash",
  328. .id = 0,
  329. .dev = {
  330. .platform_data = &sx1_flash_data,
  331. },
  332. .num_resources = 1,
  333. .resource = &sx1_new_flash_resource,
  334. };
  335. #endif
  336. /*----------- USB -------------------------*/
  337. static struct omap_usb_config sx1_usb_config __initdata = {
  338. .otg = 0,
  339. .register_dev = 1,
  340. .register_host = 0,
  341. .hmc_mode = 0,
  342. .pins[0] = 2,
  343. .pins[1] = 0,
  344. .pins[2] = 0,
  345. };
  346. /*----------- MMC -------------------------*/
  347. static struct omap_mmc_config sx1_mmc_config __initdata = {
  348. .mmc [0] = {
  349. .enabled = 1,
  350. .wire4 = 0,
  351. },
  352. };
  353. /*----------- LCD -------------------------*/
  354. static struct platform_device sx1_lcd_device = {
  355. .name = "lcd_sx1",
  356. .id = -1,
  357. };
  358. static struct omap_lcd_config sx1_lcd_config __initdata = {
  359. .ctrl_name = "internal",
  360. };
  361. /*-----------------------------------------*/
  362. static struct platform_device *sx1_devices[] __initdata = {
  363. &sx1_flash_device,
  364. &sx1_kp_device,
  365. &sx1_lcd_device,
  366. &sx1_mcbsp1_device,
  367. &sx1_irda_device,
  368. };
  369. /*-----------------------------------------*/
  370. static struct omap_uart_config sx1_uart_config __initdata = {
  371. .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
  372. };
  373. static struct omap_board_config_kernel sx1_config[] __initdata = {
  374. { OMAP_TAG_USB, &sx1_usb_config },
  375. { OMAP_TAG_MMC, &sx1_mmc_config },
  376. { OMAP_TAG_LCD, &sx1_lcd_config },
  377. { OMAP_TAG_UART, &sx1_uart_config },
  378. };
  379. /*-----------------------------------------*/
  380. static void __init omap_sx1_init(void)
  381. {
  382. platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
  383. omap_board_config = sx1_config;
  384. omap_board_config_size = ARRAY_SIZE(sx1_config);
  385. omap_serial_init();
  386. omap_register_i2c_bus(1, 100, NULL, 0);
  387. sx1_mmc_init();
  388. /* turn on USB power */
  389. /* sx1_setusbpower(1); cant do it here because i2c is not ready */
  390. omap_request_gpio(1); /* A_IRDA_OFF */
  391. omap_request_gpio(11); /* A_SWITCH */
  392. omap_request_gpio(15); /* A_USB_ON */
  393. omap_set_gpio_direction(1, 0);/* gpio1 -> output */
  394. omap_set_gpio_direction(11, 0);/* gpio11 -> output */
  395. omap_set_gpio_direction(15, 0);/* gpio15 -> output */
  396. /* set GPIO data */
  397. omap_set_gpio_dataout(1, 1);/*A_IRDA_OFF = 1 */
  398. omap_set_gpio_dataout(11, 0);/*A_SWITCH = 0 */
  399. omap_set_gpio_dataout(15, 0);/*A_USB_ON = 0 */
  400. }
  401. /*----------------------------------------*/
  402. static void __init omap_sx1_init_irq(void)
  403. {
  404. omap1_init_common_hw();
  405. omap_init_irq();
  406. omap_gpio_init();
  407. }
  408. /*----------------------------------------*/
  409. static void __init omap_sx1_map_io(void)
  410. {
  411. omap1_map_common_io();
  412. }
  413. MACHINE_START(SX1, "OMAP310 based Siemens SX1")
  414. .phys_io = 0xfff00000,
  415. .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
  416. .boot_params = 0x10000100,
  417. .map_io = omap_sx1_map_io,
  418. .init_irq = omap_sx1_init_irq,
  419. .init_machine = omap_sx1_init,
  420. .timer = &omap_timer,
  421. MACHINE_END