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