board-sx1.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-omap1/board-sx1.c
  4. *
  5. * Modified from board-generic.c
  6. *
  7. * Support for the Siemens SX1 mobile phone.
  8. *
  9. * Original version : Vladimir Ananiev (Vovan888-at-gmail com)
  10. *
  11. * Maintainters : Vladimir Ananiev (aka Vovan888), Sergge
  12. * oslik.ru
  13. */
  14. #include <linux/gpio/machine.h>
  15. #include <linux/gpio/consumer.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/input.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/notifier.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/partitions.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/types.h>
  25. #include <linux/i2c.h>
  26. #include <linux/errno.h>
  27. #include <linux/export.h>
  28. #include <linux/omapfb.h>
  29. #include <linux/platform_data/keypad-omap.h>
  30. #include <linux/omap-dma.h>
  31. #include "tc.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 "mux.h"
  37. #include "board-sx1.h"
  38. #include "hardware.h"
  39. #include "usb.h"
  40. #include "common.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 const unsigned int sx1_keymap[] = {
  152. KEY(3, 5, GROUP_0 | 117), /* camera Qt::Key_F17 */
  153. KEY(4, 0, GROUP_0 | 114), /* voice memo Qt::Key_F14 */
  154. KEY(4, 1, GROUP_2 | 114), /* voice memo */
  155. KEY(4, 2, GROUP_3 | 114), /* voice memo */
  156. KEY(0, 0, GROUP_1 | KEY_F12), /* red button Qt::Key_Hangup */
  157. KEY(3, 4, GROUP_1 | KEY_LEFT),
  158. KEY(3, 2, GROUP_1 | KEY_DOWN),
  159. KEY(3, 1, GROUP_1 | KEY_RIGHT),
  160. KEY(3, 0, GROUP_1 | KEY_UP),
  161. KEY(3, 3, GROUP_1 | KEY_POWER), /* joystick press or Qt::Key_Select */
  162. KEY(0, 5, GROUP_1 | KEY_1),
  163. KEY(0, 4, GROUP_1 | KEY_2),
  164. KEY(0, 3, GROUP_1 | KEY_3),
  165. KEY(4, 3, GROUP_1 | KEY_4),
  166. KEY(4, 4, GROUP_1 | KEY_5),
  167. KEY(4, 5, GROUP_1 | KEY_KPASTERISK),/* "*" */
  168. KEY(1, 4, GROUP_1 | KEY_6),
  169. KEY(1, 5, GROUP_1 | KEY_7),
  170. KEY(1, 3, GROUP_1 | KEY_8),
  171. KEY(2, 3, GROUP_1 | KEY_9),
  172. KEY(2, 5, GROUP_1 | KEY_0),
  173. KEY(2, 4, GROUP_1 | 113), /* # F13 Toggle input method Qt::Key_F13 */
  174. KEY(1, 0, GROUP_1 | KEY_F11), /* green button Qt::Key_Call */
  175. KEY(2, 1, GROUP_1 | KEY_YEN), /* left soft Qt::Key_Context1 */
  176. KEY(2, 2, GROUP_1 | KEY_F8), /* right soft Qt::Key_Back */
  177. KEY(1, 2, GROUP_1 | KEY_LEFTSHIFT), /* shift */
  178. KEY(1, 1, GROUP_1 | KEY_BACKSPACE), /* C (clear) */
  179. KEY(2, 0, GROUP_1 | KEY_F7), /* menu Qt::Key_Menu */
  180. };
  181. static struct resource sx1_kp_resources[] = {
  182. [0] = {
  183. .start = INT_KEYBOARD,
  184. .end = INT_KEYBOARD,
  185. .flags = IORESOURCE_IRQ,
  186. },
  187. };
  188. static const struct matrix_keymap_data sx1_keymap_data = {
  189. .keymap = sx1_keymap,
  190. .keymap_size = ARRAY_SIZE(sx1_keymap),
  191. };
  192. static struct omap_kp_platform_data sx1_kp_data = {
  193. .rows = 6,
  194. .cols = 6,
  195. .keymap_data = &sx1_keymap_data,
  196. .delay = 80,
  197. };
  198. static struct platform_device sx1_kp_device = {
  199. .name = "omap-keypad",
  200. .id = -1,
  201. .dev = {
  202. .platform_data = &sx1_kp_data,
  203. },
  204. .num_resources = ARRAY_SIZE(sx1_kp_resources),
  205. .resource = sx1_kp_resources,
  206. };
  207. /*----------- MTD -------------------------*/
  208. static struct mtd_partition sx1_partitions[] = {
  209. /* bootloader (U-Boot, etc) in first sector */
  210. {
  211. .name = "bootloader",
  212. .offset = 0x01800000,
  213. .size = SZ_128K,
  214. .mask_flags = MTD_WRITEABLE, /* force read-only */
  215. },
  216. /* bootloader params in the next sector */
  217. {
  218. .name = "params",
  219. .offset = MTDPART_OFS_APPEND,
  220. .size = SZ_128K,
  221. .mask_flags = 0,
  222. },
  223. /* kernel */
  224. {
  225. .name = "kernel",
  226. .offset = MTDPART_OFS_APPEND,
  227. .size = SZ_2M - 2 * SZ_128K,
  228. .mask_flags = 0
  229. },
  230. /* file system */
  231. {
  232. .name = "filesystem",
  233. .offset = MTDPART_OFS_APPEND,
  234. .size = MTDPART_SIZ_FULL,
  235. .mask_flags = 0
  236. }
  237. };
  238. static struct physmap_flash_data sx1_flash_data = {
  239. .width = 2,
  240. .set_vpp = omap1_set_vpp,
  241. .parts = sx1_partitions,
  242. .nr_parts = ARRAY_SIZE(sx1_partitions),
  243. };
  244. /* MTD Intel 4000 flash - new flashes */
  245. static struct resource sx1_new_flash_resource = {
  246. .start = OMAP_CS0_PHYS,
  247. .end = OMAP_CS0_PHYS + SZ_32M - 1,
  248. .flags = IORESOURCE_MEM,
  249. };
  250. static struct platform_device sx1_flash_device = {
  251. .name = "physmap-flash",
  252. .id = 0,
  253. .dev = {
  254. .platform_data = &sx1_flash_data,
  255. },
  256. .num_resources = 1,
  257. .resource = &sx1_new_flash_resource,
  258. };
  259. /*----------- USB -------------------------*/
  260. static struct omap_usb_config sx1_usb_config __initdata = {
  261. .otg = 0,
  262. .register_dev = 1,
  263. .register_host = 0,
  264. .hmc_mode = 0,
  265. .pins[0] = 2,
  266. .pins[1] = 0,
  267. .pins[2] = 0,
  268. };
  269. /*----------- LCD -------------------------*/
  270. static const struct omap_lcd_config sx1_lcd_config __initconst = {
  271. .ctrl_name = "internal",
  272. };
  273. /*-----------------------------------------*/
  274. static struct platform_device *sx1_devices[] __initdata = {
  275. &sx1_flash_device,
  276. &sx1_kp_device,
  277. };
  278. /*-----------------------------------------*/
  279. static struct gpiod_lookup_table sx1_gpio_table = {
  280. .dev_id = NULL,
  281. .table = {
  282. GPIO_LOOKUP("gpio-0-15", 1, "irda_off",
  283. GPIO_ACTIVE_HIGH),
  284. GPIO_LOOKUP("gpio-0-15", 11, "switch",
  285. GPIO_ACTIVE_HIGH),
  286. GPIO_LOOKUP("gpio-0-15", 15, "usb_on",
  287. GPIO_ACTIVE_HIGH),
  288. { }
  289. },
  290. };
  291. static void __init omap_sx1_init(void)
  292. {
  293. struct gpio_desc *d;
  294. /* mux pins for uarts */
  295. omap_cfg_reg(UART1_TX);
  296. omap_cfg_reg(UART1_RTS);
  297. omap_cfg_reg(UART2_TX);
  298. omap_cfg_reg(UART2_RTS);
  299. omap_cfg_reg(UART3_TX);
  300. omap_cfg_reg(UART3_RX);
  301. platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
  302. omap_serial_init();
  303. omap_register_i2c_bus(1, 100, NULL, 0);
  304. omap1_usb_init(&sx1_usb_config);
  305. sx1_mmc_init();
  306. gpiod_add_lookup_table(&sx1_gpio_table);
  307. /* turn on USB power */
  308. /* sx1_setusbpower(1); can't do it here because i2c is not ready */
  309. d = gpiod_get(NULL, "irda_off", GPIOD_OUT_HIGH);
  310. if (IS_ERR(d))
  311. pr_err("Unable to get IRDA OFF GPIO descriptor\n");
  312. else
  313. gpiod_put(d);
  314. d = gpiod_get(NULL, "switch", GPIOD_OUT_LOW);
  315. if (IS_ERR(d))
  316. pr_err("Unable to get SWITCH GPIO descriptor\n");
  317. else
  318. gpiod_put(d);
  319. d = gpiod_get(NULL, "usb_on", GPIOD_OUT_LOW);
  320. if (IS_ERR(d))
  321. pr_err("Unable to get USB ON GPIO descriptor\n");
  322. else
  323. gpiod_put(d);
  324. omapfb_set_lcd_config(&sx1_lcd_config);
  325. }
  326. MACHINE_START(SX1, "OMAP310 based Siemens SX1")
  327. .atag_offset = 0x100,
  328. .map_io = omap1_map_io,
  329. .init_early = omap1_init_early,
  330. .init_irq = omap1_init_irq,
  331. .init_machine = omap_sx1_init,
  332. .init_late = omap1_init_late,
  333. .init_time = omap1_timer_init,
  334. .restart = omap1_restart,
  335. MACHINE_END