diff options
Diffstat (limited to 'arch/arm/common')
-rw-r--r-- | arch/arm/common/Kconfig | 24 | ||||
-rw-r--r-- | arch/arm/common/Makefile | 15 | ||||
-rw-r--r-- | arch/arm/common/amba.c | 357 | ||||
-rw-r--r-- | arch/arm/common/dmabounce.c | 682 | ||||
-rw-r--r-- | arch/arm/common/icst307.c | 161 | ||||
-rw-r--r-- | arch/arm/common/icst525.c | 160 | ||||
-rw-r--r-- | arch/arm/common/locomo.c | 1058 | ||||
-rw-r--r-- | arch/arm/common/rtctime.c | 506 | ||||
-rw-r--r-- | arch/arm/common/sa1111.c | 1292 | ||||
-rw-r--r-- | arch/arm/common/scoop.c | 176 | ||||
-rw-r--r-- | arch/arm/common/sharpsl_param.c | 60 | ||||
-rw-r--r-- | arch/arm/common/time-acorn.c | 96 | ||||
-rw-r--r-- | arch/arm/common/via82c505.c | 94 |
13 files changed, 4681 insertions, 0 deletions
diff --git a/arch/arm/common/Kconfig b/arch/arm/common/Kconfig new file mode 100644 index 000000000000..692af6b5e8ff --- /dev/null +++ b/arch/arm/common/Kconfig | |||
@@ -0,0 +1,24 @@ | |||
1 | config ICST525 | ||
2 | bool | ||
3 | |||
4 | config ICST307 | ||
5 | bool | ||
6 | |||
7 | config SA1111 | ||
8 | bool | ||
9 | select DMABOUNCE | ||
10 | |||
11 | config DMABOUNCE | ||
12 | bool | ||
13 | |||
14 | config TIMER_ACORN | ||
15 | bool | ||
16 | |||
17 | config SHARP_LOCOMO | ||
18 | bool | ||
19 | |||
20 | config SHARP_PARAM | ||
21 | bool | ||
22 | |||
23 | config SHARP_SCOOP | ||
24 | bool | ||
diff --git a/arch/arm/common/Makefile b/arch/arm/common/Makefile new file mode 100644 index 000000000000..11f20a43ee3a --- /dev/null +++ b/arch/arm/common/Makefile | |||
@@ -0,0 +1,15 @@ | |||
1 | # | ||
2 | # Makefile for the linux kernel. | ||
3 | # | ||
4 | |||
5 | obj-y += rtctime.o | ||
6 | obj-$(CONFIG_ARM_AMBA) += amba.o | ||
7 | obj-$(CONFIG_ICST525) += icst525.o | ||
8 | obj-$(CONFIG_ICST307) += icst307.o | ||
9 | obj-$(CONFIG_SA1111) += sa1111.o | ||
10 | obj-$(CONFIG_PCI_HOST_VIA82C505) += via82c505.o | ||
11 | obj-$(CONFIG_DMABOUNCE) += dmabounce.o | ||
12 | obj-$(CONFIG_TIMER_ACORN) += time-acorn.o | ||
13 | obj-$(CONFIG_SHARP_LOCOMO) += locomo.o | ||
14 | obj-$(CONFIG_SHARP_PARAM) += sharpsl_param.o | ||
15 | obj-$(CONFIG_SHARP_SCOOP) += scoop.o | ||
diff --git a/arch/arm/common/amba.c b/arch/arm/common/amba.c new file mode 100644 index 000000000000..a0507f8c33fe --- /dev/null +++ b/arch/arm/common/amba.c | |||
@@ -0,0 +1,357 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/common/amba.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 | #include <linux/module.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/device.h> | ||
13 | |||
14 | #include <asm/io.h> | ||
15 | #include <asm/irq.h> | ||
16 | #include <asm/hardware/amba.h> | ||
17 | #include <asm/sizes.h> | ||
18 | |||
19 | #define to_amba_device(d) container_of(d, struct amba_device, dev) | ||
20 | #define to_amba_driver(d) container_of(d, struct amba_driver, drv) | ||
21 | |||
22 | static struct amba_id * | ||
23 | amba_lookup(struct amba_id *table, struct amba_device *dev) | ||
24 | { | ||
25 | int ret = 0; | ||
26 | |||
27 | while (table->mask) { | ||
28 | ret = (dev->periphid & table->mask) == table->id; | ||
29 | if (ret) | ||
30 | break; | ||
31 | table++; | ||
32 | } | ||
33 | |||
34 | return ret ? table : NULL; | ||
35 | } | ||
36 | |||
37 | static int amba_match(struct device *dev, struct device_driver *drv) | ||
38 | { | ||
39 | struct amba_device *pcdev = to_amba_device(dev); | ||
40 | struct amba_driver *pcdrv = to_amba_driver(drv); | ||
41 | |||
42 | return amba_lookup(pcdrv->id_table, pcdev) != NULL; | ||
43 | } | ||
44 | |||
45 | #ifdef CONFIG_HOTPLUG | ||
46 | static int amba_hotplug(struct device *dev, char **envp, int nr_env, char *buf, int bufsz) | ||
47 | { | ||
48 | struct amba_device *pcdev = to_amba_device(dev); | ||
49 | |||
50 | if (nr_env < 2) | ||
51 | return -ENOMEM; | ||
52 | |||
53 | snprintf(buf, bufsz, "AMBA_ID=%08x", pcdev->periphid); | ||
54 | *envp++ = buf; | ||
55 | *envp++ = NULL; | ||
56 | return 0; | ||
57 | } | ||
58 | #else | ||
59 | #define amba_hotplug NULL | ||
60 | #endif | ||
61 | |||
62 | static int amba_suspend(struct device *dev, pm_message_t state) | ||
63 | { | ||
64 | struct amba_driver *drv = to_amba_driver(dev->driver); | ||
65 | int ret = 0; | ||
66 | |||
67 | if (dev->driver && drv->suspend) | ||
68 | ret = drv->suspend(to_amba_device(dev), state); | ||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | static int amba_resume(struct device *dev) | ||
73 | { | ||
74 | struct amba_driver *drv = to_amba_driver(dev->driver); | ||
75 | int ret = 0; | ||
76 | |||
77 | if (dev->driver && drv->resume) | ||
78 | ret = drv->resume(to_amba_device(dev)); | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * Primecells are part of the Advanced Microcontroller Bus Architecture, | ||
84 | * so we call the bus "amba". | ||
85 | */ | ||
86 | static struct bus_type amba_bustype = { | ||
87 | .name = "amba", | ||
88 | .match = amba_match, | ||
89 | .hotplug = amba_hotplug, | ||
90 | .suspend = amba_suspend, | ||
91 | .resume = amba_resume, | ||
92 | }; | ||
93 | |||
94 | static int __init amba_init(void) | ||
95 | { | ||
96 | return bus_register(&amba_bustype); | ||
97 | } | ||
98 | |||
99 | postcore_initcall(amba_init); | ||
100 | |||
101 | /* | ||
102 | * These are the device model conversion veneers; they convert the | ||
103 | * device model structures to our more specific structures. | ||
104 | */ | ||
105 | static int amba_probe(struct device *dev) | ||
106 | { | ||
107 | struct amba_device *pcdev = to_amba_device(dev); | ||
108 | struct amba_driver *pcdrv = to_amba_driver(dev->driver); | ||
109 | struct amba_id *id; | ||
110 | |||
111 | id = amba_lookup(pcdrv->id_table, pcdev); | ||
112 | |||
113 | return pcdrv->probe(pcdev, id); | ||
114 | } | ||
115 | |||
116 | static int amba_remove(struct device *dev) | ||
117 | { | ||
118 | struct amba_driver *drv = to_amba_driver(dev->driver); | ||
119 | return drv->remove(to_amba_device(dev)); | ||
120 | } | ||
121 | |||
122 | static void amba_shutdown(struct device *dev) | ||
123 | { | ||
124 | struct amba_driver *drv = to_amba_driver(dev->driver); | ||
125 | drv->shutdown(to_amba_device(dev)); | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * amba_driver_register - register an AMBA device driver | ||
130 | * @drv: amba device driver structure | ||
131 | * | ||
132 | * Register an AMBA device driver with the Linux device model | ||
133 | * core. If devices pre-exist, the drivers probe function will | ||
134 | * be called. | ||
135 | */ | ||
136 | int amba_driver_register(struct amba_driver *drv) | ||
137 | { | ||
138 | drv->drv.bus = &amba_bustype; | ||
139 | |||
140 | #define SETFN(fn) if (drv->fn) drv->drv.fn = amba_##fn | ||
141 | SETFN(probe); | ||
142 | SETFN(remove); | ||
143 | SETFN(shutdown); | ||
144 | |||
145 | return driver_register(&drv->drv); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * amba_driver_unregister - remove an AMBA device driver | ||
150 | * @drv: AMBA device driver structure to remove | ||
151 | * | ||
152 | * Unregister an AMBA device driver from the Linux device | ||
153 | * model. The device model will call the drivers remove function | ||
154 | * for each device the device driver is currently handling. | ||
155 | */ | ||
156 | void amba_driver_unregister(struct amba_driver *drv) | ||
157 | { | ||
158 | driver_unregister(&drv->drv); | ||
159 | } | ||
160 | |||
161 | |||
162 | static void amba_device_release(struct device *dev) | ||
163 | { | ||
164 | struct amba_device *d = to_amba_device(dev); | ||
165 | |||
166 | if (d->res.parent) | ||
167 | release_resource(&d->res); | ||
168 | kfree(d); | ||
169 | } | ||
170 | |||
171 | #define amba_attr(name,fmt,arg...) \ | ||
172 | static ssize_t show_##name(struct device *_dev, char *buf) \ | ||
173 | { \ | ||
174 | struct amba_device *dev = to_amba_device(_dev); \ | ||
175 | return sprintf(buf, fmt, arg); \ | ||
176 | } \ | ||
177 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) | ||
178 | |||
179 | amba_attr(id, "%08x\n", dev->periphid); | ||
180 | amba_attr(irq0, "%u\n", dev->irq[0]); | ||
181 | amba_attr(irq1, "%u\n", dev->irq[1]); | ||
182 | amba_attr(resource, "\t%08lx\t%08lx\t%08lx\n", | ||
183 | dev->res.start, dev->res.end, dev->res.flags); | ||
184 | |||
185 | /** | ||
186 | * amba_device_register - register an AMBA device | ||
187 | * @dev: AMBA device to register | ||
188 | * @parent: parent memory resource | ||
189 | * | ||
190 | * Setup the AMBA device, reading the cell ID if present. | ||
191 | * Claim the resource, and register the AMBA device with | ||
192 | * the Linux device manager. | ||
193 | */ | ||
194 | int amba_device_register(struct amba_device *dev, struct resource *parent) | ||
195 | { | ||
196 | u32 pid, cid; | ||
197 | void __iomem *tmp; | ||
198 | int i, ret; | ||
199 | |||
200 | dev->dev.release = amba_device_release; | ||
201 | dev->dev.bus = &amba_bustype; | ||
202 | dev->dev.dma_mask = &dev->dma_mask; | ||
203 | dev->res.name = dev->dev.bus_id; | ||
204 | |||
205 | if (!dev->dev.coherent_dma_mask && dev->dma_mask) | ||
206 | dev_warn(&dev->dev, "coherent dma mask is unset\n"); | ||
207 | |||
208 | ret = request_resource(parent, &dev->res); | ||
209 | if (ret == 0) { | ||
210 | tmp = ioremap(dev->res.start, SZ_4K); | ||
211 | if (!tmp) { | ||
212 | ret = -ENOMEM; | ||
213 | goto out; | ||
214 | } | ||
215 | |||
216 | for (pid = 0, i = 0; i < 4; i++) | ||
217 | pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8); | ||
218 | for (cid = 0, i = 0; i < 4; i++) | ||
219 | cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8); | ||
220 | |||
221 | iounmap(tmp); | ||
222 | |||
223 | if (cid == 0xb105f00d) | ||
224 | dev->periphid = pid; | ||
225 | |||
226 | if (dev->periphid) | ||
227 | ret = device_register(&dev->dev); | ||
228 | else | ||
229 | ret = -ENODEV; | ||
230 | |||
231 | if (ret == 0) { | ||
232 | device_create_file(&dev->dev, &dev_attr_id); | ||
233 | if (dev->irq[0] != NO_IRQ) | ||
234 | device_create_file(&dev->dev, &dev_attr_irq0); | ||
235 | if (dev->irq[1] != NO_IRQ) | ||
236 | device_create_file(&dev->dev, &dev_attr_irq1); | ||
237 | device_create_file(&dev->dev, &dev_attr_resource); | ||
238 | } else { | ||
239 | out: | ||
240 | release_resource(&dev->res); | ||
241 | } | ||
242 | } | ||
243 | return ret; | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * amba_device_unregister - unregister an AMBA device | ||
248 | * @dev: AMBA device to remove | ||
249 | * | ||
250 | * Remove the specified AMBA device from the Linux device | ||
251 | * manager. All files associated with this object will be | ||
252 | * destroyed, and device drivers notified that the device has | ||
253 | * been removed. The AMBA device's resources including | ||
254 | * the amba_device structure will be freed once all | ||
255 | * references to it have been dropped. | ||
256 | */ | ||
257 | void amba_device_unregister(struct amba_device *dev) | ||
258 | { | ||
259 | device_unregister(&dev->dev); | ||
260 | } | ||
261 | |||
262 | |||
263 | struct find_data { | ||
264 | struct amba_device *dev; | ||
265 | struct device *parent; | ||
266 | const char *busid; | ||
267 | unsigned int id; | ||
268 | unsigned int mask; | ||
269 | }; | ||
270 | |||
271 | static int amba_find_match(struct device *dev, void *data) | ||
272 | { | ||
273 | struct find_data *d = data; | ||
274 | struct amba_device *pcdev = to_amba_device(dev); | ||
275 | int r; | ||
276 | |||
277 | r = (pcdev->periphid & d->mask) == d->id; | ||
278 | if (d->parent) | ||
279 | r &= d->parent == dev->parent; | ||
280 | if (d->busid) | ||
281 | r &= strcmp(dev->bus_id, d->busid) == 0; | ||
282 | |||
283 | if (r) { | ||
284 | get_device(dev); | ||
285 | d->dev = pcdev; | ||
286 | } | ||
287 | |||
288 | return r; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * amba_find_device - locate an AMBA device given a bus id | ||
293 | * @busid: bus id for device (or NULL) | ||
294 | * @parent: parent device (or NULL) | ||
295 | * @id: peripheral ID (or 0) | ||
296 | * @mask: peripheral ID mask (or 0) | ||
297 | * | ||
298 | * Return the AMBA device corresponding to the supplied parameters. | ||
299 | * If no device matches, returns NULL. | ||
300 | * | ||
301 | * NOTE: When a valid device is found, its refcount is | ||
302 | * incremented, and must be decremented before the returned | ||
303 | * reference. | ||
304 | */ | ||
305 | struct amba_device * | ||
306 | amba_find_device(const char *busid, struct device *parent, unsigned int id, | ||
307 | unsigned int mask) | ||
308 | { | ||
309 | struct find_data data; | ||
310 | |||
311 | data.dev = NULL; | ||
312 | data.parent = parent; | ||
313 | data.busid = busid; | ||
314 | data.id = id; | ||
315 | data.mask = mask; | ||
316 | |||
317 | bus_for_each_dev(&amba_bustype, NULL, &data, amba_find_match); | ||
318 | |||
319 | return data.dev; | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * amba_request_regions - request all mem regions associated with device | ||
324 | * @dev: amba_device structure for device | ||
325 | * @name: name, or NULL to use driver name | ||
326 | */ | ||
327 | int amba_request_regions(struct amba_device *dev, const char *name) | ||
328 | { | ||
329 | int ret = 0; | ||
330 | |||
331 | if (!name) | ||
332 | name = dev->dev.driver->name; | ||
333 | |||
334 | if (!request_mem_region(dev->res.start, SZ_4K, name)) | ||
335 | ret = -EBUSY; | ||
336 | |||
337 | return ret; | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * amba_release_regions - release mem regions assoicated with device | ||
342 | * @dev: amba_device structure for device | ||
343 | * | ||
344 | * Release regions claimed by a successful call to amba_request_regions. | ||
345 | */ | ||
346 | void amba_release_regions(struct amba_device *dev) | ||
347 | { | ||
348 | release_mem_region(dev->res.start, SZ_4K); | ||
349 | } | ||
350 | |||
351 | EXPORT_SYMBOL(amba_driver_register); | ||
352 | EXPORT_SYMBOL(amba_driver_unregister); | ||
353 | EXPORT_SYMBOL(amba_device_register); | ||
354 | EXPORT_SYMBOL(amba_device_unregister); | ||
355 | EXPORT_SYMBOL(amba_find_device); | ||
356 | EXPORT_SYMBOL(amba_request_regions); | ||
357 | EXPORT_SYMBOL(amba_release_regions); | ||
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c new file mode 100644 index 000000000000..5797b1b100a1 --- /dev/null +++ b/arch/arm/common/dmabounce.c | |||
@@ -0,0 +1,682 @@ | |||
1 | /* | ||
2 | * arch/arm/common/dmabounce.c | ||
3 | * | ||
4 | * Special dma_{map/unmap/dma_sync}_* routines for systems that have | ||
5 | * limited DMA windows. These functions utilize bounce buffers to | ||
6 | * copy data to/from buffers located outside the DMA region. This | ||
7 | * only works for systems in which DMA memory is at the bottom of | ||
8 | * RAM and the remainder of memory is at the top an the DMA memory | ||
9 | * can be marked as ZONE_DMA. Anything beyond that such as discontigous | ||
10 | * DMA windows will require custom implementations that reserve memory | ||
11 | * areas at early bootup. | ||
12 | * | ||
13 | * Original version by Brad Parker (brad@heeltoe.com) | ||
14 | * Re-written by Christopher Hoover <ch@murgatroid.com> | ||
15 | * Made generic by Deepak Saxena <dsaxena@plexity.net> | ||
16 | * | ||
17 | * Copyright (C) 2002 Hewlett Packard Company. | ||
18 | * Copyright (C) 2004 MontaVista Software, Inc. | ||
19 | * | ||
20 | * This program is free software; you can redistribute it and/or | ||
21 | * modify it under the terms of the GNU General Public License | ||
22 | * version 2 as published by the Free Software Foundation. | ||
23 | */ | ||
24 | |||
25 | #include <linux/module.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/device.h> | ||
29 | #include <linux/dma-mapping.h> | ||
30 | #include <linux/dmapool.h> | ||
31 | #include <linux/list.h> | ||
32 | |||
33 | #undef DEBUG | ||
34 | |||
35 | #undef STATS | ||
36 | #ifdef STATS | ||
37 | #define DO_STATS(X) do { X ; } while (0) | ||
38 | #else | ||
39 | #define DO_STATS(X) do { } while (0) | ||
40 | #endif | ||
41 | |||
42 | /* ************************************************** */ | ||
43 | |||
44 | struct safe_buffer { | ||
45 | struct list_head node; | ||
46 | |||
47 | /* original request */ | ||
48 | void *ptr; | ||
49 | size_t size; | ||
50 | int direction; | ||
51 | |||
52 | /* safe buffer info */ | ||
53 | struct dma_pool *pool; | ||
54 | void *safe; | ||
55 | dma_addr_t safe_dma_addr; | ||
56 | }; | ||
57 | |||
58 | struct dmabounce_device_info { | ||
59 | struct list_head node; | ||
60 | |||
61 | struct device *dev; | ||
62 | struct dma_pool *small_buffer_pool; | ||
63 | struct dma_pool *large_buffer_pool; | ||
64 | struct list_head safe_buffers; | ||
65 | unsigned long small_buffer_size, large_buffer_size; | ||
66 | #ifdef STATS | ||
67 | unsigned long sbp_allocs; | ||
68 | unsigned long lbp_allocs; | ||
69 | unsigned long total_allocs; | ||
70 | unsigned long map_op_count; | ||
71 | unsigned long bounce_count; | ||
72 | #endif | ||
73 | }; | ||
74 | |||
75 | static LIST_HEAD(dmabounce_devs); | ||
76 | |||
77 | #ifdef STATS | ||
78 | static void print_alloc_stats(struct dmabounce_device_info *device_info) | ||
79 | { | ||
80 | printk(KERN_INFO | ||
81 | "%s: dmabounce: sbp: %lu, lbp: %lu, other: %lu, total: %lu\n", | ||
82 | device_info->dev->bus_id, | ||
83 | device_info->sbp_allocs, device_info->lbp_allocs, | ||
84 | device_info->total_allocs - device_info->sbp_allocs - | ||
85 | device_info->lbp_allocs, | ||
86 | device_info->total_allocs); | ||
87 | } | ||
88 | #endif | ||
89 | |||
90 | /* find the given device in the dmabounce device list */ | ||
91 | static inline struct dmabounce_device_info * | ||
92 | find_dmabounce_dev(struct device *dev) | ||
93 | { | ||
94 | struct list_head *entry; | ||
95 | |||
96 | list_for_each(entry, &dmabounce_devs) { | ||
97 | struct dmabounce_device_info *d = | ||
98 | list_entry(entry, struct dmabounce_device_info, node); | ||
99 | |||
100 | if (d->dev == dev) | ||
101 | return d; | ||
102 | } | ||
103 | return NULL; | ||
104 | } | ||
105 | |||
106 | |||
107 | /* allocate a 'safe' buffer and keep track of it */ | ||
108 | static inline struct safe_buffer * | ||
109 | alloc_safe_buffer(struct dmabounce_device_info *device_info, void *ptr, | ||
110 | size_t size, enum dma_data_direction dir) | ||
111 | { | ||
112 | struct safe_buffer *buf; | ||
113 | struct dma_pool *pool; | ||
114 | struct device *dev = device_info->dev; | ||
115 | void *safe; | ||
116 | dma_addr_t safe_dma_addr; | ||
117 | |||
118 | dev_dbg(dev, "%s(ptr=%p, size=%d, dir=%d)\n", | ||
119 | __func__, ptr, size, dir); | ||
120 | |||
121 | DO_STATS ( device_info->total_allocs++ ); | ||
122 | |||
123 | buf = kmalloc(sizeof(struct safe_buffer), GFP_ATOMIC); | ||
124 | if (buf == NULL) { | ||
125 | dev_warn(dev, "%s: kmalloc failed\n", __func__); | ||
126 | return NULL; | ||
127 | } | ||
128 | |||
129 | if (size <= device_info->small_buffer_size) { | ||
130 | pool = device_info->small_buffer_pool; | ||
131 | safe = dma_pool_alloc(pool, GFP_ATOMIC, &safe_dma_addr); | ||
132 | |||
133 | DO_STATS ( device_info->sbp_allocs++ ); | ||
134 | } else if (size <= device_info->large_buffer_size) { | ||
135 | pool = device_info->large_buffer_pool; | ||
136 | safe = dma_pool_alloc(pool, GFP_ATOMIC, &safe_dma_addr); | ||
137 | |||
138 | DO_STATS ( device_info->lbp_allocs++ ); | ||
139 | } else { | ||
140 | pool = NULL; | ||
141 | safe = dma_alloc_coherent(dev, size, &safe_dma_addr, GFP_ATOMIC); | ||
142 | } | ||
143 | |||
144 | if (safe == NULL) { | ||
145 | dev_warn(device_info->dev, | ||
146 | "%s: could not alloc dma memory (size=%d)\n", | ||
147 | __func__, size); | ||
148 | kfree(buf); | ||
149 | return NULL; | ||
150 | } | ||
151 | |||
152 | #ifdef STATS | ||
153 | if (device_info->total_allocs % 1000 == 0) | ||
154 | print_alloc_stats(device_info); | ||
155 | #endif | ||
156 | |||
157 | buf->ptr = ptr; | ||
158 | buf->size = size; | ||
159 | buf->direction = dir; | ||
160 | buf->pool = pool; | ||
161 | buf->safe = safe; | ||
162 | buf->safe_dma_addr = safe_dma_addr; | ||
163 | |||
164 | list_add(&buf->node, &device_info->safe_buffers); | ||
165 | |||
166 | return buf; | ||
167 | } | ||
168 | |||
169 | /* determine if a buffer is from our "safe" pool */ | ||
170 | static inline struct safe_buffer * | ||
171 | find_safe_buffer(struct dmabounce_device_info *device_info, dma_addr_t safe_dma_addr) | ||
172 | { | ||
173 | struct list_head *entry; | ||
174 | |||
175 | list_for_each(entry, &device_info->safe_buffers) { | ||
176 | struct safe_buffer *b = | ||
177 | list_entry(entry, struct safe_buffer, node); | ||
178 | |||
179 | if (b->safe_dma_addr == safe_dma_addr) | ||
180 | return b; | ||
181 | } | ||
182 | |||
183 | return NULL; | ||
184 | } | ||
185 | |||
186 | static inline void | ||
187 | free_safe_buffer(struct dmabounce_device_info *device_info, struct safe_buffer *buf) | ||
188 | { | ||
189 | dev_dbg(device_info->dev, "%s(buf=%p)\n", __func__, buf); | ||
190 | |||
191 | list_del(&buf->node); | ||
192 | |||
193 | if (buf->pool) | ||
194 | dma_pool_free(buf->pool, buf->safe, buf->safe_dma_addr); | ||
195 | else | ||
196 | dma_free_coherent(device_info->dev, buf->size, buf->safe, | ||
197 | buf->safe_dma_addr); | ||
198 | |||
199 | kfree(buf); | ||
200 | } | ||
201 | |||
202 | /* ************************************************** */ | ||
203 | |||
204 | #ifdef STATS | ||
205 | |||
206 | static void print_map_stats(struct dmabounce_device_info *device_info) | ||
207 | { | ||
208 | printk(KERN_INFO | ||
209 | "%s: dmabounce: map_op_count=%lu, bounce_count=%lu\n", | ||
210 | device_info->dev->bus_id, | ||
211 | device_info->map_op_count, device_info->bounce_count); | ||
212 | } | ||
213 | #endif | ||
214 | |||
215 | static inline dma_addr_t | ||
216 | map_single(struct device *dev, void *ptr, size_t size, | ||
217 | enum dma_data_direction dir) | ||
218 | { | ||
219 | struct dmabounce_device_info *device_info = find_dmabounce_dev(dev); | ||
220 | dma_addr_t dma_addr; | ||
221 | int needs_bounce = 0; | ||
222 | |||
223 | if (device_info) | ||
224 | DO_STATS ( device_info->map_op_count++ ); | ||
225 | |||
226 | dma_addr = virt_to_dma(dev, ptr); | ||
227 | |||
228 | if (dev->dma_mask) { | ||
229 | unsigned long mask = *dev->dma_mask; | ||
230 | unsigned long limit; | ||
231 | |||
232 | limit = (mask + 1) & ~mask; | ||
233 | if (limit && size > limit) { | ||
234 | dev_err(dev, "DMA mapping too big (requested %#x " | ||
235 | "mask %#Lx)\n", size, *dev->dma_mask); | ||
236 | return ~0; | ||
237 | } | ||
238 | |||
239 | /* | ||
240 | * Figure out if we need to bounce from the DMA mask. | ||
241 | */ | ||
242 | needs_bounce = (dma_addr | (dma_addr + size - 1)) & ~mask; | ||
243 | } | ||
244 | |||
245 | if (device_info && (needs_bounce || dma_needs_bounce(dev, dma_addr, size))) { | ||
246 | struct safe_buffer *buf; | ||
247 | |||
248 | buf = alloc_safe_buffer(device_info, ptr, size, dir); | ||
249 | if (buf == 0) { | ||
250 | dev_err(dev, "%s: unable to map unsafe buffer %p!\n", | ||
251 | __func__, ptr); | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | dev_dbg(dev, | ||
256 | "%s: unsafe buffer %p (phy=%p) mapped to %p (phy=%p)\n", | ||
257 | __func__, buf->ptr, (void *) virt_to_dma(dev, buf->ptr), | ||
258 | buf->safe, (void *) buf->safe_dma_addr); | ||
259 | |||
260 | if ((dir == DMA_TO_DEVICE) || | ||
261 | (dir == DMA_BIDIRECTIONAL)) { | ||
262 | dev_dbg(dev, "%s: copy unsafe %p to safe %p, size %d\n", | ||
263 | __func__, ptr, buf->safe, size); | ||
264 | memcpy(buf->safe, ptr, size); | ||
265 | } | ||
266 | consistent_sync(buf->safe, size, dir); | ||
267 | |||
268 | dma_addr = buf->safe_dma_addr; | ||
269 | } else { | ||
270 | consistent_sync(ptr, size, dir); | ||
271 | } | ||
272 | |||
273 | return dma_addr; | ||
274 | } | ||
275 | |||
276 | static inline void | ||
277 | unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, | ||
278 | enum dma_data_direction dir) | ||
279 | { | ||
280 | struct dmabounce_device_info *device_info = find_dmabounce_dev(dev); | ||
281 | struct safe_buffer *buf = NULL; | ||
282 | |||
283 | /* | ||
284 | * Trying to unmap an invalid mapping | ||
285 | */ | ||
286 | if (dma_addr == ~0) { | ||
287 | dev_err(dev, "Trying to unmap invalid mapping\n"); | ||
288 | return; | ||
289 | } | ||
290 | |||
291 | if (device_info) | ||
292 | buf = find_safe_buffer(device_info, dma_addr); | ||
293 | |||
294 | if (buf) { | ||
295 | BUG_ON(buf->size != size); | ||
296 | |||
297 | dev_dbg(dev, | ||
298 | "%s: unsafe buffer %p (phy=%p) mapped to %p (phy=%p)\n", | ||
299 | __func__, buf->ptr, (void *) virt_to_dma(dev, buf->ptr), | ||
300 | buf->safe, (void *) buf->safe_dma_addr); | ||
301 | |||
302 | |||
303 | DO_STATS ( device_info->bounce_count++ ); | ||
304 | |||
305 | if ((dir == DMA_FROM_DEVICE) || | ||
306 | (dir == DMA_BIDIRECTIONAL)) { | ||
307 | dev_dbg(dev, | ||
308 | "%s: copy back safe %p to unsafe %p size %d\n", | ||
309 | __func__, buf->safe, buf->ptr, size); | ||
310 | memcpy(buf->ptr, buf->safe, size); | ||
311 | } | ||
312 | free_safe_buffer(device_info, buf); | ||
313 | } | ||
314 | } | ||
315 | |||
316 | static inline void | ||
317 | sync_single(struct device *dev, dma_addr_t dma_addr, size_t size, | ||
318 | enum dma_data_direction dir) | ||
319 | { | ||
320 | struct dmabounce_device_info *device_info = find_dmabounce_dev(dev); | ||
321 | struct safe_buffer *buf = NULL; | ||
322 | |||
323 | if (device_info) | ||
324 | buf = find_safe_buffer(device_info, dma_addr); | ||
325 | |||
326 | if (buf) { | ||
327 | /* | ||
328 | * Both of these checks from original code need to be | ||
329 | * commented out b/c some drivers rely on the following: | ||
330 | * | ||
331 | * 1) Drivers may map a large chunk of memory into DMA space | ||
332 | * but only sync a small portion of it. Good example is | ||
333 | * allocating a large buffer, mapping it, and then | ||
334 | * breaking it up into small descriptors. No point | ||
335 | * in syncing the whole buffer if you only have to | ||
336 | * touch one descriptor. | ||
337 | * | ||
338 | * 2) Buffers that are mapped as DMA_BIDIRECTIONAL are | ||
339 | * usually only synced in one dir at a time. | ||
340 | * | ||
341 | * See drivers/net/eepro100.c for examples of both cases. | ||
342 | * | ||
343 | * -ds | ||
344 | * | ||
345 | * BUG_ON(buf->size != size); | ||
346 | * BUG_ON(buf->direction != dir); | ||
347 | */ | ||
348 | |||
349 | dev_dbg(dev, | ||
350 | "%s: unsafe buffer %p (phy=%p) mapped to %p (phy=%p)\n", | ||
351 | __func__, buf->ptr, (void *) virt_to_dma(dev, buf->ptr), | ||
352 | buf->safe, (void *) buf->safe_dma_addr); | ||
353 | |||
354 | DO_STATS ( device_info->bounce_count++ ); | ||
355 | |||
356 | switch (dir) { | ||
357 | case DMA_FROM_DEVICE: | ||
358 | dev_dbg(dev, | ||
359 | "%s: copy back safe %p to unsafe %p size %d\n", | ||
360 | __func__, buf->safe, buf->ptr, size); | ||
361 | memcpy(buf->ptr, buf->safe, size); | ||
362 | break; | ||
363 | case DMA_TO_DEVICE: | ||
364 | dev_dbg(dev, | ||
365 | "%s: copy out unsafe %p to safe %p, size %d\n", | ||
366 | __func__,buf->ptr, buf->safe, size); | ||
367 | memcpy(buf->safe, buf->ptr, size); | ||
368 | break; | ||
369 | case DMA_BIDIRECTIONAL: | ||
370 | BUG(); /* is this allowed? what does it mean? */ | ||
371 | default: | ||
372 | BUG(); | ||
373 | } | ||
374 | consistent_sync(buf->safe, size, dir); | ||
375 | } else { | ||
376 | consistent_sync(dma_to_virt(dev, dma_addr), size, dir); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | /* ************************************************** */ | ||
381 | |||
382 | /* | ||
383 | * see if a buffer address is in an 'unsafe' range. if it is | ||
384 | * allocate a 'safe' buffer and copy the unsafe buffer into it. | ||
385 | * substitute the safe buffer for the unsafe one. | ||
386 | * (basically move the buffer from an unsafe area to a safe one) | ||
387 | */ | ||
388 | dma_addr_t | ||
389 | dma_map_single(struct device *dev, void *ptr, size_t size, | ||
390 | enum dma_data_direction dir) | ||
391 | { | ||
392 | unsigned long flags; | ||
393 | dma_addr_t dma_addr; | ||
394 | |||
395 | dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", | ||
396 | __func__, ptr, size, dir); | ||
397 | |||
398 | BUG_ON(dir == DMA_NONE); | ||
399 | |||
400 | local_irq_save(flags); | ||
401 | |||
402 | dma_addr = map_single(dev, ptr, size, dir); | ||
403 | |||
404 | local_irq_restore(flags); | ||
405 | |||
406 | return dma_addr; | ||
407 | } | ||
408 | |||
409 | /* | ||
410 | * see if a mapped address was really a "safe" buffer and if so, copy | ||
411 | * the data from the safe buffer back to the unsafe buffer and free up | ||
412 | * the safe buffer. (basically return things back to the way they | ||
413 | * should be) | ||
414 | */ | ||
415 | |||
416 | void | ||
417 | dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, | ||
418 | enum dma_data_direction dir) | ||
419 | { | ||
420 | unsigned long flags; | ||
421 | |||
422 | dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", | ||
423 | __func__, (void *) dma_addr, size, dir); | ||
424 | |||
425 | BUG_ON(dir == DMA_NONE); | ||
426 | |||
427 | local_irq_save(flags); | ||
428 | |||
429 | unmap_single(dev, dma_addr, size, dir); | ||
430 | |||
431 | local_irq_restore(flags); | ||
432 | } | ||
433 | |||
434 | int | ||
435 | dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, | ||
436 | enum dma_data_direction dir) | ||
437 | { | ||
438 | unsigned long flags; | ||
439 | int i; | ||
440 | |||
441 | dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", | ||
442 | __func__, sg, nents, dir); | ||
443 | |||
444 | BUG_ON(dir == DMA_NONE); | ||
445 | |||
446 | local_irq_save(flags); | ||
447 | |||
448 | for (i = 0; i < nents; i++, sg++) { | ||
449 | struct page *page = sg->page; | ||
450 | unsigned int offset = sg->offset; | ||
451 | unsigned int length = sg->length; | ||
452 | void *ptr = page_address(page) + offset; | ||
453 | |||
454 | sg->dma_address = | ||
455 | map_single(dev, ptr, length, dir); | ||
456 | } | ||
457 | |||
458 | local_irq_restore(flags); | ||
459 | |||
460 | return nents; | ||
461 | } | ||
462 | |||
463 | void | ||
464 | dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, | ||
465 | enum dma_data_direction dir) | ||
466 | { | ||
467 | unsigned long flags; | ||
468 | int i; | ||
469 | |||
470 | dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", | ||
471 | __func__, sg, nents, dir); | ||
472 | |||
473 | BUG_ON(dir == DMA_NONE); | ||
474 | |||
475 | local_irq_save(flags); | ||
476 | |||
477 | for (i = 0; i < nents; i++, sg++) { | ||
478 | dma_addr_t dma_addr = sg->dma_address; | ||
479 | unsigned int length = sg->length; | ||
480 | |||
481 | unmap_single(dev, dma_addr, length, dir); | ||
482 | } | ||
483 | |||
484 | local_irq_restore(flags); | ||
485 | } | ||
486 | |||
487 | void | ||
488 | dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, size_t size, | ||
489 | enum dma_data_direction dir) | ||
490 | { | ||
491 | unsigned long flags; | ||
492 | |||
493 | dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", | ||
494 | __func__, (void *) dma_addr, size, dir); | ||
495 | |||
496 | local_irq_save(flags); | ||
497 | |||
498 | sync_single(dev, dma_addr, size, dir); | ||
499 | |||
500 | local_irq_restore(flags); | ||
501 | } | ||
502 | |||
503 | void | ||
504 | dma_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, size_t size, | ||
505 | enum dma_data_direction dir) | ||
506 | { | ||
507 | unsigned long flags; | ||
508 | |||
509 | dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", | ||
510 | __func__, (void *) dma_addr, size, dir); | ||
511 | |||
512 | local_irq_save(flags); | ||
513 | |||
514 | sync_single(dev, dma_addr, size, dir); | ||
515 | |||
516 | local_irq_restore(flags); | ||
517 | } | ||
518 | |||
519 | void | ||
520 | dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents, | ||
521 | enum dma_data_direction dir) | ||
522 | { | ||
523 | unsigned long flags; | ||
524 | int i; | ||
525 | |||
526 | dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", | ||
527 | __func__, sg, nents, dir); | ||
528 | |||
529 | BUG_ON(dir == DMA_NONE); | ||
530 | |||
531 | local_irq_save(flags); | ||
532 | |||
533 | for (i = 0; i < nents; i++, sg++) { | ||
534 | dma_addr_t dma_addr = sg->dma_address; | ||
535 | unsigned int length = sg->length; | ||
536 | |||
537 | sync_single(dev, dma_addr, length, dir); | ||
538 | } | ||
539 | |||
540 | local_irq_restore(flags); | ||
541 | } | ||
542 | |||
543 | void | ||
544 | dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nents, | ||
545 | enum dma_data_direction dir) | ||
546 | { | ||
547 | unsigned long flags; | ||
548 | int i; | ||
549 | |||
550 | dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", | ||
551 | __func__, sg, nents, dir); | ||
552 | |||
553 | BUG_ON(dir == DMA_NONE); | ||
554 | |||
555 | local_irq_save(flags); | ||
556 | |||
557 | for (i = 0; i < nents; i++, sg++) { | ||
558 | dma_addr_t dma_addr = sg->dma_address; | ||
559 | unsigned int length = sg->length; | ||
560 | |||
561 | sync_single(dev, dma_addr, length, dir); | ||
562 | } | ||
563 | |||
564 | local_irq_restore(flags); | ||
565 | } | ||
566 | |||
567 | int | ||
568 | dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size, | ||
569 | unsigned long large_buffer_size) | ||
570 | { | ||
571 | struct dmabounce_device_info *device_info; | ||
572 | |||
573 | device_info = kmalloc(sizeof(struct dmabounce_device_info), GFP_ATOMIC); | ||
574 | if (!device_info) { | ||
575 | printk(KERN_ERR | ||
576 | "Could not allocated dmabounce_device_info for %s", | ||
577 | dev->bus_id); | ||
578 | return -ENOMEM; | ||
579 | } | ||
580 | |||
581 | device_info->small_buffer_pool = | ||
582 | dma_pool_create("small_dmabounce_pool", | ||
583 | dev, | ||
584 | small_buffer_size, | ||
585 | 0 /* byte alignment */, | ||
586 | 0 /* no page-crossing issues */); | ||
587 | if (!device_info->small_buffer_pool) { | ||
588 | printk(KERN_ERR | ||
589 | "dmabounce: could not allocate small DMA pool for %s\n", | ||
590 | dev->bus_id); | ||
591 | kfree(device_info); | ||
592 | return -ENOMEM; | ||
593 | } | ||
594 | |||
595 | if (large_buffer_size) { | ||
596 | device_info->large_buffer_pool = | ||
597 | dma_pool_create("large_dmabounce_pool", | ||
598 | dev, | ||
599 | large_buffer_size, | ||
600 | 0 /* byte alignment */, | ||
601 | 0 /* no page-crossing issues */); | ||
602 | if (!device_info->large_buffer_pool) { | ||
603 | printk(KERN_ERR | ||
604 | "dmabounce: could not allocate large DMA pool for %s\n", | ||
605 | dev->bus_id); | ||
606 | dma_pool_destroy(device_info->small_buffer_pool); | ||
607 | |||
608 | return -ENOMEM; | ||
609 | } | ||
610 | } | ||
611 | |||
612 | device_info->dev = dev; | ||
613 | device_info->small_buffer_size = small_buffer_size; | ||
614 | device_info->large_buffer_size = large_buffer_size; | ||
615 | INIT_LIST_HEAD(&device_info->safe_buffers); | ||
616 | |||
617 | #ifdef STATS | ||
618 | device_info->sbp_allocs = 0; | ||
619 | device_info->lbp_allocs = 0; | ||
620 | device_info->total_allocs = 0; | ||
621 | device_info->map_op_count = 0; | ||
622 | device_info->bounce_count = 0; | ||
623 | #endif | ||
624 | |||
625 | list_add(&device_info->node, &dmabounce_devs); | ||
626 | |||
627 | printk(KERN_INFO "dmabounce: registered device %s on %s bus\n", | ||
628 | dev->bus_id, dev->bus->name); | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | void | ||
634 | dmabounce_unregister_dev(struct device *dev) | ||
635 | { | ||
636 | struct dmabounce_device_info *device_info = find_dmabounce_dev(dev); | ||
637 | |||
638 | if (!device_info) { | ||
639 | printk(KERN_WARNING | ||
640 | "%s: Never registered with dmabounce but attempting" \ | ||
641 | "to unregister!\n", dev->bus_id); | ||
642 | return; | ||
643 | } | ||
644 | |||
645 | if (!list_empty(&device_info->safe_buffers)) { | ||
646 | printk(KERN_ERR | ||
647 | "%s: Removing from dmabounce with pending buffers!\n", | ||
648 | dev->bus_id); | ||
649 | BUG(); | ||
650 | } | ||
651 | |||
652 | if (device_info->small_buffer_pool) | ||
653 | dma_pool_destroy(device_info->small_buffer_pool); | ||
654 | if (device_info->large_buffer_pool) | ||
655 | dma_pool_destroy(device_info->large_buffer_pool); | ||
656 | |||
657 | #ifdef STATS | ||
658 | print_alloc_stats(device_info); | ||
659 | print_map_stats(device_info); | ||
660 | #endif | ||
661 | |||
662 | list_del(&device_info->node); | ||
663 | |||
664 | kfree(device_info); | ||
665 | |||
666 | printk(KERN_INFO "dmabounce: device %s on %s bus unregistered\n", | ||
667 | dev->bus_id, dev->bus->name); | ||
668 | } | ||
669 | |||
670 | |||
671 | EXPORT_SYMBOL(dma_map_single); | ||
672 | EXPORT_SYMBOL(dma_unmap_single); | ||
673 | EXPORT_SYMBOL(dma_map_sg); | ||
674 | EXPORT_SYMBOL(dma_unmap_sg); | ||
675 | EXPORT_SYMBOL(dma_sync_single); | ||
676 | EXPORT_SYMBOL(dma_sync_sg); | ||
677 | EXPORT_SYMBOL(dmabounce_register_dev); | ||
678 | EXPORT_SYMBOL(dmabounce_unregister_dev); | ||
679 | |||
680 | MODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>, Deepak Saxena <dsaxena@plexity.net>"); | ||
681 | MODULE_DESCRIPTION("Special dma_{map/unmap/dma_sync}_* routines for systems with limited DMA windows"); | ||
682 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/arm/common/icst307.c b/arch/arm/common/icst307.c new file mode 100644 index 000000000000..bafe8b19be82 --- /dev/null +++ b/arch/arm/common/icst307.c | |||
@@ -0,0 +1,161 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/common/icst307.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 | * Support functions for calculating clocks/divisors for the ICST307 | ||
11 | * clock generators. See http://www.icst.com/ for more information | ||
12 | * on these devices. | ||
13 | * | ||
14 | * This is an almost identical implementation to the ICST525 clock generator. | ||
15 | * The s2div and idx2s files are different | ||
16 | */ | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/kernel.h> | ||
19 | |||
20 | #include <asm/hardware/icst307.h> | ||
21 | |||
22 | /* | ||
23 | * Divisors for each OD setting. | ||
24 | */ | ||
25 | static unsigned char s2div[8] = { 10, 2, 8, 4, 5, 7, 3, 6 }; | ||
26 | |||
27 | unsigned long icst307_khz(const struct icst307_params *p, struct icst307_vco vco) | ||
28 | { | ||
29 | return p->ref * 2 * (vco.v + 8) / ((vco.r + 2) * s2div[vco.s]); | ||
30 | } | ||
31 | |||
32 | EXPORT_SYMBOL(icst307_khz); | ||
33 | |||
34 | /* | ||
35 | * Ascending divisor S values. | ||
36 | */ | ||
37 | static unsigned char idx2s[8] = { 1, 6, 3, 4, 7, 5, 2, 0 }; | ||
38 | |||
39 | struct icst307_vco | ||
40 | icst307_khz_to_vco(const struct icst307_params *p, unsigned long freq) | ||
41 | { | ||
42 | struct icst307_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max }; | ||
43 | unsigned long f; | ||
44 | unsigned int i = 0, rd, best = (unsigned int)-1; | ||
45 | |||
46 | /* | ||
47 | * First, find the PLL output divisor such | ||
48 | * that the PLL output is within spec. | ||
49 | */ | ||
50 | do { | ||
51 | f = freq * s2div[idx2s[i]]; | ||
52 | |||
53 | /* | ||
54 | * f must be between 6MHz and 200MHz (3.3 or 5V) | ||
55 | */ | ||
56 | if (f > 6000 && f <= p->vco_max) | ||
57 | break; | ||
58 | } while (i < ARRAY_SIZE(idx2s)); | ||
59 | |||
60 | if (i > ARRAY_SIZE(idx2s)) | ||
61 | return vco; | ||
62 | |||
63 | vco.s = idx2s[i]; | ||
64 | |||
65 | /* | ||
66 | * Now find the closest divisor combination | ||
67 | * which gives a PLL output of 'f'. | ||
68 | */ | ||
69 | for (rd = p->rd_min; rd <= p->rd_max; rd++) { | ||
70 | unsigned long fref_div, f_pll; | ||
71 | unsigned int vd; | ||
72 | int f_diff; | ||
73 | |||
74 | fref_div = (2 * p->ref) / rd; | ||
75 | |||
76 | vd = (f + fref_div / 2) / fref_div; | ||
77 | if (vd < p->vd_min || vd > p->vd_max) | ||
78 | continue; | ||
79 | |||
80 | f_pll = fref_div * vd; | ||
81 | f_diff = f_pll - f; | ||
82 | if (f_diff < 0) | ||
83 | f_diff = -f_diff; | ||
84 | |||
85 | if ((unsigned)f_diff < best) { | ||
86 | vco.v = vd - 8; | ||
87 | vco.r = rd - 2; | ||
88 | if (f_diff == 0) | ||
89 | break; | ||
90 | best = f_diff; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | return vco; | ||
95 | } | ||
96 | |||
97 | EXPORT_SYMBOL(icst307_khz_to_vco); | ||
98 | |||
99 | struct icst307_vco | ||
100 | icst307_ps_to_vco(const struct icst307_params *p, unsigned long period) | ||
101 | { | ||
102 | struct icst307_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max }; | ||
103 | unsigned long f, ps; | ||
104 | unsigned int i = 0, rd, best = (unsigned int)-1; | ||
105 | |||
106 | ps = 1000000000UL / p->vco_max; | ||
107 | |||
108 | /* | ||
109 | * First, find the PLL output divisor such | ||
110 | * that the PLL output is within spec. | ||
111 | */ | ||
112 | do { | ||
113 | f = period / s2div[idx2s[i]]; | ||
114 | |||
115 | /* | ||
116 | * f must be between 6MHz and 200MHz (3.3 or 5V) | ||
117 | */ | ||
118 | if (f >= ps && f < 1000000000UL / 6000 + 1) | ||
119 | break; | ||
120 | } while (i < ARRAY_SIZE(idx2s)); | ||
121 | |||
122 | if (i > ARRAY_SIZE(idx2s)) | ||
123 | return vco; | ||
124 | |||
125 | vco.s = idx2s[i]; | ||
126 | |||
127 | ps = 500000000UL / p->ref; | ||
128 | |||
129 | /* | ||
130 | * Now find the closest divisor combination | ||
131 | * which gives a PLL output of 'f'. | ||
132 | */ | ||
133 | for (rd = p->rd_min; rd <= p->rd_max; rd++) { | ||
134 | unsigned long f_in_div, f_pll; | ||
135 | unsigned int vd; | ||
136 | int f_diff; | ||
137 | |||
138 | f_in_div = ps * rd; | ||
139 | |||
140 | vd = (f_in_div + f / 2) / f; | ||
141 | if (vd < p->vd_min || vd > p->vd_max) | ||
142 | continue; | ||
143 | |||
144 | f_pll = (f_in_div + vd / 2) / vd; | ||
145 | f_diff = f_pll - f; | ||
146 | if (f_diff < 0) | ||
147 | f_diff = -f_diff; | ||
148 | |||
149 | if ((unsigned)f_diff < best) { | ||
150 | vco.v = vd - 8; | ||
151 | vco.r = rd - 2; | ||
152 | if (f_diff == 0) | ||
153 | break; | ||
154 | best = f_diff; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | return vco; | ||
159 | } | ||
160 | |||
161 | EXPORT_SYMBOL(icst307_ps_to_vco); | ||
diff --git a/arch/arm/common/icst525.c b/arch/arm/common/icst525.c new file mode 100644 index 000000000000..943ef88c0379 --- /dev/null +++ b/arch/arm/common/icst525.c | |||
@@ -0,0 +1,160 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/common/icst525.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 | * Support functions for calculating clocks/divisors for the ICST525 | ||
11 | * clock generators. See http://www.icst.com/ for more information | ||
12 | * on these devices. | ||
13 | */ | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/kernel.h> | ||
16 | |||
17 | #include <asm/hardware/icst525.h> | ||
18 | |||
19 | /* | ||
20 | * Divisors for each OD setting. | ||
21 | */ | ||
22 | static unsigned char s2div[8] = { 10, 2, 8, 4, 5, 7, 9, 6 }; | ||
23 | |||
24 | unsigned long icst525_khz(const struct icst525_params *p, struct icst525_vco vco) | ||
25 | { | ||
26 | return p->ref * 2 * (vco.v + 8) / ((vco.r + 2) * s2div[vco.s]); | ||
27 | } | ||
28 | |||
29 | EXPORT_SYMBOL(icst525_khz); | ||
30 | |||
31 | /* | ||
32 | * Ascending divisor S values. | ||
33 | */ | ||
34 | static unsigned char idx2s[] = { 1, 3, 4, 7, 5, 2, 6, 0 }; | ||
35 | |||
36 | struct icst525_vco | ||
37 | icst525_khz_to_vco(const struct icst525_params *p, unsigned long freq) | ||
38 | { | ||
39 | struct icst525_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max }; | ||
40 | unsigned long f; | ||
41 | unsigned int i = 0, rd, best = (unsigned int)-1; | ||
42 | |||
43 | /* | ||
44 | * First, find the PLL output divisor such | ||
45 | * that the PLL output is within spec. | ||
46 | */ | ||
47 | do { | ||
48 | f = freq * s2div[idx2s[i]]; | ||
49 | |||
50 | /* | ||
51 | * f must be between 10MHz and | ||
52 | * 320MHz (5V) or 200MHz (3V) | ||
53 | */ | ||
54 | if (f > 10000 && f <= p->vco_max) | ||
55 | break; | ||
56 | } while (i < ARRAY_SIZE(idx2s)); | ||
57 | |||
58 | if (i > ARRAY_SIZE(idx2s)) | ||
59 | return vco; | ||
60 | |||
61 | vco.s = idx2s[i]; | ||
62 | |||
63 | /* | ||
64 | * Now find the closest divisor combination | ||
65 | * which gives a PLL output of 'f'. | ||
66 | */ | ||
67 | for (rd = p->rd_min; rd <= p->rd_max; rd++) { | ||
68 | unsigned long fref_div, f_pll; | ||
69 | unsigned int vd; | ||
70 | int f_diff; | ||
71 | |||
72 | fref_div = (2 * p->ref) / rd; | ||
73 | |||
74 | vd = (f + fref_div / 2) / fref_div; | ||
75 | if (vd < p->vd_min || vd > p->vd_max) | ||
76 | continue; | ||
77 | |||
78 | f_pll = fref_div * vd; | ||
79 | f_diff = f_pll - f; | ||
80 | if (f_diff < 0) | ||
81 | f_diff = -f_diff; | ||
82 | |||
83 | if ((unsigned)f_diff < best) { | ||
84 | vco.v = vd - 8; | ||
85 | vco.r = rd - 2; | ||
86 | if (f_diff == 0) | ||
87 | break; | ||
88 | best = f_diff; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | return vco; | ||
93 | } | ||
94 | |||
95 | EXPORT_SYMBOL(icst525_khz_to_vco); | ||
96 | |||
97 | struct icst525_vco | ||
98 | icst525_ps_to_vco(const struct icst525_params *p, unsigned long period) | ||
99 | { | ||
100 | struct icst525_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max }; | ||
101 | unsigned long f, ps; | ||
102 | unsigned int i = 0, rd, best = (unsigned int)-1; | ||
103 | |||
104 | ps = 1000000000UL / p->vco_max; | ||
105 | |||
106 | /* | ||
107 | * First, find the PLL output divisor such | ||
108 | * that the PLL output is within spec. | ||
109 | */ | ||
110 | do { | ||
111 | f = period / s2div[idx2s[i]]; | ||
112 | |||
113 | /* | ||
114 | * f must be between 10MHz and | ||
115 | * 320MHz (5V) or 200MHz (3V) | ||
116 | */ | ||
117 | if (f >= ps && f < 100000) | ||
118 | break; | ||
119 | } while (i < ARRAY_SIZE(idx2s)); | ||
120 | |||
121 | if (i > ARRAY_SIZE(idx2s)) | ||
122 | return vco; | ||
123 | |||
124 | vco.s = idx2s[i]; | ||
125 | |||
126 | ps = 500000000UL / p->ref; | ||
127 | |||
128 | /* | ||
129 | * Now find the closest divisor combination | ||
130 | * which gives a PLL output of 'f'. | ||
131 | */ | ||
132 | for (rd = p->rd_min; rd <= p->rd_max; rd++) { | ||
133 | unsigned long f_in_div, f_pll; | ||
134 | unsigned int vd; | ||
135 | int f_diff; | ||
136 | |||
137 | f_in_div = ps * rd; | ||
138 | |||
139 | vd = (f_in_div + f / 2) / f; | ||
140 | if (vd < p->vd_min || vd > p->vd_max) | ||
141 | continue; | ||
142 | |||
143 | f_pll = (f_in_div + vd / 2) / vd; | ||
144 | f_diff = f_pll - f; | ||
145 | if (f_diff < 0) | ||
146 | f_diff = -f_diff; | ||
147 | |||
148 | if ((unsigned)f_diff < best) { | ||
149 | vco.v = vd - 8; | ||
150 | vco.r = rd - 2; | ||
151 | if (f_diff == 0) | ||
152 | break; | ||
153 | best = f_diff; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | return vco; | ||
158 | } | ||
159 | |||
160 | EXPORT_SYMBOL(icst525_ps_to_vco); | ||
diff --git a/arch/arm/common/locomo.c b/arch/arm/common/locomo.c new file mode 100644 index 000000000000..41f12658c8b4 --- /dev/null +++ b/arch/arm/common/locomo.c | |||
@@ -0,0 +1,1058 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/common/locomo.c | ||
3 | * | ||
4 | * Sharp LoCoMo support | ||
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 contains all generic LoCoMo support. | ||
11 | * | ||
12 | * All initialization functions provided here are intended to be called | ||
13 | * from machine specific code with proper arguments when required. | ||
14 | * | ||
15 | * Based on sa1111.c | ||
16 | */ | ||
17 | |||
18 | #include <linux/config.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/spinlock.h> | ||
28 | |||
29 | #include <asm/hardware.h> | ||
30 | #include <asm/mach-types.h> | ||
31 | #include <asm/io.h> | ||
32 | #include <asm/irq.h> | ||
33 | #include <asm/mach/irq.h> | ||
34 | |||
35 | #include <asm/hardware/locomo.h> | ||
36 | |||
37 | /* M62332 output channel selection */ | ||
38 | #define M62332_EVR_CH 1 /* M62332 volume channel number */ | ||
39 | /* 0 : CH.1 , 1 : CH. 2 */ | ||
40 | /* DAC send data */ | ||
41 | #define M62332_SLAVE_ADDR 0x4e /* Slave address */ | ||
42 | #define M62332_W_BIT 0x00 /* W bit (0 only) */ | ||
43 | #define M62332_SUB_ADDR 0x00 /* Sub address */ | ||
44 | #define M62332_A_BIT 0x00 /* A bit (0 only) */ | ||
45 | |||
46 | /* DAC setup and hold times (expressed in us) */ | ||
47 | #define DAC_BUS_FREE_TIME 5 /* 4.7 us */ | ||
48 | #define DAC_START_SETUP_TIME 5 /* 4.7 us */ | ||
49 | #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */ | ||
50 | #define DAC_START_HOLD_TIME 5 /* 4.7 us */ | ||
51 | #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */ | ||
52 | #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */ | ||
53 | #define DAC_DATA_SETUP_TIME 1 /* 250 ns */ | ||
54 | #define DAC_DATA_HOLD_TIME 1 /* 300 ns */ | ||
55 | #define DAC_LOW_SETUP_TIME 1 /* 300 ns */ | ||
56 | #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */ | ||
57 | |||
58 | /* the following is the overall data for the locomo chip */ | ||
59 | struct locomo { | ||
60 | struct device *dev; | ||
61 | unsigned long phys; | ||
62 | unsigned int irq; | ||
63 | spinlock_t lock; | ||
64 | void *base; | ||
65 | }; | ||
66 | |||
67 | struct locomo_dev_info { | ||
68 | unsigned long offset; | ||
69 | unsigned long length; | ||
70 | unsigned int devid; | ||
71 | unsigned int irq[1]; | ||
72 | const char * name; | ||
73 | }; | ||
74 | |||
75 | /* All the locomo devices. If offset is non-zero, the mapbase for the | ||
76 | * locomo_dev will be set to the chip base plus offset. If offset is | ||
77 | * zero, then the mapbase for the locomo_dev will be set to zero. An | ||
78 | * offset of zero means the device only uses GPIOs or other helper | ||
79 | * functions inside this file */ | ||
80 | static struct locomo_dev_info locomo_devices[] = { | ||
81 | { | ||
82 | .devid = LOCOMO_DEVID_KEYBOARD, | ||
83 | .irq = { | ||
84 | IRQ_LOCOMO_KEY, | ||
85 | }, | ||
86 | .name = "locomo-keyboard", | ||
87 | .offset = LOCOMO_KEYBOARD, | ||
88 | .length = 16, | ||
89 | }, | ||
90 | { | ||
91 | .devid = LOCOMO_DEVID_FRONTLIGHT, | ||
92 | .irq = {}, | ||
93 | .name = "locomo-frontlight", | ||
94 | .offset = LOCOMO_FRONTLIGHT, | ||
95 | .length = 8, | ||
96 | |||
97 | }, | ||
98 | { | ||
99 | .devid = LOCOMO_DEVID_BACKLIGHT, | ||
100 | .irq = {}, | ||
101 | .name = "locomo-backlight", | ||
102 | .offset = LOCOMO_BACKLIGHT, | ||
103 | .length = 8, | ||
104 | }, | ||
105 | { | ||
106 | .devid = LOCOMO_DEVID_AUDIO, | ||
107 | .irq = {}, | ||
108 | .name = "locomo-audio", | ||
109 | .offset = LOCOMO_AUDIO, | ||
110 | .length = 4, | ||
111 | }, | ||
112 | { | ||
113 | .devid = LOCOMO_DEVID_LED, | ||
114 | .irq = {}, | ||
115 | .name = "locomo-led", | ||
116 | .offset = LOCOMO_LED, | ||
117 | .length = 8, | ||
118 | }, | ||
119 | { | ||
120 | .devid = LOCOMO_DEVID_UART, | ||
121 | .irq = {}, | ||
122 | .name = "locomo-uart", | ||
123 | .offset = 0, | ||
124 | .length = 0, | ||
125 | }, | ||
126 | }; | ||
127 | |||
128 | |||
129 | /** LoCoMo interrupt handling stuff. | ||
130 | * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs. | ||
131 | * that is, there is only one real hardware interrupt | ||
132 | * we determine which interrupt it is by reading some IO memory. | ||
133 | * We have two levels of expansion, first in the handler for the | ||
134 | * hardware interrupt we generate an interrupt | ||
135 | * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts | ||
136 | * | ||
137 | * hardware irq reads LOCOMO_ICR & 0x0f00 | ||
138 | * IRQ_LOCOMO_KEY_BASE | ||
139 | * IRQ_LOCOMO_GPIO_BASE | ||
140 | * IRQ_LOCOMO_LT_BASE | ||
141 | * IRQ_LOCOMO_SPI_BASE | ||
142 | * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001 | ||
143 | * IRQ_LOCOMO_KEY | ||
144 | * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff | ||
145 | * IRQ_LOCOMO_GPIO[0-15] | ||
146 | * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001 | ||
147 | * IRQ_LOCOMO_LT | ||
148 | * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F | ||
149 | * IRQ_LOCOMO_SPI_RFR | ||
150 | * IRQ_LOCOMO_SPI_RFW | ||
151 | * IRQ_LOCOMO_SPI_OVRN | ||
152 | * IRQ_LOCOMO_SPI_TEND | ||
153 | */ | ||
154 | |||
155 | #define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE) | ||
156 | #define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY) | ||
157 | #define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0) | ||
158 | #define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT) | ||
159 | #define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR) | ||
160 | |||
161 | static void locomo_handler(unsigned int irq, struct irqdesc *desc, | ||
162 | struct pt_regs *regs) | ||
163 | { | ||
164 | int req, i; | ||
165 | struct irqdesc *d; | ||
166 | void *mapbase = get_irq_chipdata(irq); | ||
167 | |||
168 | /* Acknowledge the parent IRQ */ | ||
169 | desc->chip->ack(irq); | ||
170 | |||
171 | /* check why this interrupt was generated */ | ||
172 | req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00; | ||
173 | |||
174 | if (req) { | ||
175 | /* generate the next interrupt(s) */ | ||
176 | irq = LOCOMO_IRQ_START; | ||
177 | d = irq_desc + irq; | ||
178 | for (i = 0; i <= 3; i++, d++, irq++) { | ||
179 | if (req & (0x0100 << i)) { | ||
180 | d->handle(irq, d, regs); | ||
181 | } | ||
182 | |||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | static void locomo_ack_irq(unsigned int irq) | ||
188 | { | ||
189 | } | ||
190 | |||
191 | static void locomo_mask_irq(unsigned int irq) | ||
192 | { | ||
193 | void *mapbase = get_irq_chipdata(irq); | ||
194 | unsigned int r; | ||
195 | r = locomo_readl(mapbase + LOCOMO_ICR); | ||
196 | r &= ~(0x0010 << (irq - LOCOMO_IRQ_START)); | ||
197 | locomo_writel(r, mapbase + LOCOMO_ICR); | ||
198 | } | ||
199 | |||
200 | static void locomo_unmask_irq(unsigned int irq) | ||
201 | { | ||
202 | void *mapbase = get_irq_chipdata(irq); | ||
203 | unsigned int r; | ||
204 | r = locomo_readl(mapbase + LOCOMO_ICR); | ||
205 | r |= (0x0010 << (irq - LOCOMO_IRQ_START)); | ||
206 | locomo_writel(r, mapbase + LOCOMO_ICR); | ||
207 | } | ||
208 | |||
209 | static struct irqchip locomo_chip = { | ||
210 | .ack = locomo_ack_irq, | ||
211 | .mask = locomo_mask_irq, | ||
212 | .unmask = locomo_unmask_irq, | ||
213 | }; | ||
214 | |||
215 | static void locomo_key_handler(unsigned int irq, struct irqdesc *desc, | ||
216 | struct pt_regs *regs) | ||
217 | { | ||
218 | struct irqdesc *d; | ||
219 | void *mapbase = get_irq_chipdata(irq); | ||
220 | |||
221 | if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) { | ||
222 | d = irq_desc + LOCOMO_IRQ_KEY_START; | ||
223 | d->handle(LOCOMO_IRQ_KEY_START, d, regs); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | static void locomo_key_ack_irq(unsigned int irq) | ||
228 | { | ||
229 | void *mapbase = get_irq_chipdata(irq); | ||
230 | unsigned int r; | ||
231 | r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
232 | r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START)); | ||
233 | locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
234 | } | ||
235 | |||
236 | static void locomo_key_mask_irq(unsigned int irq) | ||
237 | { | ||
238 | void *mapbase = get_irq_chipdata(irq); | ||
239 | unsigned int r; | ||
240 | r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
241 | r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START)); | ||
242 | locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
243 | } | ||
244 | |||
245 | static void locomo_key_unmask_irq(unsigned int irq) | ||
246 | { | ||
247 | void *mapbase = get_irq_chipdata(irq); | ||
248 | unsigned int r; | ||
249 | r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
250 | r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START)); | ||
251 | locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
252 | } | ||
253 | |||
254 | static struct irqchip locomo_key_chip = { | ||
255 | .ack = locomo_key_ack_irq, | ||
256 | .mask = locomo_key_mask_irq, | ||
257 | .unmask = locomo_key_unmask_irq, | ||
258 | }; | ||
259 | |||
260 | static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc, | ||
261 | struct pt_regs *regs) | ||
262 | { | ||
263 | int req, i; | ||
264 | struct irqdesc *d; | ||
265 | void *mapbase = get_irq_chipdata(irq); | ||
266 | |||
267 | req = locomo_readl(mapbase + LOCOMO_GIR) & | ||
268 | locomo_readl(mapbase + LOCOMO_GPD) & | ||
269 | 0xffff; | ||
270 | |||
271 | if (req) { | ||
272 | irq = LOCOMO_IRQ_GPIO_START; | ||
273 | d = irq_desc + LOCOMO_IRQ_GPIO_START; | ||
274 | for (i = 0; i <= 15; i++, irq++, d++) { | ||
275 | if (req & (0x0001 << i)) { | ||
276 | d->handle(irq, d, regs); | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | |||
282 | static void locomo_gpio_ack_irq(unsigned int irq) | ||
283 | { | ||
284 | void *mapbase = get_irq_chipdata(irq); | ||
285 | unsigned int r; | ||
286 | r = locomo_readl(mapbase + LOCOMO_GWE); | ||
287 | r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); | ||
288 | locomo_writel(r, mapbase + LOCOMO_GWE); | ||
289 | |||
290 | r = locomo_readl(mapbase + LOCOMO_GIS); | ||
291 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); | ||
292 | locomo_writel(r, mapbase + LOCOMO_GIS); | ||
293 | |||
294 | r = locomo_readl(mapbase + LOCOMO_GWE); | ||
295 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); | ||
296 | locomo_writel(r, mapbase + LOCOMO_GWE); | ||
297 | } | ||
298 | |||
299 | static void locomo_gpio_mask_irq(unsigned int irq) | ||
300 | { | ||
301 | void *mapbase = get_irq_chipdata(irq); | ||
302 | unsigned int r; | ||
303 | r = locomo_readl(mapbase + LOCOMO_GIE); | ||
304 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); | ||
305 | locomo_writel(r, mapbase + LOCOMO_GIE); | ||
306 | } | ||
307 | |||
308 | static void locomo_gpio_unmask_irq(unsigned int irq) | ||
309 | { | ||
310 | void *mapbase = get_irq_chipdata(irq); | ||
311 | unsigned int r; | ||
312 | r = locomo_readl(mapbase + LOCOMO_GIE); | ||
313 | r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); | ||
314 | locomo_writel(r, mapbase + LOCOMO_GIE); | ||
315 | } | ||
316 | |||
317 | static struct irqchip locomo_gpio_chip = { | ||
318 | .ack = locomo_gpio_ack_irq, | ||
319 | .mask = locomo_gpio_mask_irq, | ||
320 | .unmask = locomo_gpio_unmask_irq, | ||
321 | }; | ||
322 | |||
323 | static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc, | ||
324 | struct pt_regs *regs) | ||
325 | { | ||
326 | struct irqdesc *d; | ||
327 | void *mapbase = get_irq_chipdata(irq); | ||
328 | |||
329 | if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) { | ||
330 | d = irq_desc + LOCOMO_IRQ_LT_START; | ||
331 | d->handle(LOCOMO_IRQ_LT_START, d, regs); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | static void locomo_lt_ack_irq(unsigned int irq) | ||
336 | { | ||
337 | void *mapbase = get_irq_chipdata(irq); | ||
338 | unsigned int r; | ||
339 | r = locomo_readl(mapbase + LOCOMO_LTINT); | ||
340 | r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START)); | ||
341 | locomo_writel(r, mapbase + LOCOMO_LTINT); | ||
342 | } | ||
343 | |||
344 | static void locomo_lt_mask_irq(unsigned int irq) | ||
345 | { | ||
346 | void *mapbase = get_irq_chipdata(irq); | ||
347 | unsigned int r; | ||
348 | r = locomo_readl(mapbase + LOCOMO_LTINT); | ||
349 | r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START)); | ||
350 | locomo_writel(r, mapbase + LOCOMO_LTINT); | ||
351 | } | ||
352 | |||
353 | static void locomo_lt_unmask_irq(unsigned int irq) | ||
354 | { | ||
355 | void *mapbase = get_irq_chipdata(irq); | ||
356 | unsigned int r; | ||
357 | r = locomo_readl(mapbase + LOCOMO_LTINT); | ||
358 | r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START)); | ||
359 | locomo_writel(r, mapbase + LOCOMO_LTINT); | ||
360 | } | ||
361 | |||
362 | static struct irqchip locomo_lt_chip = { | ||
363 | .ack = locomo_lt_ack_irq, | ||
364 | .mask = locomo_lt_mask_irq, | ||
365 | .unmask = locomo_lt_unmask_irq, | ||
366 | }; | ||
367 | |||
368 | static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc, | ||
369 | struct pt_regs *regs) | ||
370 | { | ||
371 | int req, i; | ||
372 | struct irqdesc *d; | ||
373 | void *mapbase = get_irq_chipdata(irq); | ||
374 | |||
375 | req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F; | ||
376 | if (req) { | ||
377 | irq = LOCOMO_IRQ_SPI_START; | ||
378 | d = irq_desc + irq; | ||
379 | |||
380 | for (i = 0; i <= 3; i++, irq++, d++) { | ||
381 | if (req & (0x0001 << i)) { | ||
382 | d->handle(irq, d, regs); | ||
383 | } | ||
384 | } | ||
385 | } | ||
386 | } | ||
387 | |||
388 | static void locomo_spi_ack_irq(unsigned int irq) | ||
389 | { | ||
390 | void *mapbase = get_irq_chipdata(irq); | ||
391 | unsigned int r; | ||
392 | r = locomo_readl(mapbase + LOCOMO_SPIWE); | ||
393 | r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START)); | ||
394 | locomo_writel(r, mapbase + LOCOMO_SPIWE); | ||
395 | |||
396 | r = locomo_readl(mapbase + LOCOMO_SPIIS); | ||
397 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START)); | ||
398 | locomo_writel(r, mapbase + LOCOMO_SPIIS); | ||
399 | |||
400 | r = locomo_readl(mapbase + LOCOMO_SPIWE); | ||
401 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START)); | ||
402 | locomo_writel(r, mapbase + LOCOMO_SPIWE); | ||
403 | } | ||
404 | |||
405 | static void locomo_spi_mask_irq(unsigned int irq) | ||
406 | { | ||
407 | void *mapbase = get_irq_chipdata(irq); | ||
408 | unsigned int r; | ||
409 | r = locomo_readl(mapbase + LOCOMO_SPIIE); | ||
410 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START)); | ||
411 | locomo_writel(r, mapbase + LOCOMO_SPIIE); | ||
412 | } | ||
413 | |||
414 | static void locomo_spi_unmask_irq(unsigned int irq) | ||
415 | { | ||
416 | void *mapbase = get_irq_chipdata(irq); | ||
417 | unsigned int r; | ||
418 | r = locomo_readl(mapbase + LOCOMO_SPIIE); | ||
419 | r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START)); | ||
420 | locomo_writel(r, mapbase + LOCOMO_SPIIE); | ||
421 | } | ||
422 | |||
423 | static struct irqchip locomo_spi_chip = { | ||
424 | .ack = locomo_spi_ack_irq, | ||
425 | .mask = locomo_spi_mask_irq, | ||
426 | .unmask = locomo_spi_unmask_irq, | ||
427 | }; | ||
428 | |||
429 | static void locomo_setup_irq(struct locomo *lchip) | ||
430 | { | ||
431 | int irq; | ||
432 | void *irqbase = lchip->base; | ||
433 | |||
434 | /* | ||
435 | * Install handler for IRQ_LOCOMO_HW. | ||
436 | */ | ||
437 | set_irq_type(lchip->irq, IRQT_FALLING); | ||
438 | set_irq_chipdata(lchip->irq, irqbase); | ||
439 | set_irq_chained_handler(lchip->irq, locomo_handler); | ||
440 | |||
441 | /* Install handlers for IRQ_LOCOMO_*_BASE */ | ||
442 | set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip); | ||
443 | set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase); | ||
444 | set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler); | ||
445 | set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE); | ||
446 | |||
447 | set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip); | ||
448 | set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase); | ||
449 | set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler); | ||
450 | set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE); | ||
451 | |||
452 | set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip); | ||
453 | set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase); | ||
454 | set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler); | ||
455 | set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE); | ||
456 | |||
457 | set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip); | ||
458 | set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase); | ||
459 | set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler); | ||
460 | set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE); | ||
461 | |||
462 | /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */ | ||
463 | set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip); | ||
464 | set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase); | ||
465 | set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ); | ||
466 | set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE); | ||
467 | |||
468 | /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */ | ||
469 | for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) { | ||
470 | set_irq_chip(irq, &locomo_gpio_chip); | ||
471 | set_irq_chipdata(irq, irqbase); | ||
472 | set_irq_handler(irq, do_edge_IRQ); | ||
473 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
474 | } | ||
475 | |||
476 | /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */ | ||
477 | set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip); | ||
478 | set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase); | ||
479 | set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ); | ||
480 | set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE); | ||
481 | |||
482 | /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */ | ||
483 | for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) { | ||
484 | set_irq_chip(irq, &locomo_spi_chip); | ||
485 | set_irq_chipdata(irq, irqbase); | ||
486 | set_irq_handler(irq, do_edge_IRQ); | ||
487 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
488 | } | ||
489 | } | ||
490 | |||
491 | |||
492 | static void locomo_dev_release(struct device *_dev) | ||
493 | { | ||
494 | struct locomo_dev *dev = LOCOMO_DEV(_dev); | ||
495 | |||
496 | kfree(dev); | ||
497 | } | ||
498 | |||
499 | static int | ||
500 | locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info) | ||
501 | { | ||
502 | struct locomo_dev *dev; | ||
503 | int ret; | ||
504 | |||
505 | dev = kmalloc(sizeof(struct locomo_dev), GFP_KERNEL); | ||
506 | if (!dev) { | ||
507 | ret = -ENOMEM; | ||
508 | goto out; | ||
509 | } | ||
510 | memset(dev, 0, sizeof(struct locomo_dev)); | ||
511 | |||
512 | strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id)); | ||
513 | /* | ||
514 | * If the parent device has a DMA mask associated with it, | ||
515 | * propagate it down to the children. | ||
516 | */ | ||
517 | if (lchip->dev->dma_mask) { | ||
518 | dev->dma_mask = *lchip->dev->dma_mask; | ||
519 | dev->dev.dma_mask = &dev->dma_mask; | ||
520 | } | ||
521 | |||
522 | dev->devid = info->devid; | ||
523 | dev->dev.parent = lchip->dev; | ||
524 | dev->dev.bus = &locomo_bus_type; | ||
525 | dev->dev.release = locomo_dev_release; | ||
526 | dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask; | ||
527 | |||
528 | if (info->offset) | ||
529 | dev->mapbase = lchip->base + info->offset; | ||
530 | else | ||
531 | dev->mapbase = 0; | ||
532 | dev->length = info->length; | ||
533 | |||
534 | memmove(dev->irq, info->irq, sizeof(dev->irq)); | ||
535 | |||
536 | ret = device_register(&dev->dev); | ||
537 | if (ret) { | ||
538 | out: | ||
539 | kfree(dev); | ||
540 | } | ||
541 | return ret; | ||
542 | } | ||
543 | |||
544 | /** | ||
545 | * locomo_probe - probe for a single LoCoMo chip. | ||
546 | * @phys_addr: physical address of device. | ||
547 | * | ||
548 | * Probe for a LoCoMo chip. This must be called | ||
549 | * before any other locomo-specific code. | ||
550 | * | ||
551 | * Returns: | ||
552 | * %-ENODEV device not found. | ||
553 | * %-EBUSY physical address already marked in-use. | ||
554 | * %0 successful. | ||
555 | */ | ||
556 | static int | ||
557 | __locomo_probe(struct device *me, struct resource *mem, int irq) | ||
558 | { | ||
559 | struct locomo *lchip; | ||
560 | unsigned long r; | ||
561 | int i, ret = -ENODEV; | ||
562 | |||
563 | lchip = kmalloc(sizeof(struct locomo), GFP_KERNEL); | ||
564 | if (!lchip) | ||
565 | return -ENOMEM; | ||
566 | |||
567 | memset(lchip, 0, sizeof(struct locomo)); | ||
568 | |||
569 | spin_lock_init(&lchip->lock); | ||
570 | |||
571 | lchip->dev = me; | ||
572 | dev_set_drvdata(lchip->dev, lchip); | ||
573 | |||
574 | lchip->phys = mem->start; | ||
575 | lchip->irq = irq; | ||
576 | |||
577 | /* | ||
578 | * Map the whole region. This also maps the | ||
579 | * registers for our children. | ||
580 | */ | ||
581 | lchip->base = ioremap(mem->start, PAGE_SIZE); | ||
582 | if (!lchip->base) { | ||
583 | ret = -ENOMEM; | ||
584 | goto out; | ||
585 | } | ||
586 | |||
587 | /* locomo initialize */ | ||
588 | locomo_writel(0, lchip->base + LOCOMO_ICR); | ||
589 | /* KEYBOARD */ | ||
590 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); | ||
591 | |||
592 | /* GPIO */ | ||
593 | locomo_writel(0, lchip->base + LOCOMO_GPO); | ||
594 | locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14)) | ||
595 | , lchip->base + LOCOMO_GPE); | ||
596 | locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14)) | ||
597 | , lchip->base + LOCOMO_GPD); | ||
598 | locomo_writel(0, lchip->base + LOCOMO_GIE); | ||
599 | |||
600 | /* FrontLight */ | ||
601 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); | ||
602 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); | ||
603 | /* Longtime timer */ | ||
604 | locomo_writel(0, lchip->base + LOCOMO_LTINT); | ||
605 | /* SPI */ | ||
606 | locomo_writel(0, lchip->base + LOCOMO_SPIIE); | ||
607 | |||
608 | locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD); | ||
609 | r = locomo_readl(lchip->base + LOCOMO_ASD); | ||
610 | r |= 0x8000; | ||
611 | locomo_writel(r, lchip->base + LOCOMO_ASD); | ||
612 | |||
613 | locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD); | ||
614 | r = locomo_readl(lchip->base + LOCOMO_HSD); | ||
615 | r |= 0x8000; | ||
616 | locomo_writel(r, lchip->base + LOCOMO_HSD); | ||
617 | |||
618 | locomo_writel(128 / 8, lchip->base + LOCOMO_HSC); | ||
619 | |||
620 | /* XON */ | ||
621 | locomo_writel(0x80, lchip->base + LOCOMO_TADC); | ||
622 | udelay(1000); | ||
623 | /* CLK9MEN */ | ||
624 | r = locomo_readl(lchip->base + LOCOMO_TADC); | ||
625 | r |= 0x10; | ||
626 | locomo_writel(r, lchip->base + LOCOMO_TADC); | ||
627 | udelay(100); | ||
628 | |||
629 | /* init DAC */ | ||
630 | r = locomo_readl(lchip->base + LOCOMO_DAC); | ||
631 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; | ||
632 | locomo_writel(r, lchip->base + LOCOMO_DAC); | ||
633 | |||
634 | r = locomo_readl(lchip->base + LOCOMO_VER); | ||
635 | printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff)); | ||
636 | |||
637 | /* | ||
638 | * The interrupt controller must be initialised before any | ||
639 | * other device to ensure that the interrupts are available. | ||
640 | */ | ||
641 | if (lchip->irq != NO_IRQ) | ||
642 | locomo_setup_irq(lchip); | ||
643 | |||
644 | for (i = 0; i < ARRAY_SIZE(locomo_devices); i++) | ||
645 | locomo_init_one_child(lchip, &locomo_devices[i]); | ||
646 | |||
647 | return 0; | ||
648 | |||
649 | out: | ||
650 | kfree(lchip); | ||
651 | return ret; | ||
652 | } | ||
653 | |||
654 | static void __locomo_remove(struct locomo *lchip) | ||
655 | { | ||
656 | struct list_head *l, *n; | ||
657 | |||
658 | list_for_each_safe(l, n, &lchip->dev->children) { | ||
659 | struct device *d = list_to_dev(l); | ||
660 | |||
661 | device_unregister(d); | ||
662 | } | ||
663 | |||
664 | if (lchip->irq != NO_IRQ) { | ||
665 | set_irq_chained_handler(lchip->irq, NULL); | ||
666 | set_irq_data(lchip->irq, NULL); | ||
667 | } | ||
668 | |||
669 | iounmap(lchip->base); | ||
670 | kfree(lchip); | ||
671 | } | ||
672 | |||
673 | static int locomo_probe(struct device *dev) | ||
674 | { | ||
675 | struct platform_device *pdev = to_platform_device(dev); | ||
676 | struct resource *mem; | ||
677 | int irq; | ||
678 | |||
679 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
680 | if (!mem) | ||
681 | return -EINVAL; | ||
682 | irq = platform_get_irq(pdev, 0); | ||
683 | |||
684 | return __locomo_probe(dev, mem, irq); | ||
685 | } | ||
686 | |||
687 | static int locomo_remove(struct device *dev) | ||
688 | { | ||
689 | struct locomo *lchip = dev_get_drvdata(dev); | ||
690 | |||
691 | if (lchip) { | ||
692 | __locomo_remove(lchip); | ||
693 | dev_set_drvdata(dev, NULL); | ||
694 | } | ||
695 | |||
696 | return 0; | ||
697 | } | ||
698 | |||
699 | /* | ||
700 | * Not sure if this should be on the system bus or not yet. | ||
701 | * We really want some way to register a system device at | ||
702 | * the per-machine level, and then have this driver pick | ||
703 | * up the registered devices. | ||
704 | */ | ||
705 | static struct device_driver locomo_device_driver = { | ||
706 | .name = "locomo", | ||
707 | .bus = &platform_bus_type, | ||
708 | .probe = locomo_probe, | ||
709 | .remove = locomo_remove, | ||
710 | }; | ||
711 | |||
712 | /* | ||
713 | * Get the parent device driver (us) structure | ||
714 | * from a child function device | ||
715 | */ | ||
716 | static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev) | ||
717 | { | ||
718 | return (struct locomo *)dev_get_drvdata(ldev->dev.parent); | ||
719 | } | ||
720 | |||
721 | void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir) | ||
722 | { | ||
723 | struct locomo *lchip = locomo_chip_driver(ldev); | ||
724 | unsigned long flags; | ||
725 | unsigned int r; | ||
726 | |||
727 | spin_lock_irqsave(&lchip->lock, flags); | ||
728 | |||
729 | r = locomo_readl(lchip->base + LOCOMO_GPD); | ||
730 | r &= ~bits; | ||
731 | locomo_writel(r, lchip->base + LOCOMO_GPD); | ||
732 | |||
733 | r = locomo_readl(lchip->base + LOCOMO_GPE); | ||
734 | if (dir) | ||
735 | r |= bits; | ||
736 | else | ||
737 | r &= ~bits; | ||
738 | locomo_writel(r, lchip->base + LOCOMO_GPE); | ||
739 | |||
740 | spin_unlock_irqrestore(&lchip->lock, flags); | ||
741 | } | ||
742 | |||
743 | unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits) | ||
744 | { | ||
745 | struct locomo *lchip = locomo_chip_driver(ldev); | ||
746 | unsigned long flags; | ||
747 | unsigned int ret; | ||
748 | |||
749 | spin_lock_irqsave(&lchip->lock, flags); | ||
750 | ret = locomo_readl(lchip->base + LOCOMO_GPL); | ||
751 | spin_unlock_irqrestore(&lchip->lock, flags); | ||
752 | |||
753 | ret &= bits; | ||
754 | return ret; | ||
755 | } | ||
756 | |||
757 | unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits) | ||
758 | { | ||
759 | struct locomo *lchip = locomo_chip_driver(ldev); | ||
760 | unsigned long flags; | ||
761 | unsigned int ret; | ||
762 | |||
763 | spin_lock_irqsave(&lchip->lock, flags); | ||
764 | ret = locomo_readl(lchip->base + LOCOMO_GPO); | ||
765 | spin_unlock_irqrestore(&lchip->lock, flags); | ||
766 | |||
767 | ret &= bits; | ||
768 | return ret; | ||
769 | } | ||
770 | |||
771 | void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set) | ||
772 | { | ||
773 | struct locomo *lchip = locomo_chip_driver(ldev); | ||
774 | unsigned long flags; | ||
775 | unsigned int r; | ||
776 | |||
777 | spin_lock_irqsave(&lchip->lock, flags); | ||
778 | |||
779 | r = locomo_readl(lchip->base + LOCOMO_GPO); | ||
780 | if (set) | ||
781 | r |= bits; | ||
782 | else | ||
783 | r &= ~bits; | ||
784 | locomo_writel(r, lchip->base + LOCOMO_GPO); | ||
785 | |||
786 | spin_unlock_irqrestore(&lchip->lock, flags); | ||
787 | } | ||
788 | |||
789 | static void locomo_m62332_sendbit(void *mapbase, int bit) | ||
790 | { | ||
791 | unsigned int r; | ||
792 | |||
793 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
794 | r &= ~(LOCOMO_DAC_SCLOEB); | ||
795 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
796 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
797 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ | ||
798 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
799 | r &= ~(LOCOMO_DAC_SCLOEB); | ||
800 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
801 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
802 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | ||
803 | |||
804 | if (bit & 1) { | ||
805 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
806 | r |= LOCOMO_DAC_SDAOEB; | ||
807 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
808 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
809 | } else { | ||
810 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
811 | r &= ~(LOCOMO_DAC_SDAOEB); | ||
812 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
813 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
814 | } | ||
815 | |||
816 | udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */ | ||
817 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
818 | r |= LOCOMO_DAC_SCLOEB; | ||
819 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
820 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
821 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ | ||
822 | } | ||
823 | |||
824 | void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel) | ||
825 | { | ||
826 | struct locomo *lchip = locomo_chip_driver(ldev); | ||
827 | int i; | ||
828 | unsigned char data; | ||
829 | unsigned int r; | ||
830 | void *mapbase = lchip->base; | ||
831 | unsigned long flags; | ||
832 | |||
833 | spin_lock_irqsave(&lchip->lock, flags); | ||
834 | |||
835 | /* Start */ | ||
836 | udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */ | ||
837 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
838 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; | ||
839 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
840 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
841 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ | ||
842 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
843 | r &= ~(LOCOMO_DAC_SDAOEB); | ||
844 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
845 | udelay(DAC_START_HOLD_TIME); /* 5.0 usec */ | ||
846 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ | ||
847 | |||
848 | /* Send slave address and W bit (LSB is W bit) */ | ||
849 | data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT; | ||
850 | for (i = 1; i <= 8; i++) { | ||
851 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); | ||
852 | } | ||
853 | |||
854 | /* Check A bit */ | ||
855 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
856 | r &= ~(LOCOMO_DAC_SCLOEB); | ||
857 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
858 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
859 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | ||
860 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
861 | r &= ~(LOCOMO_DAC_SDAOEB); | ||
862 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
863 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
864 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
865 | r |= LOCOMO_DAC_SCLOEB; | ||
866 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
867 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
868 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ | ||
869 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ | ||
870 | printk(KERN_WARNING "locomo: m62332_senddata Error 1\n"); | ||
871 | return; | ||
872 | } | ||
873 | |||
874 | /* Send Sub address (LSB is channel select) */ | ||
875 | /* channel = 0 : ch1 select */ | ||
876 | /* = 1 : ch2 select */ | ||
877 | data = M62332_SUB_ADDR + channel; | ||
878 | for (i = 1; i <= 8; i++) { | ||
879 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); | ||
880 | } | ||
881 | |||
882 | /* Check A bit */ | ||
883 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
884 | r &= ~(LOCOMO_DAC_SCLOEB); | ||
885 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
886 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
887 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | ||
888 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
889 | r &= ~(LOCOMO_DAC_SDAOEB); | ||
890 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
891 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
892 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
893 | r |= LOCOMO_DAC_SCLOEB; | ||
894 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
895 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
896 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ | ||
897 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ | ||
898 | printk(KERN_WARNING "locomo: m62332_senddata Error 2\n"); | ||
899 | return; | ||
900 | } | ||
901 | |||
902 | /* Send DAC data */ | ||
903 | for (i = 1; i <= 8; i++) { | ||
904 | locomo_m62332_sendbit(mapbase, dac_data >> (8 - i)); | ||
905 | } | ||
906 | |||
907 | /* Check A bit */ | ||
908 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
909 | r &= ~(LOCOMO_DAC_SCLOEB); | ||
910 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
911 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
912 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | ||
913 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
914 | r &= ~(LOCOMO_DAC_SDAOEB); | ||
915 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
916 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
917 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
918 | r |= LOCOMO_DAC_SCLOEB; | ||
919 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
920 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
921 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ | ||
922 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ | ||
923 | printk(KERN_WARNING "locomo: m62332_senddata Error 3\n"); | ||
924 | return; | ||
925 | } | ||
926 | |||
927 | /* stop */ | ||
928 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
929 | r &= ~(LOCOMO_DAC_SCLOEB); | ||
930 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
931 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | ||
932 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | ||
933 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
934 | r |= LOCOMO_DAC_SCLOEB; | ||
935 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
936 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
937 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ | ||
938 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
939 | r |= LOCOMO_DAC_SDAOEB; | ||
940 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
941 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | ||
942 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ | ||
943 | |||
944 | r = locomo_readl(mapbase + LOCOMO_DAC); | ||
945 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; | ||
946 | locomo_writel(r, mapbase + LOCOMO_DAC); | ||
947 | udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */ | ||
948 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | ||
949 | |||
950 | spin_unlock_irqrestore(&lchip->lock, flags); | ||
951 | } | ||
952 | |||
953 | /* | ||
954 | * LoCoMo "Register Access Bus." | ||
955 | * | ||
956 | * We model this as a regular bus type, and hang devices directly | ||
957 | * off this. | ||
958 | */ | ||
959 | static int locomo_match(struct device *_dev, struct device_driver *_drv) | ||
960 | { | ||
961 | struct locomo_dev *dev = LOCOMO_DEV(_dev); | ||
962 | struct locomo_driver *drv = LOCOMO_DRV(_drv); | ||
963 | |||
964 | return dev->devid == drv->devid; | ||
965 | } | ||
966 | |||
967 | static int locomo_bus_suspend(struct device *dev, pm_message_t state) | ||
968 | { | ||
969 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | ||
970 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | ||
971 | int ret = 0; | ||
972 | |||
973 | if (drv && drv->suspend) | ||
974 | ret = drv->suspend(ldev, state); | ||
975 | return ret; | ||
976 | } | ||
977 | |||
978 | static int locomo_bus_resume(struct device *dev) | ||
979 | { | ||
980 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | ||
981 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | ||
982 | int ret = 0; | ||
983 | |||
984 | if (drv && drv->resume) | ||
985 | ret = drv->resume(ldev); | ||
986 | return ret; | ||
987 | } | ||
988 | |||
989 | static int locomo_bus_probe(struct device *dev) | ||
990 | { | ||
991 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | ||
992 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | ||
993 | int ret = -ENODEV; | ||
994 | |||
995 | if (drv->probe) | ||
996 | ret = drv->probe(ldev); | ||
997 | return ret; | ||
998 | } | ||
999 | |||
1000 | static int locomo_bus_remove(struct device *dev) | ||
1001 | { | ||
1002 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | ||
1003 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | ||
1004 | int ret = 0; | ||
1005 | |||
1006 | if (drv->remove) | ||
1007 | ret = drv->remove(ldev); | ||
1008 | return ret; | ||
1009 | } | ||
1010 | |||
1011 | struct bus_type locomo_bus_type = { | ||
1012 | .name = "locomo-bus", | ||
1013 | .match = locomo_match, | ||
1014 | .suspend = locomo_bus_suspend, | ||
1015 | .resume = locomo_bus_resume, | ||
1016 | }; | ||
1017 | |||
1018 | int locomo_driver_register(struct locomo_driver *driver) | ||
1019 | { | ||
1020 | driver->drv.probe = locomo_bus_probe; | ||
1021 | driver->drv.remove = locomo_bus_remove; | ||
1022 | driver->drv.bus = &locomo_bus_type; | ||
1023 | return driver_register(&driver->drv); | ||
1024 | } | ||
1025 | |||
1026 | void locomo_driver_unregister(struct locomo_driver *driver) | ||
1027 | { | ||
1028 | driver_unregister(&driver->drv); | ||
1029 | } | ||
1030 | |||
1031 | static int __init locomo_init(void) | ||
1032 | { | ||
1033 | int ret = bus_register(&locomo_bus_type); | ||
1034 | if (ret == 0) | ||
1035 | driver_register(&locomo_device_driver); | ||
1036 | return ret; | ||
1037 | } | ||
1038 | |||
1039 | static void __exit locomo_exit(void) | ||
1040 | { | ||
1041 | driver_unregister(&locomo_device_driver); | ||
1042 | bus_unregister(&locomo_bus_type); | ||
1043 | } | ||
1044 | |||
1045 | module_init(locomo_init); | ||
1046 | module_exit(locomo_exit); | ||
1047 | |||
1048 | MODULE_DESCRIPTION("Sharp LoCoMo core driver"); | ||
1049 | MODULE_LICENSE("GPL"); | ||
1050 | MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); | ||
1051 | |||
1052 | EXPORT_SYMBOL(locomo_driver_register); | ||
1053 | EXPORT_SYMBOL(locomo_driver_unregister); | ||
1054 | EXPORT_SYMBOL(locomo_gpio_set_dir); | ||
1055 | EXPORT_SYMBOL(locomo_gpio_read_level); | ||
1056 | EXPORT_SYMBOL(locomo_gpio_read_output); | ||
1057 | EXPORT_SYMBOL(locomo_gpio_write); | ||
1058 | EXPORT_SYMBOL(locomo_m62332_senddata); | ||
diff --git a/arch/arm/common/rtctime.c b/arch/arm/common/rtctime.c new file mode 100644 index 000000000000..c397e71f938d --- /dev/null +++ b/arch/arm/common/rtctime.c | |||
@@ -0,0 +1,506 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/common/rtctime.c | ||
3 | * | ||
4 | * Copyright (C) 2003 Deep Blue Solutions Ltd. | ||
5 | * Based on sa1100-rtc.c, Nils Faerber, CIH, Nicolas Pitre. | ||
6 | * Based on rtc.c by Paul Gortmaker | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/time.h> | ||
15 | #include <linux/rtc.h> | ||
16 | #include <linux/poll.h> | ||
17 | #include <linux/proc_fs.h> | ||
18 | #include <linux/miscdevice.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | #include <linux/device.h> | ||
21 | |||
22 | #include <asm/rtc.h> | ||
23 | #include <asm/semaphore.h> | ||
24 | |||
25 | static DECLARE_WAIT_QUEUE_HEAD(rtc_wait); | ||
26 | static struct fasync_struct *rtc_async_queue; | ||
27 | |||
28 | /* | ||
29 | * rtc_lock protects rtc_irq_data | ||
30 | */ | ||
31 | static DEFINE_SPINLOCK(rtc_lock); | ||
32 | static unsigned long rtc_irq_data; | ||
33 | |||
34 | /* | ||
35 | * rtc_sem protects rtc_inuse and rtc_ops | ||
36 | */ | ||
37 | static DECLARE_MUTEX(rtc_sem); | ||
38 | static unsigned long rtc_inuse; | ||
39 | static struct rtc_ops *rtc_ops; | ||
40 | |||
41 | #define rtc_epoch 1900UL | ||
42 | |||
43 | static const unsigned char days_in_month[] = { | ||
44 | 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 | ||
45 | }; | ||
46 | |||
47 | #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) | ||
48 | #define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400)) | ||
49 | |||
50 | static int month_days(unsigned int month, unsigned int year) | ||
51 | { | ||
52 | return days_in_month[month] + (LEAP_YEAR(year) && month == 1); | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. | ||
57 | */ | ||
58 | void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) | ||
59 | { | ||
60 | int days, month, year; | ||
61 | |||
62 | days = time / 86400; | ||
63 | time -= days * 86400; | ||
64 | |||
65 | tm->tm_wday = (days + 4) % 7; | ||
66 | |||
67 | year = 1970 + days / 365; | ||
68 | days -= (year - 1970) * 365 | ||
69 | + LEAPS_THRU_END_OF(year - 1) | ||
70 | - LEAPS_THRU_END_OF(1970 - 1); | ||
71 | if (days < 0) { | ||
72 | year -= 1; | ||
73 | days += 365 + LEAP_YEAR(year); | ||
74 | } | ||
75 | tm->tm_year = year - 1900; | ||
76 | tm->tm_yday = days + 1; | ||
77 | |||
78 | for (month = 0; month < 11; month++) { | ||
79 | int newdays; | ||
80 | |||
81 | newdays = days - month_days(month, year); | ||
82 | if (newdays < 0) | ||
83 | break; | ||
84 | days = newdays; | ||
85 | } | ||
86 | tm->tm_mon = month; | ||
87 | tm->tm_mday = days + 1; | ||
88 | |||
89 | tm->tm_hour = time / 3600; | ||
90 | time -= tm->tm_hour * 3600; | ||
91 | tm->tm_min = time / 60; | ||
92 | tm->tm_sec = time - tm->tm_min * 60; | ||
93 | } | ||
94 | EXPORT_SYMBOL(rtc_time_to_tm); | ||
95 | |||
96 | /* | ||
97 | * Does the rtc_time represent a valid date/time? | ||
98 | */ | ||
99 | int rtc_valid_tm(struct rtc_time *tm) | ||
100 | { | ||
101 | if (tm->tm_year < 70 || | ||
102 | tm->tm_mon >= 12 || | ||
103 | tm->tm_mday < 1 || | ||
104 | tm->tm_mday > month_days(tm->tm_mon, tm->tm_year + 1900) || | ||
105 | tm->tm_hour >= 24 || | ||
106 | tm->tm_min >= 60 || | ||
107 | tm->tm_sec >= 60) | ||
108 | return -EINVAL; | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | EXPORT_SYMBOL(rtc_valid_tm); | ||
113 | |||
114 | /* | ||
115 | * Convert Gregorian date to seconds since 01-01-1970 00:00:00. | ||
116 | */ | ||
117 | int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) | ||
118 | { | ||
119 | *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | ||
120 | tm->tm_hour, tm->tm_min, tm->tm_sec); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | EXPORT_SYMBOL(rtc_tm_to_time); | ||
125 | |||
126 | /* | ||
127 | * Calculate the next alarm time given the requested alarm time mask | ||
128 | * and the current time. | ||
129 | * | ||
130 | * FIXME: for now, we just copy the alarm time because we're lazy (and | ||
131 | * is therefore buggy - setting a 10am alarm at 8pm will not result in | ||
132 | * the alarm triggering.) | ||
133 | */ | ||
134 | void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc_time *alrm) | ||
135 | { | ||
136 | next->tm_year = now->tm_year; | ||
137 | next->tm_mon = now->tm_mon; | ||
138 | next->tm_mday = now->tm_mday; | ||
139 | next->tm_hour = alrm->tm_hour; | ||
140 | next->tm_min = alrm->tm_min; | ||
141 | next->tm_sec = alrm->tm_sec; | ||
142 | } | ||
143 | |||
144 | static inline void rtc_read_time(struct rtc_ops *ops, struct rtc_time *tm) | ||
145 | { | ||
146 | memset(tm, 0, sizeof(struct rtc_time)); | ||
147 | ops->read_time(tm); | ||
148 | } | ||
149 | |||
150 | static inline int rtc_set_time(struct rtc_ops *ops, struct rtc_time *tm) | ||
151 | { | ||
152 | int ret; | ||
153 | |||
154 | ret = rtc_valid_tm(tm); | ||
155 | if (ret == 0) | ||
156 | ret = ops->set_time(tm); | ||
157 | |||
158 | return ret; | ||
159 | } | ||
160 | |||
161 | static inline int rtc_read_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) | ||
162 | { | ||
163 | int ret = -EINVAL; | ||
164 | if (ops->read_alarm) { | ||
165 | memset(alrm, 0, sizeof(struct rtc_wkalrm)); | ||
166 | ops->read_alarm(alrm); | ||
167 | ret = 0; | ||
168 | } | ||
169 | return ret; | ||
170 | } | ||
171 | |||
172 | static inline int rtc_set_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm) | ||
173 | { | ||
174 | int ret = -EINVAL; | ||
175 | if (ops->set_alarm) | ||
176 | ret = ops->set_alarm(alrm); | ||
177 | return ret; | ||
178 | } | ||
179 | |||
180 | void rtc_update(unsigned long num, unsigned long events) | ||
181 | { | ||
182 | spin_lock(&rtc_lock); | ||
183 | rtc_irq_data = (rtc_irq_data + (num << 8)) | events; | ||
184 | spin_unlock(&rtc_lock); | ||
185 | |||
186 | wake_up_interruptible(&rtc_wait); | ||
187 | kill_fasync(&rtc_async_queue, SIGIO, POLL_IN); | ||
188 | } | ||
189 | EXPORT_SYMBOL(rtc_update); | ||
190 | |||
191 | |||
192 | static ssize_t | ||
193 | rtc_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) | ||
194 | { | ||
195 | DECLARE_WAITQUEUE(wait, current); | ||
196 | unsigned long data; | ||
197 | ssize_t ret; | ||
198 | |||
199 | if (count < sizeof(unsigned long)) | ||
200 | return -EINVAL; | ||
201 | |||
202 | add_wait_queue(&rtc_wait, &wait); | ||
203 | do { | ||
204 | __set_current_state(TASK_INTERRUPTIBLE); | ||
205 | |||
206 | spin_lock_irq(&rtc_lock); | ||
207 | data = rtc_irq_data; | ||
208 | rtc_irq_data = 0; | ||
209 | spin_unlock_irq(&rtc_lock); | ||
210 | |||
211 | if (data != 0) { | ||
212 | ret = 0; | ||
213 | break; | ||
214 | } | ||
215 | if (file->f_flags & O_NONBLOCK) { | ||
216 | ret = -EAGAIN; | ||
217 | break; | ||
218 | } | ||
219 | if (signal_pending(current)) { | ||
220 | ret = -ERESTARTSYS; | ||
221 | break; | ||
222 | } | ||
223 | schedule(); | ||
224 | } while (1); | ||
225 | set_current_state(TASK_RUNNING); | ||
226 | remove_wait_queue(&rtc_wait, &wait); | ||
227 | |||
228 | if (ret == 0) { | ||
229 | ret = put_user(data, (unsigned long __user *)buf); | ||
230 | if (ret == 0) | ||
231 | ret = sizeof(unsigned long); | ||
232 | } | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | static unsigned int rtc_poll(struct file *file, poll_table *wait) | ||
237 | { | ||
238 | unsigned long data; | ||
239 | |||
240 | poll_wait(file, &rtc_wait, wait); | ||
241 | |||
242 | spin_lock_irq(&rtc_lock); | ||
243 | data = rtc_irq_data; | ||
244 | spin_unlock_irq(&rtc_lock); | ||
245 | |||
246 | return data != 0 ? POLLIN | POLLRDNORM : 0; | ||
247 | } | ||
248 | |||
249 | static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | ||
250 | unsigned long arg) | ||
251 | { | ||
252 | struct rtc_ops *ops = file->private_data; | ||
253 | struct rtc_time tm; | ||
254 | struct rtc_wkalrm alrm; | ||
255 | void __user *uarg = (void __user *)arg; | ||
256 | int ret = -EINVAL; | ||
257 | |||
258 | switch (cmd) { | ||
259 | case RTC_ALM_READ: | ||
260 | ret = rtc_read_alarm(ops, &alrm); | ||
261 | if (ret) | ||
262 | break; | ||
263 | ret = copy_to_user(uarg, &alrm.time, sizeof(tm)); | ||
264 | if (ret) | ||
265 | ret = -EFAULT; | ||
266 | break; | ||
267 | |||
268 | case RTC_ALM_SET: | ||
269 | ret = copy_from_user(&alrm.time, uarg, sizeof(tm)); | ||
270 | if (ret) { | ||
271 | ret = -EFAULT; | ||
272 | break; | ||
273 | } | ||
274 | alrm.enabled = 0; | ||
275 | alrm.pending = 0; | ||
276 | alrm.time.tm_mday = -1; | ||
277 | alrm.time.tm_mon = -1; | ||
278 | alrm.time.tm_year = -1; | ||
279 | alrm.time.tm_wday = -1; | ||
280 | alrm.time.tm_yday = -1; | ||
281 | alrm.time.tm_isdst = -1; | ||
282 | ret = rtc_set_alarm(ops, &alrm); | ||
283 | break; | ||
284 | |||
285 | case RTC_RD_TIME: | ||
286 | rtc_read_time(ops, &tm); | ||
287 | ret = copy_to_user(uarg, &tm, sizeof(tm)); | ||
288 | if (ret) | ||
289 | ret = -EFAULT; | ||
290 | break; | ||
291 | |||
292 | case RTC_SET_TIME: | ||
293 | if (!capable(CAP_SYS_TIME)) { | ||
294 | ret = -EACCES; | ||
295 | break; | ||
296 | } | ||
297 | ret = copy_from_user(&tm, uarg, sizeof(tm)); | ||
298 | if (ret) { | ||
299 | ret = -EFAULT; | ||
300 | break; | ||
301 | } | ||
302 | ret = rtc_set_time(ops, &tm); | ||
303 | break; | ||
304 | |||
305 | case RTC_EPOCH_SET: | ||
306 | #ifndef rtc_epoch | ||
307 | /* | ||
308 | * There were no RTC clocks before 1900. | ||
309 | */ | ||
310 | if (arg < 1900) { | ||
311 | ret = -EINVAL; | ||
312 | break; | ||
313 | } | ||
314 | if (!capable(CAP_SYS_TIME)) { | ||
315 | ret = -EACCES; | ||
316 | break; | ||
317 | } | ||
318 | rtc_epoch = arg; | ||
319 | ret = 0; | ||
320 | #endif | ||
321 | break; | ||
322 | |||
323 | case RTC_EPOCH_READ: | ||
324 | ret = put_user(rtc_epoch, (unsigned long __user *)uarg); | ||
325 | break; | ||
326 | |||
327 | case RTC_WKALM_SET: | ||
328 | ret = copy_from_user(&alrm, uarg, sizeof(alrm)); | ||
329 | if (ret) { | ||
330 | ret = -EFAULT; | ||
331 | break; | ||
332 | } | ||
333 | ret = rtc_set_alarm(ops, &alrm); | ||
334 | break; | ||
335 | |||
336 | case RTC_WKALM_RD: | ||
337 | ret = rtc_read_alarm(ops, &alrm); | ||
338 | if (ret) | ||
339 | break; | ||
340 | ret = copy_to_user(uarg, &alrm, sizeof(alrm)); | ||
341 | if (ret) | ||
342 | ret = -EFAULT; | ||
343 | break; | ||
344 | |||
345 | default: | ||
346 | if (ops->ioctl) | ||
347 | ret = ops->ioctl(cmd, arg); | ||
348 | break; | ||
349 | } | ||
350 | return ret; | ||
351 | } | ||
352 | |||
353 | static int rtc_open(struct inode *inode, struct file *file) | ||
354 | { | ||
355 | int ret; | ||
356 | |||
357 | down(&rtc_sem); | ||
358 | |||
359 | if (rtc_inuse) { | ||
360 | ret = -EBUSY; | ||
361 | } else if (!rtc_ops || !try_module_get(rtc_ops->owner)) { | ||
362 | ret = -ENODEV; | ||
363 | } else { | ||
364 | file->private_data = rtc_ops; | ||
365 | |||
366 | ret = rtc_ops->open ? rtc_ops->open() : 0; | ||
367 | if (ret == 0) { | ||
368 | spin_lock_irq(&rtc_lock); | ||
369 | rtc_irq_data = 0; | ||
370 | spin_unlock_irq(&rtc_lock); | ||
371 | |||
372 | rtc_inuse = 1; | ||
373 | } | ||
374 | } | ||
375 | up(&rtc_sem); | ||
376 | |||
377 | return ret; | ||
378 | } | ||
379 | |||
380 | static int rtc_release(struct inode *inode, struct file *file) | ||
381 | { | ||
382 | struct rtc_ops *ops = file->private_data; | ||
383 | |||
384 | if (ops->release) | ||
385 | ops->release(); | ||
386 | |||
387 | spin_lock_irq(&rtc_lock); | ||
388 | rtc_irq_data = 0; | ||
389 | spin_unlock_irq(&rtc_lock); | ||
390 | |||
391 | module_put(rtc_ops->owner); | ||
392 | rtc_inuse = 0; | ||
393 | |||
394 | return 0; | ||
395 | } | ||
396 | |||
397 | static int rtc_fasync(int fd, struct file *file, int on) | ||
398 | { | ||
399 | return fasync_helper(fd, file, on, &rtc_async_queue); | ||
400 | } | ||
401 | |||
402 | static struct file_operations rtc_fops = { | ||
403 | .owner = THIS_MODULE, | ||
404 | .llseek = no_llseek, | ||
405 | .read = rtc_read, | ||
406 | .poll = rtc_poll, | ||
407 | .ioctl = rtc_ioctl, | ||
408 | .open = rtc_open, | ||
409 | .release = rtc_release, | ||
410 | .fasync = rtc_fasync, | ||
411 | }; | ||
412 | |||
413 | static struct miscdevice rtc_miscdev = { | ||
414 | .minor = RTC_MINOR, | ||
415 | .name = "rtc", | ||
416 | .fops = &rtc_fops, | ||
417 | }; | ||
418 | |||
419 | |||
420 | static int rtc_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) | ||
421 | { | ||
422 | struct rtc_ops *ops = data; | ||
423 | struct rtc_wkalrm alrm; | ||
424 | struct rtc_time tm; | ||
425 | char *p = page; | ||
426 | |||
427 | rtc_read_time(ops, &tm); | ||
428 | |||
429 | p += sprintf(p, | ||
430 | "rtc_time\t: %02d:%02d:%02d\n" | ||
431 | "rtc_date\t: %04d-%02d-%02d\n" | ||
432 | "rtc_epoch\t: %04lu\n", | ||
433 | tm.tm_hour, tm.tm_min, tm.tm_sec, | ||
434 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, | ||
435 | rtc_epoch); | ||
436 | |||
437 | if (rtc_read_alarm(ops, &alrm) == 0) { | ||
438 | p += sprintf(p, "alrm_time\t: "); | ||
439 | if ((unsigned int)alrm.time.tm_hour <= 24) | ||
440 | p += sprintf(p, "%02d:", alrm.time.tm_hour); | ||
441 | else | ||
442 | p += sprintf(p, "**:"); | ||
443 | if ((unsigned int)alrm.time.tm_min <= 59) | ||
444 | p += sprintf(p, "%02d:", alrm.time.tm_min); | ||
445 | else | ||
446 | p += sprintf(p, "**:"); | ||
447 | if ((unsigned int)alrm.time.tm_sec <= 59) | ||
448 | p += sprintf(p, "%02d\n", alrm.time.tm_sec); | ||
449 | else | ||
450 | p += sprintf(p, "**\n"); | ||
451 | |||
452 | p += sprintf(p, "alrm_date\t: "); | ||
453 | if ((unsigned int)alrm.time.tm_year <= 200) | ||
454 | p += sprintf(p, "%04d-", alrm.time.tm_year + 1900); | ||
455 | else | ||
456 | p += sprintf(p, "****-"); | ||
457 | if ((unsigned int)alrm.time.tm_mon <= 11) | ||
458 | p += sprintf(p, "%02d-", alrm.time.tm_mon + 1); | ||
459 | else | ||
460 | p += sprintf(p, "**-"); | ||
461 | if ((unsigned int)alrm.time.tm_mday <= 31) | ||
462 | p += sprintf(p, "%02d\n", alrm.time.tm_mday); | ||
463 | else | ||
464 | p += sprintf(p, "**\n"); | ||
465 | p += sprintf(p, "alrm_wakeup\t: %s\n", | ||
466 | alrm.enabled ? "yes" : "no"); | ||
467 | p += sprintf(p, "alrm_pending\t: %s\n", | ||
468 | alrm.pending ? "yes" : "no"); | ||
469 | } | ||
470 | |||
471 | if (ops->proc) | ||
472 | p += ops->proc(p); | ||
473 | |||
474 | return p - page; | ||
475 | } | ||
476 | |||
477 | int register_rtc(struct rtc_ops *ops) | ||
478 | { | ||
479 | int ret = -EBUSY; | ||
480 | |||
481 | down(&rtc_sem); | ||
482 | if (rtc_ops == NULL) { | ||
483 | rtc_ops = ops; | ||
484 | |||
485 | ret = misc_register(&rtc_miscdev); | ||
486 | if (ret == 0) | ||
487 | create_proc_read_entry("driver/rtc", 0, NULL, | ||
488 | rtc_read_proc, ops); | ||
489 | } | ||
490 | up(&rtc_sem); | ||
491 | |||
492 | return ret; | ||
493 | } | ||
494 | EXPORT_SYMBOL(register_rtc); | ||
495 | |||
496 | void unregister_rtc(struct rtc_ops *rtc) | ||
497 | { | ||
498 | down(&rtc_sem); | ||
499 | if (rtc == rtc_ops) { | ||
500 | remove_proc_entry("driver/rtc", NULL); | ||
501 | misc_deregister(&rtc_miscdev); | ||
502 | rtc_ops = NULL; | ||
503 | } | ||
504 | up(&rtc_sem); | ||
505 | } | ||
506 | EXPORT_SYMBOL(unregister_rtc); | ||
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c new file mode 100644 index 000000000000..21fce3414ed1 --- /dev/null +++ b/arch/arm/common/sa1111.c | |||
@@ -0,0 +1,1292 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-sa1100/sa1111.c | ||
3 | * | ||
4 | * SA1111 support | ||
5 | * | ||
6 | * Original code by John Dorsey | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * This file contains all generic SA1111 support. | ||
13 | * | ||
14 | * All initialization functions provided here are intended to be called | ||
15 | * from machine specific code with proper arguments when required. | ||
16 | */ | ||
17 | #include <linux/config.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/ptrace.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/spinlock.h> | ||
28 | #include <linux/dma-mapping.h> | ||
29 | |||
30 | #include <asm/hardware.h> | ||
31 | #include <asm/mach-types.h> | ||
32 | #include <asm/io.h> | ||
33 | #include <asm/irq.h> | ||
34 | #include <asm/mach/irq.h> | ||
35 | |||
36 | #include <asm/hardware/sa1111.h> | ||
37 | |||
38 | #ifdef CONFIG_ARCH_PXA | ||
39 | #include <asm/arch/pxa-regs.h> | ||
40 | #endif | ||
41 | |||
42 | extern void __init sa1110_mb_enable(void); | ||
43 | |||
44 | /* | ||
45 | * We keep the following data for the overall SA1111. Note that the | ||
46 | * struct device and struct resource are "fake"; they should be supplied | ||
47 | * by the bus above us. However, in the interests of getting all SA1111 | ||
48 | * drivers converted over to the device model, we provide this as an | ||
49 | * anchor point for all the other drivers. | ||
50 | */ | ||
51 | struct sa1111 { | ||
52 | struct device *dev; | ||
53 | unsigned long phys; | ||
54 | int irq; | ||
55 | spinlock_t lock; | ||
56 | void __iomem *base; | ||
57 | }; | ||
58 | |||
59 | /* | ||
60 | * We _really_ need to eliminate this. Its only users | ||
61 | * are the PWM and DMA checking code. | ||
62 | */ | ||
63 | static struct sa1111 *g_sa1111; | ||
64 | |||
65 | struct sa1111_dev_info { | ||
66 | unsigned long offset; | ||
67 | unsigned long skpcr_mask; | ||
68 | unsigned int devid; | ||
69 | unsigned int irq[6]; | ||
70 | }; | ||
71 | |||
72 | static struct sa1111_dev_info sa1111_devices[] = { | ||
73 | { | ||
74 | .offset = SA1111_USB, | ||
75 | .skpcr_mask = SKPCR_UCLKEN, | ||
76 | .devid = SA1111_DEVID_USB, | ||
77 | .irq = { | ||
78 | IRQ_USBPWR, | ||
79 | IRQ_HCIM, | ||
80 | IRQ_HCIBUFFACC, | ||
81 | IRQ_HCIRMTWKP, | ||
82 | IRQ_NHCIMFCIR, | ||
83 | IRQ_USB_PORT_RESUME | ||
84 | }, | ||
85 | }, | ||
86 | { | ||
87 | .offset = 0x0600, | ||
88 | .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN, | ||
89 | .devid = SA1111_DEVID_SAC, | ||
90 | .irq = { | ||
91 | AUDXMTDMADONEA, | ||
92 | AUDXMTDMADONEB, | ||
93 | AUDRCVDMADONEA, | ||
94 | AUDRCVDMADONEB | ||
95 | }, | ||
96 | }, | ||
97 | { | ||
98 | .offset = 0x0800, | ||
99 | .skpcr_mask = SKPCR_SCLKEN, | ||
100 | .devid = SA1111_DEVID_SSP, | ||
101 | }, | ||
102 | { | ||
103 | .offset = SA1111_KBD, | ||
104 | .skpcr_mask = SKPCR_PTCLKEN, | ||
105 | .devid = SA1111_DEVID_PS2, | ||
106 | .irq = { | ||
107 | IRQ_TPRXINT, | ||
108 | IRQ_TPTXINT | ||
109 | }, | ||
110 | }, | ||
111 | { | ||
112 | .offset = SA1111_MSE, | ||
113 | .skpcr_mask = SKPCR_PMCLKEN, | ||
114 | .devid = SA1111_DEVID_PS2, | ||
115 | .irq = { | ||
116 | IRQ_MSRXINT, | ||
117 | IRQ_MSTXINT | ||
118 | }, | ||
119 | }, | ||
120 | { | ||
121 | .offset = 0x1800, | ||
122 | .skpcr_mask = 0, | ||
123 | .devid = SA1111_DEVID_PCMCIA, | ||
124 | .irq = { | ||
125 | IRQ_S0_READY_NINT, | ||
126 | IRQ_S0_CD_VALID, | ||
127 | IRQ_S0_BVD1_STSCHG, | ||
128 | IRQ_S1_READY_NINT, | ||
129 | IRQ_S1_CD_VALID, | ||
130 | IRQ_S1_BVD1_STSCHG, | ||
131 | }, | ||
132 | }, | ||
133 | }; | ||
134 | |||
135 | /* | ||
136 | * SA1111 interrupt support. Since clearing an IRQ while there are | ||
137 | * active IRQs causes the interrupt output to pulse, the upper levels | ||
138 | * will call us again if there are more interrupts to process. | ||
139 | */ | ||
140 | static void | ||
141 | sa1111_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs) | ||
142 | { | ||
143 | unsigned int stat0, stat1, i; | ||
144 | void __iomem *base = desc->data; | ||
145 | |||
146 | stat0 = sa1111_readl(base + SA1111_INTSTATCLR0); | ||
147 | stat1 = sa1111_readl(base + SA1111_INTSTATCLR1); | ||
148 | |||
149 | sa1111_writel(stat0, base + SA1111_INTSTATCLR0); | ||
150 | |||
151 | desc->chip->ack(irq); | ||
152 | |||
153 | sa1111_writel(stat1, base + SA1111_INTSTATCLR1); | ||
154 | |||
155 | if (stat0 == 0 && stat1 == 0) { | ||
156 | do_bad_IRQ(irq, desc, regs); | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | for (i = IRQ_SA1111_START; stat0; i++, stat0 >>= 1) | ||
161 | if (stat0 & 1) | ||
162 | do_edge_IRQ(i, irq_desc + i, regs); | ||
163 | |||
164 | for (i = IRQ_SA1111_START + 32; stat1; i++, stat1 >>= 1) | ||
165 | if (stat1 & 1) | ||
166 | do_edge_IRQ(i, irq_desc + i, regs); | ||
167 | |||
168 | /* For level-based interrupts */ | ||
169 | desc->chip->unmask(irq); | ||
170 | } | ||
171 | |||
172 | #define SA1111_IRQMASK_LO(x) (1 << (x - IRQ_SA1111_START)) | ||
173 | #define SA1111_IRQMASK_HI(x) (1 << (x - IRQ_SA1111_START - 32)) | ||
174 | |||
175 | static void sa1111_ack_irq(unsigned int irq) | ||
176 | { | ||
177 | } | ||
178 | |||
179 | static void sa1111_mask_lowirq(unsigned int irq) | ||
180 | { | ||
181 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
182 | unsigned long ie0; | ||
183 | |||
184 | ie0 = sa1111_readl(mapbase + SA1111_INTEN0); | ||
185 | ie0 &= ~SA1111_IRQMASK_LO(irq); | ||
186 | writel(ie0, mapbase + SA1111_INTEN0); | ||
187 | } | ||
188 | |||
189 | static void sa1111_unmask_lowirq(unsigned int irq) | ||
190 | { | ||
191 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
192 | unsigned long ie0; | ||
193 | |||
194 | ie0 = sa1111_readl(mapbase + SA1111_INTEN0); | ||
195 | ie0 |= SA1111_IRQMASK_LO(irq); | ||
196 | sa1111_writel(ie0, mapbase + SA1111_INTEN0); | ||
197 | } | ||
198 | |||
199 | /* | ||
200 | * Attempt to re-trigger the interrupt. The SA1111 contains a register | ||
201 | * (INTSET) which claims to do this. However, in practice no amount of | ||
202 | * manipulation of INTEN and INTSET guarantees that the interrupt will | ||
203 | * be triggered. In fact, its very difficult, if not impossible to get | ||
204 | * INTSET to re-trigger the interrupt. | ||
205 | */ | ||
206 | static int sa1111_retrigger_lowirq(unsigned int irq) | ||
207 | { | ||
208 | unsigned int mask = SA1111_IRQMASK_LO(irq); | ||
209 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
210 | unsigned long ip0; | ||
211 | int i; | ||
212 | |||
213 | ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); | ||
214 | for (i = 0; i < 8; i++) { | ||
215 | sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0); | ||
216 | sa1111_writel(ip0, mapbase + SA1111_INTPOL0); | ||
217 | if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) | ||
218 | break; | ||
219 | } | ||
220 | |||
221 | if (i == 8) | ||
222 | printk(KERN_ERR "Danger Will Robinson: failed to " | ||
223 | "re-trigger IRQ%d\n", irq); | ||
224 | return i == 8 ? -1 : 0; | ||
225 | } | ||
226 | |||
227 | static int sa1111_type_lowirq(unsigned int irq, unsigned int flags) | ||
228 | { | ||
229 | unsigned int mask = SA1111_IRQMASK_LO(irq); | ||
230 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
231 | unsigned long ip0; | ||
232 | |||
233 | if (flags == IRQT_PROBE) | ||
234 | return 0; | ||
235 | |||
236 | if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0) | ||
237 | return -EINVAL; | ||
238 | |||
239 | ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); | ||
240 | if (flags & __IRQT_RISEDGE) | ||
241 | ip0 &= ~mask; | ||
242 | else | ||
243 | ip0 |= mask; | ||
244 | sa1111_writel(ip0, mapbase + SA1111_INTPOL0); | ||
245 | sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0); | ||
246 | |||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | static int sa1111_wake_lowirq(unsigned int irq, unsigned int on) | ||
251 | { | ||
252 | unsigned int mask = SA1111_IRQMASK_LO(irq); | ||
253 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
254 | unsigned long we0; | ||
255 | |||
256 | we0 = sa1111_readl(mapbase + SA1111_WAKEEN0); | ||
257 | if (on) | ||
258 | we0 |= mask; | ||
259 | else | ||
260 | we0 &= ~mask; | ||
261 | sa1111_writel(we0, mapbase + SA1111_WAKEEN0); | ||
262 | |||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static struct irqchip sa1111_low_chip = { | ||
267 | .ack = sa1111_ack_irq, | ||
268 | .mask = sa1111_mask_lowirq, | ||
269 | .unmask = sa1111_unmask_lowirq, | ||
270 | .retrigger = sa1111_retrigger_lowirq, | ||
271 | .type = sa1111_type_lowirq, | ||
272 | .wake = sa1111_wake_lowirq, | ||
273 | }; | ||
274 | |||
275 | static void sa1111_mask_highirq(unsigned int irq) | ||
276 | { | ||
277 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
278 | unsigned long ie1; | ||
279 | |||
280 | ie1 = sa1111_readl(mapbase + SA1111_INTEN1); | ||
281 | ie1 &= ~SA1111_IRQMASK_HI(irq); | ||
282 | sa1111_writel(ie1, mapbase + SA1111_INTEN1); | ||
283 | } | ||
284 | |||
285 | static void sa1111_unmask_highirq(unsigned int irq) | ||
286 | { | ||
287 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
288 | unsigned long ie1; | ||
289 | |||
290 | ie1 = sa1111_readl(mapbase + SA1111_INTEN1); | ||
291 | ie1 |= SA1111_IRQMASK_HI(irq); | ||
292 | sa1111_writel(ie1, mapbase + SA1111_INTEN1); | ||
293 | } | ||
294 | |||
295 | /* | ||
296 | * Attempt to re-trigger the interrupt. The SA1111 contains a register | ||
297 | * (INTSET) which claims to do this. However, in practice no amount of | ||
298 | * manipulation of INTEN and INTSET guarantees that the interrupt will | ||
299 | * be triggered. In fact, its very difficult, if not impossible to get | ||
300 | * INTSET to re-trigger the interrupt. | ||
301 | */ | ||
302 | static int sa1111_retrigger_highirq(unsigned int irq) | ||
303 | { | ||
304 | unsigned int mask = SA1111_IRQMASK_HI(irq); | ||
305 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
306 | unsigned long ip1; | ||
307 | int i; | ||
308 | |||
309 | ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); | ||
310 | for (i = 0; i < 8; i++) { | ||
311 | sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1); | ||
312 | sa1111_writel(ip1, mapbase + SA1111_INTPOL1); | ||
313 | if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) | ||
314 | break; | ||
315 | } | ||
316 | |||
317 | if (i == 8) | ||
318 | printk(KERN_ERR "Danger Will Robinson: failed to " | ||
319 | "re-trigger IRQ%d\n", irq); | ||
320 | return i == 8 ? -1 : 0; | ||
321 | } | ||
322 | |||
323 | static int sa1111_type_highirq(unsigned int irq, unsigned int flags) | ||
324 | { | ||
325 | unsigned int mask = SA1111_IRQMASK_HI(irq); | ||
326 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
327 | unsigned long ip1; | ||
328 | |||
329 | if (flags == IRQT_PROBE) | ||
330 | return 0; | ||
331 | |||
332 | if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0) | ||
333 | return -EINVAL; | ||
334 | |||
335 | ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); | ||
336 | if (flags & __IRQT_RISEDGE) | ||
337 | ip1 &= ~mask; | ||
338 | else | ||
339 | ip1 |= mask; | ||
340 | sa1111_writel(ip1, mapbase + SA1111_INTPOL1); | ||
341 | sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1); | ||
342 | |||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | static int sa1111_wake_highirq(unsigned int irq, unsigned int on) | ||
347 | { | ||
348 | unsigned int mask = SA1111_IRQMASK_HI(irq); | ||
349 | void __iomem *mapbase = get_irq_chipdata(irq); | ||
350 | unsigned long we1; | ||
351 | |||
352 | we1 = sa1111_readl(mapbase + SA1111_WAKEEN1); | ||
353 | if (on) | ||
354 | we1 |= mask; | ||
355 | else | ||
356 | we1 &= ~mask; | ||
357 | sa1111_writel(we1, mapbase + SA1111_WAKEEN1); | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static struct irqchip sa1111_high_chip = { | ||
363 | .ack = sa1111_ack_irq, | ||
364 | .mask = sa1111_mask_highirq, | ||
365 | .unmask = sa1111_unmask_highirq, | ||
366 | .retrigger = sa1111_retrigger_highirq, | ||
367 | .type = sa1111_type_highirq, | ||
368 | .wake = sa1111_wake_highirq, | ||
369 | }; | ||
370 | |||
371 | static void sa1111_setup_irq(struct sa1111 *sachip) | ||
372 | { | ||
373 | void __iomem *irqbase = sachip->base + SA1111_INTC; | ||
374 | unsigned int irq; | ||
375 | |||
376 | /* | ||
377 | * We're guaranteed that this region hasn't been taken. | ||
378 | */ | ||
379 | request_mem_region(sachip->phys + SA1111_INTC, 512, "irq"); | ||
380 | |||
381 | /* disable all IRQs */ | ||
382 | sa1111_writel(0, irqbase + SA1111_INTEN0); | ||
383 | sa1111_writel(0, irqbase + SA1111_INTEN1); | ||
384 | sa1111_writel(0, irqbase + SA1111_WAKEEN0); | ||
385 | sa1111_writel(0, irqbase + SA1111_WAKEEN1); | ||
386 | |||
387 | /* | ||
388 | * detect on rising edge. Note: Feb 2001 Errata for SA1111 | ||
389 | * specifies that S0ReadyInt and S1ReadyInt should be '1'. | ||
390 | */ | ||
391 | sa1111_writel(0, irqbase + SA1111_INTPOL0); | ||
392 | sa1111_writel(SA1111_IRQMASK_HI(IRQ_S0_READY_NINT) | | ||
393 | SA1111_IRQMASK_HI(IRQ_S1_READY_NINT), | ||
394 | irqbase + SA1111_INTPOL1); | ||
395 | |||
396 | /* clear all IRQs */ | ||
397 | sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0); | ||
398 | sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1); | ||
399 | |||
400 | for (irq = IRQ_GPAIN0; irq <= SSPROR; irq++) { | ||
401 | set_irq_chip(irq, &sa1111_low_chip); | ||
402 | set_irq_chipdata(irq, irqbase); | ||
403 | set_irq_handler(irq, do_edge_IRQ); | ||
404 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
405 | } | ||
406 | |||
407 | for (irq = AUDXMTDMADONEA; irq <= IRQ_S1_BVD1_STSCHG; irq++) { | ||
408 | set_irq_chip(irq, &sa1111_high_chip); | ||
409 | set_irq_chipdata(irq, irqbase); | ||
410 | set_irq_handler(irq, do_edge_IRQ); | ||
411 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
412 | } | ||
413 | |||
414 | /* | ||
415 | * Register SA1111 interrupt | ||
416 | */ | ||
417 | set_irq_type(sachip->irq, IRQT_RISING); | ||
418 | set_irq_data(sachip->irq, irqbase); | ||
419 | set_irq_chained_handler(sachip->irq, sa1111_irq_handler); | ||
420 | } | ||
421 | |||
422 | /* | ||
423 | * Bring the SA1111 out of reset. This requires a set procedure: | ||
424 | * 1. nRESET asserted (by hardware) | ||
425 | * 2. CLK turned on from SA1110 | ||
426 | * 3. nRESET deasserted | ||
427 | * 4. VCO turned on, PLL_BYPASS turned off | ||
428 | * 5. Wait lock time, then assert RCLKEn | ||
429 | * 7. PCR set to allow clocking of individual functions | ||
430 | * | ||
431 | * Until we've done this, the only registers we can access are: | ||
432 | * SBI_SKCR | ||
433 | * SBI_SMCR | ||
434 | * SBI_SKID | ||
435 | */ | ||
436 | static void sa1111_wake(struct sa1111 *sachip) | ||
437 | { | ||
438 | unsigned long flags, r; | ||
439 | |||
440 | spin_lock_irqsave(&sachip->lock, flags); | ||
441 | |||
442 | #ifdef CONFIG_ARCH_SA1100 | ||
443 | /* | ||
444 | * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111: | ||
445 | * (SA-1110 Developer's Manual, section 9.1.2.1) | ||
446 | */ | ||
447 | GAFR |= GPIO_32_768kHz; | ||
448 | GPDR |= GPIO_32_768kHz; | ||
449 | TUCR = TUCR_3_6864MHz; | ||
450 | #elif CONFIG_ARCH_PXA | ||
451 | pxa_gpio_mode(GPIO11_3_6MHz_MD); | ||
452 | #else | ||
453 | #error missing clock setup | ||
454 | #endif | ||
455 | |||
456 | /* | ||
457 | * Turn VCO on, and disable PLL Bypass. | ||
458 | */ | ||
459 | r = sa1111_readl(sachip->base + SA1111_SKCR); | ||
460 | r &= ~SKCR_VCO_OFF; | ||
461 | sa1111_writel(r, sachip->base + SA1111_SKCR); | ||
462 | r |= SKCR_PLL_BYPASS | SKCR_OE_EN; | ||
463 | sa1111_writel(r, sachip->base + SA1111_SKCR); | ||
464 | |||
465 | /* | ||
466 | * Wait lock time. SA1111 manual _doesn't_ | ||
467 | * specify a figure for this! We choose 100us. | ||
468 | */ | ||
469 | udelay(100); | ||
470 | |||
471 | /* | ||
472 | * Enable RCLK. We also ensure that RDYEN is set. | ||
473 | */ | ||
474 | r |= SKCR_RCLKEN | SKCR_RDYEN; | ||
475 | sa1111_writel(r, sachip->base + SA1111_SKCR); | ||
476 | |||
477 | /* | ||
478 | * Wait 14 RCLK cycles for the chip to finish coming out | ||
479 | * of reset. (RCLK=24MHz). This is 590ns. | ||
480 | */ | ||
481 | udelay(1); | ||
482 | |||
483 | /* | ||
484 | * Ensure all clocks are initially off. | ||
485 | */ | ||
486 | sa1111_writel(0, sachip->base + SA1111_SKPCR); | ||
487 | |||
488 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
489 | } | ||
490 | |||
491 | #ifdef CONFIG_ARCH_SA1100 | ||
492 | |||
493 | static u32 sa1111_dma_mask[] = { | ||
494 | ~0, | ||
495 | ~(1 << 20), | ||
496 | ~(1 << 23), | ||
497 | ~(1 << 24), | ||
498 | ~(1 << 25), | ||
499 | ~(1 << 20), | ||
500 | ~(1 << 20), | ||
501 | 0, | ||
502 | }; | ||
503 | |||
504 | /* | ||
505 | * Configure the SA1111 shared memory controller. | ||
506 | */ | ||
507 | void | ||
508 | sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac, | ||
509 | unsigned int cas_latency) | ||
510 | { | ||
511 | unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC); | ||
512 | |||
513 | if (cas_latency == 3) | ||
514 | smcr |= SMCR_CLAT; | ||
515 | |||
516 | sa1111_writel(smcr, sachip->base + SA1111_SMCR); | ||
517 | |||
518 | /* | ||
519 | * Now clear the bits in the DMA mask to work around the SA1111 | ||
520 | * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion | ||
521 | * Chip Specification Update, June 2000, Erratum #7). | ||
522 | */ | ||
523 | if (sachip->dev->dma_mask) | ||
524 | *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2]; | ||
525 | |||
526 | sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2]; | ||
527 | } | ||
528 | |||
529 | #endif | ||
530 | |||
531 | static void sa1111_dev_release(struct device *_dev) | ||
532 | { | ||
533 | struct sa1111_dev *dev = SA1111_DEV(_dev); | ||
534 | |||
535 | release_resource(&dev->res); | ||
536 | kfree(dev); | ||
537 | } | ||
538 | |||
539 | static int | ||
540 | sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent, | ||
541 | struct sa1111_dev_info *info) | ||
542 | { | ||
543 | struct sa1111_dev *dev; | ||
544 | int ret; | ||
545 | |||
546 | dev = kmalloc(sizeof(struct sa1111_dev), GFP_KERNEL); | ||
547 | if (!dev) { | ||
548 | ret = -ENOMEM; | ||
549 | goto out; | ||
550 | } | ||
551 | memset(dev, 0, sizeof(struct sa1111_dev)); | ||
552 | |||
553 | snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), | ||
554 | "%4.4lx", info->offset); | ||
555 | |||
556 | dev->devid = info->devid; | ||
557 | dev->dev.parent = sachip->dev; | ||
558 | dev->dev.bus = &sa1111_bus_type; | ||
559 | dev->dev.release = sa1111_dev_release; | ||
560 | dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask; | ||
561 | dev->res.start = sachip->phys + info->offset; | ||
562 | dev->res.end = dev->res.start + 511; | ||
563 | dev->res.name = dev->dev.bus_id; | ||
564 | dev->res.flags = IORESOURCE_MEM; | ||
565 | dev->mapbase = sachip->base + info->offset; | ||
566 | dev->skpcr_mask = info->skpcr_mask; | ||
567 | memmove(dev->irq, info->irq, sizeof(dev->irq)); | ||
568 | |||
569 | ret = request_resource(parent, &dev->res); | ||
570 | if (ret) { | ||
571 | printk("SA1111: failed to allocate resource for %s\n", | ||
572 | dev->res.name); | ||
573 | kfree(dev); | ||
574 | goto out; | ||
575 | } | ||
576 | |||
577 | |||
578 | ret = device_register(&dev->dev); | ||
579 | if (ret) { | ||
580 | release_resource(&dev->res); | ||
581 | kfree(dev); | ||
582 | goto out; | ||
583 | } | ||
584 | |||
585 | /* | ||
586 | * If the parent device has a DMA mask associated with it, | ||
587 | * propagate it down to the children. | ||
588 | */ | ||
589 | if (sachip->dev->dma_mask) { | ||
590 | dev->dma_mask = *sachip->dev->dma_mask; | ||
591 | dev->dev.dma_mask = &dev->dma_mask; | ||
592 | |||
593 | if (dev->dma_mask != 0xffffffffUL) { | ||
594 | ret = dmabounce_register_dev(&dev->dev, 1024, 4096); | ||
595 | if (ret) { | ||
596 | printk("SA1111: Failed to register %s with dmabounce", dev->dev.bus_id); | ||
597 | device_unregister(&dev->dev); | ||
598 | } | ||
599 | } | ||
600 | } | ||
601 | |||
602 | out: | ||
603 | return ret; | ||
604 | } | ||
605 | |||
606 | /** | ||
607 | * sa1111_probe - probe for a single SA1111 chip. | ||
608 | * @phys_addr: physical address of device. | ||
609 | * | ||
610 | * Probe for a SA1111 chip. This must be called | ||
611 | * before any other SA1111-specific code. | ||
612 | * | ||
613 | * Returns: | ||
614 | * %-ENODEV device not found. | ||
615 | * %-EBUSY physical address already marked in-use. | ||
616 | * %0 successful. | ||
617 | */ | ||
618 | static int | ||
619 | __sa1111_probe(struct device *me, struct resource *mem, int irq) | ||
620 | { | ||
621 | struct sa1111 *sachip; | ||
622 | unsigned long id; | ||
623 | unsigned int has_devs, val; | ||
624 | int i, ret = -ENODEV; | ||
625 | |||
626 | sachip = kmalloc(sizeof(struct sa1111), GFP_KERNEL); | ||
627 | if (!sachip) | ||
628 | return -ENOMEM; | ||
629 | |||
630 | memset(sachip, 0, sizeof(struct sa1111)); | ||
631 | |||
632 | spin_lock_init(&sachip->lock); | ||
633 | |||
634 | sachip->dev = me; | ||
635 | dev_set_drvdata(sachip->dev, sachip); | ||
636 | |||
637 | sachip->phys = mem->start; | ||
638 | sachip->irq = irq; | ||
639 | |||
640 | /* | ||
641 | * Map the whole region. This also maps the | ||
642 | * registers for our children. | ||
643 | */ | ||
644 | sachip->base = ioremap(mem->start, PAGE_SIZE * 2); | ||
645 | if (!sachip->base) { | ||
646 | ret = -ENOMEM; | ||
647 | goto out; | ||
648 | } | ||
649 | |||
650 | /* | ||
651 | * Probe for the chip. Only touch the SBI registers. | ||
652 | */ | ||
653 | id = sa1111_readl(sachip->base + SA1111_SKID); | ||
654 | if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { | ||
655 | printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id); | ||
656 | ret = -ENODEV; | ||
657 | goto unmap; | ||
658 | } | ||
659 | |||
660 | printk(KERN_INFO "SA1111 Microprocessor Companion Chip: " | ||
661 | "silicon revision %lx, metal revision %lx\n", | ||
662 | (id & SKID_SIREV_MASK)>>4, (id & SKID_MTREV_MASK)); | ||
663 | |||
664 | /* | ||
665 | * We found it. Wake the chip up, and initialise. | ||
666 | */ | ||
667 | sa1111_wake(sachip); | ||
668 | |||
669 | #ifdef CONFIG_ARCH_SA1100 | ||
670 | /* | ||
671 | * The SDRAM configuration of the SA1110 and the SA1111 must | ||
672 | * match. This is very important to ensure that SA1111 accesses | ||
673 | * don't corrupt the SDRAM. Note that this ungates the SA1111's | ||
674 | * MBGNT signal, so we must have called sa1110_mb_disable() | ||
675 | * beforehand. | ||
676 | */ | ||
677 | sa1111_configure_smc(sachip, 1, | ||
678 | FExtr(MDCNFG, MDCNFG_SA1110_DRAC0), | ||
679 | FExtr(MDCNFG, MDCNFG_SA1110_TDL0)); | ||
680 | |||
681 | /* | ||
682 | * We only need to turn on DCLK whenever we want to use the | ||
683 | * DMA. It can otherwise be held firmly in the off position. | ||
684 | * (currently, we always enable it.) | ||
685 | */ | ||
686 | val = sa1111_readl(sachip->base + SA1111_SKPCR); | ||
687 | sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR); | ||
688 | |||
689 | /* | ||
690 | * Enable the SA1110 memory bus request and grant signals. | ||
691 | */ | ||
692 | sa1110_mb_enable(); | ||
693 | #endif | ||
694 | |||
695 | /* | ||
696 | * The interrupt controller must be initialised before any | ||
697 | * other device to ensure that the interrupts are available. | ||
698 | */ | ||
699 | if (sachip->irq != NO_IRQ) | ||
700 | sa1111_setup_irq(sachip); | ||
701 | |||
702 | g_sa1111 = sachip; | ||
703 | |||
704 | has_devs = ~0; | ||
705 | if (machine_is_assabet() || machine_is_jornada720() || | ||
706 | machine_is_badge4()) | ||
707 | has_devs &= ~(1 << 4); | ||
708 | else | ||
709 | has_devs &= ~(1 << 1); | ||
710 | |||
711 | for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++) | ||
712 | if (has_devs & (1 << i)) | ||
713 | sa1111_init_one_child(sachip, mem, &sa1111_devices[i]); | ||
714 | |||
715 | return 0; | ||
716 | |||
717 | unmap: | ||
718 | iounmap(sachip->base); | ||
719 | out: | ||
720 | kfree(sachip); | ||
721 | return ret; | ||
722 | } | ||
723 | |||
724 | static void __sa1111_remove(struct sa1111 *sachip) | ||
725 | { | ||
726 | struct list_head *l, *n; | ||
727 | void __iomem *irqbase = sachip->base + SA1111_INTC; | ||
728 | |||
729 | list_for_each_safe(l, n, &sachip->dev->children) { | ||
730 | struct device *d = list_to_dev(l); | ||
731 | |||
732 | device_unregister(d); | ||
733 | } | ||
734 | |||
735 | /* disable all IRQs */ | ||
736 | sa1111_writel(0, irqbase + SA1111_INTEN0); | ||
737 | sa1111_writel(0, irqbase + SA1111_INTEN1); | ||
738 | sa1111_writel(0, irqbase + SA1111_WAKEEN0); | ||
739 | sa1111_writel(0, irqbase + SA1111_WAKEEN1); | ||
740 | |||
741 | if (sachip->irq != NO_IRQ) { | ||
742 | set_irq_chained_handler(sachip->irq, NULL); | ||
743 | set_irq_data(sachip->irq, NULL); | ||
744 | |||
745 | release_mem_region(sachip->phys + SA1111_INTC, 512); | ||
746 | } | ||
747 | |||
748 | iounmap(sachip->base); | ||
749 | kfree(sachip); | ||
750 | } | ||
751 | |||
752 | /* | ||
753 | * According to the "Intel StrongARM SA-1111 Microprocessor Companion | ||
754 | * Chip Specification Update" (June 2000), erratum #7, there is a | ||
755 | * significant bug in the SA1111 SDRAM shared memory controller. If | ||
756 | * an access to a region of memory above 1MB relative to the bank base, | ||
757 | * it is important that address bit 10 _NOT_ be asserted. Depending | ||
758 | * on the configuration of the RAM, bit 10 may correspond to one | ||
759 | * of several different (processor-relative) address bits. | ||
760 | * | ||
761 | * This routine only identifies whether or not a given DMA address | ||
762 | * is susceptible to the bug. | ||
763 | * | ||
764 | * This should only get called for sa1111_device types due to the | ||
765 | * way we configure our device dma_masks. | ||
766 | */ | ||
767 | int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size) | ||
768 | { | ||
769 | /* | ||
770 | * Section 4.6 of the "Intel StrongARM SA-1111 Development Module | ||
771 | * User's Guide" mentions that jumpers R51 and R52 control the | ||
772 | * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or | ||
773 | * SDRAM bank 1 on Neponset). The default configuration selects | ||
774 | * Assabet, so any address in bank 1 is necessarily invalid. | ||
775 | */ | ||
776 | return ((machine_is_assabet() || machine_is_pfs168()) && | ||
777 | (addr >= 0xc8000000 || (addr + size) >= 0xc8000000)); | ||
778 | } | ||
779 | |||
780 | struct sa1111_save_data { | ||
781 | unsigned int skcr; | ||
782 | unsigned int skpcr; | ||
783 | unsigned int skcdr; | ||
784 | unsigned char skaud; | ||
785 | unsigned char skpwm0; | ||
786 | unsigned char skpwm1; | ||
787 | |||
788 | /* | ||
789 | * Interrupt controller | ||
790 | */ | ||
791 | unsigned int intpol0; | ||
792 | unsigned int intpol1; | ||
793 | unsigned int inten0; | ||
794 | unsigned int inten1; | ||
795 | unsigned int wakepol0; | ||
796 | unsigned int wakepol1; | ||
797 | unsigned int wakeen0; | ||
798 | unsigned int wakeen1; | ||
799 | }; | ||
800 | |||
801 | #ifdef CONFIG_PM | ||
802 | |||
803 | static int sa1111_suspend(struct device *dev, pm_message_t state, u32 level) | ||
804 | { | ||
805 | struct sa1111 *sachip = dev_get_drvdata(dev); | ||
806 | struct sa1111_save_data *save; | ||
807 | unsigned long flags; | ||
808 | unsigned int val; | ||
809 | void __iomem *base; | ||
810 | |||
811 | if (level != SUSPEND_DISABLE) | ||
812 | return 0; | ||
813 | |||
814 | save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL); | ||
815 | if (!save) | ||
816 | return -ENOMEM; | ||
817 | dev->power.saved_state = save; | ||
818 | |||
819 | spin_lock_irqsave(&sachip->lock, flags); | ||
820 | |||
821 | /* | ||
822 | * Save state. | ||
823 | */ | ||
824 | base = sachip->base; | ||
825 | save->skcr = sa1111_readl(base + SA1111_SKCR); | ||
826 | save->skpcr = sa1111_readl(base + SA1111_SKPCR); | ||
827 | save->skcdr = sa1111_readl(base + SA1111_SKCDR); | ||
828 | save->skaud = sa1111_readl(base + SA1111_SKAUD); | ||
829 | save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0); | ||
830 | save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1); | ||
831 | |||
832 | base = sachip->base + SA1111_INTC; | ||
833 | save->intpol0 = sa1111_readl(base + SA1111_INTPOL0); | ||
834 | save->intpol1 = sa1111_readl(base + SA1111_INTPOL1); | ||
835 | save->inten0 = sa1111_readl(base + SA1111_INTEN0); | ||
836 | save->inten1 = sa1111_readl(base + SA1111_INTEN1); | ||
837 | save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0); | ||
838 | save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1); | ||
839 | save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0); | ||
840 | save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1); | ||
841 | |||
842 | /* | ||
843 | * Disable. | ||
844 | */ | ||
845 | val = sa1111_readl(sachip->base + SA1111_SKCR); | ||
846 | sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR); | ||
847 | sa1111_writel(0, sachip->base + SA1111_SKPWM0); | ||
848 | sa1111_writel(0, sachip->base + SA1111_SKPWM1); | ||
849 | |||
850 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
851 | |||
852 | return 0; | ||
853 | } | ||
854 | |||
855 | /* | ||
856 | * sa1111_resume - Restore the SA1111 device state. | ||
857 | * @dev: device to restore | ||
858 | * @level: resume level | ||
859 | * | ||
860 | * Restore the general state of the SA1111; clock control and | ||
861 | * interrupt controller. Other parts of the SA1111 must be | ||
862 | * restored by their respective drivers, and must be called | ||
863 | * via LDM after this function. | ||
864 | */ | ||
865 | static int sa1111_resume(struct device *dev, u32 level) | ||
866 | { | ||
867 | struct sa1111 *sachip = dev_get_drvdata(dev); | ||
868 | struct sa1111_save_data *save; | ||
869 | unsigned long flags, id; | ||
870 | void __iomem *base; | ||
871 | |||
872 | if (level != RESUME_ENABLE) | ||
873 | return 0; | ||
874 | |||
875 | save = (struct sa1111_save_data *)dev->power.saved_state; | ||
876 | if (!save) | ||
877 | return 0; | ||
878 | |||
879 | spin_lock_irqsave(&sachip->lock, flags); | ||
880 | |||
881 | /* | ||
882 | * Ensure that the SA1111 is still here. | ||
883 | * FIXME: shouldn't do this here. | ||
884 | */ | ||
885 | id = sa1111_readl(sachip->base + SA1111_SKID); | ||
886 | if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { | ||
887 | __sa1111_remove(sachip); | ||
888 | dev_set_drvdata(dev, NULL); | ||
889 | kfree(save); | ||
890 | return 0; | ||
891 | } | ||
892 | |||
893 | /* | ||
894 | * First of all, wake up the chip. | ||
895 | */ | ||
896 | sa1111_wake(sachip); | ||
897 | sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0); | ||
898 | sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1); | ||
899 | |||
900 | base = sachip->base; | ||
901 | sa1111_writel(save->skcr, base + SA1111_SKCR); | ||
902 | sa1111_writel(save->skpcr, base + SA1111_SKPCR); | ||
903 | sa1111_writel(save->skcdr, base + SA1111_SKCDR); | ||
904 | sa1111_writel(save->skaud, base + SA1111_SKAUD); | ||
905 | sa1111_writel(save->skpwm0, base + SA1111_SKPWM0); | ||
906 | sa1111_writel(save->skpwm1, base + SA1111_SKPWM1); | ||
907 | |||
908 | base = sachip->base + SA1111_INTC; | ||
909 | sa1111_writel(save->intpol0, base + SA1111_INTPOL0); | ||
910 | sa1111_writel(save->intpol1, base + SA1111_INTPOL1); | ||
911 | sa1111_writel(save->inten0, base + SA1111_INTEN0); | ||
912 | sa1111_writel(save->inten1, base + SA1111_INTEN1); | ||
913 | sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0); | ||
914 | sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1); | ||
915 | sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0); | ||
916 | sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1); | ||
917 | |||
918 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
919 | |||
920 | dev->power.saved_state = NULL; | ||
921 | kfree(save); | ||
922 | |||
923 | return 0; | ||
924 | } | ||
925 | |||
926 | #else | ||
927 | #define sa1111_suspend NULL | ||
928 | #define sa1111_resume NULL | ||
929 | #endif | ||
930 | |||
931 | static int sa1111_probe(struct device *dev) | ||
932 | { | ||
933 | struct platform_device *pdev = to_platform_device(dev); | ||
934 | struct resource *mem; | ||
935 | int irq; | ||
936 | |||
937 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
938 | if (!mem) | ||
939 | return -EINVAL; | ||
940 | irq = platform_get_irq(pdev, 0); | ||
941 | |||
942 | return __sa1111_probe(dev, mem, irq); | ||
943 | } | ||
944 | |||
945 | static int sa1111_remove(struct device *dev) | ||
946 | { | ||
947 | struct sa1111 *sachip = dev_get_drvdata(dev); | ||
948 | |||
949 | if (sachip) { | ||
950 | __sa1111_remove(sachip); | ||
951 | dev_set_drvdata(dev, NULL); | ||
952 | |||
953 | #ifdef CONFIG_PM | ||
954 | kfree(dev->power.saved_state); | ||
955 | dev->power.saved_state = NULL; | ||
956 | #endif | ||
957 | } | ||
958 | |||
959 | return 0; | ||
960 | } | ||
961 | |||
962 | /* | ||
963 | * Not sure if this should be on the system bus or not yet. | ||
964 | * We really want some way to register a system device at | ||
965 | * the per-machine level, and then have this driver pick | ||
966 | * up the registered devices. | ||
967 | * | ||
968 | * We also need to handle the SDRAM configuration for | ||
969 | * PXA250/SA1110 machine classes. | ||
970 | */ | ||
971 | static struct device_driver sa1111_device_driver = { | ||
972 | .name = "sa1111", | ||
973 | .bus = &platform_bus_type, | ||
974 | .probe = sa1111_probe, | ||
975 | .remove = sa1111_remove, | ||
976 | .suspend = sa1111_suspend, | ||
977 | .resume = sa1111_resume, | ||
978 | }; | ||
979 | |||
980 | /* | ||
981 | * Get the parent device driver (us) structure | ||
982 | * from a child function device | ||
983 | */ | ||
984 | static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev) | ||
985 | { | ||
986 | return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent); | ||
987 | } | ||
988 | |||
989 | /* | ||
990 | * The bits in the opdiv field are non-linear. | ||
991 | */ | ||
992 | static unsigned char opdiv_table[] = { 1, 4, 2, 8 }; | ||
993 | |||
994 | static unsigned int __sa1111_pll_clock(struct sa1111 *sachip) | ||
995 | { | ||
996 | unsigned int skcdr, fbdiv, ipdiv, opdiv; | ||
997 | |||
998 | skcdr = sa1111_readl(sachip->base + SA1111_SKCDR); | ||
999 | |||
1000 | fbdiv = (skcdr & 0x007f) + 2; | ||
1001 | ipdiv = ((skcdr & 0x0f80) >> 7) + 2; | ||
1002 | opdiv = opdiv_table[(skcdr & 0x3000) >> 12]; | ||
1003 | |||
1004 | return 3686400 * fbdiv / (ipdiv * opdiv); | ||
1005 | } | ||
1006 | |||
1007 | /** | ||
1008 | * sa1111_pll_clock - return the current PLL clock frequency. | ||
1009 | * @sadev: SA1111 function block | ||
1010 | * | ||
1011 | * BUG: we should look at SKCR. We also blindly believe that | ||
1012 | * the chip is being fed with the 3.6864MHz clock. | ||
1013 | * | ||
1014 | * Returns the PLL clock in Hz. | ||
1015 | */ | ||
1016 | unsigned int sa1111_pll_clock(struct sa1111_dev *sadev) | ||
1017 | { | ||
1018 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1019 | |||
1020 | return __sa1111_pll_clock(sachip); | ||
1021 | } | ||
1022 | |||
1023 | /** | ||
1024 | * sa1111_select_audio_mode - select I2S or AC link mode | ||
1025 | * @sadev: SA1111 function block | ||
1026 | * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S | ||
1027 | * | ||
1028 | * Frob the SKCR to select AC Link mode or I2S mode for | ||
1029 | * the audio block. | ||
1030 | */ | ||
1031 | void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode) | ||
1032 | { | ||
1033 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1034 | unsigned long flags; | ||
1035 | unsigned int val; | ||
1036 | |||
1037 | spin_lock_irqsave(&sachip->lock, flags); | ||
1038 | |||
1039 | val = sa1111_readl(sachip->base + SA1111_SKCR); | ||
1040 | if (mode == SA1111_AUDIO_I2S) { | ||
1041 | val &= ~SKCR_SELAC; | ||
1042 | } else { | ||
1043 | val |= SKCR_SELAC; | ||
1044 | } | ||
1045 | sa1111_writel(val, sachip->base + SA1111_SKCR); | ||
1046 | |||
1047 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
1048 | } | ||
1049 | |||
1050 | /** | ||
1051 | * sa1111_set_audio_rate - set the audio sample rate | ||
1052 | * @sadev: SA1111 SAC function block | ||
1053 | * @rate: sample rate to select | ||
1054 | */ | ||
1055 | int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate) | ||
1056 | { | ||
1057 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1058 | unsigned int div; | ||
1059 | |||
1060 | if (sadev->devid != SA1111_DEVID_SAC) | ||
1061 | return -EINVAL; | ||
1062 | |||
1063 | div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate; | ||
1064 | if (div == 0) | ||
1065 | div = 1; | ||
1066 | if (div > 128) | ||
1067 | div = 128; | ||
1068 | |||
1069 | sa1111_writel(div - 1, sachip->base + SA1111_SKAUD); | ||
1070 | |||
1071 | return 0; | ||
1072 | } | ||
1073 | |||
1074 | /** | ||
1075 | * sa1111_get_audio_rate - get the audio sample rate | ||
1076 | * @sadev: SA1111 SAC function block device | ||
1077 | */ | ||
1078 | int sa1111_get_audio_rate(struct sa1111_dev *sadev) | ||
1079 | { | ||
1080 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1081 | unsigned long div; | ||
1082 | |||
1083 | if (sadev->devid != SA1111_DEVID_SAC) | ||
1084 | return -EINVAL; | ||
1085 | |||
1086 | div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1; | ||
1087 | |||
1088 | return __sa1111_pll_clock(sachip) / (256 * div); | ||
1089 | } | ||
1090 | |||
1091 | void sa1111_set_io_dir(struct sa1111_dev *sadev, | ||
1092 | unsigned int bits, unsigned int dir, | ||
1093 | unsigned int sleep_dir) | ||
1094 | { | ||
1095 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1096 | unsigned long flags; | ||
1097 | unsigned int val; | ||
1098 | void __iomem *gpio = sachip->base + SA1111_GPIO; | ||
1099 | |||
1100 | #define MODIFY_BITS(port, mask, dir) \ | ||
1101 | if (mask) { \ | ||
1102 | val = sa1111_readl(port); \ | ||
1103 | val &= ~(mask); \ | ||
1104 | val |= (dir) & (mask); \ | ||
1105 | sa1111_writel(val, port); \ | ||
1106 | } | ||
1107 | |||
1108 | spin_lock_irqsave(&sachip->lock, flags); | ||
1109 | MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir); | ||
1110 | MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8); | ||
1111 | MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16); | ||
1112 | |||
1113 | MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir); | ||
1114 | MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8); | ||
1115 | MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16); | ||
1116 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
1117 | } | ||
1118 | |||
1119 | void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) | ||
1120 | { | ||
1121 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1122 | unsigned long flags; | ||
1123 | unsigned int val; | ||
1124 | void __iomem *gpio = sachip->base + SA1111_GPIO; | ||
1125 | |||
1126 | spin_lock_irqsave(&sachip->lock, flags); | ||
1127 | MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v); | ||
1128 | MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8); | ||
1129 | MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16); | ||
1130 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
1131 | } | ||
1132 | |||
1133 | void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) | ||
1134 | { | ||
1135 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1136 | unsigned long flags; | ||
1137 | unsigned int val; | ||
1138 | void __iomem *gpio = sachip->base + SA1111_GPIO; | ||
1139 | |||
1140 | spin_lock_irqsave(&sachip->lock, flags); | ||
1141 | MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v); | ||
1142 | MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8); | ||
1143 | MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16); | ||
1144 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
1145 | } | ||
1146 | |||
1147 | /* | ||
1148 | * Individual device operations. | ||
1149 | */ | ||
1150 | |||
1151 | /** | ||
1152 | * sa1111_enable_device - enable an on-chip SA1111 function block | ||
1153 | * @sadev: SA1111 function block device to enable | ||
1154 | */ | ||
1155 | void sa1111_enable_device(struct sa1111_dev *sadev) | ||
1156 | { | ||
1157 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1158 | unsigned long flags; | ||
1159 | unsigned int val; | ||
1160 | |||
1161 | spin_lock_irqsave(&sachip->lock, flags); | ||
1162 | val = sa1111_readl(sachip->base + SA1111_SKPCR); | ||
1163 | sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR); | ||
1164 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
1165 | } | ||
1166 | |||
1167 | /** | ||
1168 | * sa1111_disable_device - disable an on-chip SA1111 function block | ||
1169 | * @sadev: SA1111 function block device to disable | ||
1170 | */ | ||
1171 | void sa1111_disable_device(struct sa1111_dev *sadev) | ||
1172 | { | ||
1173 | struct sa1111 *sachip = sa1111_chip_driver(sadev); | ||
1174 | unsigned long flags; | ||
1175 | unsigned int val; | ||
1176 | |||
1177 | spin_lock_irqsave(&sachip->lock, flags); | ||
1178 | val = sa1111_readl(sachip->base + SA1111_SKPCR); | ||
1179 | sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR); | ||
1180 | spin_unlock_irqrestore(&sachip->lock, flags); | ||
1181 | } | ||
1182 | |||
1183 | /* | ||
1184 | * SA1111 "Register Access Bus." | ||
1185 | * | ||
1186 | * We model this as a regular bus type, and hang devices directly | ||
1187 | * off this. | ||
1188 | */ | ||
1189 | static int sa1111_match(struct device *_dev, struct device_driver *_drv) | ||
1190 | { | ||
1191 | struct sa1111_dev *dev = SA1111_DEV(_dev); | ||
1192 | struct sa1111_driver *drv = SA1111_DRV(_drv); | ||
1193 | |||
1194 | return dev->devid == drv->devid; | ||
1195 | } | ||
1196 | |||
1197 | static int sa1111_bus_suspend(struct device *dev, pm_message_t state) | ||
1198 | { | ||
1199 | struct sa1111_dev *sadev = SA1111_DEV(dev); | ||
1200 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); | ||
1201 | int ret = 0; | ||
1202 | |||
1203 | if (drv && drv->suspend) | ||
1204 | ret = drv->suspend(sadev, state); | ||
1205 | return ret; | ||
1206 | } | ||
1207 | |||
1208 | static int sa1111_bus_resume(struct device *dev) | ||
1209 | { | ||
1210 | struct sa1111_dev *sadev = SA1111_DEV(dev); | ||
1211 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); | ||
1212 | int ret = 0; | ||
1213 | |||
1214 | if (drv && drv->resume) | ||
1215 | ret = drv->resume(sadev); | ||
1216 | return ret; | ||
1217 | } | ||
1218 | |||
1219 | static int sa1111_bus_probe(struct device *dev) | ||
1220 | { | ||
1221 | struct sa1111_dev *sadev = SA1111_DEV(dev); | ||
1222 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); | ||
1223 | int ret = -ENODEV; | ||
1224 | |||
1225 | if (drv->probe) | ||
1226 | ret = drv->probe(sadev); | ||
1227 | return ret; | ||
1228 | } | ||
1229 | |||
1230 | static int sa1111_bus_remove(struct device *dev) | ||
1231 | { | ||
1232 | struct sa1111_dev *sadev = SA1111_DEV(dev); | ||
1233 | struct sa1111_driver *drv = SA1111_DRV(dev->driver); | ||
1234 | int ret = 0; | ||
1235 | |||
1236 | if (drv->remove) | ||
1237 | ret = drv->remove(sadev); | ||
1238 | return ret; | ||
1239 | } | ||
1240 | |||
1241 | struct bus_type sa1111_bus_type = { | ||
1242 | .name = "sa1111-rab", | ||
1243 | .match = sa1111_match, | ||
1244 | .suspend = sa1111_bus_suspend, | ||
1245 | .resume = sa1111_bus_resume, | ||
1246 | }; | ||
1247 | |||
1248 | int sa1111_driver_register(struct sa1111_driver *driver) | ||
1249 | { | ||
1250 | driver->drv.probe = sa1111_bus_probe; | ||
1251 | driver->drv.remove = sa1111_bus_remove; | ||
1252 | driver->drv.bus = &sa1111_bus_type; | ||
1253 | return driver_register(&driver->drv); | ||
1254 | } | ||
1255 | |||
1256 | void sa1111_driver_unregister(struct sa1111_driver *driver) | ||
1257 | { | ||
1258 | driver_unregister(&driver->drv); | ||
1259 | } | ||
1260 | |||
1261 | static int __init sa1111_init(void) | ||
1262 | { | ||
1263 | int ret = bus_register(&sa1111_bus_type); | ||
1264 | if (ret == 0) | ||
1265 | driver_register(&sa1111_device_driver); | ||
1266 | return ret; | ||
1267 | } | ||
1268 | |||
1269 | static void __exit sa1111_exit(void) | ||
1270 | { | ||
1271 | driver_unregister(&sa1111_device_driver); | ||
1272 | bus_unregister(&sa1111_bus_type); | ||
1273 | } | ||
1274 | |||
1275 | module_init(sa1111_init); | ||
1276 | module_exit(sa1111_exit); | ||
1277 | |||
1278 | MODULE_DESCRIPTION("Intel Corporation SA1111 core driver"); | ||
1279 | MODULE_LICENSE("GPL"); | ||
1280 | |||
1281 | EXPORT_SYMBOL(sa1111_select_audio_mode); | ||
1282 | EXPORT_SYMBOL(sa1111_set_audio_rate); | ||
1283 | EXPORT_SYMBOL(sa1111_get_audio_rate); | ||
1284 | EXPORT_SYMBOL(sa1111_set_io_dir); | ||
1285 | EXPORT_SYMBOL(sa1111_set_io); | ||
1286 | EXPORT_SYMBOL(sa1111_set_sleep_io); | ||
1287 | EXPORT_SYMBOL(sa1111_enable_device); | ||
1288 | EXPORT_SYMBOL(sa1111_disable_device); | ||
1289 | EXPORT_SYMBOL(sa1111_pll_clock); | ||
1290 | EXPORT_SYMBOL(sa1111_bus_type); | ||
1291 | EXPORT_SYMBOL(sa1111_driver_register); | ||
1292 | EXPORT_SYMBOL(sa1111_driver_unregister); | ||
diff --git a/arch/arm/common/scoop.c b/arch/arm/common/scoop.c new file mode 100644 index 000000000000..cfd0d3e550d9 --- /dev/null +++ b/arch/arm/common/scoop.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Support code for the SCOOP interface found on various Sharp PDAs | ||
3 | * | ||
4 | * Copyright (c) 2004 Richard Purdie | ||
5 | * | ||
6 | * Based on code written by Sharp/Lineo for 2.4 kernels | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/device.h> | ||
15 | #include <asm/io.h> | ||
16 | #include <asm/hardware/scoop.h> | ||
17 | |||
18 | #define SCOOP_REG(d,adr) (*(volatile unsigned short*)(d +(adr))) | ||
19 | |||
20 | struct scoop_dev { | ||
21 | void *base; | ||
22 | spinlock_t scoop_lock; | ||
23 | u32 scoop_gpwr; | ||
24 | }; | ||
25 | |||
26 | void reset_scoop(struct device *dev) | ||
27 | { | ||
28 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
29 | |||
30 | SCOOP_REG(sdev->base,SCOOP_MCR) = 0x0100; // 00 | ||
31 | SCOOP_REG(sdev->base,SCOOP_CDR) = 0x0000; // 04 | ||
32 | SCOOP_REG(sdev->base,SCOOP_CPR) = 0x0000; // 0C | ||
33 | SCOOP_REG(sdev->base,SCOOP_CCR) = 0x0000; // 10 | ||
34 | SCOOP_REG(sdev->base,SCOOP_IMR) = 0x0000; // 18 | ||
35 | SCOOP_REG(sdev->base,SCOOP_IRM) = 0x00FF; // 14 | ||
36 | SCOOP_REG(sdev->base,SCOOP_ISR) = 0x0000; // 1C | ||
37 | SCOOP_REG(sdev->base,SCOOP_IRM) = 0x0000; | ||
38 | } | ||
39 | |||
40 | unsigned short set_scoop_gpio(struct device *dev, unsigned short bit) | ||
41 | { | ||
42 | unsigned short gpio_bit; | ||
43 | unsigned long flag; | ||
44 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
45 | |||
46 | spin_lock_irqsave(&sdev->scoop_lock, flag); | ||
47 | gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) | bit; | ||
48 | SCOOP_REG(sdev->base, SCOOP_GPWR) = gpio_bit; | ||
49 | spin_unlock_irqrestore(&sdev->scoop_lock, flag); | ||
50 | |||
51 | return gpio_bit; | ||
52 | } | ||
53 | |||
54 | unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit) | ||
55 | { | ||
56 | unsigned short gpio_bit; | ||
57 | unsigned long flag; | ||
58 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
59 | |||
60 | spin_lock_irqsave(&sdev->scoop_lock, flag); | ||
61 | gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) & ~bit; | ||
62 | SCOOP_REG(sdev->base,SCOOP_GPWR) = gpio_bit; | ||
63 | spin_unlock_irqrestore(&sdev->scoop_lock, flag); | ||
64 | |||
65 | return gpio_bit; | ||
66 | } | ||
67 | |||
68 | EXPORT_SYMBOL(set_scoop_gpio); | ||
69 | EXPORT_SYMBOL(reset_scoop_gpio); | ||
70 | |||
71 | unsigned short read_scoop_reg(struct device *dev, unsigned short reg) | ||
72 | { | ||
73 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
74 | return SCOOP_REG(sdev->base,reg); | ||
75 | } | ||
76 | |||
77 | void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data) | ||
78 | { | ||
79 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
80 | SCOOP_REG(sdev->base,reg)=data; | ||
81 | } | ||
82 | |||
83 | EXPORT_SYMBOL(reset_scoop); | ||
84 | EXPORT_SYMBOL(read_scoop_reg); | ||
85 | EXPORT_SYMBOL(write_scoop_reg); | ||
86 | |||
87 | #ifdef CONFIG_PM | ||
88 | static int scoop_suspend(struct device *dev, uint32_t state, uint32_t level) | ||
89 | { | ||
90 | if (level == SUSPEND_POWER_DOWN) { | ||
91 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
92 | |||
93 | sdev->scoop_gpwr = SCOOP_REG(sdev->base,SCOOP_GPWR); | ||
94 | SCOOP_REG(sdev->base,SCOOP_GPWR) = 0; | ||
95 | } | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | static int scoop_resume(struct device *dev, uint32_t level) | ||
100 | { | ||
101 | if (level == RESUME_POWER_ON) { | ||
102 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
103 | |||
104 | SCOOP_REG(sdev->base,SCOOP_GPWR) = sdev->scoop_gpwr; | ||
105 | } | ||
106 | return 0; | ||
107 | } | ||
108 | #else | ||
109 | #define scoop_suspend NULL | ||
110 | #define scoop_resume NULL | ||
111 | #endif | ||
112 | |||
113 | int __init scoop_probe(struct device *dev) | ||
114 | { | ||
115 | struct scoop_dev *devptr; | ||
116 | struct scoop_config *inf; | ||
117 | struct platform_device *pdev = to_platform_device(dev); | ||
118 | struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
119 | |||
120 | if (!mem) | ||
121 | return -EINVAL; | ||
122 | |||
123 | devptr = kmalloc(sizeof(struct scoop_dev), GFP_KERNEL); | ||
124 | |||
125 | if (!devptr) | ||
126 | return -ENOMEM; | ||
127 | |||
128 | memset(devptr, 0, sizeof(struct scoop_dev)); | ||
129 | spin_lock_init(&devptr->scoop_lock); | ||
130 | |||
131 | inf = dev->platform_data; | ||
132 | devptr->base = ioremap(mem->start, mem->end - mem->start + 1); | ||
133 | |||
134 | if (!devptr->base) { | ||
135 | kfree(devptr); | ||
136 | return -ENOMEM; | ||
137 | } | ||
138 | |||
139 | dev_set_drvdata(dev, devptr); | ||
140 | |||
141 | printk("Sharp Scoop Device found at 0x%08x -> 0x%08x\n",(unsigned int)mem->start,(unsigned int)devptr->base); | ||
142 | |||
143 | SCOOP_REG(devptr->base, SCOOP_MCR) = 0x0140; | ||
144 | reset_scoop(dev); | ||
145 | SCOOP_REG(devptr->base, SCOOP_GPCR) = inf->io_dir & 0xffff; | ||
146 | SCOOP_REG(devptr->base, SCOOP_GPWR) = inf->io_out & 0xffff; | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static int scoop_remove(struct device *dev) | ||
152 | { | ||
153 | struct scoop_dev *sdev = dev_get_drvdata(dev); | ||
154 | if (sdev) { | ||
155 | iounmap(sdev->base); | ||
156 | kfree(sdev); | ||
157 | dev_set_drvdata(dev, NULL); | ||
158 | } | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static struct device_driver scoop_driver = { | ||
163 | .name = "sharp-scoop", | ||
164 | .bus = &platform_bus_type, | ||
165 | .probe = scoop_probe, | ||
166 | .remove = scoop_remove, | ||
167 | .suspend = scoop_suspend, | ||
168 | .resume = scoop_resume, | ||
169 | }; | ||
170 | |||
171 | int __init scoop_init(void) | ||
172 | { | ||
173 | return driver_register(&scoop_driver); | ||
174 | } | ||
175 | |||
176 | subsys_initcall(scoop_init); | ||
diff --git a/arch/arm/common/sharpsl_param.c b/arch/arm/common/sharpsl_param.c new file mode 100644 index 000000000000..c2c557a224c2 --- /dev/null +++ b/arch/arm/common/sharpsl_param.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Hardware parameter area specific to Sharp SL series devices | ||
3 | * | ||
4 | * Copyright (c) 2005 Richard Purdie | ||
5 | * | ||
6 | * Based on Sharp's 2.4 kernel patches | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/string.h> | ||
16 | #include <asm/mach/sharpsl_param.h> | ||
17 | |||
18 | /* | ||
19 | * Certain hardware parameters determined at the time of device manufacture, | ||
20 | * typically including LCD parameters are loaded by the bootloader at the | ||
21 | * address PARAM_BASE. As the kernel will overwrite them, we need to store | ||
22 | * them early in the boot process, then pass them to the appropriate drivers. | ||
23 | * Not all devices use all paramaters but the format is common to all. | ||
24 | */ | ||
25 | #ifdef ARCH_SA1100 | ||
26 | #define PARAM_BASE 0xe8ffc000 | ||
27 | #else | ||
28 | #define PARAM_BASE 0xa0000a00 | ||
29 | #endif | ||
30 | #define MAGIC_CHG(a,b,c,d) ( ( d << 24 ) | ( c << 16 ) | ( b << 8 ) | a ) | ||
31 | |||
32 | #define COMADJ_MAGIC MAGIC_CHG('C','M','A','D') | ||
33 | #define UUID_MAGIC MAGIC_CHG('U','U','I','D') | ||
34 | #define TOUCH_MAGIC MAGIC_CHG('T','U','C','H') | ||
35 | #define AD_MAGIC MAGIC_CHG('B','V','A','D') | ||
36 | #define PHAD_MAGIC MAGIC_CHG('P','H','A','D') | ||
37 | |||
38 | struct sharpsl_param_info sharpsl_param; | ||
39 | |||
40 | void sharpsl_save_param(void) | ||
41 | { | ||
42 | memcpy(&sharpsl_param, (void *)PARAM_BASE, sizeof(struct sharpsl_param_info)); | ||
43 | |||
44 | if (sharpsl_param.comadj_keyword != COMADJ_MAGIC) | ||
45 | sharpsl_param.comadj=-1; | ||
46 | |||
47 | if (sharpsl_param.phad_keyword != PHAD_MAGIC) | ||
48 | sharpsl_param.phadadj=-1; | ||
49 | |||
50 | if (sharpsl_param.uuid_keyword != UUID_MAGIC) | ||
51 | sharpsl_param.uuid[0]=-1; | ||
52 | |||
53 | if (sharpsl_param.touch_keyword != TOUCH_MAGIC) | ||
54 | sharpsl_param.touch_xp=-1; | ||
55 | |||
56 | if (sharpsl_param.adadj_keyword != AD_MAGIC) | ||
57 | sharpsl_param.adadj=-1; | ||
58 | } | ||
59 | |||
60 | |||
diff --git a/arch/arm/common/time-acorn.c b/arch/arm/common/time-acorn.c new file mode 100644 index 000000000000..486add853fb8 --- /dev/null +++ b/arch/arm/common/time-acorn.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/common/time-acorn.c | ||
3 | * | ||
4 | * Copyright (c) 1996-2000 Russell King. | ||
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 | * Changelog: | ||
11 | * 24-Sep-1996 RMK Created | ||
12 | * 10-Oct-1996 RMK Brought up to date with arch-sa110eval | ||
13 | * 04-Dec-1997 RMK Updated for new arch/arm/time.c | ||
14 | * 13=Jun-2004 DS Moved to arch/arm/common b/c shared w/CLPS7500 | ||
15 | */ | ||
16 | #include <linux/timex.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/interrupt.h> | ||
19 | |||
20 | #include <asm/hardware.h> | ||
21 | #include <asm/io.h> | ||
22 | #include <asm/hardware/ioc.h> | ||
23 | |||
24 | #include <asm/mach/time.h> | ||
25 | |||
26 | unsigned long ioc_timer_gettimeoffset(void) | ||
27 | { | ||
28 | unsigned int count1, count2, status; | ||
29 | long offset; | ||
30 | |||
31 | ioc_writeb (0, IOC_T0LATCH); | ||
32 | barrier (); | ||
33 | count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8); | ||
34 | barrier (); | ||
35 | status = ioc_readb(IOC_IRQREQA); | ||
36 | barrier (); | ||
37 | ioc_writeb (0, IOC_T0LATCH); | ||
38 | barrier (); | ||
39 | count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8); | ||
40 | |||
41 | offset = count2; | ||
42 | if (count2 < count1) { | ||
43 | /* | ||
44 | * We have not had an interrupt between reading count1 | ||
45 | * and count2. | ||
46 | */ | ||
47 | if (status & (1 << 5)) | ||
48 | offset -= LATCH; | ||
49 | } else if (count2 > count1) { | ||
50 | /* | ||
51 | * We have just had another interrupt between reading | ||
52 | * count1 and count2. | ||
53 | */ | ||
54 | offset -= LATCH; | ||
55 | } | ||
56 | |||
57 | offset = (LATCH - offset) * (tick_nsec / 1000); | ||
58 | return (offset + LATCH/2) / LATCH; | ||
59 | } | ||
60 | |||
61 | void __init ioctime_init(void) | ||
62 | { | ||
63 | ioc_writeb(LATCH & 255, IOC_T0LTCHL); | ||
64 | ioc_writeb(LATCH >> 8, IOC_T0LTCHH); | ||
65 | ioc_writeb(0, IOC_T0GO); | ||
66 | } | ||
67 | |||
68 | static irqreturn_t | ||
69 | ioc_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
70 | { | ||
71 | write_seqlock(&xtime_lock); | ||
72 | timer_tick(regs); | ||
73 | write_sequnlock(&xtime_lock); | ||
74 | return IRQ_HANDLED; | ||
75 | } | ||
76 | |||
77 | static struct irqaction ioc_timer_irq = { | ||
78 | .name = "timer", | ||
79 | .flags = SA_INTERRUPT, | ||
80 | .handler = ioc_timer_interrupt | ||
81 | }; | ||
82 | |||
83 | /* | ||
84 | * Set up timer interrupt. | ||
85 | */ | ||
86 | static void __init ioc_timer_init(void) | ||
87 | { | ||
88 | ioctime_init(); | ||
89 | setup_irq(IRQ_TIMER, &ioc_timer_irq); | ||
90 | } | ||
91 | |||
92 | struct sys_timer ioc_timer = { | ||
93 | .init = ioc_timer_init, | ||
94 | .offset = ioc_timer_gettimeoffset, | ||
95 | }; | ||
96 | |||
diff --git a/arch/arm/common/via82c505.c b/arch/arm/common/via82c505.c new file mode 100644 index 000000000000..ef716a5b07ac --- /dev/null +++ b/arch/arm/common/via82c505.c | |||
@@ -0,0 +1,94 @@ | |||
1 | #include <linux/config.h> | ||
2 | #include <linux/kernel.h> | ||
3 | #include <linux/pci.h> | ||
4 | #include <linux/ptrace.h> | ||
5 | #include <linux/interrupt.h> | ||
6 | #include <linux/mm.h> | ||
7 | #include <linux/init.h> | ||
8 | #include <linux/ioport.h> | ||
9 | |||
10 | #include <asm/io.h> | ||
11 | #include <asm/system.h> | ||
12 | |||
13 | #include <asm/mach/pci.h> | ||
14 | |||
15 | #define MAX_SLOTS 7 | ||
16 | |||
17 | #define CONFIG_CMD(bus, devfn, where) (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3)) | ||
18 | |||
19 | static int | ||
20 | via82c505_read_config(struct pci_bus *bus, unsigned int devfn, int where, | ||
21 | int size, u32 *value) | ||
22 | { | ||
23 | outl(CONFIG_CMD(bus,devfn,where),0xCF8); | ||
24 | switch (size) { | ||
25 | case 1: | ||
26 | *value=inb(0xCFC + (where&3)); | ||
27 | break; | ||
28 | case 2: | ||
29 | *value=inw(0xCFC + (where&2)); | ||
30 | break; | ||
31 | case 4: | ||
32 | *value=inl(0xCFC); | ||
33 | break; | ||
34 | } | ||
35 | return PCIBIOS_SUCCESSFUL; | ||
36 | } | ||
37 | |||
38 | static int | ||
39 | via82c505_write_config(struct pci_bus *bus, unsigned int devfn, int where, | ||
40 | int size, u32 value) | ||
41 | { | ||
42 | outl(CONFIG_CMD(bus,devfn,where),0xCF8); | ||
43 | switch (size) { | ||
44 | case 1: | ||
45 | outb(value, 0xCFC + (where&3)); | ||
46 | break; | ||
47 | case 2: | ||
48 | outw(value, 0xCFC + (where&2)); | ||
49 | break; | ||
50 | case 4: | ||
51 | outl(value, 0xCFC); | ||
52 | break; | ||
53 | } | ||
54 | return PCIBIOS_SUCCESSFUL; | ||
55 | } | ||
56 | |||
57 | static struct pci_ops via82c505_ops = { | ||
58 | .read = via82c505_read_config, | ||
59 | .write = via82c505_write_config, | ||
60 | }; | ||
61 | |||
62 | void __init via82c505_preinit(void) | ||
63 | { | ||
64 | printk(KERN_DEBUG "PCI: VIA 82c505\n"); | ||
65 | if (!request_region(0xA8,2,"via config")) { | ||
66 | printk(KERN_WARNING"VIA 82c505: Unable to request region 0xA8\n"); | ||
67 | return; | ||
68 | } | ||
69 | if (!request_region(0xCF8,8,"pci config")) { | ||
70 | printk(KERN_WARNING"VIA 82c505: Unable to request region 0xCF8\n"); | ||
71 | release_region(0xA8, 2); | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | /* Enable compatible Mode */ | ||
76 | outb(0x96,0xA8); | ||
77 | outb(0x18,0xA9); | ||
78 | outb(0x93,0xA8); | ||
79 | outb(0xd0,0xA9); | ||
80 | |||
81 | } | ||
82 | |||
83 | int __init via82c505_setup(int nr, struct pci_sys_data *sys) | ||
84 | { | ||
85 | return (nr == 0); | ||
86 | } | ||
87 | |||
88 | struct pci_bus * __init via82c505_scan_bus(int nr, struct pci_sys_data *sysdata) | ||
89 | { | ||
90 | if (nr == 0) | ||
91 | return pci_scan_bus(0, &via82c505_ops, sysdata); | ||
92 | |||
93 | return NULL; | ||
94 | } | ||