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>
32 module_param_named(lmid, module_id, int, 0444);
33 MODULE_PARM_DESC(lmid, "logic module stack position");
40 static const struct icst525_params impd1_vco_params = {
41 .ref = 24000, /* 24 MHz */
42 .vco_max = 200000, /* 200 MHz */
49 static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
51 struct impd1_module *impd1 = clk->data;
52 int vconr = clk - impd1->vcos;
55 val = vco.v | (vco.r << 9) | (vco.s << 16);
57 writel(0xa05f, impd1->base + IMPD1_LOCK);
60 writel(val, impd1->base + IMPD1_OSC1);
63 writel(val, impd1->base + IMPD1_OSC2);
66 writel(0, impd1->base + IMPD1_LOCK);
70 vco.r = (val >> 9) & 0x7f;
71 vco.s = (val >> 16) & 7;
73 pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
74 vconr, icst525_khz(&impd1_vco_params, vco));
78 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
80 struct impd1_module *impd1 = dev_get_drvdata(dev);
84 cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
85 writel(cur | val, impd1->base + IMPD1_CTRL);
88 EXPORT_SYMBOL(impd1_tweak_control);
96 static struct impd1_device impd1_devs[] = {
101 .offset = 0x00100000,
105 .offset = 0x00200000,
109 .offset = 0x00300000,
113 .offset = 0x00400000,
117 .offset = 0x00500000,
121 .offset = 0x00600000,
125 .offset = 0x00700000,
129 .offset = 0x00800000,
133 .offset = 0x01000000,
139 static const char *impd1_vconames[2] = {
144 static int impd1_probe(struct lm_device *dev)
146 struct impd1_module *impd1;
149 if (dev->id != module_id)
152 if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
155 impd1 = kmalloc(sizeof(struct impd1_module), GFP_KERNEL);
160 memset(impd1, 0, sizeof(struct impd1_module));
162 impd1->base = ioremap(dev->resource.start, SZ_4K);
168 lm_set_drvdata(dev, impd1);
170 printk("IM-PD1 found at 0x%08lx\n", dev->resource.start);
172 for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
173 impd1->vcos[i].owner = THIS_MODULE,
174 impd1->vcos[i].name = impd1_vconames[i],
175 impd1->vcos[i].params = &impd1_vco_params,
176 impd1->vcos[i].data = impd1,
177 impd1->vcos[i].setvco = impd1_setvco;
179 clk_register(&impd1->vcos[i]);
182 for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
183 struct impd1_device *idev = impd1_devs + i;
184 struct amba_device *d;
185 unsigned long pc_base;
187 pc_base = dev->resource.start + idev->offset;
189 d = kmalloc(sizeof(struct amba_device), GFP_KERNEL);
193 memset(d, 0, sizeof(struct amba_device));
195 snprintf(d->dev.bus_id, sizeof(d->dev.bus_id),
196 "lm%x:%5.5lx", dev->id, idev->offset >> 12);
198 d->dev.parent = &dev->dev;
199 d->res.start = dev->resource.start + idev->offset;
200 d->res.end = d->res.start + SZ_4K - 1;
201 d->res.flags = IORESOURCE_MEM;
202 d->irq[0] = dev->irq;
203 d->irq[1] = dev->irq;
204 d->periphid = idev->id;
206 ret = amba_device_register(d, &dev->resource);
208 printk("unable to register device %s: %d\n",
217 if (impd1 && impd1->base)
218 iounmap(impd1->base);
222 release_mem_region(dev->resource.start, SZ_4K);
226 static void impd1_remove(struct lm_device *dev)
228 struct impd1_module *impd1 = lm_get_drvdata(dev);
229 struct list_head *l, *n;
232 list_for_each_safe(l, n, &dev->dev.children) {
233 struct device *d = list_to_dev(l);
235 device_unregister(d);
238 for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++)
239 clk_unregister(&impd1->vcos[i]);
241 lm_set_drvdata(dev, NULL);
243 iounmap(impd1->base);
245 release_mem_region(dev->resource.start, SZ_4K);
248 static struct lm_driver impd1_driver = {
252 .probe = impd1_probe,
253 .remove = impd1_remove,
256 static int __init impd1_init(void)
258 return lm_driver_register(&impd1_driver);
261 static void __exit impd1_exit(void)
263 lm_driver_unregister(&impd1_driver);
266 module_init(impd1_init);
267 module_exit(impd1_exit);
269 MODULE_LICENSE("GPL");
270 MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
271 MODULE_AUTHOR("Deep Blue Solutions Ltd");