mainstone.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * linux/arch/arm/mach-pxa/mainstone.c
  3. *
  4. * Support for the Intel HCDDBBVA0 Development Platform.
  5. * (go figure how they came up with such name...)
  6. *
  7. * Author: Nicolas Pitre
  8. * Created: Nov 05, 2002
  9. * Copyright: MontaVista Software Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/device.h>
  17. #include <linux/sysdev.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/sched.h>
  20. #include <linux/bitops.h>
  21. #include <linux/fb.h>
  22. #include <asm/types.h>
  23. #include <asm/setup.h>
  24. #include <asm/memory.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/hardware.h>
  27. #include <asm/irq.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/mach/irq.h>
  31. #include <asm/arch/pxa-regs.h>
  32. #include <asm/arch/mainstone.h>
  33. #include <asm/arch/audio.h>
  34. #include <asm/arch/pxafb.h>
  35. #include <asm/arch/mmc.h>
  36. #include "generic.h"
  37. static unsigned long mainstone_irq_enabled;
  38. static void mainstone_mask_irq(unsigned int irq)
  39. {
  40. int mainstone_irq = (irq - MAINSTONE_IRQ(0));
  41. MST_INTMSKENA = (mainstone_irq_enabled &= ~(1 << mainstone_irq));
  42. }
  43. static void mainstone_unmask_irq(unsigned int irq)
  44. {
  45. int mainstone_irq = (irq - MAINSTONE_IRQ(0));
  46. /* the irq can be acknowledged only if deasserted, so it's done here */
  47. MST_INTSETCLR &= ~(1 << mainstone_irq);
  48. MST_INTMSKENA = (mainstone_irq_enabled |= (1 << mainstone_irq));
  49. }
  50. static struct irqchip mainstone_irq_chip = {
  51. .ack = mainstone_mask_irq,
  52. .mask = mainstone_mask_irq,
  53. .unmask = mainstone_unmask_irq,
  54. };
  55. static void mainstone_irq_handler(unsigned int irq, struct irqdesc *desc,
  56. struct pt_regs *regs)
  57. {
  58. unsigned long pending = MST_INTSETCLR & mainstone_irq_enabled;
  59. do {
  60. GEDR(0) = GPIO_bit(0); /* clear useless edge notification */
  61. if (likely(pending)) {
  62. irq = MAINSTONE_IRQ(0) + __ffs(pending);
  63. desc = irq_desc + irq;
  64. desc_handle_irq(irq, desc, regs);
  65. }
  66. pending = MST_INTSETCLR & mainstone_irq_enabled;
  67. } while (pending);
  68. }
  69. static void __init mainstone_init_irq(void)
  70. {
  71. int irq;
  72. pxa_init_irq();
  73. /* setup extra Mainstone irqs */
  74. for(irq = MAINSTONE_IRQ(0); irq <= MAINSTONE_IRQ(15); irq++) {
  75. set_irq_chip(irq, &mainstone_irq_chip);
  76. set_irq_handler(irq, do_level_IRQ);
  77. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  78. }
  79. set_irq_flags(MAINSTONE_IRQ(8), 0);
  80. set_irq_flags(MAINSTONE_IRQ(12), 0);
  81. MST_INTMSKENA = 0;
  82. MST_INTSETCLR = 0;
  83. set_irq_chained_handler(IRQ_GPIO(0), mainstone_irq_handler);
  84. set_irq_type(IRQ_GPIO(0), IRQT_FALLING);
  85. }
  86. #ifdef CONFIG_PM
  87. static int mainstone_irq_resume(struct sys_device *dev)
  88. {
  89. MST_INTMSKENA = mainstone_irq_enabled;
  90. return 0;
  91. }
  92. static struct sysdev_class mainstone_irq_sysclass = {
  93. set_kset_name("cpld_irq"),
  94. .resume = mainstone_irq_resume,
  95. };
  96. static struct sys_device mainstone_irq_device = {
  97. .cls = &mainstone_irq_sysclass,
  98. };
  99. static int __init mainstone_irq_device_init(void)
  100. {
  101. int ret = sysdev_class_register(&mainstone_irq_sysclass);
  102. if (ret == 0)
  103. ret = sysdev_register(&mainstone_irq_device);
  104. return ret;
  105. }
  106. device_initcall(mainstone_irq_device_init);
  107. #endif
  108. static struct resource smc91x_resources[] = {
  109. [0] = {
  110. .start = (MST_ETH_PHYS + 0x300),
  111. .end = (MST_ETH_PHYS + 0xfffff),
  112. .flags = IORESOURCE_MEM,
  113. },
  114. [1] = {
  115. .start = MAINSTONE_IRQ(3),
  116. .end = MAINSTONE_IRQ(3),
  117. .flags = IORESOURCE_IRQ,
  118. }
  119. };
  120. static struct platform_device smc91x_device = {
  121. .name = "smc91x",
  122. .id = 0,
  123. .num_resources = ARRAY_SIZE(smc91x_resources),
  124. .resource = smc91x_resources,
  125. };
  126. static int mst_audio_startup(snd_pcm_substream_t *substream, void *priv)
  127. {
  128. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  129. MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
  130. return 0;
  131. }
  132. static void mst_audio_shutdown(snd_pcm_substream_t *substream, void *priv)
  133. {
  134. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  135. MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
  136. }
  137. static long mst_audio_suspend_mask;
  138. static void mst_audio_suspend(void *priv)
  139. {
  140. mst_audio_suspend_mask = MST_MSCWR2;
  141. MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
  142. }
  143. static void mst_audio_resume(void *priv)
  144. {
  145. MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
  146. }
  147. static pxa2xx_audio_ops_t mst_audio_ops = {
  148. .startup = mst_audio_startup,
  149. .shutdown = mst_audio_shutdown,
  150. .suspend = mst_audio_suspend,
  151. .resume = mst_audio_resume,
  152. };
  153. static struct platform_device mst_audio_device = {
  154. .name = "pxa2xx-ac97",
  155. .id = -1,
  156. .dev = { .platform_data = &mst_audio_ops },
  157. };
  158. static void mainstone_backlight_power(int on)
  159. {
  160. if (on) {
  161. pxa_gpio_mode(GPIO16_PWM0_MD);
  162. pxa_set_cken(CKEN0_PWM0, 1);
  163. PWM_CTRL0 = 0;
  164. PWM_PWDUTY0 = 0x3ff;
  165. PWM_PERVAL0 = 0x3ff;
  166. } else {
  167. PWM_CTRL0 = 0;
  168. PWM_PWDUTY0 = 0x0;
  169. PWM_PERVAL0 = 0x3FF;
  170. pxa_set_cken(CKEN0_PWM0, 0);
  171. }
  172. }
  173. static struct pxafb_mach_info toshiba_ltm04c380k __initdata = {
  174. .pixclock = 50000,
  175. .xres = 640,
  176. .yres = 480,
  177. .bpp = 16,
  178. .hsync_len = 1,
  179. .left_margin = 0x9f,
  180. .right_margin = 1,
  181. .vsync_len = 44,
  182. .upper_margin = 0,
  183. .lower_margin = 0,
  184. .sync = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  185. .lccr0 = LCCR0_Act,
  186. .lccr3 = LCCR3_PCP,
  187. .pxafb_backlight_power = mainstone_backlight_power,
  188. };
  189. static struct pxafb_mach_info toshiba_ltm035a776c __initdata = {
  190. .pixclock = 110000,
  191. .xres = 240,
  192. .yres = 320,
  193. .bpp = 16,
  194. .hsync_len = 4,
  195. .left_margin = 8,
  196. .right_margin = 20,
  197. .vsync_len = 3,
  198. .upper_margin = 1,
  199. .lower_margin = 10,
  200. .sync = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  201. .lccr0 = LCCR0_Act,
  202. .lccr3 = LCCR3_PCP,
  203. .pxafb_backlight_power = mainstone_backlight_power,
  204. };
  205. static int mainstone_mci_init(struct device *dev, irqreturn_t (*mstone_detect_int)(int, void *, struct pt_regs *), void *data)
  206. {
  207. int err;
  208. /*
  209. * setup GPIO for PXA27x MMC controller
  210. */
  211. pxa_gpio_mode(GPIO32_MMCCLK_MD);
  212. pxa_gpio_mode(GPIO112_MMCCMD_MD);
  213. pxa_gpio_mode(GPIO92_MMCDAT0_MD);
  214. pxa_gpio_mode(GPIO109_MMCDAT1_MD);
  215. pxa_gpio_mode(GPIO110_MMCDAT2_MD);
  216. pxa_gpio_mode(GPIO111_MMCDAT3_MD);
  217. /* make sure SD/Memory Stick multiplexer's signals
  218. * are routed to MMC controller
  219. */
  220. MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL;
  221. err = request_irq(MAINSTONE_MMC_IRQ, mstone_detect_int, SA_INTERRUPT,
  222. "MMC card detect", data);
  223. if (err) {
  224. printk(KERN_ERR "mainstone_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  225. return -1;
  226. }
  227. return 0;
  228. }
  229. static void mainstone_mci_setpower(struct device *dev, unsigned int vdd)
  230. {
  231. struct pxamci_platform_data* p_d = dev->platform_data;
  232. if (( 1 << vdd) & p_d->ocr_mask) {
  233. printk(KERN_DEBUG "%s: on\n", __FUNCTION__);
  234. MST_MSCWR1 |= MST_MSCWR1_MMC_ON;
  235. MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL;
  236. } else {
  237. printk(KERN_DEBUG "%s: off\n", __FUNCTION__);
  238. MST_MSCWR1 &= ~MST_MSCWR1_MMC_ON;
  239. }
  240. }
  241. static void mainstone_mci_exit(struct device *dev, void *data)
  242. {
  243. free_irq(MAINSTONE_MMC_IRQ, data);
  244. }
  245. static struct pxamci_platform_data mainstone_mci_platform_data = {
  246. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  247. .init = mainstone_mci_init,
  248. .setpower = mainstone_mci_setpower,
  249. .exit = mainstone_mci_exit,
  250. };
  251. static void __init mainstone_init(void)
  252. {
  253. /*
  254. * On Mainstone, we route AC97_SYSCLK via GPIO45 to
  255. * the audio daughter card
  256. */
  257. pxa_gpio_mode(GPIO45_SYSCLK_AC97_MD);
  258. platform_device_register(&smc91x_device);
  259. platform_device_register(&mst_audio_device);
  260. /* reading Mainstone's "Virtual Configuration Register"
  261. might be handy to select LCD type here */
  262. if (0)
  263. set_pxa_fb_info(&toshiba_ltm04c380k);
  264. else
  265. set_pxa_fb_info(&toshiba_ltm035a776c);
  266. pxa_set_mci_info(&mainstone_mci_platform_data);
  267. }
  268. static struct map_desc mainstone_io_desc[] __initdata = {
  269. { MST_FPGA_VIRT, MST_FPGA_PHYS, 0x00100000, MT_DEVICE }, /* CPLD */
  270. };
  271. static void __init mainstone_map_io(void)
  272. {
  273. pxa_map_io();
  274. iotable_init(mainstone_io_desc, ARRAY_SIZE(mainstone_io_desc));
  275. /* initialize sleep mode regs (wake-up sources, etc) */
  276. PGSR0 = 0x00008800;
  277. PGSR1 = 0x00000002;
  278. PGSR2 = 0x0001FC00;
  279. PGSR3 = 0x00001F81;
  280. PWER = 0xC0000002;
  281. PRER = 0x00000002;
  282. PFER = 0x00000002;
  283. /* for use I SRAM as framebuffer. */
  284. PSLR |= 0xF04;
  285. PCFR = 0x66;
  286. /* For Keypad wakeup. */
  287. KPC &=~KPC_ASACT;
  288. KPC |=KPC_AS;
  289. PKWR = 0x000FD000;
  290. /* Need read PKWR back after set it. */
  291. PKWR;
  292. }
  293. MACHINE_START(MAINSTONE, "Intel HCDDBBVA0 Development Platform (aka Mainstone)")
  294. /* Maintainer: MontaVista Software Inc. */
  295. .phys_ram = 0xa0000000,
  296. .phys_io = 0x40000000,
  297. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  298. .map_io = mainstone_map_io,
  299. .init_irq = mainstone_init_irq,
  300. .timer = &pxa_timer,
  301. .init_machine = mainstone_init,
  302. MACHINE_END