board-nokia770.c 7.1 KB

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