impd1.c 10 KB

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