lpd270.c 12 KB

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