mainstone.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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/platform_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 <linux/ioport.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/backlight.h>
  26. #include <asm/types.h>
  27. #include <asm/setup.h>
  28. #include <asm/memory.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/hardware.h>
  31. #include <asm/irq.h>
  32. #include <asm/sizes.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include <asm/mach/irq.h>
  36. #include <asm/mach/flash.h>
  37. #include <asm/arch/pxa-regs.h>
  38. #include <asm/arch/pxa2xx-regs.h>
  39. #include <asm/arch/pxa2xx-gpio.h>
  40. #include <asm/arch/mainstone.h>
  41. #include <asm/arch/audio.h>
  42. #include <asm/arch/pxafb.h>
  43. #include <asm/arch/mmc.h>
  44. #include <asm/arch/irda.h>
  45. #include <asm/arch/ohci.h>
  46. #include "generic.h"
  47. #include "devices.h"
  48. static unsigned long mainstone_irq_enabled;
  49. static void mainstone_mask_irq(unsigned int irq)
  50. {
  51. int mainstone_irq = (irq - MAINSTONE_IRQ(0));
  52. MST_INTMSKENA = (mainstone_irq_enabled &= ~(1 << mainstone_irq));
  53. }
  54. static void mainstone_unmask_irq(unsigned int irq)
  55. {
  56. int mainstone_irq = (irq - MAINSTONE_IRQ(0));
  57. /* the irq can be acknowledged only if deasserted, so it's done here */
  58. MST_INTSETCLR &= ~(1 << mainstone_irq);
  59. MST_INTMSKENA = (mainstone_irq_enabled |= (1 << mainstone_irq));
  60. }
  61. static struct irq_chip mainstone_irq_chip = {
  62. .name = "FPGA",
  63. .ack = mainstone_mask_irq,
  64. .mask = mainstone_mask_irq,
  65. .unmask = mainstone_unmask_irq,
  66. };
  67. static void mainstone_irq_handler(unsigned int irq, struct irq_desc *desc)
  68. {
  69. unsigned long pending = MST_INTSETCLR & mainstone_irq_enabled;
  70. do {
  71. GEDR(0) = GPIO_bit(0); /* clear useless edge notification */
  72. if (likely(pending)) {
  73. irq = MAINSTONE_IRQ(0) + __ffs(pending);
  74. desc = irq_desc + irq;
  75. desc_handle_irq(irq, desc);
  76. }
  77. pending = MST_INTSETCLR & mainstone_irq_enabled;
  78. } while (pending);
  79. }
  80. static void __init mainstone_init_irq(void)
  81. {
  82. int irq;
  83. pxa27x_init_irq();
  84. /* setup extra Mainstone irqs */
  85. for(irq = MAINSTONE_IRQ(0); irq <= MAINSTONE_IRQ(15); irq++) {
  86. set_irq_chip(irq, &mainstone_irq_chip);
  87. set_irq_handler(irq, handle_level_irq);
  88. if (irq == MAINSTONE_IRQ(10) || irq == MAINSTONE_IRQ(14))
  89. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_NOAUTOEN);
  90. else
  91. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  92. }
  93. set_irq_flags(MAINSTONE_IRQ(8), 0);
  94. set_irq_flags(MAINSTONE_IRQ(12), 0);
  95. MST_INTMSKENA = 0;
  96. MST_INTSETCLR = 0;
  97. set_irq_chained_handler(IRQ_GPIO(0), mainstone_irq_handler);
  98. set_irq_type(IRQ_GPIO(0), IRQT_FALLING);
  99. }
  100. #ifdef CONFIG_PM
  101. static int mainstone_irq_resume(struct sys_device *dev)
  102. {
  103. MST_INTMSKENA = mainstone_irq_enabled;
  104. return 0;
  105. }
  106. static struct sysdev_class mainstone_irq_sysclass = {
  107. .name = "cpld_irq",
  108. .resume = mainstone_irq_resume,
  109. };
  110. static struct sys_device mainstone_irq_device = {
  111. .cls = &mainstone_irq_sysclass,
  112. };
  113. static int __init mainstone_irq_device_init(void)
  114. {
  115. int ret = -ENODEV;
  116. if (machine_is_mainstone()) {
  117. ret = sysdev_class_register(&mainstone_irq_sysclass);
  118. if (ret == 0)
  119. ret = sysdev_register(&mainstone_irq_device);
  120. }
  121. return ret;
  122. }
  123. device_initcall(mainstone_irq_device_init);
  124. #endif
  125. static struct resource smc91x_resources[] = {
  126. [0] = {
  127. .start = (MST_ETH_PHYS + 0x300),
  128. .end = (MST_ETH_PHYS + 0xfffff),
  129. .flags = IORESOURCE_MEM,
  130. },
  131. [1] = {
  132. .start = MAINSTONE_IRQ(3),
  133. .end = MAINSTONE_IRQ(3),
  134. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  135. }
  136. };
  137. static struct platform_device smc91x_device = {
  138. .name = "smc91x",
  139. .id = 0,
  140. .num_resources = ARRAY_SIZE(smc91x_resources),
  141. .resource = smc91x_resources,
  142. };
  143. static int mst_audio_startup(struct snd_pcm_substream *substream, void *priv)
  144. {
  145. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  146. MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
  147. return 0;
  148. }
  149. static void mst_audio_shutdown(struct snd_pcm_substream *substream, void *priv)
  150. {
  151. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  152. MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
  153. }
  154. static long mst_audio_suspend_mask;
  155. static void mst_audio_suspend(void *priv)
  156. {
  157. mst_audio_suspend_mask = MST_MSCWR2;
  158. MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
  159. }
  160. static void mst_audio_resume(void *priv)
  161. {
  162. MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
  163. }
  164. static pxa2xx_audio_ops_t mst_audio_ops = {
  165. .startup = mst_audio_startup,
  166. .shutdown = mst_audio_shutdown,
  167. .suspend = mst_audio_suspend,
  168. .resume = mst_audio_resume,
  169. };
  170. static struct platform_device mst_audio_device = {
  171. .name = "pxa2xx-ac97",
  172. .id = -1,
  173. .dev = { .platform_data = &mst_audio_ops },
  174. };
  175. static struct resource flash_resources[] = {
  176. [0] = {
  177. .start = PXA_CS0_PHYS,
  178. .end = PXA_CS0_PHYS + SZ_64M - 1,
  179. .flags = IORESOURCE_MEM,
  180. },
  181. [1] = {
  182. .start = PXA_CS1_PHYS,
  183. .end = PXA_CS1_PHYS + SZ_64M - 1,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. };
  187. static struct mtd_partition mainstoneflash0_partitions[] = {
  188. {
  189. .name = "Bootloader",
  190. .size = 0x00040000,
  191. .offset = 0,
  192. .mask_flags = MTD_WRITEABLE /* force read-only */
  193. },{
  194. .name = "Kernel",
  195. .size = 0x00400000,
  196. .offset = 0x00040000,
  197. },{
  198. .name = "Filesystem",
  199. .size = MTDPART_SIZ_FULL,
  200. .offset = 0x00440000
  201. }
  202. };
  203. static struct flash_platform_data mst_flash_data[2] = {
  204. {
  205. .map_name = "cfi_probe",
  206. .parts = mainstoneflash0_partitions,
  207. .nr_parts = ARRAY_SIZE(mainstoneflash0_partitions),
  208. }, {
  209. .map_name = "cfi_probe",
  210. .parts = NULL,
  211. .nr_parts = 0,
  212. }
  213. };
  214. static struct platform_device mst_flash_device[2] = {
  215. {
  216. .name = "pxa2xx-flash",
  217. .id = 0,
  218. .dev = {
  219. .platform_data = &mst_flash_data[0],
  220. },
  221. .resource = &flash_resources[0],
  222. .num_resources = 1,
  223. },
  224. {
  225. .name = "pxa2xx-flash",
  226. .id = 1,
  227. .dev = {
  228. .platform_data = &mst_flash_data[1],
  229. },
  230. .resource = &flash_resources[1],
  231. .num_resources = 1,
  232. },
  233. };
  234. #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
  235. static int mainstone_backlight_update_status(struct backlight_device *bl)
  236. {
  237. int brightness = bl->props.brightness;
  238. if (bl->props.power != FB_BLANK_UNBLANK ||
  239. bl->props.fb_blank != FB_BLANK_UNBLANK)
  240. brightness = 0;
  241. if (brightness != 0) {
  242. pxa_gpio_mode(GPIO16_PWM0_MD);
  243. pxa_set_cken(CKEN_PWM0, 1);
  244. }
  245. PWM_CTRL0 = 0;
  246. PWM_PWDUTY0 = brightness;
  247. PWM_PERVAL0 = bl->props.max_brightness;
  248. if (brightness == 0)
  249. pxa_set_cken(CKEN_PWM0, 0);
  250. return 0; /* pointless return value */
  251. }
  252. static int mainstone_backlight_get_brightness(struct backlight_device *bl)
  253. {
  254. return PWM_PWDUTY0;
  255. }
  256. static /*const*/ struct backlight_ops mainstone_backlight_ops = {
  257. .update_status = mainstone_backlight_update_status,
  258. .get_brightness = mainstone_backlight_get_brightness,
  259. };
  260. static void __init mainstone_backlight_register(void)
  261. {
  262. struct backlight_device *bl;
  263. bl = backlight_device_register("mainstone-bl", &pxa_device_fb.dev,
  264. NULL, &mainstone_backlight_ops);
  265. if (IS_ERR(bl)) {
  266. printk(KERN_ERR "mainstone: unable to register backlight: %ld\n",
  267. PTR_ERR(bl));
  268. return;
  269. }
  270. /*
  271. * broken design - register-then-setup interfaces are
  272. * utterly broken by definition.
  273. */
  274. bl->props.max_brightness = 1023;
  275. bl->props.brightness = 1023;
  276. backlight_update_status(bl);
  277. }
  278. #else
  279. #define mainstone_backlight_register() do { } while (0)
  280. #endif
  281. static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
  282. .pixclock = 50000,
  283. .xres = 640,
  284. .yres = 480,
  285. .bpp = 16,
  286. .hsync_len = 1,
  287. .left_margin = 0x9f,
  288. .right_margin = 1,
  289. .vsync_len = 44,
  290. .upper_margin = 0,
  291. .lower_margin = 0,
  292. .sync = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  293. };
  294. static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
  295. .pixclock = 110000,
  296. .xres = 240,
  297. .yres = 320,
  298. .bpp = 16,
  299. .hsync_len = 4,
  300. .left_margin = 8,
  301. .right_margin = 20,
  302. .vsync_len = 3,
  303. .upper_margin = 1,
  304. .lower_margin = 10,
  305. .sync = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  306. };
  307. static struct pxafb_mach_info mainstone_pxafb_info = {
  308. .num_modes = 1,
  309. .lccr0 = LCCR0_Act,
  310. .lccr3 = LCCR3_PCP,
  311. };
  312. static int mainstone_mci_init(struct device *dev, irq_handler_t mstone_detect_int, void *data)
  313. {
  314. int err;
  315. /*
  316. * setup GPIO for PXA27x MMC controller
  317. */
  318. pxa_gpio_mode(GPIO32_MMCCLK_MD);
  319. pxa_gpio_mode(GPIO112_MMCCMD_MD);
  320. pxa_gpio_mode(GPIO92_MMCDAT0_MD);
  321. pxa_gpio_mode(GPIO109_MMCDAT1_MD);
  322. pxa_gpio_mode(GPIO110_MMCDAT2_MD);
  323. pxa_gpio_mode(GPIO111_MMCDAT3_MD);
  324. /* make sure SD/Memory Stick multiplexer's signals
  325. * are routed to MMC controller
  326. */
  327. MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL;
  328. err = request_irq(MAINSTONE_MMC_IRQ, mstone_detect_int, IRQF_DISABLED,
  329. "MMC card detect", data);
  330. if (err)
  331. printk(KERN_ERR "mainstone_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  332. return err;
  333. }
  334. static void mainstone_mci_setpower(struct device *dev, unsigned int vdd)
  335. {
  336. struct pxamci_platform_data* p_d = dev->platform_data;
  337. if (( 1 << vdd) & p_d->ocr_mask) {
  338. printk(KERN_DEBUG "%s: on\n", __func__);
  339. MST_MSCWR1 |= MST_MSCWR1_MMC_ON;
  340. MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL;
  341. } else {
  342. printk(KERN_DEBUG "%s: off\n", __func__);
  343. MST_MSCWR1 &= ~MST_MSCWR1_MMC_ON;
  344. }
  345. }
  346. static void mainstone_mci_exit(struct device *dev, void *data)
  347. {
  348. free_irq(MAINSTONE_MMC_IRQ, data);
  349. }
  350. static struct pxamci_platform_data mainstone_mci_platform_data = {
  351. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  352. .init = mainstone_mci_init,
  353. .setpower = mainstone_mci_setpower,
  354. .exit = mainstone_mci_exit,
  355. };
  356. static void mainstone_irda_transceiver_mode(struct device *dev, int mode)
  357. {
  358. unsigned long flags;
  359. local_irq_save(flags);
  360. if (mode & IR_SIRMODE) {
  361. MST_MSCWR1 &= ~MST_MSCWR1_IRDA_FIR;
  362. } else if (mode & IR_FIRMODE) {
  363. MST_MSCWR1 |= MST_MSCWR1_IRDA_FIR;
  364. }
  365. if (mode & IR_OFF) {
  366. MST_MSCWR1 = (MST_MSCWR1 & ~MST_MSCWR1_IRDA_MASK) | MST_MSCWR1_IRDA_OFF;
  367. } else {
  368. MST_MSCWR1 = (MST_MSCWR1 & ~MST_MSCWR1_IRDA_MASK) | MST_MSCWR1_IRDA_FULL;
  369. }
  370. local_irq_restore(flags);
  371. }
  372. static struct pxaficp_platform_data mainstone_ficp_platform_data = {
  373. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  374. .transceiver_mode = mainstone_irda_transceiver_mode,
  375. };
  376. static struct platform_device *platform_devices[] __initdata = {
  377. &smc91x_device,
  378. &mst_audio_device,
  379. &mst_flash_device[0],
  380. &mst_flash_device[1],
  381. };
  382. static int mainstone_ohci_init(struct device *dev)
  383. {
  384. /* setup Port1 GPIO pin. */
  385. pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */
  386. pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
  387. /* Set the Power Control Polarity Low and Power Sense
  388. Polarity Low to active low. */
  389. UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
  390. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
  391. return 0;
  392. }
  393. static struct pxaohci_platform_data mainstone_ohci_platform_data = {
  394. .port_mode = PMM_PERPORT_MODE,
  395. .init = mainstone_ohci_init,
  396. };
  397. static void __init mainstone_init(void)
  398. {
  399. int SW7 = 0; /* FIXME: get from SCR (Mst doc section 3.2.1.1) */
  400. mst_flash_data[0].width = (BOOT_DEF & 1) ? 2 : 4;
  401. mst_flash_data[1].width = 4;
  402. /* Compensate for SW7 which swaps the flash banks */
  403. mst_flash_data[SW7].name = "processor-flash";
  404. mst_flash_data[SW7 ^ 1].name = "mainboard-flash";
  405. printk(KERN_NOTICE "Mainstone configured to boot from %s\n",
  406. mst_flash_data[0].name);
  407. /* system bus arbiter setting
  408. * - Core_Park
  409. * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
  410. */
  411. ARB_CNTRL = ARB_CORE_PARK | 0x234;
  412. /*
  413. * On Mainstone, we route AC97_SYSCLK via GPIO45 to
  414. * the audio daughter card
  415. */
  416. pxa_gpio_mode(GPIO45_SYSCLK_AC97_MD);
  417. GPSR(GPIO48_nPOE) =
  418. GPIO_bit(GPIO48_nPOE) |
  419. GPIO_bit(GPIO49_nPWE) |
  420. GPIO_bit(GPIO50_nPIOR) |
  421. GPIO_bit(GPIO51_nPIOW) |
  422. GPIO_bit(GPIO85_nPCE_1) |
  423. GPIO_bit(GPIO54_nPCE_2);
  424. pxa_gpio_mode(GPIO48_nPOE_MD);
  425. pxa_gpio_mode(GPIO49_nPWE_MD);
  426. pxa_gpio_mode(GPIO50_nPIOR_MD);
  427. pxa_gpio_mode(GPIO51_nPIOW_MD);
  428. pxa_gpio_mode(GPIO85_nPCE_1_MD);
  429. pxa_gpio_mode(GPIO54_nPCE_2_MD);
  430. pxa_gpio_mode(GPIO79_pSKTSEL_MD);
  431. pxa_gpio_mode(GPIO55_nPREG_MD);
  432. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  433. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  434. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  435. /* reading Mainstone's "Virtual Configuration Register"
  436. might be handy to select LCD type here */
  437. if (0)
  438. mainstone_pxafb_info.modes = &toshiba_ltm04c380k_mode;
  439. else
  440. mainstone_pxafb_info.modes = &toshiba_ltm035a776c_mode;
  441. set_pxa_fb_info(&mainstone_pxafb_info);
  442. mainstone_backlight_register();
  443. pxa_set_mci_info(&mainstone_mci_platform_data);
  444. pxa_set_ficp_info(&mainstone_ficp_platform_data);
  445. pxa_set_ohci_info(&mainstone_ohci_platform_data);
  446. }
  447. static struct map_desc mainstone_io_desc[] __initdata = {
  448. { /* CPLD */
  449. .virtual = MST_FPGA_VIRT,
  450. .pfn = __phys_to_pfn(MST_FPGA_PHYS),
  451. .length = 0x00100000,
  452. .type = MT_DEVICE
  453. }
  454. };
  455. static void __init mainstone_map_io(void)
  456. {
  457. pxa_map_io();
  458. iotable_init(mainstone_io_desc, ARRAY_SIZE(mainstone_io_desc));
  459. /* initialize sleep mode regs (wake-up sources, etc) */
  460. PGSR0 = 0x00008800;
  461. PGSR1 = 0x00000002;
  462. PGSR2 = 0x0001FC00;
  463. PGSR3 = 0x00001F81;
  464. PWER = 0xC0000002;
  465. PRER = 0x00000002;
  466. PFER = 0x00000002;
  467. /* for use I SRAM as framebuffer. */
  468. PSLR |= 0xF04;
  469. PCFR = 0x66;
  470. /* For Keypad wakeup. */
  471. KPC &=~KPC_ASACT;
  472. KPC |=KPC_AS;
  473. PKWR = 0x000FD000;
  474. /* Need read PKWR back after set it. */
  475. PKWR;
  476. }
  477. MACHINE_START(MAINSTONE, "Intel HCDDBBVA0 Development Platform (aka Mainstone)")
  478. /* Maintainer: MontaVista Software Inc. */
  479. .phys_io = 0x40000000,
  480. .boot_params = 0xa0000100, /* BLOB boot parameter setting */
  481. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  482. .map_io = mainstone_map_io,
  483. .init_irq = mainstone_init_irq,
  484. .timer = &pxa_timer,
  485. .init_machine = mainstone_init,
  486. MACHINE_END