impd1.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 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. int vconr = clk - impd1->vcos;
  53. u32 val;
  54. val = vco.v | (vco.r << 9) | (vco.s << 16);
  55. writel(0xa05f, impd1->base + IMPD1_LOCK);
  56. switch (vconr) {
  57. case 0:
  58. writel(val, impd1->base + IMPD1_OSC1);
  59. break;
  60. case 1:
  61. writel(val, impd1->base + IMPD1_OSC2);
  62. break;
  63. }
  64. writel(0, impd1->base + IMPD1_LOCK);
  65. #ifdef DEBUG
  66. vco.v = val & 0x1ff;
  67. vco.r = (val >> 9) & 0x7f;
  68. vco.s = (val >> 16) & 7;
  69. pr_debug("IM-PD1: VCO%d clock is %ld Hz\n",
  70. vconr, icst525_hz(&impd1_vco_params, vco));
  71. #endif
  72. }
  73. void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
  74. {
  75. struct impd1_module *impd1 = dev_get_drvdata(dev);
  76. u32 cur;
  77. val &= mask;
  78. cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
  79. writel(cur | val, impd1->base + IMPD1_CTRL);
  80. }
  81. EXPORT_SYMBOL(impd1_tweak_control);
  82. /*
  83. * CLCD support
  84. */
  85. #define PANEL PROSPECTOR
  86. #define LTM10C209 1
  87. #define PROSPECTOR 2
  88. #define SVGA 3
  89. #define VGA 4
  90. #if PANEL == VGA
  91. #define PANELTYPE vga
  92. static struct clcd_panel vga = {
  93. .mode = {
  94. .name = "VGA",
  95. .refresh = 60,
  96. .xres = 640,
  97. .yres = 480,
  98. .pixclock = 39721,
  99. .left_margin = 40,
  100. .right_margin = 24,
  101. .upper_margin = 32,
  102. .lower_margin = 11,
  103. .hsync_len = 96,
  104. .vsync_len = 2,
  105. .sync = 0,
  106. .vmode = FB_VMODE_NONINTERLACED,
  107. },
  108. .width = -1,
  109. .height = -1,
  110. .tim2 = TIM2_BCD | TIM2_IPC,
  111. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  112. .connector = IMPD1_CTRL_DISP_VGA,
  113. .bpp = 16,
  114. .grayscale = 0,
  115. };
  116. #elif PANEL == SVGA
  117. #define PANELTYPE svga
  118. static struct clcd_panel svga = {
  119. .mode = {
  120. .name = "SVGA",
  121. .refresh = 0,
  122. .xres = 800,
  123. .yres = 600,
  124. .pixclock = 27778,
  125. .left_margin = 20,
  126. .right_margin = 20,
  127. .upper_margin = 5,
  128. .lower_margin = 5,
  129. .hsync_len = 164,
  130. .vsync_len = 62,
  131. .sync = 0,
  132. .vmode = FB_VMODE_NONINTERLACED,
  133. },
  134. .width = -1,
  135. .height = -1,
  136. .tim2 = TIM2_BCD,
  137. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  138. .connector = IMPD1_CTRL_DISP_VGA,
  139. .bpp = 16,
  140. .grayscale = 0,
  141. };
  142. #elif PANEL == PROSPECTOR
  143. #define PANELTYPE prospector
  144. static struct clcd_panel prospector = {
  145. .mode = {
  146. .name = "PROSPECTOR",
  147. .refresh = 0,
  148. .xres = 640,
  149. .yres = 480,
  150. .pixclock = 40000,
  151. .left_margin = 33,
  152. .right_margin = 64,
  153. .upper_margin = 36,
  154. .lower_margin = 7,
  155. .hsync_len = 64,
  156. .vsync_len = 25,
  157. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  158. .vmode = FB_VMODE_NONINTERLACED,
  159. },
  160. .width = -1,
  161. .height = -1,
  162. .tim2 = TIM2_BCD,
  163. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  164. .fixedtimings = 1,
  165. .connector = IMPD1_CTRL_DISP_LCD,
  166. .bpp = 16,
  167. .grayscale = 0,
  168. };
  169. #elif PANEL == LTM10C209
  170. #define PANELTYPE ltm10c209
  171. /*
  172. * Untested.
  173. */
  174. static struct clcd_panel ltm10c209 = {
  175. .mode = {
  176. .name = "LTM10C209",
  177. .refresh = 0,
  178. .xres = 640,
  179. .yres = 480,
  180. .pixclock = 40000,
  181. .left_margin = 20,
  182. .right_margin = 20,
  183. .upper_margin = 19,
  184. .lower_margin = 19,
  185. .hsync_len = 20,
  186. .vsync_len = 10,
  187. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  188. .vmode = FB_VMODE_NONINTERLACED,
  189. },
  190. .width = -1,
  191. .height = -1,
  192. .tim2 = TIM2_BCD,
  193. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  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. .check = clcdfb_check,
  254. .decode = clcdfb_decode,
  255. .disable = impd1fb_clcd_disable,
  256. .enable = impd1fb_clcd_enable,
  257. .setup = impd1fb_clcd_setup,
  258. .mmap = impd1fb_clcd_mmap,
  259. .remove = impd1fb_clcd_remove,
  260. };
  261. struct impd1_device {
  262. unsigned long offset;
  263. unsigned int irq[2];
  264. unsigned int id;
  265. void *platform_data;
  266. };
  267. static struct impd1_device impd1_devs[] = {
  268. {
  269. .offset = 0x03000000,
  270. .id = 0x00041190,
  271. }, {
  272. .offset = 0x00100000,
  273. .irq = { 1 },
  274. .id = 0x00141011,
  275. }, {
  276. .offset = 0x00200000,
  277. .irq = { 2 },
  278. .id = 0x00141011,
  279. }, {
  280. .offset = 0x00300000,
  281. .irq = { 3 },
  282. .id = 0x00041022,
  283. }, {
  284. .offset = 0x00400000,
  285. .irq = { 4 },
  286. .id = 0x00041061,
  287. }, {
  288. .offset = 0x00500000,
  289. .irq = { 5 },
  290. .id = 0x00041061,
  291. }, {
  292. .offset = 0x00600000,
  293. .irq = { 6 },
  294. .id = 0x00041130,
  295. }, {
  296. .offset = 0x00700000,
  297. .irq = { 7, 8 },
  298. .id = 0x00041181,
  299. }, {
  300. .offset = 0x00800000,
  301. .irq = { 9 },
  302. .id = 0x00041041,
  303. }, {
  304. .offset = 0x01000000,
  305. .irq = { 11 },
  306. .id = 0x00041110,
  307. .platform_data = &impd1_clcd_data,
  308. }
  309. };
  310. static struct clk fixed_14745600 = {
  311. .rate = 14745600,
  312. };
  313. static int impd1_probe(struct lm_device *dev)
  314. {
  315. struct impd1_module *impd1;
  316. int i, ret;
  317. if (dev->id != module_id)
  318. return -EINVAL;
  319. if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
  320. return -EBUSY;
  321. impd1 = kzalloc(sizeof(struct impd1_module), GFP_KERNEL);
  322. if (!impd1) {
  323. ret = -ENOMEM;
  324. goto release_lm;
  325. }
  326. impd1->base = ioremap(dev->resource.start, SZ_4K);
  327. if (!impd1->base) {
  328. ret = -ENOMEM;
  329. goto free_impd1;
  330. }
  331. lm_set_drvdata(dev, impd1);
  332. printk("IM-PD1 found at 0x%08lx\n",
  333. (unsigned long)dev->resource.start);
  334. for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
  335. impd1->vcos[i].owner = THIS_MODULE,
  336. impd1->vcos[i].params = &impd1_vco_params,
  337. impd1->vcos[i].data = impd1,
  338. impd1->vcos[i].setvco = impd1_setvco;
  339. }
  340. impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
  341. dev->id);
  342. impd1->clks[1] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00100",
  343. dev->id);
  344. impd1->clks[2] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00200",
  345. dev->id);
  346. for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  347. clkdev_add(impd1->clks[i]);
  348. for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
  349. struct impd1_device *idev = impd1_devs + i;
  350. struct amba_device *d;
  351. unsigned long pc_base;
  352. pc_base = dev->resource.start + idev->offset;
  353. d = kzalloc(sizeof(struct amba_device), GFP_KERNEL);
  354. if (!d)
  355. continue;
  356. dev_set_name(&d->dev, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
  357. d->dev.parent = &dev->dev;
  358. d->res.start = dev->resource.start + idev->offset;
  359. d->res.end = d->res.start + SZ_4K - 1;
  360. d->res.flags = IORESOURCE_MEM;
  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_register(d, &dev->resource);
  366. if (ret) {
  367. dev_err(&d->dev, "unable to register device: %d\n", ret);
  368. kfree(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");