board-sx1.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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 <asm/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 <asm/arch/gpio.h>
  33. #include <asm/arch/mux.h>
  34. #include <asm/arch/irda.h>
  35. #include <asm/arch/usb.h>
  36. #include <asm/arch/tc.h>
  37. #include <asm/arch/board.h>
  38. #include <asm/arch/common.h>
  39. #include <asm/arch/mcbsp.h>
  40. #include <asm/arch/omap-alsa.h>
  41. #include <asm/arch/keypad.h>
  42. /* Write to I2C device */
  43. int 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. if (err >= 0)
  60. return 0;
  61. return err;
  62. }
  63. /* Read from I2C device */
  64. int 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. if (err >= 0)
  86. return 0;
  87. return err;
  88. }
  89. /* set keyboard backlight intensity */
  90. int sx1_setkeylight(u8 keylight)
  91. {
  92. if (keylight > SOFIA_MAX_LIGHT_VAL)
  93. keylight = SOFIA_MAX_LIGHT_VAL;
  94. return i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
  95. }
  96. /* get current keylight intensity */
  97. int sx1_getkeylight(u8 * keylight)
  98. {
  99. return i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
  100. }
  101. /* set LCD backlight intensity */
  102. int sx1_setbacklight(u8 backlight)
  103. {
  104. if (backlight > SOFIA_MAX_LIGHT_VAL)
  105. backlight = SOFIA_MAX_LIGHT_VAL;
  106. return i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG, backlight);
  107. }
  108. /* get current LCD backlight intensity */
  109. int sx1_getbacklight (u8 * backlight)
  110. {
  111. return i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG, backlight);
  112. }
  113. /* set LCD backlight power on/off */
  114. int sx1_setmmipower(u8 onoff)
  115. {
  116. int err;
  117. u8 dat = 0;
  118. err = i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
  119. if (err < 0)
  120. return err;
  121. if (onoff)
  122. dat |= SOFIA_MMILIGHT_POWER;
  123. else
  124. dat &= ~SOFIA_MMILIGHT_POWER;
  125. return i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
  126. }
  127. /* set MMC power on/off */
  128. int sx1_setmmcpower(u8 onoff)
  129. {
  130. int err;
  131. u8 dat = 0;
  132. err = i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
  133. if (err < 0)
  134. return err;
  135. if (onoff)
  136. dat |= SOFIA_MMC_POWER;
  137. else
  138. dat &= ~SOFIA_MMC_POWER;
  139. return i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
  140. }
  141. /* set USB power on/off */
  142. int sx1_setusbpower(u8 onoff)
  143. {
  144. int err;
  145. u8 dat = 0;
  146. err = i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
  147. if (err < 0)
  148. return err;
  149. if (onoff)
  150. dat |= SOFIA_USB_POWER;
  151. else
  152. dat &= ~SOFIA_USB_POWER;
  153. return i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
  154. }
  155. EXPORT_SYMBOL(sx1_setkeylight);
  156. EXPORT_SYMBOL(sx1_getkeylight);
  157. EXPORT_SYMBOL(sx1_setbacklight);
  158. EXPORT_SYMBOL(sx1_getbacklight);
  159. EXPORT_SYMBOL(sx1_setmmipower);
  160. EXPORT_SYMBOL(sx1_setmmcpower);
  161. EXPORT_SYMBOL(sx1_setusbpower);
  162. /*----------- Keypad -------------------------*/
  163. static int sx1_keymap[] = {
  164. KEY(5, 3, GROUP_0 | 117), /* camera Qt::Key_F17 */
  165. KEY(0, 4, GROUP_0 | 114), /* voice memo Qt::Key_F14 */
  166. KEY(1, 4, GROUP_2 | 114), /* voice memo */
  167. KEY(2, 4, GROUP_3 | 114), /* voice memo */
  168. KEY(0, 0, GROUP_1 | KEY_F12), /* red button Qt::Key_Hangup */
  169. KEY(4, 3, GROUP_1 | KEY_LEFT),
  170. KEY(2, 3, GROUP_1 | KEY_DOWN),
  171. KEY(1, 3, GROUP_1 | KEY_RIGHT),
  172. KEY(0, 3, GROUP_1 | KEY_UP),
  173. KEY(3, 3, GROUP_1 | KEY_POWER), /* joystick press or Qt::Key_Select */
  174. KEY(5, 0, GROUP_1 | KEY_1),
  175. KEY(4, 0, GROUP_1 | KEY_2),
  176. KEY(3, 0, GROUP_1 | KEY_3),
  177. KEY(3, 4, GROUP_1 | KEY_4),
  178. KEY(4, 4, GROUP_1 | KEY_5),
  179. KEY(5, 4, GROUP_1 | KEY_KPASTERISK),/* "*" */
  180. KEY(4, 1, GROUP_1 | KEY_6),
  181. KEY(5, 1, GROUP_1 | KEY_7),
  182. KEY(3, 1, GROUP_1 | KEY_8),
  183. KEY(3, 2, GROUP_1 | KEY_9),
  184. KEY(5, 2, GROUP_1 | KEY_0),
  185. KEY(4, 2, GROUP_1 | 113), /* # F13 Toggle input method Qt::Key_F13 */
  186. KEY(0, 1, GROUP_1 | KEY_F11), /* green button Qt::Key_Call */
  187. KEY(1, 2, GROUP_1 | KEY_YEN), /* left soft Qt::Key_Context1 */
  188. KEY(2, 2, GROUP_1 | KEY_F8), /* right soft Qt::Key_Back */
  189. KEY(2, 1, GROUP_1 | KEY_LEFTSHIFT), /* shift */
  190. KEY(1, 1, GROUP_1 | KEY_BACKSPACE), /* C (clear) */
  191. KEY(0, 2, GROUP_1 | KEY_F7), /* menu Qt::Key_Menu */
  192. 0
  193. };
  194. static struct resource sx1_kp_resources[] = {
  195. [0] = {
  196. .start = INT_KEYBOARD,
  197. .end = INT_KEYBOARD,
  198. .flags = IORESOURCE_IRQ,
  199. },
  200. };
  201. static struct omap_kp_platform_data sx1_kp_data = {
  202. .rows = 6,
  203. .cols = 6,
  204. .keymap = sx1_keymap,
  205. .keymapsize = ARRAY_SIZE(sx1_keymap),
  206. .delay = 80,
  207. };
  208. static struct platform_device sx1_kp_device = {
  209. .name = "omap-keypad",
  210. .id = -1,
  211. .dev = {
  212. .platform_data = &sx1_kp_data,
  213. },
  214. .num_resources = ARRAY_SIZE(sx1_kp_resources),
  215. .resource = sx1_kp_resources,
  216. };
  217. /*----------- IRDA -------------------------*/
  218. static struct omap_irda_config sx1_irda_data = {
  219. .transceiver_cap = IR_SIRMODE,
  220. .rx_channel = OMAP_DMA_UART3_RX,
  221. .tx_channel = OMAP_DMA_UART3_TX,
  222. .dest_start = UART3_THR,
  223. .src_start = UART3_RHR,
  224. .tx_trigger = 0,
  225. .rx_trigger = 0,
  226. };
  227. static struct resource sx1_irda_resources[] = {
  228. [0] = {
  229. .start = INT_UART3,
  230. .end = INT_UART3,
  231. .flags = IORESOURCE_IRQ,
  232. },
  233. };
  234. static u64 irda_dmamask = 0xffffffff;
  235. static struct platform_device sx1_irda_device = {
  236. .name = "omapirda",
  237. .id = 0,
  238. .dev = {
  239. .platform_data = &sx1_irda_data,
  240. .dma_mask = &irda_dmamask,
  241. },
  242. .num_resources = ARRAY_SIZE(sx1_irda_resources),
  243. .resource = sx1_irda_resources,
  244. };
  245. /*----------- McBSP & Sound -------------------------*/
  246. /* Playback interface - McBSP1 */
  247. static struct omap_mcbsp_reg_cfg mcbsp1_regs = {
  248. .spcr2 = XINTM(3), /* SPCR2=30 */
  249. .spcr1 = RINTM(3), /* SPCR1=30 */
  250. .rcr2 = 0, /* RCR2 =00 */
  251. .rcr1 = RFRLEN1(1) | RWDLEN1(OMAP_MCBSP_WORD_16), /* RCR1=140 */
  252. .xcr2 = 0, /* XCR2 = 0 */
  253. .xcr1 = XFRLEN1(1) | XWDLEN1(OMAP_MCBSP_WORD_16), /* XCR1 = 140 */
  254. .srgr1 = FWID(15) | CLKGDV(12), /* SRGR1=0f0c */
  255. .srgr2 = FSGM | FPER(31), /* SRGR2=101f */
  256. .pcr0 = FSXM | FSRM | CLKXM | CLKRM | FSXP | FSRP | CLKXP | CLKRP,
  257. /* PCR0 =0f0f */
  258. };
  259. /* TODO: PCM interface - McBSP2 */
  260. static struct omap_mcbsp_reg_cfg mcbsp2_regs = {
  261. .spcr2 = FRST | GRST | XRST | XINTM(3), /* SPCR2=F1 */
  262. .spcr1 = RINTM(3) | RRST, /* SPCR1=30 */
  263. .rcr2 = 0, /* RCR2 =00 */
  264. .rcr1 = RFRLEN1(1) | RWDLEN1(OMAP_MCBSP_WORD_16), /* RCR1 = 140 */
  265. .xcr2 = 0, /* XCR2 = 0 */
  266. .xcr1 = XFRLEN1(1) | XWDLEN1(OMAP_MCBSP_WORD_16), /* XCR1 = 140 */
  267. .srgr1 = FWID(15) | CLKGDV(12), /* SRGR1=0f0c */
  268. .srgr2 = FSGM | FPER(31), /* SRGR2=101f */
  269. .pcr0 = FSXM | FSRM | CLKXM | CLKRM | FSXP | FSRP | CLKXP | CLKRP,
  270. /* PCR0=0f0f */
  271. /* mcbsp: slave */
  272. };
  273. static struct omap_alsa_codec_config sx1_alsa_config = {
  274. .name = "SX1 EGold",
  275. .mcbsp_regs_alsa = &mcbsp1_regs,
  276. };
  277. static struct platform_device sx1_mcbsp1_device = {
  278. .name = "omap_alsa_mcbsp",
  279. .id = 1,
  280. .dev = {
  281. .platform_data = &sx1_alsa_config,
  282. },
  283. };
  284. /*----------- MTD -------------------------*/
  285. static struct mtd_partition sx1_partitions[] = {
  286. /* bootloader (U-Boot, etc) in first sector */
  287. {
  288. .name = "bootloader",
  289. .offset = 0x01800000,
  290. .size = SZ_128K,
  291. .mask_flags = MTD_WRITEABLE, /* force read-only */
  292. },
  293. /* bootloader params in the next sector */
  294. {
  295. .name = "params",
  296. .offset = MTDPART_OFS_APPEND,
  297. .size = SZ_128K,
  298. .mask_flags = 0,
  299. },
  300. /* kernel */
  301. {
  302. .name = "kernel",
  303. .offset = MTDPART_OFS_APPEND,
  304. .size = SZ_2M - 2 * SZ_128K,
  305. .mask_flags = 0
  306. },
  307. /* file system */
  308. {
  309. .name = "filesystem",
  310. .offset = MTDPART_OFS_APPEND,
  311. .size = MTDPART_SIZ_FULL,
  312. .mask_flags = 0
  313. }
  314. };
  315. static struct flash_platform_data sx1_flash_data = {
  316. .map_name = "cfi_probe",
  317. .width = 2,
  318. .parts = sx1_partitions,
  319. .nr_parts = ARRAY_SIZE(sx1_partitions),
  320. };
  321. #ifdef CONFIG_SX1_OLD_FLASH
  322. /* MTD Intel StrataFlash - old flashes */
  323. static struct resource sx1_old_flash_resource[] = {
  324. [0] = {
  325. .start = OMAP_CS0_PHYS, /* Physical */
  326. .end = OMAP_CS0_PHYS + SZ_16M - 1,,
  327. .flags = IORESOURCE_MEM,
  328. },
  329. [1] = {
  330. .start = OMAP_CS1_PHYS,
  331. .end = OMAP_CS1_PHYS + SZ_8M - 1,
  332. .flags = IORESOURCE_MEM,
  333. },
  334. };
  335. static struct platform_device sx1_flash_device = {
  336. .name = "omapflash",
  337. .id = 0,
  338. .dev = {
  339. .platform_data = &sx1_flash_data,
  340. },
  341. .num_resources = 2,
  342. .resource = &sx1_old_flash_resource,
  343. };
  344. #else
  345. /* MTD Intel 4000 flash - new flashes */
  346. static struct resource sx1_new_flash_resource = {
  347. .start = OMAP_CS0_PHYS,
  348. .end = OMAP_CS0_PHYS + SZ_32M - 1,
  349. .flags = IORESOURCE_MEM,
  350. };
  351. static struct platform_device sx1_flash_device = {
  352. .name = "omapflash",
  353. .id = 0,
  354. .dev = {
  355. .platform_data = &sx1_flash_data,
  356. },
  357. .num_resources = 1,
  358. .resource = &sx1_new_flash_resource,
  359. };
  360. #endif
  361. /*----------- USB -------------------------*/
  362. static struct omap_usb_config sx1_usb_config __initdata = {
  363. .otg = 0,
  364. .register_dev = 1,
  365. .register_host = 0,
  366. .hmc_mode = 0,
  367. .pins[0] = 2,
  368. .pins[1] = 0,
  369. .pins[2] = 0,
  370. };
  371. /*----------- MMC -------------------------*/
  372. static struct omap_mmc_config sx1_mmc_config __initdata = {
  373. .mmc [0] = {
  374. .enabled = 1,
  375. .wire4 = 0,
  376. .wp_pin = -1,
  377. .power_pin = -1, /* power is in Sofia */
  378. .switch_pin = OMAP_MPUIO(3),
  379. },
  380. };
  381. /*----------- LCD -------------------------*/
  382. static struct platform_device sx1_lcd_device = {
  383. .name = "lcd_sx1",
  384. .id = -1,
  385. };
  386. static struct omap_lcd_config sx1_lcd_config __initdata = {
  387. .ctrl_name = "internal",
  388. };
  389. /*-----------------------------------------*/
  390. static struct platform_device *sx1_devices[] __initdata = {
  391. &sx1_flash_device,
  392. &sx1_kp_device,
  393. &sx1_lcd_device,
  394. &sx1_mcbsp1_device,
  395. &sx1_irda_device,
  396. };
  397. /*-----------------------------------------*/
  398. static struct omap_uart_config sx1_uart_config __initdata = {
  399. .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
  400. };
  401. static struct omap_board_config_kernel sx1_config[] = {
  402. { OMAP_TAG_USB, &sx1_usb_config },
  403. { OMAP_TAG_MMC, &sx1_mmc_config },
  404. { OMAP_TAG_LCD, &sx1_lcd_config },
  405. { OMAP_TAG_UART, &sx1_uart_config },
  406. };
  407. /*-----------------------------------------*/
  408. static void __init omap_sx1_init(void)
  409. {
  410. platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
  411. omap_board_config = sx1_config;
  412. omap_board_config_size = ARRAY_SIZE(sx1_config);
  413. omap_serial_init();
  414. /* turn on USB power */
  415. /* sx1_setusbpower(1); cant do it here because i2c is not ready */
  416. omap_request_gpio(1); /* A_IRDA_OFF */
  417. omap_request_gpio(11); /* A_SWITCH */
  418. omap_request_gpio(15); /* A_USB_ON */
  419. omap_set_gpio_direction(1, 0);/* gpio1 -> output */
  420. omap_set_gpio_direction(11, 0);/* gpio11 -> output */
  421. omap_set_gpio_direction(15, 0);/* gpio15 -> output */
  422. /* set GPIO data */
  423. omap_set_gpio_dataout(1, 1);/*A_IRDA_OFF = 1 */
  424. omap_set_gpio_dataout(11, 0);/*A_SWITCH = 0 */
  425. omap_set_gpio_dataout(15, 0);/*A_USB_ON = 0 */
  426. }
  427. /*----------------------------------------*/
  428. static void __init omap_sx1_init_irq(void)
  429. {
  430. omap1_init_common_hw();
  431. omap_init_irq();
  432. omap_gpio_init();
  433. }
  434. /*----------------------------------------*/
  435. static void __init omap_sx1_map_io(void)
  436. {
  437. omap1_map_common_io();
  438. }
  439. MACHINE_START(SX1, "OMAP310 based Siemens SX1")
  440. .phys_io = 0xfff00000,
  441. .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
  442. .boot_params = 0x10000100,
  443. .map_io = omap_sx1_map_io,
  444. .init_irq = omap_sx1_init_irq,
  445. .init_machine = omap_sx1_init,
  446. .timer = &omap_timer,
  447. MACHINE_END