board-nokia770.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-omap1/board-nokia770.c
  4. *
  5. * Modified from board-generic.c
  6. */
  7. #include <linux/clkdev.h>
  8. #include <linux/irq.h>
  9. #include <linux/gpio/consumer.h>
  10. #include <linux/gpio/machine.h>
  11. #include <linux/gpio/property.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/mutex.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/property.h>
  17. #include <linux/input.h>
  18. #include <linux/omapfb.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/delay.h>
  22. #include <linux/platform_data/keypad-omap.h>
  23. #include <linux/platform_data/lcd-mipid.h>
  24. #include <linux/platform_data/gpio-omap.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include "mux.h"
  29. #include "hardware.h"
  30. #include "usb.h"
  31. #include "common.h"
  32. #include "clock.h"
  33. #include "mmc.h"
  34. static const struct software_node nokia770_mpuio_gpiochip_node = {
  35. .name = "mpuio",
  36. };
  37. static const struct software_node nokia770_gpiochip1_node = {
  38. .name = "gpio-0-15",
  39. };
  40. static const struct software_node nokia770_gpiochip2_node = {
  41. .name = "gpio-16-31",
  42. };
  43. static const struct software_node *nokia770_gpiochip_nodes[] = {
  44. &nokia770_mpuio_gpiochip_node,
  45. &nokia770_gpiochip1_node,
  46. &nokia770_gpiochip2_node,
  47. NULL
  48. };
  49. #define ADS7846_PENDOWN_GPIO 15
  50. static const unsigned int nokia770_keymap[] = {
  51. KEY(1, 0, GROUP_0 | KEY_UP),
  52. KEY(2, 0, GROUP_1 | KEY_F5),
  53. KEY(0, 1, GROUP_0 | KEY_LEFT),
  54. KEY(1, 1, GROUP_0 | KEY_ENTER),
  55. KEY(2, 1, GROUP_0 | KEY_RIGHT),
  56. KEY(0, 2, GROUP_1 | KEY_ESC),
  57. KEY(1, 2, GROUP_0 | KEY_DOWN),
  58. KEY(2, 2, GROUP_1 | KEY_F4),
  59. KEY(0, 3, GROUP_2 | KEY_F7),
  60. KEY(1, 3, GROUP_2 | KEY_F8),
  61. KEY(2, 3, GROUP_2 | KEY_F6),
  62. };
  63. static struct resource nokia770_kp_resources[] = {
  64. [0] = {
  65. .start = INT_KEYBOARD,
  66. .end = INT_KEYBOARD,
  67. .flags = IORESOURCE_IRQ,
  68. },
  69. };
  70. static const struct matrix_keymap_data nokia770_keymap_data = {
  71. .keymap = nokia770_keymap,
  72. .keymap_size = ARRAY_SIZE(nokia770_keymap),
  73. };
  74. static struct omap_kp_platform_data nokia770_kp_data = {
  75. .rows = 8,
  76. .cols = 8,
  77. .keymap_data = &nokia770_keymap_data,
  78. .delay = 4,
  79. };
  80. static struct platform_device nokia770_kp_device = {
  81. .name = "omap-keypad",
  82. .id = -1,
  83. .dev = {
  84. .platform_data = &nokia770_kp_data,
  85. },
  86. .num_resources = ARRAY_SIZE(nokia770_kp_resources),
  87. .resource = nokia770_kp_resources,
  88. };
  89. static struct platform_device *nokia770_devices[] __initdata = {
  90. &nokia770_kp_device,
  91. };
  92. static struct mipid_platform_data nokia770_mipid_platform_data = { };
  93. static const struct omap_lcd_config nokia770_lcd_config __initconst = {
  94. .ctrl_name = "hwa742",
  95. };
  96. static const struct property_entry nokia770_mipid_props[] = {
  97. PROPERTY_ENTRY_GPIO("reset-gpios", &nokia770_gpiochip1_node,
  98. 13, GPIO_ACTIVE_LOW),
  99. { }
  100. };
  101. static const struct software_node nokia770_mipid_swnode = {
  102. .name = "lcd_mipid",
  103. .properties = nokia770_mipid_props,
  104. };
  105. static void __init mipid_dev_init(void)
  106. {
  107. nokia770_mipid_platform_data.data_lines = 16;
  108. omapfb_set_lcd_config(&nokia770_lcd_config);
  109. }
  110. static const struct property_entry nokia770_ads7846_props[] = {
  111. PROPERTY_ENTRY_STRING("compatible", "ti,ads7846"),
  112. PROPERTY_ENTRY_U32("touchscreen-size-x", 4096),
  113. PROPERTY_ENTRY_U32("touchscreen-size-y", 4096),
  114. PROPERTY_ENTRY_U32("touchscreen-max-pressure", 256),
  115. PROPERTY_ENTRY_U32("touchscreen-average-samples", 10),
  116. PROPERTY_ENTRY_U16("ti,x-plate-ohms", 180),
  117. PROPERTY_ENTRY_U16("ti,debounce-tol", 3),
  118. PROPERTY_ENTRY_U16("ti,debounce-rep", 1),
  119. PROPERTY_ENTRY_GPIO("pendown-gpios", &nokia770_gpiochip1_node,
  120. ADS7846_PENDOWN_GPIO, GPIO_ACTIVE_LOW),
  121. { }
  122. };
  123. static const struct software_node nokia770_ads7846_swnode = {
  124. .name = "ads7846",
  125. .properties = nokia770_ads7846_props,
  126. };
  127. static struct spi_board_info nokia770_spi_board_info[] __initdata = {
  128. [0] = {
  129. .modalias = "lcd_mipid",
  130. .bus_num = 2,
  131. .chip_select = 3,
  132. .max_speed_hz = 12000000,
  133. .platform_data = &nokia770_mipid_platform_data,
  134. .swnode = &nokia770_mipid_swnode,
  135. },
  136. [1] = {
  137. .modalias = "ads7846",
  138. .bus_num = 2,
  139. .chip_select = 0,
  140. .max_speed_hz = 2500000,
  141. .swnode = &nokia770_ads7846_swnode,
  142. },
  143. };
  144. static void __init hwa742_dev_init(void)
  145. {
  146. clk_add_alias("hwa_sys_ck", NULL, "bclk", NULL);
  147. }
  148. /* assume no Mini-AB port */
  149. static struct omap_usb_config nokia770_usb_config __initdata = {
  150. .otg = 1,
  151. .register_host = 1,
  152. .register_dev = 1,
  153. .hmc_mode = 16,
  154. .pins[0] = 6,
  155. .extcon = "tahvo-usb",
  156. };
  157. #if IS_ENABLED(CONFIG_MMC_OMAP)
  158. static struct gpiod_lookup_table nokia770_mmc_gpio_table = {
  159. .dev_id = "mmci-omap.1",
  160. .table = {
  161. /* Slot index 0, VSD power, GPIO 41 */
  162. GPIO_LOOKUP_IDX("gpio-32-47", 9,
  163. "vsd", 0, GPIO_ACTIVE_HIGH),
  164. /* Slot index 0, switch, GPIO 23 */
  165. GPIO_LOOKUP_IDX("gpio-16-31", 7,
  166. "cover", 0, GPIO_ACTIVE_HIGH),
  167. { }
  168. },
  169. };
  170. static struct omap_mmc_platform_data nokia770_mmc2_data = {
  171. .nr_slots = 1,
  172. .max_freq = 12000000,
  173. .slots[0] = {
  174. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  175. .name = "mmcblk",
  176. },
  177. };
  178. static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC];
  179. static void __init nokia770_mmc_init(void)
  180. {
  181. gpiod_add_lookup_table(&nokia770_mmc_gpio_table);
  182. /* Only the second MMC controller is used */
  183. nokia770_mmc_data[1] = &nokia770_mmc2_data;
  184. omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);
  185. }
  186. #else
  187. static inline void nokia770_mmc_init(void)
  188. {
  189. }
  190. #endif
  191. #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO)
  192. static const struct software_node_ref_args nokia770_cbus_gpio_refs[] = {
  193. SOFTWARE_NODE_REFERENCE(&nokia770_mpuio_gpiochip_node, 9, 0),
  194. SOFTWARE_NODE_REFERENCE(&nokia770_mpuio_gpiochip_node, 10, 0),
  195. SOFTWARE_NODE_REFERENCE(&nokia770_mpuio_gpiochip_node, 11, 0),
  196. };
  197. static const struct property_entry nokia770_cbus_props[] = {
  198. PROPERTY_ENTRY_REF_ARRAY("gpios", nokia770_cbus_gpio_refs),
  199. { }
  200. };
  201. static struct platform_device nokia770_cbus_device = {
  202. .name = "i2c-cbus-gpio",
  203. .id = 2,
  204. };
  205. static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = {
  206. {
  207. I2C_BOARD_INFO("retu", 0x01),
  208. },
  209. {
  210. I2C_BOARD_INFO("tahvo", 0x02),
  211. },
  212. };
  213. static void __init nokia770_cbus_init(void)
  214. {
  215. struct gpio_desc *d;
  216. int irq;
  217. d = gpiod_get(NULL, "retu_irq", GPIOD_IN);
  218. if (IS_ERR(d)) {
  219. pr_err("Unable to get CBUS Retu IRQ GPIO descriptor\n");
  220. } else {
  221. irq = gpiod_to_irq(d);
  222. irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
  223. nokia770_i2c_board_info_2[0].irq = irq;
  224. }
  225. d = gpiod_get(NULL, "tahvo_irq", GPIOD_IN);
  226. if (IS_ERR(d)) {
  227. pr_err("Unable to get CBUS Tahvo IRQ GPIO descriptor\n");
  228. } else {
  229. irq = gpiod_to_irq(d);
  230. irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
  231. nokia770_i2c_board_info_2[1].irq = irq;
  232. }
  233. i2c_register_board_info(2, nokia770_i2c_board_info_2,
  234. ARRAY_SIZE(nokia770_i2c_board_info_2));
  235. device_create_managed_software_node(&nokia770_cbus_device.dev,
  236. nokia770_cbus_props, NULL);
  237. platform_device_register(&nokia770_cbus_device);
  238. }
  239. #else /* CONFIG_I2C_CBUS_GPIO */
  240. static void __init nokia770_cbus_init(void)
  241. {
  242. }
  243. #endif /* CONFIG_I2C_CBUS_GPIO */
  244. static struct gpiod_lookup_table nokia770_irq_gpio_table = {
  245. .dev_id = NULL,
  246. .table = {
  247. /* GPIO used by SPI device 1 */
  248. GPIO_LOOKUP("gpio-0-15", 15, "ads7846_irq",
  249. GPIO_ACTIVE_HIGH),
  250. /* GPIO used for retu IRQ */
  251. GPIO_LOOKUP("gpio-48-63", 14, "retu_irq",
  252. GPIO_ACTIVE_HIGH),
  253. /* GPIO used for tahvo IRQ */
  254. GPIO_LOOKUP("gpio-32-47", 8, "tahvo_irq",
  255. GPIO_ACTIVE_HIGH),
  256. /* GPIOs used by serial wakeup IRQs */
  257. GPIO_LOOKUP_IDX("gpio-32-47", 5, "wakeup", 0,
  258. GPIO_ACTIVE_HIGH),
  259. GPIO_LOOKUP_IDX("gpio-16-31", 2, "wakeup", 1,
  260. GPIO_ACTIVE_HIGH),
  261. GPIO_LOOKUP_IDX("gpio-48-63", 1, "wakeup", 2,
  262. GPIO_ACTIVE_HIGH),
  263. { }
  264. },
  265. };
  266. static void __init omap_nokia770_init(void)
  267. {
  268. struct gpio_desc *d;
  269. /* On Nokia 770, the SleepX signal is masked with an
  270. * MPUIO line by default. It has to be unmasked for it
  271. * to become functional */
  272. /* SleepX mask direction */
  273. omap_writew((omap_readw(0xfffb5008) & ~2), 0xfffb5008);
  274. /* Unmask SleepX signal */
  275. omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
  276. software_node_register_node_group(nokia770_gpiochip_nodes);
  277. platform_add_devices(nokia770_devices, ARRAY_SIZE(nokia770_devices));
  278. gpiod_add_lookup_table(&nokia770_irq_gpio_table);
  279. d = gpiod_get(NULL, "ads7846_irq", GPIOD_IN);
  280. if (IS_ERR(d))
  281. pr_err("Unable to get ADS7846 IRQ GPIO descriptor\n");
  282. else
  283. nokia770_spi_board_info[1].irq = gpiod_to_irq(d);
  284. spi_register_board_info(nokia770_spi_board_info,
  285. ARRAY_SIZE(nokia770_spi_board_info));
  286. omap_serial_init();
  287. omap_register_i2c_bus(1, 100, NULL, 0);
  288. hwa742_dev_init();
  289. mipid_dev_init();
  290. omap1_usb_init(&nokia770_usb_config);
  291. nokia770_mmc_init();
  292. nokia770_cbus_init();
  293. }
  294. MACHINE_START(NOKIA770, "Nokia 770")
  295. .atag_offset = 0x100,
  296. .map_io = omap1_map_io,
  297. .init_early = omap1_init_early,
  298. .init_irq = omap1_init_irq,
  299. .init_machine = omap_nokia770_init,
  300. .init_late = omap1_init_late,
  301. .init_time = omap1_timer_init,
  302. .restart = omap1_restart,
  303. MACHINE_END