board-nokia770.c 6.4 KB

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