impd1.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * linux/arch/arm/mach-integrator/impd1.c
  3. *
  4. * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This file provides the core support for the IM-PD1 module.
  11. *
  12. * Module / boot parameters.
  13. * lmid=n impd1.lmid=n - set the logic module position in stack to 'n'
  14. */
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/init.h>
  18. #include <linux/device.h>
  19. #include <linux/errno.h>
  20. #include <linux/mm.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/amba/clcd.h>
  23. #include <linux/amba/mmci.h>
  24. #include <linux/io.h>
  25. #include <linux/platform_data/clk-integrator.h>
  26. #include <linux/slab.h>
  27. #include <linux/irqchip/arm-vic.h>
  28. #include <linux/gpio/machine.h>
  29. #include <asm/sizes.h>
  30. #include "lm.h"
  31. #include "impd1.h"
  32. static int module_id;
  33. module_param_named(lmid, module_id, int, 0444);
  34. MODULE_PARM_DESC(lmid, "logic module stack position");
  35. struct impd1_module {
  36. void __iomem *base;
  37. void __iomem *vic_base;
  38. };
  39. void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
  40. {
  41. struct impd1_module *impd1 = dev_get_drvdata(dev);
  42. u32 cur;
  43. val &= mask;
  44. cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
  45. writel(cur | val, impd1->base + IMPD1_CTRL);
  46. }
  47. EXPORT_SYMBOL(impd1_tweak_control);
  48. /*
  49. * MMC support
  50. */
  51. static struct mmci_platform_data mmc_data = {
  52. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  53. };
  54. /*
  55. * CLCD support
  56. */
  57. #define PANEL PROSPECTOR
  58. #define LTM10C209 1
  59. #define PROSPECTOR 2
  60. #define SVGA 3
  61. #define VGA 4
  62. #if PANEL == VGA
  63. #define PANELTYPE vga
  64. static struct clcd_panel vga = {
  65. .mode = {
  66. .name = "VGA",
  67. .refresh = 60,
  68. .xres = 640,
  69. .yres = 480,
  70. .pixclock = 39721,
  71. .left_margin = 40,
  72. .right_margin = 24,
  73. .upper_margin = 32,
  74. .lower_margin = 11,
  75. .hsync_len = 96,
  76. .vsync_len = 2,
  77. .sync = 0,
  78. .vmode = FB_VMODE_NONINTERLACED,
  79. },
  80. .width = -1,
  81. .height = -1,
  82. .tim2 = TIM2_BCD | TIM2_IPC,
  83. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  84. .caps = CLCD_CAP_5551,
  85. .connector = IMPD1_CTRL_DISP_VGA,
  86. .bpp = 16,
  87. .grayscale = 0,
  88. };
  89. #elif PANEL == SVGA
  90. #define PANELTYPE svga
  91. static struct clcd_panel svga = {
  92. .mode = {
  93. .name = "SVGA",
  94. .refresh = 0,
  95. .xres = 800,
  96. .yres = 600,
  97. .pixclock = 27778,
  98. .left_margin = 20,
  99. .right_margin = 20,
  100. .upper_margin = 5,
  101. .lower_margin = 5,
  102. .hsync_len = 164,
  103. .vsync_len = 62,
  104. .sync = 0,
  105. .vmode = FB_VMODE_NONINTERLACED,
  106. },
  107. .width = -1,
  108. .height = -1,
  109. .tim2 = TIM2_BCD,
  110. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  111. .connector = IMPD1_CTRL_DISP_VGA,
  112. .caps = CLCD_CAP_5551,
  113. .bpp = 16,
  114. .grayscale = 0,
  115. };
  116. #elif PANEL == PROSPECTOR
  117. #define PANELTYPE prospector
  118. static struct clcd_panel prospector = {
  119. .mode = {
  120. .name = "PROSPECTOR",
  121. .refresh = 0,
  122. .xres = 640,
  123. .yres = 480,
  124. .pixclock = 40000,
  125. .left_margin = 33,
  126. .right_margin = 64,
  127. .upper_margin = 36,
  128. .lower_margin = 7,
  129. .hsync_len = 64,
  130. .vsync_len = 25,
  131. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  132. .vmode = FB_VMODE_NONINTERLACED,
  133. },
  134. .width = -1,
  135. .height = -1,
  136. .tim2 = TIM2_BCD,
  137. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  138. .caps = CLCD_CAP_5551,
  139. .fixedtimings = 1,
  140. .connector = IMPD1_CTRL_DISP_LCD,
  141. .bpp = 16,
  142. .grayscale = 0,
  143. };
  144. #elif PANEL == LTM10C209
  145. #define PANELTYPE ltm10c209
  146. /*
  147. * Untested.
  148. */
  149. static struct clcd_panel ltm10c209 = {
  150. .mode = {
  151. .name = "LTM10C209",
  152. .refresh = 0,
  153. .xres = 640,
  154. .yres = 480,
  155. .pixclock = 40000,
  156. .left_margin = 20,
  157. .right_margin = 20,
  158. .upper_margin = 19,
  159. .lower_margin = 19,
  160. .hsync_len = 20,
  161. .vsync_len = 10,
  162. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  163. .vmode = FB_VMODE_NONINTERLACED,
  164. },
  165. .width = -1,
  166. .height = -1,
  167. .tim2 = TIM2_BCD,
  168. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  169. .caps = CLCD_CAP_5551,
  170. .fixedtimings = 1,
  171. .connector = IMPD1_CTRL_DISP_LCD,
  172. .bpp = 16,
  173. .grayscale = 0,
  174. };
  175. #endif
  176. /*
  177. * Disable all display connectors on the interface module.
  178. */
  179. static void impd1fb_clcd_disable(struct clcd_fb *fb)
  180. {
  181. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
  182. }
  183. /*
  184. * Enable the relevant connector on the interface module.
  185. */
  186. static void impd1fb_clcd_enable(struct clcd_fb *fb)
  187. {
  188. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
  189. fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
  190. }
  191. static int impd1fb_clcd_setup(struct clcd_fb *fb)
  192. {
  193. unsigned long framebase = fb->dev->res.start + 0x01000000;
  194. unsigned long framesize = SZ_1M;
  195. int ret = 0;
  196. fb->panel = &PANELTYPE;
  197. if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
  198. printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
  199. return -EBUSY;
  200. }
  201. fb->fb.screen_base = ioremap(framebase, framesize);
  202. if (!fb->fb.screen_base) {
  203. printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
  204. ret = -ENOMEM;
  205. goto free_buffer;
  206. }
  207. fb->fb.fix.smem_start = framebase;
  208. fb->fb.fix.smem_len = framesize;
  209. return 0;
  210. free_buffer:
  211. release_mem_region(framebase, framesize);
  212. return ret;
  213. }
  214. static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  215. {
  216. unsigned long start, size;
  217. start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
  218. size = vma->vm_end - vma->vm_start;
  219. return remap_pfn_range(vma, vma->vm_start, start, size,
  220. vma->vm_page_prot);
  221. }
  222. static void impd1fb_clcd_remove(struct clcd_fb *fb)
  223. {
  224. iounmap(fb->fb.screen_base);
  225. release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
  226. }
  227. static struct clcd_board impd1_clcd_data = {
  228. .name = "IM-PD/1",
  229. .caps = CLCD_CAP_5551 | CLCD_CAP_888,
  230. .check = clcdfb_check,
  231. .decode = clcdfb_decode,
  232. .disable = impd1fb_clcd_disable,
  233. .enable = impd1fb_clcd_enable,
  234. .setup = impd1fb_clcd_setup,
  235. .mmap = impd1fb_clcd_mmap,
  236. .remove = impd1fb_clcd_remove,
  237. };
  238. struct impd1_device {
  239. unsigned long offset;
  240. unsigned int irq[2];
  241. unsigned int id;
  242. void *platform_data;
  243. };
  244. static struct impd1_device impd1_devs[] = {
  245. {
  246. .offset = 0x00100000,
  247. .irq = { 1 },
  248. .id = 0x00141011,
  249. }, {
  250. .offset = 0x00200000,
  251. .irq = { 2 },
  252. .id = 0x00141011,
  253. }, {
  254. .offset = 0x00300000,
  255. .irq = { 3 },
  256. .id = 0x00041022,
  257. }, {
  258. .offset = 0x00400000,
  259. .irq = { 4 },
  260. .id = 0x00041061,
  261. }, {
  262. .offset = 0x00500000,
  263. .irq = { 5 },
  264. .id = 0x00041061,
  265. }, {
  266. .offset = 0x00600000,
  267. .irq = { 6 },
  268. .id = 0x00041130,
  269. }, {
  270. .offset = 0x00700000,
  271. .irq = { 7, 8 },
  272. .id = 0x00041181,
  273. .platform_data = &mmc_data,
  274. }, {
  275. .offset = 0x00800000,
  276. .irq = { 9 },
  277. .id = 0x00041041,
  278. }, {
  279. .offset = 0x01000000,
  280. .irq = { 11 },
  281. .id = 0x00041110,
  282. .platform_data = &impd1_clcd_data,
  283. }
  284. };
  285. /*
  286. * Valid IRQs: 0 thru 9 and 11, 10 unused.
  287. */
  288. #define IMPD1_VALID_IRQS 0x00000bffU
  289. /*
  290. * As this module is bool, it is OK to have this as __ref() - no
  291. * probe calls will be done after the initial system bootup, as devices
  292. * are discovered as part of the machine startup.
  293. */
  294. static int __ref impd1_probe(struct lm_device *dev)
  295. {
  296. struct impd1_module *impd1;
  297. int irq_base;
  298. int i;
  299. if (dev->id != module_id)
  300. return -EINVAL;
  301. if (!devm_request_mem_region(&dev->dev, dev->resource.start,
  302. SZ_4K, "LM registers"))
  303. return -EBUSY;
  304. impd1 = devm_kzalloc(&dev->dev, sizeof(struct impd1_module),
  305. GFP_KERNEL);
  306. if (!impd1)
  307. return -ENOMEM;
  308. impd1->base = devm_ioremap(&dev->dev, dev->resource.start, SZ_4K);
  309. if (!impd1->base)
  310. return -ENOMEM;
  311. integrator_impd1_clk_init(impd1->base, dev->id);
  312. if (!devm_request_mem_region(&dev->dev,
  313. dev->resource.start + 0x03000000,
  314. SZ_4K, "VIC"))
  315. return -EBUSY;
  316. impd1->vic_base = devm_ioremap(&dev->dev,
  317. dev->resource.start + 0x03000000,
  318. SZ_4K);
  319. if (!impd1->vic_base)
  320. return -ENOMEM;
  321. irq_base = vic_init_cascaded(impd1->vic_base, dev->irq,
  322. IMPD1_VALID_IRQS, 0);
  323. lm_set_drvdata(dev, impd1);
  324. dev_info(&dev->dev, "IM-PD1 found at 0x%08lx\n",
  325. (unsigned long)dev->resource.start);
  326. for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
  327. struct impd1_device *idev = impd1_devs + i;
  328. struct amba_device *d;
  329. unsigned long pc_base;
  330. char devname[32];
  331. int irq1 = idev->irq[0];
  332. int irq2 = idev->irq[1];
  333. /* Translate IRQs to IM-PD1 local numberspace */
  334. if (irq1)
  335. irq1 += irq_base;
  336. if (irq2)
  337. irq2 += irq_base;
  338. pc_base = dev->resource.start + idev->offset;
  339. snprintf(devname, 32, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
  340. /* Add GPIO descriptor lookup table for the PL061 block */
  341. if (idev->offset == 0x00400000) {
  342. struct gpiod_lookup_table *lookup;
  343. char *chipname;
  344. char *mmciname;
  345. lookup = devm_kzalloc(&dev->dev,
  346. sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup),
  347. GFP_KERNEL);
  348. chipname = devm_kstrdup(&dev->dev, devname, GFP_KERNEL);
  349. mmciname = devm_kasprintf(&dev->dev, GFP_KERNEL,
  350. "lm%x:00700", dev->id);
  351. if (!lookup || !chipname || !mmciname)
  352. return -ENOMEM;
  353. lookup->dev_id = mmciname;
  354. /*
  355. * Offsets on GPIO block 1:
  356. * 3 = MMC WP (write protect)
  357. * 4 = MMC CD (card detect)
  358. *
  359. * Offsets on GPIO block 2:
  360. * 0 = Up key
  361. * 1 = Down key
  362. * 2 = Left key
  363. * 3 = Right key
  364. * 4 = Key lower left
  365. * 5 = Key lower right
  366. */
  367. /* We need the two MMCI GPIO entries */
  368. lookup->table[0].chip_label = chipname;
  369. lookup->table[0].chip_hwnum = 3;
  370. lookup->table[0].con_id = "wp";
  371. lookup->table[1].chip_label = chipname;
  372. lookup->table[1].chip_hwnum = 4;
  373. lookup->table[1].con_id = "cd";
  374. lookup->table[1].flags = GPIO_ACTIVE_LOW;
  375. gpiod_add_lookup_table(lookup);
  376. }
  377. d = amba_ahb_device_add_res(&dev->dev, devname, pc_base, SZ_4K,
  378. irq1, irq2,
  379. idev->platform_data, idev->id,
  380. &dev->resource);
  381. if (IS_ERR(d)) {
  382. dev_err(&dev->dev, "unable to register device: %ld\n", PTR_ERR(d));
  383. continue;
  384. }
  385. }
  386. return 0;
  387. }
  388. static int impd1_remove_one(struct device *dev, void *data)
  389. {
  390. device_unregister(dev);
  391. return 0;
  392. }
  393. static void impd1_remove(struct lm_device *dev)
  394. {
  395. device_for_each_child(&dev->dev, NULL, impd1_remove_one);
  396. integrator_impd1_clk_exit(dev->id);
  397. lm_set_drvdata(dev, NULL);
  398. }
  399. static struct lm_driver impd1_driver = {
  400. .drv = {
  401. .name = "impd1",
  402. /*
  403. * As we're dropping the probe() function, suppress driver
  404. * binding from sysfs.
  405. */
  406. .suppress_bind_attrs = true,
  407. },
  408. .probe = impd1_probe,
  409. .remove = impd1_remove,
  410. };
  411. static int __init impd1_init(void)
  412. {
  413. return lm_driver_register(&impd1_driver);
  414. }
  415. static void __exit impd1_exit(void)
  416. {
  417. lm_driver_unregister(&impd1_driver);
  418. }
  419. module_init(impd1_init);
  420. module_exit(impd1_exit);
  421. MODULE_LICENSE("GPL");
  422. MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
  423. MODULE_AUTHOR("Deep Blue Solutions Ltd");