aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-pxa/ssp.c296
-rw-r--r--include/asm-arm/arch-pxa/ssp.h36
2 files changed, 273 insertions, 59 deletions
diff --git a/arch/arm/mach-pxa/ssp.c b/arch/arm/mach-pxa/ssp.c
index 422afee88169..be6fee78f439 100644
--- a/arch/arm/mach-pxa/ssp.c
+++ b/arch/arm/mach-pxa/ssp.c
@@ -32,39 +32,18 @@
32#include <linux/ioport.h> 32#include <linux/ioport.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/clk.h>
36#include <linux/err.h>
37#include <linux/platform_device.h>
38
35#include <asm/io.h> 39#include <asm/io.h>
36#include <asm/irq.h> 40#include <asm/irq.h>
37#include <asm/hardware.h> 41#include <asm/hardware.h>
38#include <asm/arch/ssp.h> 42#include <asm/arch/ssp.h>
39#include <asm/arch/pxa-regs.h> 43#include <asm/arch/pxa-regs.h>
40 44
41#define PXA_SSP_PORTS 3
42
43#define TIMEOUT 100000 45#define TIMEOUT 100000
44 46
45struct ssp_info_ {
46 int irq;
47 u32 clock;
48};
49
50/*
51 * SSP port clock and IRQ settings
52 */
53static const struct ssp_info_ ssp_info[PXA_SSP_PORTS] = {
54#if defined (CONFIG_PXA27x)
55 {IRQ_SSP, CKEN_SSP1},
56 {IRQ_SSP2, CKEN_SSP2},
57 {IRQ_SSP3, CKEN_SSP3},
58#else
59 {IRQ_SSP, CKEN_SSP},
60 {IRQ_NSSP, CKEN_NSSP},
61 {IRQ_ASSP, CKEN_ASSP},
62#endif
63};
64
65static DEFINE_MUTEX(mutex);
66static int use_count[PXA_SSP_PORTS] = {0, 0, 0};
67
68static irqreturn_t ssp_interrupt(int irq, void *dev_id) 47static irqreturn_t ssp_interrupt(int irq, void *dev_id)
69{ 48{
70 struct ssp_dev *dev = (struct ssp_dev*) dev_id; 49 struct ssp_dev *dev = (struct ssp_dev*) dev_id;
@@ -256,44 +235,32 @@ int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 spee
256 */ 235 */
257int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags) 236int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags)
258{ 237{
238 struct ssp_device *ssp;
259 int ret; 239 int ret;
260 240
261 if (port > PXA_SSP_PORTS || port == 0) 241 ssp = ssp_request(port, "SSP");
242 if (ssp == NULL)
262 return -ENODEV; 243 return -ENODEV;
263 244
264 mutex_lock(&mutex); 245 dev->ssp = ssp;
265 if (use_count[port - 1]) {
266 mutex_unlock(&mutex);
267 return -EBUSY;
268 }
269 use_count[port - 1]++;
270
271 if (!request_mem_region(__PREG(SSCR0_P(port)), 0x2c, "SSP")) {
272 use_count[port - 1]--;
273 mutex_unlock(&mutex);
274 return -EBUSY;
275 }
276 dev->port = port; 246 dev->port = port;
277 247
278 /* do we need to get irq */ 248 /* do we need to get irq */
279 if (!(init_flags & SSP_NO_IRQ)) { 249 if (!(init_flags & SSP_NO_IRQ)) {
280 ret = request_irq(ssp_info[port-1].irq, ssp_interrupt, 250 ret = request_irq(ssp->irq, ssp_interrupt,
281 0, "SSP", dev); 251 0, "SSP", dev);
282 if (ret) 252 if (ret)
283 goto out_region; 253 goto out_region;
284 dev->irq = ssp_info[port-1].irq; 254 dev->irq = ssp->irq;
285 } else 255 } else
286 dev->irq = 0; 256 dev->irq = 0;
287 257
288 /* turn on SSP port clock */ 258 /* turn on SSP port clock */
289 pxa_set_cken(ssp_info[port-1].clock, 1); 259 clk_enable(ssp->clk);
290 mutex_unlock(&mutex);
291 return 0; 260 return 0;
292 261
293out_region: 262out_region:
294 release_mem_region(__PREG(SSCR0_P(port)), 0x2c); 263 ssp_free(ssp);
295 use_count[port - 1]--;
296 mutex_unlock(&mutex);
297 return ret; 264 return ret;
298} 265}
299 266
@@ -304,22 +271,239 @@ out_region:
304 */ 271 */
305void ssp_exit(struct ssp_dev *dev) 272void ssp_exit(struct ssp_dev *dev)
306{ 273{
307 mutex_lock(&mutex); 274 struct ssp_device *ssp = dev->ssp;
275
308 SSCR0_P(dev->port) &= ~SSCR0_SSE; 276 SSCR0_P(dev->port) &= ~SSCR0_SSE;
277 free_irq(dev->irq, dev);
278 clk_disable(ssp->clk);
279 ssp_free(ssp);
280}
281
282static DEFINE_MUTEX(ssp_lock);
283static LIST_HEAD(ssp_list);
284
285struct ssp_device *ssp_request(int port, const char *label)
286{
287 struct ssp_device *ssp = NULL;
288
289 mutex_lock(&ssp_lock);
309 290
310 if (dev->port > PXA_SSP_PORTS || dev->port == 0) { 291 list_for_each_entry(ssp, &ssp_list, node) {
311 printk(KERN_WARNING "SSP: tried to close invalid port\n"); 292 if (ssp->port_id == port && ssp->use_count == 0) {
312 mutex_unlock(&mutex); 293 ssp->use_count++;
313 return; 294 ssp->label = label;
295 break;
296 }
314 } 297 }
315 298
316 pxa_set_cken(ssp_info[dev->port-1].clock, 0); 299 mutex_unlock(&ssp_lock);
317 if (dev->irq) 300
318 free_irq(dev->irq, dev); 301 if (ssp->port_id != port)
319 release_mem_region(__PREG(SSCR0_P(dev->port)), 0x2c); 302 return NULL;
320 use_count[dev->port - 1]--; 303
321 mutex_unlock(&mutex); 304 return ssp;
305}
306EXPORT_SYMBOL(ssp_request);
307
308void ssp_free(struct ssp_device *ssp)
309{
310 mutex_lock(&ssp_lock);
311 if (ssp->use_count) {
312 ssp->use_count--;
313 ssp->label = NULL;
314 } else
315 dev_err(&ssp->pdev->dev, "device already free\n");
316 mutex_unlock(&ssp_lock);
322} 317}
318EXPORT_SYMBOL(ssp_free);
319
320static int __devinit ssp_probe(struct platform_device *pdev, int type)
321{
322 struct resource *res;
323 struct ssp_device *ssp;
324 int ret = 0;
325
326 ssp = kzalloc(sizeof(struct ssp_device), GFP_KERNEL);
327 if (ssp == NULL) {
328 dev_err(&pdev->dev, "failed to allocate memory");
329 return -ENOMEM;
330 }
331
332 ssp->clk = clk_get(&pdev->dev, "SSPCLK");
333 if (IS_ERR(ssp->clk)) {
334 ret = PTR_ERR(ssp->clk);
335 goto err_free;
336 }
337
338 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
339 if (res == NULL) {
340 dev_err(&pdev->dev, "no memory resource defined\n");
341 ret = -ENODEV;
342 goto err_free_clk;
343 }
344
345 res = request_mem_region(res->start, res->end - res->start + 1,
346 pdev->name);
347 if (res == NULL) {
348 dev_err(&pdev->dev, "failed to request memory resource\n");
349 ret = -EBUSY;
350 goto err_free_clk;
351 }
352
353 ssp->phys_base = res->start;
354
355 ssp->mmio_base = ioremap(res->start, res->end - res->start + 1);
356 if (ssp->mmio_base == NULL) {
357 dev_err(&pdev->dev, "failed to ioremap() registers\n");
358 ret = -ENODEV;
359 goto err_free_mem;
360 }
361
362 ssp->irq = platform_get_irq(pdev, 0);
363 if (ssp->irq < 0) {
364 dev_err(&pdev->dev, "no IRQ resource defined\n");
365 ret = -ENODEV;
366 goto err_free_io;
367 }
368
369 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
370 if (res == NULL) {
371 dev_err(&pdev->dev, "no SSP RX DRCMR defined\n");
372 ret = -ENODEV;
373 goto err_free_io;
374 }
375 ssp->drcmr_rx = res->start;
376
377 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
378 if (res == NULL) {
379 dev_err(&pdev->dev, "no SSP TX DRCMR defined\n");
380 ret = -ENODEV;
381 goto err_free_io;
382 }
383 ssp->drcmr_tx = res->start;
384
385 /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id
386 * starts from 0, do a translation here
387 */
388 ssp->port_id = pdev->id + 1;
389 ssp->use_count = 0;
390 ssp->type = type;
391
392 mutex_lock(&ssp_lock);
393 list_add(&ssp->node, &ssp_list);
394 mutex_unlock(&ssp_lock);
395
396 platform_set_drvdata(pdev, ssp);
397 return 0;
398
399err_free_io:
400 iounmap(ssp->mmio_base);
401err_free_mem:
402 release_mem_region(res->start, res->end - res->start + 1);
403err_free_clk:
404 clk_put(ssp->clk);
405err_free:
406 kfree(ssp);
407 return ret;
408}
409
410static int __devexit ssp_remove(struct platform_device *pdev)
411{
412 struct resource *res;
413 struct ssp_device *ssp;
414
415 ssp = platform_get_drvdata(pdev);
416 if (ssp == NULL)
417 return -ENODEV;
418
419 iounmap(ssp->mmio_base);
420
421 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
422 release_mem_region(res->start, res->end - res->start + 1);
423
424 clk_put(ssp->clk);
425
426 mutex_lock(&ssp_lock);
427 list_del(&ssp->node);
428 mutex_unlock(&ssp_lock);
429
430 kfree(ssp);
431 return 0;
432}
433
434static int __devinit pxa25x_ssp_probe(struct platform_device *pdev)
435{
436 return ssp_probe(pdev, PXA25x_SSP);
437}
438
439static int __devinit pxa25x_nssp_probe(struct platform_device *pdev)
440{
441 return ssp_probe(pdev, PXA25x_NSSP);
442}
443
444static int __devinit pxa27x_ssp_probe(struct platform_device *pdev)
445{
446 return ssp_probe(pdev, PXA27x_SSP);
447}
448
449static struct platform_driver pxa25x_ssp_driver = {
450 .driver = {
451 .name = "pxa25x-ssp",
452 },
453 .probe = pxa25x_ssp_probe,
454 .remove = __devexit_p(ssp_remove),
455};
456
457static struct platform_driver pxa25x_nssp_driver = {
458 .driver = {
459 .name = "pxa25x-nssp",
460 },
461 .probe = pxa25x_nssp_probe,
462 .remove = __devexit_p(ssp_remove),
463};
464
465static struct platform_driver pxa27x_ssp_driver = {
466 .driver = {
467 .name = "pxa27x-ssp",
468 },
469 .probe = pxa27x_ssp_probe,
470 .remove = __devexit_p(ssp_remove),
471};
472
473static int __init pxa_ssp_init(void)
474{
475 int ret = 0;
476
477 ret = platform_driver_register(&pxa25x_ssp_driver);
478 if (ret) {
479 printk(KERN_ERR "failed to register pxa25x_ssp_driver");
480 return ret;
481 }
482
483 ret = platform_driver_register(&pxa25x_nssp_driver);
484 if (ret) {
485 printk(KERN_ERR "failed to register pxa25x_nssp_driver");
486 return ret;
487 }
488
489 ret = platform_driver_register(&pxa27x_ssp_driver);
490 if (ret) {
491 printk(KERN_ERR "failed to register pxa27x_ssp_driver");
492 return ret;
493 }
494
495 return ret;
496}
497
498static void __exit pxa_ssp_exit(void)
499{
500 platform_driver_unregister(&pxa25x_ssp_driver);
501 platform_driver_unregister(&pxa25x_nssp_driver);
502 platform_driver_unregister(&pxa27x_ssp_driver);
503}
504
505module_init(pxa_ssp_init);
506module_exit(pxa_ssp_exit);
323 507
324EXPORT_SYMBOL(ssp_write_word); 508EXPORT_SYMBOL(ssp_write_word);
325EXPORT_SYMBOL(ssp_read_word); 509EXPORT_SYMBOL(ssp_read_word);
diff --git a/include/asm-arm/arch-pxa/ssp.h b/include/asm-arm/arch-pxa/ssp.h
index ea200551a75f..a012882c9ee6 100644
--- a/include/asm-arm/arch-pxa/ssp.h
+++ b/include/asm-arm/arch-pxa/ssp.h
@@ -13,10 +13,37 @@
13 * PXA255 SSP, NSSP 13 * PXA255 SSP, NSSP
14 * PXA26x SSP, NSSP, ASSP 14 * PXA26x SSP, NSSP, ASSP
15 * PXA27x SSP1, SSP2, SSP3 15 * PXA27x SSP1, SSP2, SSP3
16 * PXA3xx SSP1, SSP2, SSP3, SSP4
16 */ 17 */
17 18
18#ifndef SSP_H 19#ifndef __ASM_ARCH_SSP_H
19#define SSP_H 20#define __ASM_ARCH_SSP_H
21
22#include <linux/list.h>
23
24enum pxa_ssp_type {
25 SSP_UNDEFINED = 0,
26 PXA25x_SSP, /* pxa 210, 250, 255, 26x */
27 PXA25x_NSSP, /* pxa 255, 26x (including ASSP) */
28 PXA27x_SSP,
29};
30
31struct ssp_device {
32 struct platform_device *pdev;
33 struct list_head node;
34
35 struct clk *clk;
36 void __iomem *mmio_base;
37 unsigned long phys_base;
38
39 const char *label;
40 int port_id;
41 int type;
42 int use_count;
43 int irq;
44 int drcmr_rx;
45 int drcmr_tx;
46};
20 47
21/* 48/*
22 * SSP initialisation flags 49 * SSP initialisation flags
@@ -31,6 +58,7 @@ struct ssp_state {
31}; 58};
32 59
33struct ssp_dev { 60struct ssp_dev {
61 struct ssp_device *ssp;
34 u32 port; 62 u32 port;
35 u32 mode; 63 u32 mode;
36 u32 flags; 64 u32 flags;
@@ -50,4 +78,6 @@ int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags);
50int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed); 78int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed);
51void ssp_exit(struct ssp_dev *dev); 79void ssp_exit(struct ssp_dev *dev);
52 80
53#endif 81struct ssp_device *ssp_request(int port, const char *label);
82void ssp_free(struct ssp_device *);
83#endif /* __ASM_ARCH_SSP_H */