board-nokia770.c 8.2 KB

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