2 * linux/arch/arm/mach-pxa/ssp.c
4 * based on linux/arch/arm/mach-sa1100/ssp.c by Russell King
6 * Copyright (C) 2003 Russell King.
7 * Copyright (C) 2003 Wolfson Microelectronics PLC
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.
13 * PXA2xx SSP driver. This provides the generic core for simple
14 * IO-based SSP applications and allows easy port setup for DMA access.
16 * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
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>
34 #include <mach/hardware.h>
36 #include <mach/regs-ssp.h>
38 static DEFINE_MUTEX(ssp_lock);
39 static LIST_HEAD(ssp_list);
41 struct ssp_device *ssp_request(int port, const char *label)
43 struct ssp_device *ssp = NULL;
45 mutex_lock(&ssp_lock);
47 list_for_each_entry(ssp, &ssp_list, node) {
48 if (ssp->port_id == port && ssp->use_count == 0) {
55 mutex_unlock(&ssp_lock);
57 if (&ssp->node == &ssp_list)
62 EXPORT_SYMBOL(ssp_request);
64 void ssp_free(struct ssp_device *ssp)
66 mutex_lock(&ssp_lock);
71 dev_err(&ssp->pdev->dev, "device already free\n");
72 mutex_unlock(&ssp_lock);
74 EXPORT_SYMBOL(ssp_free);
76 static int __devinit ssp_probe(struct platform_device *pdev)
78 const struct platform_device_id *id = platform_get_device_id(pdev);
80 struct ssp_device *ssp;
83 ssp = kzalloc(sizeof(struct ssp_device), GFP_KERNEL);
85 dev_err(&pdev->dev, "failed to allocate memory");
90 ssp->clk = clk_get(&pdev->dev, NULL);
91 if (IS_ERR(ssp->clk)) {
92 ret = PTR_ERR(ssp->clk);
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98 dev_err(&pdev->dev, "no memory resource defined\n");
103 res = request_mem_region(res->start, res->end - res->start + 1,
106 dev_err(&pdev->dev, "failed to request memory resource\n");
111 ssp->phys_base = res->start;
113 ssp->mmio_base = ioremap(res->start, res->end - res->start + 1);
114 if (ssp->mmio_base == NULL) {
115 dev_err(&pdev->dev, "failed to ioremap() registers\n");
120 ssp->irq = platform_get_irq(pdev, 0);
122 dev_err(&pdev->dev, "no IRQ resource defined\n");
127 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
129 dev_err(&pdev->dev, "no SSP RX DRCMR defined\n");
133 ssp->drcmr_rx = res->start;
135 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
137 dev_err(&pdev->dev, "no SSP TX DRCMR defined\n");
141 ssp->drcmr_tx = res->start;
143 /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id
144 * starts from 0, do a translation here
146 ssp->port_id = pdev->id + 1;
148 ssp->type = (int)id->driver_data;
150 mutex_lock(&ssp_lock);
151 list_add(&ssp->node, &ssp_list);
152 mutex_unlock(&ssp_lock);
154 platform_set_drvdata(pdev, ssp);
158 iounmap(ssp->mmio_base);
160 release_mem_region(res->start, res->end - res->start + 1);
168 static int __devexit ssp_remove(struct platform_device *pdev)
170 struct resource *res;
171 struct ssp_device *ssp;
173 ssp = platform_get_drvdata(pdev);
177 iounmap(ssp->mmio_base);
179 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
180 release_mem_region(res->start, res->end - res->start + 1);
184 mutex_lock(&ssp_lock);
185 list_del(&ssp->node);
186 mutex_unlock(&ssp_lock);
192 static const struct platform_device_id ssp_id_table[] = {
193 { "pxa25x-ssp", PXA25x_SSP },
194 { "pxa25x-nssp", PXA25x_NSSP },
195 { "pxa27x-ssp", PXA27x_SSP },
199 static struct platform_driver ssp_driver = {
201 .remove = __devexit_p(ssp_remove),
203 .owner = THIS_MODULE,
204 .name = "pxa2xx-ssp",
206 .id_table = ssp_id_table,
209 static int __init pxa_ssp_init(void)
211 return platform_driver_register(&ssp_driver);
214 static void __exit pxa_ssp_exit(void)
216 platform_driver_unregister(&ssp_driver);
219 arch_initcall(pxa_ssp_init);
220 module_exit(pxa_ssp_exit);
222 MODULE_DESCRIPTION("PXA SSP driver");
223 MODULE_AUTHOR("Liam Girdwood");
224 MODULE_LICENSE("GPL");