lpd270.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. * linux/arch/arm/mach-pxa/lpd270.c
  3. *
  4. * Support for the LogicPD PXA270 Card Engine.
  5. * Derived from the mainstone code, which carries these notices:
  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/pwm_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/lpd270.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 int lpd270_irq_enabled;
  49. static void lpd270_mask_irq(unsigned int irq)
  50. {
  51. int lpd270_irq = irq - LPD270_IRQ(0);
  52. __raw_writew(~(1 << lpd270_irq), LPD270_INT_STATUS);
  53. lpd270_irq_enabled &= ~(1 << lpd270_irq);
  54. __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
  55. }
  56. static void lpd270_unmask_irq(unsigned int irq)
  57. {
  58. int lpd270_irq = irq - LPD270_IRQ(0);
  59. lpd270_irq_enabled |= 1 << lpd270_irq;
  60. __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
  61. }
  62. static struct irq_chip lpd270_irq_chip = {
  63. .name = "CPLD",
  64. .ack = lpd270_mask_irq,
  65. .mask = lpd270_mask_irq,
  66. .unmask = lpd270_unmask_irq,
  67. };
  68. static void lpd270_irq_handler(unsigned int irq, struct irq_desc *desc)
  69. {
  70. unsigned long pending;
  71. pending = __raw_readw(LPD270_INT_STATUS) & lpd270_irq_enabled;
  72. do {
  73. GEDR(0) = GPIO_bit(0); /* clear useless edge notification */
  74. if (likely(pending)) {
  75. irq = LPD270_IRQ(0) + __ffs(pending);
  76. desc = irq_desc + irq;
  77. desc_handle_irq(irq, desc);
  78. pending = __raw_readw(LPD270_INT_STATUS) &
  79. lpd270_irq_enabled;
  80. }
  81. } while (pending);
  82. }
  83. static void __init lpd270_init_irq(void)
  84. {
  85. int irq;
  86. pxa27x_init_irq();
  87. __raw_writew(0, LPD270_INT_MASK);
  88. __raw_writew(0, LPD270_INT_STATUS);
  89. /* setup extra LogicPD PXA270 irqs */
  90. for (irq = LPD270_IRQ(2); irq <= LPD270_IRQ(4); irq++) {
  91. set_irq_chip(irq, &lpd270_irq_chip);
  92. set_irq_handler(irq, handle_level_irq);
  93. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  94. }
  95. set_irq_chained_handler(IRQ_GPIO(0), lpd270_irq_handler);
  96. set_irq_type(IRQ_GPIO(0), IRQT_FALLING);
  97. }
  98. #ifdef CONFIG_PM
  99. static int lpd270_irq_resume(struct sys_device *dev)
  100. {
  101. __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
  102. return 0;
  103. }
  104. static struct sysdev_class lpd270_irq_sysclass = {
  105. .name = "cpld_irq",
  106. .resume = lpd270_irq_resume,
  107. };
  108. static struct sys_device lpd270_irq_device = {
  109. .cls = &lpd270_irq_sysclass,
  110. };
  111. static int __init lpd270_irq_device_init(void)
  112. {
  113. int ret = -ENODEV;
  114. if (machine_is_logicpd_pxa270()) {
  115. ret = sysdev_class_register(&lpd270_irq_sysclass);
  116. if (ret == 0)
  117. ret = sysdev_register(&lpd270_irq_device);
  118. }
  119. return ret;
  120. }
  121. device_initcall(lpd270_irq_device_init);
  122. #endif
  123. static struct resource smc91x_resources[] = {
  124. [0] = {
  125. .start = LPD270_ETH_PHYS,
  126. .end = (LPD270_ETH_PHYS + 0xfffff),
  127. .flags = IORESOURCE_MEM,
  128. },
  129. [1] = {
  130. .start = LPD270_ETHERNET_IRQ,
  131. .end = LPD270_ETHERNET_IRQ,
  132. .flags = IORESOURCE_IRQ,
  133. },
  134. };
  135. static struct platform_device smc91x_device = {
  136. .name = "smc91x",
  137. .id = 0,
  138. .num_resources = ARRAY_SIZE(smc91x_resources),
  139. .resource = smc91x_resources,
  140. };
  141. static struct resource lpd270_flash_resources[] = {
  142. [0] = {
  143. .start = PXA_CS0_PHYS,
  144. .end = PXA_CS0_PHYS + SZ_64M - 1,
  145. .flags = IORESOURCE_MEM,
  146. },
  147. [1] = {
  148. .start = PXA_CS1_PHYS,
  149. .end = PXA_CS1_PHYS + SZ_64M - 1,
  150. .flags = IORESOURCE_MEM,
  151. },
  152. };
  153. static struct mtd_partition lpd270_flash0_partitions[] = {
  154. {
  155. .name = "Bootloader",
  156. .size = 0x00040000,
  157. .offset = 0,
  158. .mask_flags = MTD_WRITEABLE /* force read-only */
  159. }, {
  160. .name = "Kernel",
  161. .size = 0x00400000,
  162. .offset = 0x00040000,
  163. }, {
  164. .name = "Filesystem",
  165. .size = MTDPART_SIZ_FULL,
  166. .offset = 0x00440000
  167. },
  168. };
  169. static struct flash_platform_data lpd270_flash_data[2] = {
  170. {
  171. .name = "processor-flash",
  172. .map_name = "cfi_probe",
  173. .parts = lpd270_flash0_partitions,
  174. .nr_parts = ARRAY_SIZE(lpd270_flash0_partitions),
  175. }, {
  176. .name = "mainboard-flash",
  177. .map_name = "cfi_probe",
  178. .parts = NULL,
  179. .nr_parts = 0,
  180. }
  181. };
  182. static struct platform_device lpd270_flash_device[2] = {
  183. {
  184. .name = "pxa2xx-flash",
  185. .id = 0,
  186. .dev = {
  187. .platform_data = &lpd270_flash_data[0],
  188. },
  189. .resource = &lpd270_flash_resources[0],
  190. .num_resources = 1,
  191. }, {
  192. .name = "pxa2xx-flash",
  193. .id = 1,
  194. .dev = {
  195. .platform_data = &lpd270_flash_data[1],
  196. },
  197. .resource = &lpd270_flash_resources[1],
  198. .num_resources = 1,
  199. },
  200. };
  201. static struct platform_pwm_backlight_data lpd270_backlight_data = {
  202. .pwm_id = 0,
  203. .max_brightness = 1,
  204. .dft_brightness = 1,
  205. .pwm_period_ns = 78770,
  206. };
  207. static struct platform_device lpd270_backlight_device = {
  208. .name = "pwm-backlight",
  209. .dev = {
  210. .parent = &pxa27x_device_pwm0.dev,
  211. .platform_data = &lpd270_backlight_data,
  212. },
  213. };
  214. /* 5.7" TFT QVGA (LoLo display number 1) */
  215. static struct pxafb_mode_info sharp_lq057q3dc02_mode = {
  216. .pixclock = 150000,
  217. .xres = 320,
  218. .yres = 240,
  219. .bpp = 16,
  220. .hsync_len = 0x14,
  221. .left_margin = 0x28,
  222. .right_margin = 0x0a,
  223. .vsync_len = 0x02,
  224. .upper_margin = 0x08,
  225. .lower_margin = 0x14,
  226. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  227. };
  228. static struct pxafb_mach_info sharp_lq057q3dc02 = {
  229. .modes = &sharp_lq057q3dc02_mode,
  230. .num_modes = 1,
  231. .lccr0 = 0x07800080,
  232. .lccr3 = 0x00400000,
  233. };
  234. /* 12.1" TFT SVGA (LoLo display number 2) */
  235. static struct pxafb_mode_info sharp_lq121s1dg31_mode = {
  236. .pixclock = 50000,
  237. .xres = 800,
  238. .yres = 600,
  239. .bpp = 16,
  240. .hsync_len = 0x05,
  241. .left_margin = 0x52,
  242. .right_margin = 0x05,
  243. .vsync_len = 0x04,
  244. .upper_margin = 0x14,
  245. .lower_margin = 0x0a,
  246. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  247. };
  248. static struct pxafb_mach_info sharp_lq121s1dg31 = {
  249. .modes = &sharp_lq121s1dg31_mode,
  250. .num_modes = 1,
  251. .lccr0 = 0x07800080,
  252. .lccr3 = 0x00400000,
  253. };
  254. /* 3.6" TFT QVGA (LoLo display number 3) */
  255. static struct pxafb_mode_info sharp_lq036q1da01_mode = {
  256. .pixclock = 150000,
  257. .xres = 320,
  258. .yres = 240,
  259. .bpp = 16,
  260. .hsync_len = 0x0e,
  261. .left_margin = 0x04,
  262. .right_margin = 0x0a,
  263. .vsync_len = 0x03,
  264. .upper_margin = 0x03,
  265. .lower_margin = 0x03,
  266. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  267. };
  268. static struct pxafb_mach_info sharp_lq036q1da01 = {
  269. .modes = &sharp_lq036q1da01_mode,
  270. .num_modes = 1,
  271. .lccr0 = 0x07800080,
  272. .lccr3 = 0x00400000,
  273. };
  274. /* 6.4" TFT VGA (LoLo display number 5) */
  275. static struct pxafb_mode_info sharp_lq64d343_mode = {
  276. .pixclock = 25000,
  277. .xres = 640,
  278. .yres = 480,
  279. .bpp = 16,
  280. .hsync_len = 0x31,
  281. .left_margin = 0x89,
  282. .right_margin = 0x19,
  283. .vsync_len = 0x12,
  284. .upper_margin = 0x22,
  285. .lower_margin = 0x00,
  286. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  287. };
  288. static struct pxafb_mach_info sharp_lq64d343 = {
  289. .modes = &sharp_lq64d343_mode,
  290. .num_modes = 1,
  291. .lccr0 = 0x07800080,
  292. .lccr3 = 0x00400000,
  293. };
  294. /* 10.4" TFT VGA (LoLo display number 7) */
  295. static struct pxafb_mode_info sharp_lq10d368_mode = {
  296. .pixclock = 25000,
  297. .xres = 640,
  298. .yres = 480,
  299. .bpp = 16,
  300. .hsync_len = 0x31,
  301. .left_margin = 0x89,
  302. .right_margin = 0x19,
  303. .vsync_len = 0x12,
  304. .upper_margin = 0x22,
  305. .lower_margin = 0x00,
  306. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  307. };
  308. static struct pxafb_mach_info sharp_lq10d368 = {
  309. .modes = &sharp_lq10d368_mode,
  310. .num_modes = 1,
  311. .lccr0 = 0x07800080,
  312. .lccr3 = 0x00400000,
  313. };
  314. /* 3.5" TFT QVGA (LoLo display number 8) */
  315. static struct pxafb_mode_info sharp_lq035q7db02_20_mode = {
  316. .pixclock = 150000,
  317. .xres = 240,
  318. .yres = 320,
  319. .bpp = 16,
  320. .hsync_len = 0x0e,
  321. .left_margin = 0x0a,
  322. .right_margin = 0x0a,
  323. .vsync_len = 0x03,
  324. .upper_margin = 0x05,
  325. .lower_margin = 0x14,
  326. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  327. };
  328. static struct pxafb_mach_info sharp_lq035q7db02_20 = {
  329. .modes = &sharp_lq035q7db02_20_mode,
  330. .num_modes = 1,
  331. .lccr0 = 0x07800080,
  332. .lccr3 = 0x00400000,
  333. };
  334. static struct pxafb_mach_info *lpd270_lcd_to_use;
  335. static int __init lpd270_set_lcd(char *str)
  336. {
  337. if (!strnicmp(str, "lq057q3dc02", 11)) {
  338. lpd270_lcd_to_use = &sharp_lq057q3dc02;
  339. } else if (!strnicmp(str, "lq121s1dg31", 11)) {
  340. lpd270_lcd_to_use = &sharp_lq121s1dg31;
  341. } else if (!strnicmp(str, "lq036q1da01", 11)) {
  342. lpd270_lcd_to_use = &sharp_lq036q1da01;
  343. } else if (!strnicmp(str, "lq64d343", 8)) {
  344. lpd270_lcd_to_use = &sharp_lq64d343;
  345. } else if (!strnicmp(str, "lq10d368", 8)) {
  346. lpd270_lcd_to_use = &sharp_lq10d368;
  347. } else if (!strnicmp(str, "lq035q7db02-20", 14)) {
  348. lpd270_lcd_to_use = &sharp_lq035q7db02_20;
  349. } else {
  350. printk(KERN_INFO "lpd270: unknown lcd panel [%s]\n", str);
  351. }
  352. return 1;
  353. }
  354. __setup("lcd=", lpd270_set_lcd);
  355. static struct platform_device *platform_devices[] __initdata = {
  356. &smc91x_device,
  357. &lpd270_backlight_device,
  358. &lpd270_flash_device[0],
  359. &lpd270_flash_device[1],
  360. };
  361. static int lpd270_ohci_init(struct device *dev)
  362. {
  363. /* setup Port1 GPIO pin. */
  364. pxa_gpio_mode(88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */
  365. pxa_gpio_mode(89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
  366. /* Set the Power Control Polarity Low and Power Sense
  367. Polarity Low to active low. */
  368. UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
  369. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
  370. return 0;
  371. }
  372. static struct pxaohci_platform_data lpd270_ohci_platform_data = {
  373. .port_mode = PMM_PERPORT_MODE,
  374. .init = lpd270_ohci_init,
  375. };
  376. static void __init lpd270_init(void)
  377. {
  378. lpd270_flash_data[0].width = (BOOT_DEF & 1) ? 2 : 4;
  379. lpd270_flash_data[1].width = 4;
  380. /*
  381. * System bus arbiter setting:
  382. * - Core_Park
  383. * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
  384. */
  385. ARB_CNTRL = ARB_CORE_PARK | 0x234;
  386. /*
  387. * On LogicPD PXA270, we route AC97_SYSCLK via GPIO45.
  388. */
  389. pxa_gpio_mode(GPIO45_SYSCLK_AC97_MD);
  390. pxa_gpio_mode(GPIO16_PWM0_MD);
  391. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  392. pxa_set_ac97_info(NULL);
  393. if (lpd270_lcd_to_use != NULL)
  394. set_pxa_fb_info(lpd270_lcd_to_use);
  395. pxa_set_ohci_info(&lpd270_ohci_platform_data);
  396. }
  397. static struct map_desc lpd270_io_desc[] __initdata = {
  398. {
  399. .virtual = LPD270_CPLD_VIRT,
  400. .pfn = __phys_to_pfn(LPD270_CPLD_PHYS),
  401. .length = LPD270_CPLD_SIZE,
  402. .type = MT_DEVICE,
  403. },
  404. };
  405. static void __init lpd270_map_io(void)
  406. {
  407. pxa_map_io();
  408. iotable_init(lpd270_io_desc, ARRAY_SIZE(lpd270_io_desc));
  409. /* initialize sleep mode regs (wake-up sources, etc) */
  410. PGSR0 = 0x00008800;
  411. PGSR1 = 0x00000002;
  412. PGSR2 = 0x0001FC00;
  413. PGSR3 = 0x00001F81;
  414. PWER = 0xC0000002;
  415. PRER = 0x00000002;
  416. PFER = 0x00000002;
  417. /* for use I SRAM as framebuffer. */
  418. PSLR |= 0x00000F04;
  419. PCFR = 0x00000066;
  420. }
  421. MACHINE_START(LOGICPD_PXA270, "LogicPD PXA270 Card Engine")
  422. /* Maintainer: Peter Barada */
  423. .phys_io = 0x40000000,
  424. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  425. .boot_params = 0xa0000100,
  426. .map_io = lpd270_map_io,
  427. .init_irq = lpd270_init_irq,
  428. .timer = &pxa_timer,
  429. .init_machine = lpd270_init,
  430. MACHINE_END