impd1.c 9.2 KB

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