board-nokia770.c 9.5 KB

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