impd1.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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/slab.h>
  25. #include <linux/clkdev.h>
  26. #include <asm/hardware/icst.h>
  27. #include <mach/lm.h>
  28. #include <mach/impd1.h>
  29. #include <asm/sizes.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. struct clk vcos[2];
  36. struct clk_lookup *clks[3];
  37. };
  38. static const struct icst_params impd1_vco_params = {
  39. .ref = 24000000, /* 24 MHz */
  40. .vco_max = ICST525_VCO_MAX_3V,
  41. .vco_min = ICST525_VCO_MIN,
  42. .vd_min = 12,
  43. .vd_max = 519,
  44. .rd_min = 3,
  45. .rd_max = 120,
  46. .s2div = icst525_s2div,
  47. .idx2s = icst525_idx2s,
  48. };
  49. static void impd1_setvco(struct clk *clk, struct icst_vco vco)
  50. {
  51. struct impd1_module *impd1 = clk->data;
  52. u32 val = vco.v | (vco.r << 9) | (vco.s << 16);
  53. writel(0xa05f, impd1->base + IMPD1_LOCK);
  54. writel(val, clk->vcoreg);
  55. writel(0, impd1->base + IMPD1_LOCK);
  56. #ifdef DEBUG
  57. vco.v = val & 0x1ff;
  58. vco.r = (val >> 9) & 0x7f;
  59. vco.s = (val >> 16) & 7;
  60. pr_debug("IM-PD1: VCO%d clock is %ld Hz\n",
  61. vconr, icst525_hz(&impd1_vco_params, vco));
  62. #endif
  63. }
  64. static const struct clk_ops impd1_clk_ops = {
  65. .round = icst_clk_round,
  66. .set = icst_clk_set,
  67. .setvco = impd1_setvco,
  68. };
  69. void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
  70. {
  71. struct impd1_module *impd1 = dev_get_drvdata(dev);
  72. u32 cur;
  73. val &= mask;
  74. cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
  75. writel(cur | val, impd1->base + IMPD1_CTRL);
  76. }
  77. EXPORT_SYMBOL(impd1_tweak_control);
  78. /*
  79. * CLCD support
  80. */
  81. #define PANEL PROSPECTOR
  82. #define LTM10C209 1
  83. #define PROSPECTOR 2
  84. #define SVGA 3
  85. #define VGA 4
  86. #if PANEL == VGA
  87. #define PANELTYPE vga
  88. static struct clcd_panel vga = {
  89. .mode = {
  90. .name = "VGA",
  91. .refresh = 60,
  92. .xres = 640,
  93. .yres = 480,
  94. .pixclock = 39721,
  95. .left_margin = 40,
  96. .right_margin = 24,
  97. .upper_margin = 32,
  98. .lower_margin = 11,
  99. .hsync_len = 96,
  100. .vsync_len = 2,
  101. .sync = 0,
  102. .vmode = FB_VMODE_NONINTERLACED,
  103. },
  104. .width = -1,
  105. .height = -1,
  106. .tim2 = TIM2_BCD | TIM2_IPC,
  107. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  108. .caps = CLCD_CAP_5551,
  109. .connector = IMPD1_CTRL_DISP_VGA,
  110. .bpp = 16,
  111. .grayscale = 0,
  112. };
  113. #elif PANEL == SVGA
  114. #define PANELTYPE svga
  115. static struct clcd_panel svga = {
  116. .mode = {
  117. .name = "SVGA",
  118. .refresh = 0,
  119. .xres = 800,
  120. .yres = 600,
  121. .pixclock = 27778,
  122. .left_margin = 20,
  123. .right_margin = 20,
  124. .upper_margin = 5,
  125. .lower_margin = 5,
  126. .hsync_len = 164,
  127. .vsync_len = 62,
  128. .sync = 0,
  129. .vmode = FB_VMODE_NONINTERLACED,
  130. },
  131. .width = -1,
  132. .height = -1,
  133. .tim2 = TIM2_BCD,
  134. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  135. .connector = IMPD1_CTRL_DISP_VGA,
  136. .caps = CLCD_CAP_5551,
  137. .bpp = 16,
  138. .grayscale = 0,
  139. };
  140. #elif PANEL == PROSPECTOR
  141. #define PANELTYPE prospector
  142. static struct clcd_panel prospector = {
  143. .mode = {
  144. .name = "PROSPECTOR",
  145. .refresh = 0,
  146. .xres = 640,
  147. .yres = 480,
  148. .pixclock = 40000,
  149. .left_margin = 33,
  150. .right_margin = 64,
  151. .upper_margin = 36,
  152. .lower_margin = 7,
  153. .hsync_len = 64,
  154. .vsync_len = 25,
  155. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  156. .vmode = FB_VMODE_NONINTERLACED,
  157. },
  158. .width = -1,
  159. .height = -1,
  160. .tim2 = TIM2_BCD,
  161. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  162. .caps = CLCD_CAP_5551,
  163. .fixedtimings = 1,
  164. .connector = IMPD1_CTRL_DISP_LCD,
  165. .bpp = 16,
  166. .grayscale = 0,
  167. };
  168. #elif PANEL == LTM10C209
  169. #define PANELTYPE ltm10c209
  170. /*
  171. * Untested.
  172. */
  173. static struct clcd_panel ltm10c209 = {
  174. .mode = {
  175. .name = "LTM10C209",
  176. .refresh = 0,
  177. .xres = 640,
  178. .yres = 480,
  179. .pixclock = 40000,
  180. .left_margin = 20,
  181. .right_margin = 20,
  182. .upper_margin = 19,
  183. .lower_margin = 19,
  184. .hsync_len = 20,
  185. .vsync_len = 10,
  186. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  187. .vmode = FB_VMODE_NONINTERLACED,
  188. },
  189. .width = -1,
  190. .height = -1,
  191. .tim2 = TIM2_BCD,
  192. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  193. .caps = CLCD_CAP_5551,
  194. .fixedtimings = 1,
  195. .connector = IMPD1_CTRL_DISP_LCD,
  196. .bpp = 16,
  197. .grayscale = 0,
  198. };
  199. #endif
  200. /*
  201. * Disable all display connectors on the interface module.
  202. */
  203. static void impd1fb_clcd_disable(struct clcd_fb *fb)
  204. {
  205. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
  206. }
  207. /*
  208. * Enable the relevant connector on the interface module.
  209. */
  210. static void impd1fb_clcd_enable(struct clcd_fb *fb)
  211. {
  212. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
  213. fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
  214. }
  215. static int impd1fb_clcd_setup(struct clcd_fb *fb)
  216. {
  217. unsigned long framebase = fb->dev->res.start + 0x01000000;
  218. unsigned long framesize = SZ_1M;
  219. int ret = 0;
  220. fb->panel = &PANELTYPE;
  221. if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
  222. printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
  223. return -EBUSY;
  224. }
  225. fb->fb.screen_base = ioremap(framebase, framesize);
  226. if (!fb->fb.screen_base) {
  227. printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
  228. ret = -ENOMEM;
  229. goto free_buffer;
  230. }
  231. fb->fb.fix.smem_start = framebase;
  232. fb->fb.fix.smem_len = framesize;
  233. return 0;
  234. free_buffer:
  235. release_mem_region(framebase, framesize);
  236. return ret;
  237. }
  238. static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  239. {
  240. unsigned long start, size;
  241. start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
  242. size = vma->vm_end - vma->vm_start;
  243. return remap_pfn_range(vma, vma->vm_start, start, size,
  244. vma->vm_page_prot);
  245. }
  246. static void impd1fb_clcd_remove(struct clcd_fb *fb)
  247. {
  248. iounmap(fb->fb.screen_base);
  249. release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
  250. }
  251. static struct clcd_board impd1_clcd_data = {
  252. .name = "IM-PD/1",
  253. .caps = CLCD_CAP_5551 | CLCD_CAP_888,
  254. .check = clcdfb_check,
  255. .decode = clcdfb_decode,
  256. .disable = impd1fb_clcd_disable,
  257. .enable = impd1fb_clcd_enable,
  258. .setup = impd1fb_clcd_setup,
  259. .mmap = impd1fb_clcd_mmap,
  260. .remove = impd1fb_clcd_remove,
  261. };
  262. struct impd1_device {
  263. unsigned long offset;
  264. unsigned int irq[2];
  265. unsigned int id;
  266. void *platform_data;
  267. };
  268. static struct impd1_device impd1_devs[] = {
  269. {
  270. .offset = 0x03000000,
  271. .id = 0x00041190,
  272. }, {
  273. .offset = 0x00100000,
  274. .irq = { 1 },
  275. .id = 0x00141011,
  276. }, {
  277. .offset = 0x00200000,
  278. .irq = { 2 },
  279. .id = 0x00141011,
  280. }, {
  281. .offset = 0x00300000,
  282. .irq = { 3 },
  283. .id = 0x00041022,
  284. }, {
  285. .offset = 0x00400000,
  286. .irq = { 4 },
  287. .id = 0x00041061,
  288. }, {
  289. .offset = 0x00500000,
  290. .irq = { 5 },
  291. .id = 0x00041061,
  292. }, {
  293. .offset = 0x00600000,
  294. .irq = { 6 },
  295. .id = 0x00041130,
  296. }, {
  297. .offset = 0x00700000,
  298. .irq = { 7, 8 },
  299. .id = 0x00041181,
  300. }, {
  301. .offset = 0x00800000,
  302. .irq = { 9 },
  303. .id = 0x00041041,
  304. }, {
  305. .offset = 0x01000000,
  306. .irq = { 11 },
  307. .id = 0x00041110,
  308. .platform_data = &impd1_clcd_data,
  309. }
  310. };
  311. static struct clk fixed_14745600 = {
  312. .rate = 14745600,
  313. };
  314. static int impd1_probe(struct lm_device *dev)
  315. {
  316. struct impd1_module *impd1;
  317. int i, ret;
  318. if (dev->id != module_id)
  319. return -EINVAL;
  320. if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
  321. return -EBUSY;
  322. impd1 = kzalloc(sizeof(struct impd1_module), GFP_KERNEL);
  323. if (!impd1) {
  324. ret = -ENOMEM;
  325. goto release_lm;
  326. }
  327. impd1->base = ioremap(dev->resource.start, SZ_4K);
  328. if (!impd1->base) {
  329. ret = -ENOMEM;
  330. goto free_impd1;
  331. }
  332. lm_set_drvdata(dev, impd1);
  333. printk("IM-PD1 found at 0x%08lx\n",
  334. (unsigned long)dev->resource.start);
  335. for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
  336. impd1->vcos[i].ops = &impd1_clk_ops,
  337. impd1->vcos[i].owner = THIS_MODULE,
  338. impd1->vcos[i].params = &impd1_vco_params,
  339. impd1->vcos[i].data = impd1;
  340. }
  341. impd1->vcos[0].vcoreg = impd1->base + IMPD1_OSC1;
  342. impd1->vcos[1].vcoreg = impd1->base + IMPD1_OSC2;
  343. impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
  344. dev->id);
  345. impd1->clks[1] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00100",
  346. dev->id);
  347. impd1->clks[2] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00200",
  348. dev->id);
  349. for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  350. clkdev_add(impd1->clks[i]);
  351. for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
  352. struct impd1_device *idev = impd1_devs + i;
  353. struct amba_device *d;
  354. unsigned long pc_base;
  355. pc_base = dev->resource.start + idev->offset;
  356. d = amba_device_alloc(NULL, pc_base, SZ_4K);
  357. if (!d)
  358. continue;
  359. dev_set_name(&d->dev, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
  360. d->dev.parent = &dev->dev;
  361. d->irq[0] = dev->irq;
  362. d->irq[1] = dev->irq;
  363. d->periphid = idev->id;
  364. d->dev.platform_data = idev->platform_data;
  365. ret = amba_device_add(d, &dev->resource);
  366. if (ret) {
  367. dev_err(&d->dev, "unable to register device: %d\n", ret);
  368. amba_device_put(d);
  369. }
  370. }
  371. return 0;
  372. free_impd1:
  373. if (impd1 && impd1->base)
  374. iounmap(impd1->base);
  375. kfree(impd1);
  376. release_lm:
  377. release_mem_region(dev->resource.start, SZ_4K);
  378. return ret;
  379. }
  380. static int impd1_remove_one(struct device *dev, void *data)
  381. {
  382. device_unregister(dev);
  383. return 0;
  384. }
  385. static void impd1_remove(struct lm_device *dev)
  386. {
  387. struct impd1_module *impd1 = lm_get_drvdata(dev);
  388. int i;
  389. device_for_each_child(&dev->dev, NULL, impd1_remove_one);
  390. for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  391. clkdev_drop(impd1->clks[i]);
  392. lm_set_drvdata(dev, NULL);
  393. iounmap(impd1->base);
  394. kfree(impd1);
  395. release_mem_region(dev->resource.start, SZ_4K);
  396. }
  397. static struct lm_driver impd1_driver = {
  398. .drv = {
  399. .name = "impd1",
  400. },
  401. .probe = impd1_probe,
  402. .remove = impd1_remove,
  403. };
  404. static int __init impd1_init(void)
  405. {
  406. return lm_driver_register(&impd1_driver);
  407. }
  408. static void __exit impd1_exit(void)
  409. {
  410. lm_driver_unregister(&impd1_driver);
  411. }
  412. module_init(impd1_init);
  413. module_exit(impd1_exit);
  414. MODULE_LICENSE("GPL");
  415. MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
  416. MODULE_AUTHOR("Deep Blue Solutions Ltd");