lpd270.c 12 KB

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