board-nokia770.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * linux/arch/arm/mach-omap1/board-nokia770.c
  3. *
  4. * Modified from board-generic.c
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/clkdev.h>
  11. #include <linux/irq.h>
  12. #include <linux/gpio.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/mutex.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/input.h>
  18. #include <linux/omapfb.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/spi/ads7846.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/delay.h>
  23. #include <linux/platform_data/keypad-omap.h>
  24. #include <linux/platform_data/lcd-mipid.h>
  25. #include <linux/platform_data/gpio-omap.h>
  26. #include <linux/platform_data/i2c-cbus-gpio.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <mach/mux.h>
  31. #include <mach/hardware.h>
  32. #include <mach/usb.h>
  33. #include "common.h"
  34. #include "clock.h"
  35. #include "mmc.h"
  36. #define ADS7846_PENDOWN_GPIO 15
  37. static const unsigned int nokia770_keymap[] = {
  38. KEY(1, 0, GROUP_0 | KEY_UP),
  39. KEY(2, 0, GROUP_1 | KEY_F5),
  40. KEY(0, 1, GROUP_0 | KEY_LEFT),
  41. KEY(1, 1, GROUP_0 | KEY_ENTER),
  42. KEY(2, 1, GROUP_0 | KEY_RIGHT),
  43. KEY(0, 2, GROUP_1 | KEY_ESC),
  44. KEY(1, 2, GROUP_0 | KEY_DOWN),
  45. KEY(2, 2, GROUP_1 | KEY_F4),
  46. KEY(0, 3, GROUP_2 | KEY_F7),
  47. KEY(1, 3, GROUP_2 | KEY_F8),
  48. KEY(2, 3, GROUP_2 | KEY_F6),
  49. };
  50. static struct resource nokia770_kp_resources[] = {
  51. [0] = {
  52. .start = INT_KEYBOARD,
  53. .end = INT_KEYBOARD,
  54. .flags = IORESOURCE_IRQ,
  55. },
  56. };
  57. static const struct matrix_keymap_data nokia770_keymap_data = {
  58. .keymap = nokia770_keymap,
  59. .keymap_size = ARRAY_SIZE(nokia770_keymap),
  60. };
  61. static struct omap_kp_platform_data nokia770_kp_data = {
  62. .rows = 8,
  63. .cols = 8,
  64. .keymap_data = &nokia770_keymap_data,
  65. .delay = 4,
  66. };
  67. static struct platform_device nokia770_kp_device = {
  68. .name = "omap-keypad",
  69. .id = -1,
  70. .dev = {
  71. .platform_data = &nokia770_kp_data,
  72. },
  73. .num_resources = ARRAY_SIZE(nokia770_kp_resources),
  74. .resource = nokia770_kp_resources,
  75. };
  76. static struct platform_device *nokia770_devices[] __initdata = {
  77. &nokia770_kp_device,
  78. };
  79. static void mipid_shutdown(struct mipid_platform_data *pdata)
  80. {
  81. if (pdata->nreset_gpio != -1) {
  82. printk(KERN_INFO "shutdown LCD\n");
  83. gpio_set_value(pdata->nreset_gpio, 0);
  84. msleep(120);
  85. }
  86. }
  87. static struct mipid_platform_data nokia770_mipid_platform_data = {
  88. .shutdown = mipid_shutdown,
  89. };
  90. static const struct omap_lcd_config nokia770_lcd_config __initconst = {
  91. .ctrl_name = "hwa742",
  92. };
  93. static void __init mipid_dev_init(void)
  94. {
  95. nokia770_mipid_platform_data.nreset_gpio = 13;
  96. nokia770_mipid_platform_data.data_lines = 16;
  97. omapfb_set_lcd_config(&nokia770_lcd_config);
  98. }
  99. static struct ads7846_platform_data nokia770_ads7846_platform_data __initdata = {
  100. .x_max = 0x0fff,
  101. .y_max = 0x0fff,
  102. .x_plate_ohms = 180,
  103. .pressure_max = 255,
  104. .debounce_max = 10,
  105. .debounce_tol = 3,
  106. .debounce_rep = 1,
  107. .gpio_pendown = ADS7846_PENDOWN_GPIO,
  108. };
  109. static struct spi_board_info nokia770_spi_board_info[] __initdata = {
  110. [0] = {
  111. .modalias = "lcd_mipid",
  112. .bus_num = 2,
  113. .chip_select = 3,
  114. .max_speed_hz = 12000000,
  115. .platform_data = &nokia770_mipid_platform_data,
  116. },
  117. [1] = {
  118. .modalias = "ads7846",
  119. .bus_num = 2,
  120. .chip_select = 0,
  121. .max_speed_hz = 2500000,
  122. .platform_data = &nokia770_ads7846_platform_data,
  123. },
  124. };
  125. static void __init hwa742_dev_init(void)
  126. {
  127. clk_add_alias("hwa_sys_ck", NULL, "bclk", NULL);
  128. }
  129. /* assume no Mini-AB port */
  130. static struct omap_usb_config nokia770_usb_config __initdata = {
  131. .otg = 1,
  132. .register_host = 1,
  133. .register_dev = 1,
  134. .hmc_mode = 16,
  135. .pins[0] = 6,
  136. .extcon = "tahvo-usb",
  137. };
  138. #if IS_ENABLED(CONFIG_MMC_OMAP)
  139. #define NOKIA770_GPIO_MMC_POWER 41
  140. #define NOKIA770_GPIO_MMC_SWITCH 23
  141. static int nokia770_mmc_set_power(struct device *dev, int slot, int power_on,
  142. int vdd)
  143. {
  144. gpio_set_value(NOKIA770_GPIO_MMC_POWER, power_on);
  145. return 0;
  146. }
  147. static int nokia770_mmc_get_cover_state(struct device *dev, int slot)
  148. {
  149. return gpio_get_value(NOKIA770_GPIO_MMC_SWITCH);
  150. }
  151. static struct omap_mmc_platform_data nokia770_mmc2_data = {
  152. .nr_slots = 1,
  153. .max_freq = 12000000,
  154. .slots[0] = {
  155. .set_power = nokia770_mmc_set_power,
  156. .get_cover_state = nokia770_mmc_get_cover_state,
  157. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  158. .name = "mmcblk",
  159. },
  160. };
  161. static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC];
  162. static void __init nokia770_mmc_init(void)
  163. {
  164. int ret;
  165. ret = gpio_request(NOKIA770_GPIO_MMC_POWER, "MMC power");
  166. if (ret < 0)
  167. return;
  168. gpio_direction_output(NOKIA770_GPIO_MMC_POWER, 0);
  169. ret = gpio_request(NOKIA770_GPIO_MMC_SWITCH, "MMC cover");
  170. if (ret < 0) {
  171. gpio_free(NOKIA770_GPIO_MMC_POWER);
  172. return;
  173. }
  174. gpio_direction_input(NOKIA770_GPIO_MMC_SWITCH);
  175. /* Only the second MMC controller is used */
  176. nokia770_mmc_data[1] = &nokia770_mmc2_data;
  177. omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);
  178. }
  179. #else
  180. static inline void nokia770_mmc_init(void)
  181. {
  182. }
  183. #endif
  184. #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO)
  185. static struct i2c_cbus_platform_data nokia770_cbus_data = {
  186. .clk_gpio = OMAP_MPUIO(9),
  187. .dat_gpio = OMAP_MPUIO(10),
  188. .sel_gpio = OMAP_MPUIO(11),
  189. };
  190. static struct platform_device nokia770_cbus_device = {
  191. .name = "i2c-cbus-gpio",
  192. .id = 2,
  193. .dev = {
  194. .platform_data = &nokia770_cbus_data,
  195. },
  196. };
  197. static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = {
  198. {
  199. I2C_BOARD_INFO("retu", 0x01),
  200. },
  201. {
  202. I2C_BOARD_INFO("tahvo", 0x02),
  203. },
  204. };
  205. static void __init nokia770_cbus_init(void)
  206. {
  207. const int retu_irq_gpio = 62;
  208. const int tahvo_irq_gpio = 40;
  209. if (gpio_request_one(retu_irq_gpio, GPIOF_IN, "Retu IRQ"))
  210. return;
  211. if (gpio_request_one(tahvo_irq_gpio, GPIOF_IN, "Tahvo IRQ")) {
  212. gpio_free(retu_irq_gpio);
  213. return;
  214. }
  215. irq_set_irq_type(gpio_to_irq(retu_irq_gpio), IRQ_TYPE_EDGE_RISING);
  216. irq_set_irq_type(gpio_to_irq(tahvo_irq_gpio), IRQ_TYPE_EDGE_RISING);
  217. nokia770_i2c_board_info_2[0].irq = gpio_to_irq(retu_irq_gpio);
  218. nokia770_i2c_board_info_2[1].irq = gpio_to_irq(tahvo_irq_gpio);
  219. i2c_register_board_info(2, nokia770_i2c_board_info_2,
  220. ARRAY_SIZE(nokia770_i2c_board_info_2));
  221. platform_device_register(&nokia770_cbus_device);
  222. }
  223. #else /* CONFIG_I2C_CBUS_GPIO */
  224. static void __init nokia770_cbus_init(void)
  225. {
  226. }
  227. #endif /* CONFIG_I2C_CBUS_GPIO */
  228. static void __init omap_nokia770_init(void)
  229. {
  230. /* On Nokia 770, the SleepX signal is masked with an
  231. * MPUIO line by default. It has to be unmasked for it
  232. * to become functional */
  233. /* SleepX mask direction */
  234. omap_writew((omap_readw(0xfffb5008) & ~2), 0xfffb5008);
  235. /* Unmask SleepX signal */
  236. omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
  237. platform_add_devices(nokia770_devices, ARRAY_SIZE(nokia770_devices));
  238. nokia770_spi_board_info[1].irq = gpio_to_irq(15);
  239. spi_register_board_info(nokia770_spi_board_info,
  240. ARRAY_SIZE(nokia770_spi_board_info));
  241. omap_serial_init();
  242. omap_register_i2c_bus(1, 100, NULL, 0);
  243. hwa742_dev_init();
  244. mipid_dev_init();
  245. omap1_usb_init(&nokia770_usb_config);
  246. nokia770_mmc_init();
  247. nokia770_cbus_init();
  248. }
  249. MACHINE_START(NOKIA770, "Nokia 770")
  250. .atag_offset = 0x100,
  251. .map_io = omap16xx_map_io,
  252. .init_early = omap1_init_early,
  253. .init_irq = omap1_init_irq,
  254. .handle_irq = omap1_handle_irq,
  255. .init_machine = omap_nokia770_init,
  256. .init_late = omap1_init_late,
  257. .init_time = omap1_timer_init,
  258. .restart = omap1_restart,
  259. MACHINE_END