2 * linux/arch/arm/mach-integrator/impd1.c
4 * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
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.
10 * This file provides the core support for the IM-PD1 module.
12 * Module / boot parameters.
13 * lmid=n impd1.lmid=n - set the logic module position in stack to 'n'
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>
22 #include <asm/hardware/icst525.h>
23 #include <asm/hardware/amba.h>
24 #include <asm/arch/lm.h>
25 #include <asm/arch/impd1.h>
26 #include <asm/sizes.h>
30 module_param_named(lmid, module_id, int, 0444);
31 MODULE_PARM_DESC(lmid, "logic module stack position");
37 static const struct icst525_params impd1_vco_params = {
38 .ref = 24000, /* 24 MHz */
39 .vco_max = 200000, /* 200 MHz */
46 void impd1_set_vco(struct device *dev, int vconr, unsigned long period)
48 struct impd1_module *impd1 = dev_get_drvdata(dev);
49 struct icst525_vco vco;
52 vco = icst525_ps_to_vco(&impd1_vco_params, period);
54 pr_debug("Guessed VCO reg params: S=%d R=%d V=%d\n",
57 val = vco.v | (vco.r << 9) | (vco.s << 16);
59 writel(0xa05f, impd1->base + IMPD1_LOCK);
62 writel(val, impd1->base + IMPD1_OSC1);
65 writel(val, impd1->base + IMPD1_OSC2);
68 writel(0, impd1->base + IMPD1_LOCK);
72 vco.r = (val >> 9) & 0x7f;
73 vco.s = (val >> 16) & 7;
75 pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
76 vconr, icst525_khz(&impd1_vco_params, vco));
80 EXPORT_SYMBOL(impd1_set_vco);
82 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
84 struct impd1_module *impd1 = dev_get_drvdata(dev);
88 cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
89 writel(cur | val, impd1->base + IMPD1_CTRL);
92 EXPORT_SYMBOL(impd1_tweak_control);
100 static struct impd1_device impd1_devs[] = {
102 .offset = 0x03000000,
105 .offset = 0x00100000,
109 .offset = 0x00200000,
113 .offset = 0x00300000,
117 .offset = 0x00400000,
121 .offset = 0x00500000,
125 .offset = 0x00600000,
129 .offset = 0x00700000,
133 .offset = 0x00800000,
137 .offset = 0x01000000,
143 static int impd1_probe(struct lm_device *dev)
145 struct impd1_module *impd1;
148 if (dev->id != module_id)
151 if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
154 impd1 = kmalloc(sizeof(struct impd1_module), GFP_KERNEL);
159 memset(impd1, 0, sizeof(struct impd1_module));
161 impd1->base = ioremap(dev->resource.start, SZ_4K);
167 lm_set_drvdata(dev, impd1);
169 printk("IM-PD1 found at 0x%08lx\n", dev->resource.start);
171 for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
172 struct impd1_device *idev = impd1_devs + i;
173 struct amba_device *d;
174 unsigned long pc_base;
176 pc_base = dev->resource.start + idev->offset;
178 d = kmalloc(sizeof(struct amba_device), GFP_KERNEL);
182 memset(d, 0, sizeof(struct amba_device));
184 snprintf(d->dev.bus_id, sizeof(d->dev.bus_id),
185 "lm%x:%5.5lx", dev->id, idev->offset >> 12);
187 d->dev.parent = &dev->dev;
188 d->res.start = dev->resource.start + idev->offset;
189 d->res.end = d->res.start + SZ_4K - 1;
190 d->res.flags = IORESOURCE_MEM;
191 d->irq[0] = dev->irq;
192 d->irq[1] = dev->irq;
193 d->periphid = idev->id;
195 ret = amba_device_register(d, &dev->resource);
197 printk("unable to register device %s: %d\n",
206 if (impd1 && impd1->base)
207 iounmap(impd1->base);
211 release_mem_region(dev->resource.start, SZ_4K);
215 static void impd1_remove(struct lm_device *dev)
217 struct impd1_module *impd1 = lm_get_drvdata(dev);
218 struct list_head *l, *n;
220 list_for_each_safe(l, n, &dev->dev.children) {
221 struct device *d = list_to_dev(l);
223 device_unregister(d);
226 lm_set_drvdata(dev, NULL);
228 iounmap(impd1->base);
230 release_mem_region(dev->resource.start, SZ_4K);
233 static struct lm_driver impd1_driver = {
237 .probe = impd1_probe,
238 .remove = impd1_remove,
241 static int __init impd1_init(void)
243 return lm_driver_register(&impd1_driver);
246 static void __exit impd1_exit(void)
248 lm_driver_unregister(&impd1_driver);
251 module_init(impd1_init);
252 module_exit(impd1_exit);
254 MODULE_LICENSE("GPL");
255 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
256 MODULE_AUTHOR("Deep Blue Solutions Ltd");