diff options
Diffstat (limited to 'arch/arm/mach-pxa/ssp.c')
-rw-r--r-- | arch/arm/mach-pxa/ssp.c | 510 |
1 files changed, 0 insertions, 510 deletions
diff --git a/arch/arm/mach-pxa/ssp.c b/arch/arm/mach-pxa/ssp.c deleted file mode 100644 index a81d6dbf662d..000000000000 --- a/arch/arm/mach-pxa/ssp.c +++ /dev/null | |||
@@ -1,510 +0,0 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-pxa/ssp.c | ||
3 | * | ||
4 | * based on linux/arch/arm/mach-sa1100/ssp.c by Russell King | ||
5 | * | ||
6 | * Copyright (C) 2003 Russell King. | ||
7 | * Copyright (C) 2003 Wolfson Microelectronics PLC | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | * PXA2xx SSP driver. This provides the generic core for simple | ||
14 | * IO-based SSP applications and allows easy port setup for DMA access. | ||
15 | * | ||
16 | * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/sched.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/ioport.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/mutex.h> | ||
28 | #include <linux/clk.h> | ||
29 | #include <linux/err.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/io.h> | ||
32 | |||
33 | #include <asm/irq.h> | ||
34 | #include <mach/hardware.h> | ||
35 | #include <mach/ssp.h> | ||
36 | #include <mach/regs-ssp.h> | ||
37 | |||
38 | #ifdef CONFIG_PXA_SSP_LEGACY | ||
39 | |||
40 | #define TIMEOUT 100000 | ||
41 | |||
42 | static irqreturn_t ssp_interrupt(int irq, void *dev_id) | ||
43 | { | ||
44 | struct ssp_dev *dev = dev_id; | ||
45 | struct ssp_device *ssp = dev->ssp; | ||
46 | unsigned int status; | ||
47 | |||
48 | status = __raw_readl(ssp->mmio_base + SSSR); | ||
49 | __raw_writel(status, ssp->mmio_base + SSSR); | ||
50 | |||
51 | if (status & SSSR_ROR) | ||
52 | printk(KERN_WARNING "SSP(%d): receiver overrun\n", dev->port); | ||
53 | |||
54 | if (status & SSSR_TUR) | ||
55 | printk(KERN_WARNING "SSP(%d): transmitter underrun\n", dev->port); | ||
56 | |||
57 | if (status & SSSR_BCE) | ||
58 | printk(KERN_WARNING "SSP(%d): bit count error\n", dev->port); | ||
59 | |||
60 | return IRQ_HANDLED; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * ssp_write_word - write a word to the SSP port | ||
65 | * @data: 32-bit, MSB justified data to write. | ||
66 | * | ||
67 | * Wait for a free entry in the SSP transmit FIFO, and write a data | ||
68 | * word to the SSP port. | ||
69 | * | ||
70 | * The caller is expected to perform the necessary locking. | ||
71 | * | ||
72 | * Returns: | ||
73 | * %-ETIMEDOUT timeout occurred | ||
74 | * 0 success | ||
75 | */ | ||
76 | int ssp_write_word(struct ssp_dev *dev, u32 data) | ||
77 | { | ||
78 | struct ssp_device *ssp = dev->ssp; | ||
79 | int timeout = TIMEOUT; | ||
80 | |||
81 | while (!(__raw_readl(ssp->mmio_base + SSSR) & SSSR_TNF)) { | ||
82 | if (!--timeout) | ||
83 | return -ETIMEDOUT; | ||
84 | cpu_relax(); | ||
85 | } | ||
86 | |||
87 | __raw_writel(data, ssp->mmio_base + SSDR); | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * ssp_read_word - read a word from the SSP port | ||
94 | * | ||
95 | * Wait for a data word in the SSP receive FIFO, and return the | ||
96 | * received data. Data is LSB justified. | ||
97 | * | ||
98 | * Note: Currently, if data is not expected to be received, this | ||
99 | * function will wait for ever. | ||
100 | * | ||
101 | * The caller is expected to perform the necessary locking. | ||
102 | * | ||
103 | * Returns: | ||
104 | * %-ETIMEDOUT timeout occurred | ||
105 | * 32-bit data success | ||
106 | */ | ||
107 | int ssp_read_word(struct ssp_dev *dev, u32 *data) | ||
108 | { | ||
109 | struct ssp_device *ssp = dev->ssp; | ||
110 | int timeout = TIMEOUT; | ||
111 | |||
112 | while (!(__raw_readl(ssp->mmio_base + SSSR) & SSSR_RNE)) { | ||
113 | if (!--timeout) | ||
114 | return -ETIMEDOUT; | ||
115 | cpu_relax(); | ||
116 | } | ||
117 | |||
118 | *data = __raw_readl(ssp->mmio_base + SSDR); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * ssp_flush - flush the transmit and receive FIFOs | ||
124 | * | ||
125 | * Wait for the SSP to idle, and ensure that the receive FIFO | ||
126 | * is empty. | ||
127 | * | ||
128 | * The caller is expected to perform the necessary locking. | ||
129 | */ | ||
130 | int ssp_flush(struct ssp_dev *dev) | ||
131 | { | ||
132 | struct ssp_device *ssp = dev->ssp; | ||
133 | int timeout = TIMEOUT * 2; | ||
134 | |||
135 | /* ensure TX FIFO is empty instead of not full */ | ||
136 | if (cpu_is_pxa3xx()) { | ||
137 | while (__raw_readl(ssp->mmio_base + SSSR) & 0xf00) { | ||
138 | if (!--timeout) | ||
139 | return -ETIMEDOUT; | ||
140 | cpu_relax(); | ||
141 | } | ||
142 | timeout = TIMEOUT * 2; | ||
143 | } | ||
144 | |||
145 | do { | ||
146 | while (__raw_readl(ssp->mmio_base + SSSR) & SSSR_RNE) { | ||
147 | if (!--timeout) | ||
148 | return -ETIMEDOUT; | ||
149 | (void)__raw_readl(ssp->mmio_base + SSDR); | ||
150 | } | ||
151 | if (!--timeout) | ||
152 | return -ETIMEDOUT; | ||
153 | } while (__raw_readl(ssp->mmio_base + SSSR) & SSSR_BSY); | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * ssp_enable - enable the SSP port | ||
160 | * | ||
161 | * Turn on the SSP port. | ||
162 | */ | ||
163 | void ssp_enable(struct ssp_dev *dev) | ||
164 | { | ||
165 | struct ssp_device *ssp = dev->ssp; | ||
166 | uint32_t sscr0; | ||
167 | |||
168 | sscr0 = __raw_readl(ssp->mmio_base + SSCR0); | ||
169 | sscr0 |= SSCR0_SSE; | ||
170 | __raw_writel(sscr0, ssp->mmio_base + SSCR0); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * ssp_disable - shut down the SSP port | ||
175 | * | ||
176 | * Turn off the SSP port, optionally powering it down. | ||
177 | */ | ||
178 | void ssp_disable(struct ssp_dev *dev) | ||
179 | { | ||
180 | struct ssp_device *ssp = dev->ssp; | ||
181 | uint32_t sscr0; | ||
182 | |||
183 | sscr0 = __raw_readl(ssp->mmio_base + SSCR0); | ||
184 | sscr0 &= ~SSCR0_SSE; | ||
185 | __raw_writel(sscr0, ssp->mmio_base + SSCR0); | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * ssp_save_state - save the SSP configuration | ||
190 | * @ssp: pointer to structure to save SSP configuration | ||
191 | * | ||
192 | * Save the configured SSP state for suspend. | ||
193 | */ | ||
194 | void ssp_save_state(struct ssp_dev *dev, struct ssp_state *state) | ||
195 | { | ||
196 | struct ssp_device *ssp = dev->ssp; | ||
197 | |||
198 | state->cr0 = __raw_readl(ssp->mmio_base + SSCR0); | ||
199 | state->cr1 = __raw_readl(ssp->mmio_base + SSCR1); | ||
200 | state->to = __raw_readl(ssp->mmio_base + SSTO); | ||
201 | state->psp = __raw_readl(ssp->mmio_base + SSPSP); | ||
202 | |||
203 | ssp_disable(dev); | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * ssp_restore_state - restore a previously saved SSP configuration | ||
208 | * @ssp: pointer to configuration saved by ssp_save_state | ||
209 | * | ||
210 | * Restore the SSP configuration saved previously by ssp_save_state. | ||
211 | */ | ||
212 | void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *state) | ||
213 | { | ||
214 | struct ssp_device *ssp = dev->ssp; | ||
215 | uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE; | ||
216 | |||
217 | __raw_writel(sssr, ssp->mmio_base + SSSR); | ||
218 | |||
219 | __raw_writel(state->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0); | ||
220 | __raw_writel(state->cr1, ssp->mmio_base + SSCR1); | ||
221 | __raw_writel(state->to, ssp->mmio_base + SSTO); | ||
222 | __raw_writel(state->psp, ssp->mmio_base + SSPSP); | ||
223 | __raw_writel(state->cr0, ssp->mmio_base + SSCR0); | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * ssp_config - configure SSP port settings | ||
228 | * @mode: port operating mode | ||
229 | * @flags: port config flags | ||
230 | * @psp_flags: port PSP config flags | ||
231 | * @speed: port speed | ||
232 | * | ||
233 | * Port MUST be disabled by ssp_disable before making any config changes. | ||
234 | */ | ||
235 | int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed) | ||
236 | { | ||
237 | struct ssp_device *ssp = dev->ssp; | ||
238 | |||
239 | dev->mode = mode; | ||
240 | dev->flags = flags; | ||
241 | dev->psp_flags = psp_flags; | ||
242 | dev->speed = speed; | ||
243 | |||
244 | /* set up port type, speed, port settings */ | ||
245 | __raw_writel((dev->speed | dev->mode), ssp->mmio_base + SSCR0); | ||
246 | __raw_writel(dev->flags, ssp->mmio_base + SSCR1); | ||
247 | __raw_writel(dev->psp_flags, ssp->mmio_base + SSPSP); | ||
248 | |||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * ssp_init - setup the SSP port | ||
254 | * | ||
255 | * initialise and claim resources for the SSP port. | ||
256 | * | ||
257 | * Returns: | ||
258 | * %-ENODEV if the SSP port is unavailable | ||
259 | * %-EBUSY if the resources are already in use | ||
260 | * %0 on success | ||
261 | */ | ||
262 | int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags) | ||
263 | { | ||
264 | struct ssp_device *ssp; | ||
265 | int ret; | ||
266 | |||
267 | ssp = ssp_request(port, "SSP"); | ||
268 | if (ssp == NULL) | ||
269 | return -ENODEV; | ||
270 | |||
271 | dev->ssp = ssp; | ||
272 | dev->port = port; | ||
273 | |||
274 | /* do we need to get irq */ | ||
275 | if (!(init_flags & SSP_NO_IRQ)) { | ||
276 | ret = request_irq(ssp->irq, ssp_interrupt, | ||
277 | 0, "SSP", dev); | ||
278 | if (ret) | ||
279 | goto out_region; | ||
280 | dev->irq = ssp->irq; | ||
281 | } else | ||
282 | dev->irq = NO_IRQ; | ||
283 | |||
284 | /* turn on SSP port clock */ | ||
285 | clk_enable(ssp->clk); | ||
286 | return 0; | ||
287 | |||
288 | out_region: | ||
289 | ssp_free(ssp); | ||
290 | return ret; | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * ssp_exit - undo the effects of ssp_init | ||
295 | * | ||
296 | * release and free resources for the SSP port. | ||
297 | */ | ||
298 | void ssp_exit(struct ssp_dev *dev) | ||
299 | { | ||
300 | struct ssp_device *ssp = dev->ssp; | ||
301 | |||
302 | ssp_disable(dev); | ||
303 | if (dev->irq != NO_IRQ) | ||
304 | free_irq(dev->irq, dev); | ||
305 | clk_disable(ssp->clk); | ||
306 | ssp_free(ssp); | ||
307 | } | ||
308 | #endif /* CONFIG_PXA_SSP_LEGACY */ | ||
309 | |||
310 | static DEFINE_MUTEX(ssp_lock); | ||
311 | static LIST_HEAD(ssp_list); | ||
312 | |||
313 | struct ssp_device *ssp_request(int port, const char *label) | ||
314 | { | ||
315 | struct ssp_device *ssp = NULL; | ||
316 | |||
317 | mutex_lock(&ssp_lock); | ||
318 | |||
319 | list_for_each_entry(ssp, &ssp_list, node) { | ||
320 | if (ssp->port_id == port && ssp->use_count == 0) { | ||
321 | ssp->use_count++; | ||
322 | ssp->label = label; | ||
323 | break; | ||
324 | } | ||
325 | } | ||
326 | |||
327 | mutex_unlock(&ssp_lock); | ||
328 | |||
329 | if (&ssp->node == &ssp_list) | ||
330 | return NULL; | ||
331 | |||
332 | return ssp; | ||
333 | } | ||
334 | EXPORT_SYMBOL(ssp_request); | ||
335 | |||
336 | void ssp_free(struct ssp_device *ssp) | ||
337 | { | ||
338 | mutex_lock(&ssp_lock); | ||
339 | if (ssp->use_count) { | ||
340 | ssp->use_count--; | ||
341 | ssp->label = NULL; | ||
342 | } else | ||
343 | dev_err(&ssp->pdev->dev, "device already free\n"); | ||
344 | mutex_unlock(&ssp_lock); | ||
345 | } | ||
346 | EXPORT_SYMBOL(ssp_free); | ||
347 | |||
348 | static int __devinit ssp_probe(struct platform_device *pdev) | ||
349 | { | ||
350 | const struct platform_device_id *id = platform_get_device_id(pdev); | ||
351 | struct resource *res; | ||
352 | struct ssp_device *ssp; | ||
353 | int ret = 0; | ||
354 | |||
355 | ssp = kzalloc(sizeof(struct ssp_device), GFP_KERNEL); | ||
356 | if (ssp == NULL) { | ||
357 | dev_err(&pdev->dev, "failed to allocate memory"); | ||
358 | return -ENOMEM; | ||
359 | } | ||
360 | ssp->pdev = pdev; | ||
361 | |||
362 | ssp->clk = clk_get(&pdev->dev, NULL); | ||
363 | if (IS_ERR(ssp->clk)) { | ||
364 | ret = PTR_ERR(ssp->clk); | ||
365 | goto err_free; | ||
366 | } | ||
367 | |||
368 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
369 | if (res == NULL) { | ||
370 | dev_err(&pdev->dev, "no memory resource defined\n"); | ||
371 | ret = -ENODEV; | ||
372 | goto err_free_clk; | ||
373 | } | ||
374 | |||
375 | res = request_mem_region(res->start, res->end - res->start + 1, | ||
376 | pdev->name); | ||
377 | if (res == NULL) { | ||
378 | dev_err(&pdev->dev, "failed to request memory resource\n"); | ||
379 | ret = -EBUSY; | ||
380 | goto err_free_clk; | ||
381 | } | ||
382 | |||
383 | ssp->phys_base = res->start; | ||
384 | |||
385 | ssp->mmio_base = ioremap(res->start, res->end - res->start + 1); | ||
386 | if (ssp->mmio_base == NULL) { | ||
387 | dev_err(&pdev->dev, "failed to ioremap() registers\n"); | ||
388 | ret = -ENODEV; | ||
389 | goto err_free_mem; | ||
390 | } | ||
391 | |||
392 | ssp->irq = platform_get_irq(pdev, 0); | ||
393 | if (ssp->irq < 0) { | ||
394 | dev_err(&pdev->dev, "no IRQ resource defined\n"); | ||
395 | ret = -ENODEV; | ||
396 | goto err_free_io; | ||
397 | } | ||
398 | |||
399 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
400 | if (res == NULL) { | ||
401 | dev_err(&pdev->dev, "no SSP RX DRCMR defined\n"); | ||
402 | ret = -ENODEV; | ||
403 | goto err_free_io; | ||
404 | } | ||
405 | ssp->drcmr_rx = res->start; | ||
406 | |||
407 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
408 | if (res == NULL) { | ||
409 | dev_err(&pdev->dev, "no SSP TX DRCMR defined\n"); | ||
410 | ret = -ENODEV; | ||
411 | goto err_free_io; | ||
412 | } | ||
413 | ssp->drcmr_tx = res->start; | ||
414 | |||
415 | /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id | ||
416 | * starts from 0, do a translation here | ||
417 | */ | ||
418 | ssp->port_id = pdev->id + 1; | ||
419 | ssp->use_count = 0; | ||
420 | ssp->type = (int)id->driver_data; | ||
421 | |||
422 | mutex_lock(&ssp_lock); | ||
423 | list_add(&ssp->node, &ssp_list); | ||
424 | mutex_unlock(&ssp_lock); | ||
425 | |||
426 | platform_set_drvdata(pdev, ssp); | ||
427 | return 0; | ||
428 | |||
429 | err_free_io: | ||
430 | iounmap(ssp->mmio_base); | ||
431 | err_free_mem: | ||
432 | release_mem_region(res->start, res->end - res->start + 1); | ||
433 | err_free_clk: | ||
434 | clk_put(ssp->clk); | ||
435 | err_free: | ||
436 | kfree(ssp); | ||
437 | return ret; | ||
438 | } | ||
439 | |||
440 | static int __devexit ssp_remove(struct platform_device *pdev) | ||
441 | { | ||
442 | struct resource *res; | ||
443 | struct ssp_device *ssp; | ||
444 | |||
445 | ssp = platform_get_drvdata(pdev); | ||
446 | if (ssp == NULL) | ||
447 | return -ENODEV; | ||
448 | |||
449 | iounmap(ssp->mmio_base); | ||
450 | |||
451 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
452 | release_mem_region(res->start, res->end - res->start + 1); | ||
453 | |||
454 | clk_put(ssp->clk); | ||
455 | |||
456 | mutex_lock(&ssp_lock); | ||
457 | list_del(&ssp->node); | ||
458 | mutex_unlock(&ssp_lock); | ||
459 | |||
460 | kfree(ssp); | ||
461 | return 0; | ||
462 | } | ||
463 | |||
464 | static const struct platform_device_id ssp_id_table[] = { | ||
465 | { "pxa25x-ssp", PXA25x_SSP }, | ||
466 | { "pxa25x-nssp", PXA25x_NSSP }, | ||
467 | { "pxa27x-ssp", PXA27x_SSP }, | ||
468 | { }, | ||
469 | }; | ||
470 | |||
471 | static struct platform_driver ssp_driver = { | ||
472 | .probe = ssp_probe, | ||
473 | .remove = __devexit_p(ssp_remove), | ||
474 | .driver = { | ||
475 | .owner = THIS_MODULE, | ||
476 | .name = "pxa2xx-ssp", | ||
477 | }, | ||
478 | .id_table = ssp_id_table, | ||
479 | }; | ||
480 | |||
481 | static int __init pxa_ssp_init(void) | ||
482 | { | ||
483 | return platform_driver_register(&ssp_driver); | ||
484 | } | ||
485 | |||
486 | static void __exit pxa_ssp_exit(void) | ||
487 | { | ||
488 | platform_driver_unregister(&ssp_driver); | ||
489 | } | ||
490 | |||
491 | arch_initcall(pxa_ssp_init); | ||
492 | module_exit(pxa_ssp_exit); | ||
493 | |||
494 | #ifdef CONFIG_PXA_SSP_LEGACY | ||
495 | EXPORT_SYMBOL(ssp_write_word); | ||
496 | EXPORT_SYMBOL(ssp_read_word); | ||
497 | EXPORT_SYMBOL(ssp_flush); | ||
498 | EXPORT_SYMBOL(ssp_enable); | ||
499 | EXPORT_SYMBOL(ssp_disable); | ||
500 | EXPORT_SYMBOL(ssp_save_state); | ||
501 | EXPORT_SYMBOL(ssp_restore_state); | ||
502 | EXPORT_SYMBOL(ssp_init); | ||
503 | EXPORT_SYMBOL(ssp_exit); | ||
504 | EXPORT_SYMBOL(ssp_config); | ||
505 | #endif | ||
506 | |||
507 | MODULE_DESCRIPTION("PXA SSP driver"); | ||
508 | MODULE_AUTHOR("Liam Girdwood"); | ||
509 | MODULE_LICENSE("GPL"); | ||
510 | |||