board-nokia770.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/input.h>
  14. #include <linux/clk.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/spi/ads7846.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/delay.h>
  19. #include <asm/hardware.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/map.h>
  23. #include <asm/arch/gpio.h>
  24. #include <asm/arch/mux.h>
  25. #include <asm/arch/usb.h>
  26. #include <asm/arch/board.h>
  27. #include <asm/arch/keypad.h>
  28. #include <asm/arch/common.h>
  29. #include <asm/arch/dsp_common.h>
  30. #include <asm/arch/aic23.h>
  31. #include <asm/arch/omapfb.h>
  32. #include <asm/arch/lcd_mipid.h>
  33. #define ADS7846_PENDOWN_GPIO 15
  34. static void __init omap_nokia770_init_irq(void)
  35. {
  36. /* On Nokia 770, the SleepX signal is masked with an
  37. * MPUIO line by default. It has to be unmasked for it
  38. * to become functional */
  39. /* SleepX mask direction */
  40. omap_writew((omap_readw(0xfffb5008) & ~2), 0xfffb5008);
  41. /* Unmask SleepX signal */
  42. omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
  43. omap1_init_common_hw();
  44. omap_init_irq();
  45. }
  46. static int nokia770_keymap[] = {
  47. KEY(0, 1, GROUP_0 | KEY_UP),
  48. KEY(0, 2, GROUP_1 | KEY_F5),
  49. KEY(1, 0, GROUP_0 | KEY_LEFT),
  50. KEY(1, 1, GROUP_0 | KEY_ENTER),
  51. KEY(1, 2, GROUP_0 | KEY_RIGHT),
  52. KEY(2, 0, GROUP_1 | KEY_ESC),
  53. KEY(2, 1, GROUP_0 | KEY_DOWN),
  54. KEY(2, 2, GROUP_1 | KEY_F4),
  55. KEY(3, 0, GROUP_2 | KEY_F7),
  56. KEY(3, 1, GROUP_2 | KEY_F8),
  57. KEY(3, 2, GROUP_2 | KEY_F6),
  58. 0
  59. };
  60. static struct resource nokia770_kp_resources[] = {
  61. [0] = {
  62. .start = INT_KEYBOARD,
  63. .end = INT_KEYBOARD,
  64. .flags = IORESOURCE_IRQ,
  65. },
  66. };
  67. static struct omap_kp_platform_data nokia770_kp_data = {
  68. .rows = 8,
  69. .cols = 8,
  70. .keymap = nokia770_keymap,
  71. .keymapsize = ARRAY_SIZE(nokia770_keymap),
  72. .delay = 4,
  73. };
  74. static struct platform_device nokia770_kp_device = {
  75. .name = "omap-keypad",
  76. .id = -1,
  77. .dev = {
  78. .platform_data = &nokia770_kp_data,
  79. },
  80. .num_resources = ARRAY_SIZE(nokia770_kp_resources),
  81. .resource = nokia770_kp_resources,
  82. };
  83. static struct platform_device *nokia770_devices[] __initdata = {
  84. &nokia770_kp_device,
  85. };
  86. static void mipid_shutdown(struct mipid_platform_data *pdata)
  87. {
  88. if (pdata->nreset_gpio != -1) {
  89. printk(KERN_INFO "shutdown LCD\n");
  90. omap_set_gpio_dataout(pdata->nreset_gpio, 0);
  91. msleep(120);
  92. }
  93. }
  94. static struct mipid_platform_data nokia770_mipid_platform_data = {
  95. .shutdown = mipid_shutdown,
  96. };
  97. static void mipid_dev_init(void)
  98. {
  99. const struct omap_lcd_config *conf;
  100. conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
  101. if (conf != NULL) {
  102. nokia770_mipid_platform_data.nreset_gpio = conf->nreset_gpio;
  103. nokia770_mipid_platform_data.data_lines = conf->data_lines;
  104. }
  105. }
  106. static void ads7846_dev_init(void)
  107. {
  108. if (omap_request_gpio(ADS7846_PENDOWN_GPIO) < 0)
  109. printk(KERN_ERR "can't get ads7846 pen down GPIO\n");
  110. }
  111. static int ads7846_get_pendown_state(void)
  112. {
  113. return !omap_get_gpio_datain(ADS7846_PENDOWN_GPIO);
  114. }
  115. static struct ads7846_platform_data nokia770_ads7846_platform_data __initdata = {
  116. .x_max = 0x0fff,
  117. .y_max = 0x0fff,
  118. .x_plate_ohms = 180,
  119. .pressure_max = 255,
  120. .debounce_max = 10,
  121. .debounce_tol = 3,
  122. .debounce_rep = 1,
  123. .get_pendown_state = ads7846_get_pendown_state,
  124. };
  125. static struct spi_board_info nokia770_spi_board_info[] __initdata = {
  126. [0] = {
  127. .modalias = "lcd_mipid",
  128. .bus_num = 2,
  129. .chip_select = 3,
  130. .max_speed_hz = 12000000,
  131. .platform_data = &nokia770_mipid_platform_data,
  132. },
  133. [1] = {
  134. .modalias = "ads7846",
  135. .bus_num = 2,
  136. .chip_select = 0,
  137. .max_speed_hz = 2500000,
  138. .irq = OMAP_GPIO_IRQ(15),
  139. .platform_data = &nokia770_ads7846_platform_data,
  140. },
  141. };
  142. /* assume no Mini-AB port */
  143. static struct omap_usb_config nokia770_usb_config __initdata = {
  144. .otg = 1,
  145. .register_host = 1,
  146. .register_dev = 1,
  147. .hmc_mode = 16,
  148. .pins[0] = 6,
  149. };
  150. static struct omap_mmc_config nokia770_mmc_config __initdata = {
  151. .mmc[0] = {
  152. .enabled = 0,
  153. .wire4 = 0,
  154. .wp_pin = -1,
  155. .power_pin = -1,
  156. .switch_pin = -1,
  157. },
  158. .mmc[1] = {
  159. .enabled = 0,
  160. .wire4 = 0,
  161. .wp_pin = -1,
  162. .power_pin = -1,
  163. .switch_pin = -1,
  164. },
  165. };
  166. static struct omap_board_config_kernel nokia770_config[] __initdata = {
  167. { OMAP_TAG_USB, NULL },
  168. { OMAP_TAG_MMC, &nokia770_mmc_config },
  169. };
  170. #if defined(CONFIG_OMAP_DSP)
  171. /*
  172. * audio power control
  173. */
  174. #define HEADPHONE_GPIO 14
  175. #define AMPLIFIER_CTRL_GPIO 58
  176. static struct clk *dspxor_ck;
  177. static DECLARE_MUTEX(audio_pwr_sem);
  178. /*
  179. * audio_pwr_state
  180. * +--+-------------------------+---------------------------------------+
  181. * |-1|down |power-up request -> 0 |
  182. * +--+-------------------------+---------------------------------------+
  183. * | 0|up |power-down(1) request -> 1 |
  184. * | | |power-down(2) request -> (ignore) |
  185. * +--+-------------------------+---------------------------------------+
  186. * | 1|up, |power-up request -> 0 |
  187. * | |received down(1) request |power-down(2) request -> -1 |
  188. * +--+-------------------------+---------------------------------------+
  189. */
  190. static int audio_pwr_state = -1;
  191. /*
  192. * audio_pwr_up / down should be called under audio_pwr_sem
  193. */
  194. static void nokia770_audio_pwr_up(void)
  195. {
  196. clk_enable(dspxor_ck);
  197. /* Turn on codec */
  198. aic23_power_up();
  199. if (omap_get_gpio_datain(HEADPHONE_GPIO))
  200. /* HP not connected, turn on amplifier */
  201. omap_set_gpio_dataout(AMPLIFIER_CTRL_GPIO, 1);
  202. else
  203. /* HP connected, do not turn on amplifier */
  204. printk("HP connected\n");
  205. }
  206. static void codec_delayed_power_down(struct work_struct *work)
  207. {
  208. down(&audio_pwr_sem);
  209. if (audio_pwr_state == -1)
  210. aic23_power_down();
  211. clk_disable(dspxor_ck);
  212. up(&audio_pwr_sem);
  213. }
  214. static DECLARE_DELAYED_WORK(codec_power_down_work, codec_delayed_power_down);
  215. static void nokia770_audio_pwr_down(void)
  216. {
  217. /* Turn off amplifier */
  218. omap_set_gpio_dataout(AMPLIFIER_CTRL_GPIO, 0);
  219. /* Turn off codec: schedule delayed work */
  220. schedule_delayed_work(&codec_power_down_work, HZ / 20); /* 50ms */
  221. }
  222. static int
  223. nokia770_audio_pwr_up_request(struct dsp_kfunc_device *kdev, int stage)
  224. {
  225. down(&audio_pwr_sem);
  226. if (audio_pwr_state == -1)
  227. nokia770_audio_pwr_up();
  228. /* force audio_pwr_state = 0, even if it was 1. */
  229. audio_pwr_state = 0;
  230. up(&audio_pwr_sem);
  231. return 0;
  232. }
  233. static int
  234. nokia770_audio_pwr_down_request(struct dsp_kfunc_device *kdev, int stage)
  235. {
  236. down(&audio_pwr_sem);
  237. switch (stage) {
  238. case 1:
  239. if (audio_pwr_state == 0)
  240. audio_pwr_state = 1;
  241. break;
  242. case 2:
  243. if (audio_pwr_state == 1) {
  244. nokia770_audio_pwr_down();
  245. audio_pwr_state = -1;
  246. }
  247. break;
  248. }
  249. up(&audio_pwr_sem);
  250. return 0;
  251. }
  252. static struct dsp_kfunc_device nokia770_audio_device = {
  253. .name = "audio",
  254. .type = DSP_KFUNC_DEV_TYPE_AUDIO,
  255. .enable = nokia770_audio_pwr_up_request,
  256. .disable = nokia770_audio_pwr_down_request,
  257. };
  258. static __init int omap_dsp_init(void)
  259. {
  260. int ret;
  261. dspxor_ck = clk_get(0, "dspxor_ck");
  262. if (IS_ERR(dspxor_ck)) {
  263. printk(KERN_ERR "couldn't acquire dspxor_ck\n");
  264. return PTR_ERR(dspxor_ck);
  265. }
  266. ret = dsp_kfunc_device_register(&nokia770_audio_device);
  267. if (ret) {
  268. printk(KERN_ERR
  269. "KFUNC device registration faild: %s\n",
  270. nokia770_audio_device.name);
  271. goto out;
  272. }
  273. return 0;
  274. out:
  275. return ret;
  276. }
  277. #else
  278. #define omap_dsp_init() do {} while (0)
  279. #endif /* CONFIG_OMAP_DSP */
  280. static void __init omap_nokia770_init(void)
  281. {
  282. nokia770_config[0].data = &nokia770_usb_config;
  283. platform_add_devices(nokia770_devices, ARRAY_SIZE(nokia770_devices));
  284. spi_register_board_info(nokia770_spi_board_info,
  285. ARRAY_SIZE(nokia770_spi_board_info));
  286. omap_board_config = nokia770_config;
  287. omap_board_config_size = ARRAY_SIZE(nokia770_config);
  288. omap_gpio_init();
  289. omap_serial_init();
  290. omap_register_i2c_bus(1, 100, NULL, 0);
  291. omap_dsp_init();
  292. ads7846_dev_init();
  293. mipid_dev_init();
  294. }
  295. static void __init omap_nokia770_map_io(void)
  296. {
  297. omap1_map_common_io();
  298. }
  299. MACHINE_START(NOKIA770, "Nokia 770")
  300. .phys_io = 0xfff00000,
  301. .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
  302. .boot_params = 0x10000100,
  303. .map_io = omap_nokia770_map_io,
  304. .init_irq = omap_nokia770_init_irq,
  305. .init_machine = omap_nokia770_init,
  306. .timer = &omap_timer,
  307. MACHINE_END