lpd270.c 12 KB

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