impd1.c 10 KB

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