impd1.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. .connector = IMPD1_CTRL_DISP_VGA,
  109. .bpp = 16,
  110. .grayscale = 0,
  111. };
  112. #elif PANEL == SVGA
  113. #define PANELTYPE svga
  114. static struct clcd_panel svga = {
  115. .mode = {
  116. .name = "SVGA",
  117. .refresh = 0,
  118. .xres = 800,
  119. .yres = 600,
  120. .pixclock = 27778,
  121. .left_margin = 20,
  122. .right_margin = 20,
  123. .upper_margin = 5,
  124. .lower_margin = 5,
  125. .hsync_len = 164,
  126. .vsync_len = 62,
  127. .sync = 0,
  128. .vmode = FB_VMODE_NONINTERLACED,
  129. },
  130. .width = -1,
  131. .height = -1,
  132. .tim2 = TIM2_BCD,
  133. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  134. .connector = IMPD1_CTRL_DISP_VGA,
  135. .bpp = 16,
  136. .grayscale = 0,
  137. };
  138. #elif PANEL == PROSPECTOR
  139. #define PANELTYPE prospector
  140. static struct clcd_panel prospector = {
  141. .mode = {
  142. .name = "PROSPECTOR",
  143. .refresh = 0,
  144. .xres = 640,
  145. .yres = 480,
  146. .pixclock = 40000,
  147. .left_margin = 33,
  148. .right_margin = 64,
  149. .upper_margin = 36,
  150. .lower_margin = 7,
  151. .hsync_len = 64,
  152. .vsync_len = 25,
  153. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  154. .vmode = FB_VMODE_NONINTERLACED,
  155. },
  156. .width = -1,
  157. .height = -1,
  158. .tim2 = TIM2_BCD,
  159. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  160. .fixedtimings = 1,
  161. .connector = IMPD1_CTRL_DISP_LCD,
  162. .bpp = 16,
  163. .grayscale = 0,
  164. };
  165. #elif PANEL == LTM10C209
  166. #define PANELTYPE ltm10c209
  167. /*
  168. * Untested.
  169. */
  170. static struct clcd_panel ltm10c209 = {
  171. .mode = {
  172. .name = "LTM10C209",
  173. .refresh = 0,
  174. .xres = 640,
  175. .yres = 480,
  176. .pixclock = 40000,
  177. .left_margin = 20,
  178. .right_margin = 20,
  179. .upper_margin = 19,
  180. .lower_margin = 19,
  181. .hsync_len = 20,
  182. .vsync_len = 10,
  183. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  184. .vmode = FB_VMODE_NONINTERLACED,
  185. },
  186. .width = -1,
  187. .height = -1,
  188. .tim2 = TIM2_BCD,
  189. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  190. .fixedtimings = 1,
  191. .connector = IMPD1_CTRL_DISP_LCD,
  192. .bpp = 16,
  193. .grayscale = 0,
  194. };
  195. #endif
  196. /*
  197. * Disable all display connectors on the interface module.
  198. */
  199. static void impd1fb_clcd_disable(struct clcd_fb *fb)
  200. {
  201. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
  202. }
  203. /*
  204. * Enable the relevant connector on the interface module.
  205. */
  206. static void impd1fb_clcd_enable(struct clcd_fb *fb)
  207. {
  208. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
  209. fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
  210. }
  211. static int impd1fb_clcd_setup(struct clcd_fb *fb)
  212. {
  213. unsigned long framebase = fb->dev->res.start + 0x01000000;
  214. unsigned long framesize = SZ_1M;
  215. int ret = 0;
  216. fb->panel = &PANELTYPE;
  217. if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
  218. printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
  219. return -EBUSY;
  220. }
  221. fb->fb.screen_base = ioremap(framebase, framesize);
  222. if (!fb->fb.screen_base) {
  223. printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
  224. ret = -ENOMEM;
  225. goto free_buffer;
  226. }
  227. fb->fb.fix.smem_start = framebase;
  228. fb->fb.fix.smem_len = framesize;
  229. return 0;
  230. free_buffer:
  231. release_mem_region(framebase, framesize);
  232. return ret;
  233. }
  234. static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  235. {
  236. unsigned long start, size;
  237. start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
  238. size = vma->vm_end - vma->vm_start;
  239. return remap_pfn_range(vma, vma->vm_start, start, size,
  240. vma->vm_page_prot);
  241. }
  242. static void impd1fb_clcd_remove(struct clcd_fb *fb)
  243. {
  244. iounmap(fb->fb.screen_base);
  245. release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
  246. }
  247. static struct clcd_board impd1_clcd_data = {
  248. .name = "IM-PD/1",
  249. .check = clcdfb_check,
  250. .decode = clcdfb_decode,
  251. .disable = impd1fb_clcd_disable,
  252. .enable = impd1fb_clcd_enable,
  253. .setup = impd1fb_clcd_setup,
  254. .mmap = impd1fb_clcd_mmap,
  255. .remove = impd1fb_clcd_remove,
  256. };
  257. struct impd1_device {
  258. unsigned long offset;
  259. unsigned int irq[2];
  260. unsigned int id;
  261. void *platform_data;
  262. };
  263. static struct impd1_device impd1_devs[] = {
  264. {
  265. .offset = 0x03000000,
  266. .id = 0x00041190,
  267. }, {
  268. .offset = 0x00100000,
  269. .irq = { 1 },
  270. .id = 0x00141011,
  271. }, {
  272. .offset = 0x00200000,
  273. .irq = { 2 },
  274. .id = 0x00141011,
  275. }, {
  276. .offset = 0x00300000,
  277. .irq = { 3 },
  278. .id = 0x00041022,
  279. }, {
  280. .offset = 0x00400000,
  281. .irq = { 4 },
  282. .id = 0x00041061,
  283. }, {
  284. .offset = 0x00500000,
  285. .irq = { 5 },
  286. .id = 0x00041061,
  287. }, {
  288. .offset = 0x00600000,
  289. .irq = { 6 },
  290. .id = 0x00041130,
  291. }, {
  292. .offset = 0x00700000,
  293. .irq = { 7, 8 },
  294. .id = 0x00041181,
  295. }, {
  296. .offset = 0x00800000,
  297. .irq = { 9 },
  298. .id = 0x00041041,
  299. }, {
  300. .offset = 0x01000000,
  301. .irq = { 11 },
  302. .id = 0x00041110,
  303. .platform_data = &impd1_clcd_data,
  304. }
  305. };
  306. static struct clk fixed_14745600 = {
  307. .rate = 14745600,
  308. };
  309. static int impd1_probe(struct lm_device *dev)
  310. {
  311. struct impd1_module *impd1;
  312. int i, ret;
  313. if (dev->id != module_id)
  314. return -EINVAL;
  315. if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
  316. return -EBUSY;
  317. impd1 = kzalloc(sizeof(struct impd1_module), GFP_KERNEL);
  318. if (!impd1) {
  319. ret = -ENOMEM;
  320. goto release_lm;
  321. }
  322. impd1->base = ioremap(dev->resource.start, SZ_4K);
  323. if (!impd1->base) {
  324. ret = -ENOMEM;
  325. goto free_impd1;
  326. }
  327. lm_set_drvdata(dev, impd1);
  328. printk("IM-PD1 found at 0x%08lx\n",
  329. (unsigned long)dev->resource.start);
  330. for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
  331. impd1->vcos[i].ops = &impd1_clk_ops,
  332. impd1->vcos[i].owner = THIS_MODULE,
  333. impd1->vcos[i].params = &impd1_vco_params,
  334. impd1->vcos[i].data = impd1;
  335. }
  336. impd1->vcos[0].vcoreg = impd1->base + IMPD1_OSC1;
  337. impd1->vcos[1].vcoreg = impd1->base + IMPD1_OSC2;
  338. impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
  339. dev->id);
  340. impd1->clks[1] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00100",
  341. dev->id);
  342. impd1->clks[2] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00200",
  343. dev->id);
  344. for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  345. clkdev_add(impd1->clks[i]);
  346. for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
  347. struct impd1_device *idev = impd1_devs + i;
  348. struct amba_device *d;
  349. unsigned long pc_base;
  350. pc_base = dev->resource.start + idev->offset;
  351. d = kzalloc(sizeof(struct amba_device), GFP_KERNEL);
  352. if (!d)
  353. continue;
  354. dev_set_name(&d->dev, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
  355. d->dev.parent = &dev->dev;
  356. d->res.start = dev->resource.start + idev->offset;
  357. d->res.end = d->res.start + SZ_4K - 1;
  358. d->res.flags = IORESOURCE_MEM;
  359. d->irq[0] = dev->irq;
  360. d->irq[1] = dev->irq;
  361. d->periphid = idev->id;
  362. d->dev.platform_data = idev->platform_data;
  363. ret = amba_device_register(d, &dev->resource);
  364. if (ret) {
  365. dev_err(&d->dev, "unable to register device: %d\n", ret);
  366. kfree(d);
  367. }
  368. }
  369. return 0;
  370. free_impd1:
  371. if (impd1 && impd1->base)
  372. iounmap(impd1->base);
  373. kfree(impd1);
  374. release_lm:
  375. release_mem_region(dev->resource.start, SZ_4K);
  376. return ret;
  377. }
  378. static int impd1_remove_one(struct device *dev, void *data)
  379. {
  380. device_unregister(dev);
  381. return 0;
  382. }
  383. static void impd1_remove(struct lm_device *dev)
  384. {
  385. struct impd1_module *impd1 = lm_get_drvdata(dev);
  386. int i;
  387. device_for_each_child(&dev->dev, NULL, impd1_remove_one);
  388. for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  389. clkdev_drop(impd1->clks[i]);
  390. lm_set_drvdata(dev, NULL);
  391. iounmap(impd1->base);
  392. kfree(impd1);
  393. release_mem_region(dev->resource.start, SZ_4K);
  394. }
  395. static struct lm_driver impd1_driver = {
  396. .drv = {
  397. .name = "impd1",
  398. },
  399. .probe = impd1_probe,
  400. .remove = impd1_remove,
  401. };
  402. static int __init impd1_init(void)
  403. {
  404. return lm_driver_register(&impd1_driver);
  405. }
  406. static void __exit impd1_exit(void)
  407. {
  408. lm_driver_unregister(&impd1_driver);
  409. }
  410. module_init(impd1_init);
  411. module_exit(impd1_exit);
  412. MODULE_LICENSE("GPL");
  413. MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
  414. MODULE_AUTHOR("Deep Blue Solutions Ltd");