impd1.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 <asm/io.h>
  22. #include <asm/hardware/icst525.h>
  23. #include <asm/hardware/amba.h>
  24. #include <asm/hardware/amba_clcd.h>
  25. #include <asm/arch/lm.h>
  26. #include <asm/arch/impd1.h>
  27. #include <asm/sizes.h>
  28. #include "clock.h"
  29. static int module_id;
  30. module_param_named(lmid, module_id, int, 0444);
  31. MODULE_PARM_DESC(lmid, "logic module stack position");
  32. struct impd1_module {
  33. void __iomem *base;
  34. struct clk vcos[2];
  35. };
  36. static const struct icst525_params impd1_vco_params = {
  37. .ref = 24000, /* 24 MHz */
  38. .vco_max = 200000, /* 200 MHz */
  39. .vd_min = 12,
  40. .vd_max = 519,
  41. .rd_min = 3,
  42. .rd_max = 120,
  43. };
  44. static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
  45. {
  46. struct impd1_module *impd1 = clk->data;
  47. int vconr = clk - impd1->vcos;
  48. u32 val;
  49. val = vco.v | (vco.r << 9) | (vco.s << 16);
  50. writel(0xa05f, impd1->base + IMPD1_LOCK);
  51. switch (vconr) {
  52. case 0:
  53. writel(val, impd1->base + IMPD1_OSC1);
  54. break;
  55. case 1:
  56. writel(val, impd1->base + IMPD1_OSC2);
  57. break;
  58. }
  59. writel(0, impd1->base + IMPD1_LOCK);
  60. #if DEBUG
  61. vco.v = val & 0x1ff;
  62. vco.r = (val >> 9) & 0x7f;
  63. vco.s = (val >> 16) & 7;
  64. pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
  65. vconr, icst525_khz(&impd1_vco_params, vco));
  66. #endif
  67. }
  68. void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
  69. {
  70. struct impd1_module *impd1 = dev_get_drvdata(dev);
  71. u32 cur;
  72. val &= mask;
  73. cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
  74. writel(cur | val, impd1->base + IMPD1_CTRL);
  75. }
  76. EXPORT_SYMBOL(impd1_tweak_control);
  77. /*
  78. * CLCD support
  79. */
  80. #define PANEL PROSPECTOR
  81. #define LTM10C209 1
  82. #define PROSPECTOR 2
  83. #define SVGA 3
  84. #define VGA 4
  85. #if PANEL == VGA
  86. #define PANELTYPE vga
  87. static struct clcd_panel vga = {
  88. .mode = {
  89. .name = "VGA",
  90. .refresh = 60,
  91. .xres = 640,
  92. .yres = 480,
  93. .pixclock = 39721,
  94. .left_margin = 40,
  95. .right_margin = 24,
  96. .upper_margin = 32,
  97. .lower_margin = 11,
  98. .hsync_len = 96,
  99. .vsync_len = 2,
  100. .sync = 0,
  101. .vmode = FB_VMODE_NONINTERLACED,
  102. },
  103. .width = -1,
  104. .height = -1,
  105. .tim2 = TIM2_BCD | TIM2_IPC,
  106. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  107. .connector = IMPD1_CTRL_DISP_VGA,
  108. .bpp = 16,
  109. .grayscale = 0,
  110. };
  111. #elif PANEL == SVGA
  112. #define PANELTYPE svga
  113. static struct clcd_panel svga = {
  114. .mode = {
  115. .name = "SVGA",
  116. .refresh = 0,
  117. .xres = 800,
  118. .yres = 600,
  119. .pixclock = 27778,
  120. .left_margin = 20,
  121. .right_margin = 20,
  122. .upper_margin = 5,
  123. .lower_margin = 5,
  124. .hsync_len = 164,
  125. .vsync_len = 62,
  126. .sync = 0,
  127. .vmode = FB_VMODE_NONINTERLACED,
  128. },
  129. .width = -1,
  130. .height = -1,
  131. .tim2 = TIM2_BCD,
  132. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  133. .connector = IMPD1_CTRL_DISP_VGA,
  134. .bpp = 16,
  135. .grayscale = 0,
  136. };
  137. #elif PANEL == PROSPECTOR
  138. #define PANELTYPE prospector
  139. static struct clcd_panel prospector = {
  140. .mode = {
  141. .name = "PROSPECTOR",
  142. .refresh = 0,
  143. .xres = 640,
  144. .yres = 480,
  145. .pixclock = 40000,
  146. .left_margin = 33,
  147. .right_margin = 64,
  148. .upper_margin = 36,
  149. .lower_margin = 7,
  150. .hsync_len = 64,
  151. .vsync_len = 25,
  152. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  153. .vmode = FB_VMODE_NONINTERLACED,
  154. },
  155. .width = -1,
  156. .height = -1,
  157. .tim2 = TIM2_BCD,
  158. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  159. .fixedtimings = 1,
  160. .connector = IMPD1_CTRL_DISP_LCD,
  161. .bpp = 16,
  162. .grayscale = 0,
  163. };
  164. #elif PANEL == LTM10C209
  165. #define PANELTYPE ltm10c209
  166. /*
  167. * Untested.
  168. */
  169. static struct clcd_panel ltm10c209 = {
  170. .mode = {
  171. .name = "LTM10C209",
  172. .refresh = 0,
  173. .xres = 640,
  174. .yres = 480,
  175. .pixclock = 40000,
  176. .left_margin = 20,
  177. .right_margin = 20,
  178. .upper_margin = 19,
  179. .lower_margin = 19,
  180. .hsync_len = 20,
  181. .vsync_len = 10,
  182. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  183. .vmode = FB_VMODE_NONINTERLACED,
  184. },
  185. .width = -1,
  186. .height = -1,
  187. .tim2 = TIM2_BCD,
  188. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  189. .fixedtimings = 1,
  190. .connector = IMPD1_CTRL_DISP_LCD,
  191. .bpp = 16,
  192. .grayscale = 0,
  193. };
  194. #endif
  195. /*
  196. * Disable all display connectors on the interface module.
  197. */
  198. static void impd1fb_clcd_disable(struct clcd_fb *fb)
  199. {
  200. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
  201. }
  202. /*
  203. * Enable the relevant connector on the interface module.
  204. */
  205. static void impd1fb_clcd_enable(struct clcd_fb *fb)
  206. {
  207. impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
  208. fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
  209. }
  210. static int impd1fb_clcd_setup(struct clcd_fb *fb)
  211. {
  212. unsigned long framebase = fb->dev->res.start + 0x01000000;
  213. unsigned long framesize = SZ_1M;
  214. int ret = 0;
  215. fb->panel = &PANELTYPE;
  216. if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
  217. printk(KERN_ERR "IM-PD1: unable to reserve framebuffer\n");
  218. return -EBUSY;
  219. }
  220. fb->fb.screen_base = ioremap(framebase, framesize);
  221. if (!fb->fb.screen_base) {
  222. printk(KERN_ERR "IM-PD1: unable to map framebuffer\n");
  223. ret = -ENOMEM;
  224. goto free_buffer;
  225. }
  226. fb->fb.fix.smem_start = framebase;
  227. fb->fb.fix.smem_len = framesize;
  228. return 0;
  229. free_buffer:
  230. release_mem_region(framebase, framesize);
  231. return ret;
  232. }
  233. static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  234. {
  235. unsigned long start, size;
  236. start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
  237. size = vma->vm_end - vma->vm_start;
  238. return remap_pfn_range(vma, vma->vm_start, start, size,
  239. vma->vm_page_prot);
  240. }
  241. static void impd1fb_clcd_remove(struct clcd_fb *fb)
  242. {
  243. iounmap(fb->fb.screen_base);
  244. release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
  245. }
  246. static struct clcd_board impd1_clcd_data = {
  247. .name = "IM-PD/1",
  248. .check = clcdfb_check,
  249. .decode = clcdfb_decode,
  250. .disable = impd1fb_clcd_disable,
  251. .enable = impd1fb_clcd_enable,
  252. .setup = impd1fb_clcd_setup,
  253. .mmap = impd1fb_clcd_mmap,
  254. .remove = impd1fb_clcd_remove,
  255. };
  256. struct impd1_device {
  257. unsigned long offset;
  258. unsigned int irq[2];
  259. unsigned int id;
  260. void *platform_data;
  261. };
  262. static struct impd1_device impd1_devs[] = {
  263. {
  264. .offset = 0x03000000,
  265. .id = 0x00041190,
  266. }, {
  267. .offset = 0x00100000,
  268. .irq = { 1 },
  269. .id = 0x00141011,
  270. }, {
  271. .offset = 0x00200000,
  272. .irq = { 2 },
  273. .id = 0x00141011,
  274. }, {
  275. .offset = 0x00300000,
  276. .irq = { 3 },
  277. .id = 0x00041022,
  278. }, {
  279. .offset = 0x00400000,
  280. .irq = { 4 },
  281. .id = 0x00041061,
  282. }, {
  283. .offset = 0x00500000,
  284. .irq = { 5 },
  285. .id = 0x00041061,
  286. }, {
  287. .offset = 0x00600000,
  288. .irq = { 6 },
  289. .id = 0x00041130,
  290. }, {
  291. .offset = 0x00700000,
  292. .irq = { 7, 8 },
  293. .id = 0x00041181,
  294. }, {
  295. .offset = 0x00800000,
  296. .irq = { 9 },
  297. .id = 0x00041041,
  298. }, {
  299. .offset = 0x01000000,
  300. .irq = { 11 },
  301. .id = 0x00041110,
  302. .platform_data = &impd1_clcd_data,
  303. }
  304. };
  305. static const char *impd1_vconames[2] = {
  306. "CLCDCLK",
  307. "AUXVCO2",
  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 = kmalloc(sizeof(struct impd1_module), GFP_KERNEL);
  318. if (!impd1) {
  319. ret = -ENOMEM;
  320. goto release_lm;
  321. }
  322. memset(impd1, 0, sizeof(struct impd1_module));
  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", dev->resource.start);
  330. for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
  331. impd1->vcos[i].owner = THIS_MODULE,
  332. impd1->vcos[i].name = impd1_vconames[i],
  333. impd1->vcos[i].params = &impd1_vco_params,
  334. impd1->vcos[i].data = impd1,
  335. impd1->vcos[i].setvco = impd1_setvco;
  336. clk_register(&impd1->vcos[i]);
  337. }
  338. for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
  339. struct impd1_device *idev = impd1_devs + i;
  340. struct amba_device *d;
  341. unsigned long pc_base;
  342. pc_base = dev->resource.start + idev->offset;
  343. d = kmalloc(sizeof(struct amba_device), GFP_KERNEL);
  344. if (!d)
  345. continue;
  346. memset(d, 0, sizeof(struct amba_device));
  347. snprintf(d->dev.bus_id, sizeof(d->dev.bus_id),
  348. "lm%x:%5.5lx", dev->id, idev->offset >> 12);
  349. d->dev.parent = &dev->dev;
  350. d->res.start = dev->resource.start + idev->offset;
  351. d->res.end = d->res.start + SZ_4K - 1;
  352. d->res.flags = IORESOURCE_MEM;
  353. d->irq[0] = dev->irq;
  354. d->irq[1] = dev->irq;
  355. d->periphid = idev->id;
  356. d->dev.platform_data = idev->platform_data;
  357. ret = amba_device_register(d, &dev->resource);
  358. if (ret) {
  359. printk("unable to register device %s: %d\n",
  360. d->dev.bus_id, ret);
  361. kfree(d);
  362. }
  363. }
  364. return 0;
  365. free_impd1:
  366. if (impd1 && impd1->base)
  367. iounmap(impd1->base);
  368. if (impd1)
  369. kfree(impd1);
  370. release_lm:
  371. release_mem_region(dev->resource.start, SZ_4K);
  372. return ret;
  373. }
  374. static void impd1_remove(struct lm_device *dev)
  375. {
  376. struct impd1_module *impd1 = lm_get_drvdata(dev);
  377. struct list_head *l, *n;
  378. int i;
  379. list_for_each_safe(l, n, &dev->dev.children) {
  380. struct device *d = list_to_dev(l);
  381. device_unregister(d);
  382. }
  383. for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++)
  384. clk_unregister(&impd1->vcos[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");