lpd270.c 12 KB

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