impd1.c 11 KB

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