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>
31 #include <linux/spi/pxa2xx_spi.h>
34 #include <linux/of_device.h>
38 static DEFINE_MUTEX(ssp_lock
);
39 static LIST_HEAD(ssp_list
);
41 struct ssp_device
*pxa_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(pxa_ssp_request
);
64 struct ssp_device
*pxa_ssp_request_of(const struct device_node
*of_node
,
67 struct ssp_device
*ssp
= NULL
;
69 mutex_lock(&ssp_lock
);
71 list_for_each_entry(ssp
, &ssp_list
, node
) {
72 if (ssp
->of_node
== of_node
&& ssp
->use_count
== 0) {
79 mutex_unlock(&ssp_lock
);
81 if (&ssp
->node
== &ssp_list
)
86 EXPORT_SYMBOL(pxa_ssp_request_of
);
88 void pxa_ssp_free(struct ssp_device
*ssp
)
90 mutex_lock(&ssp_lock
);
95 dev_err(&ssp
->pdev
->dev
, "device already free\n");
96 mutex_unlock(&ssp_lock
);
98 EXPORT_SYMBOL(pxa_ssp_free
);
101 static const struct of_device_id pxa_ssp_of_ids
[] = {
102 { .compatible
= "mrvl,pxa25x-ssp", .data
= (void *) PXA25x_SSP
},
103 { .compatible
= "mvrl,pxa25x-nssp", .data
= (void *) PXA25x_NSSP
},
104 { .compatible
= "mrvl,pxa27x-ssp", .data
= (void *) PXA27x_SSP
},
105 { .compatible
= "mrvl,pxa3xx-ssp", .data
= (void *) PXA3xx_SSP
},
106 { .compatible
= "mvrl,pxa168-ssp", .data
= (void *) PXA168_SSP
},
107 { .compatible
= "mrvl,pxa910-ssp", .data
= (void *) PXA910_SSP
},
108 { .compatible
= "mrvl,ce4100-ssp", .data
= (void *) CE4100_SSP
},
111 MODULE_DEVICE_TABLE(of
, pxa_ssp_of_ids
);
114 static int pxa_ssp_probe(struct platform_device
*pdev
)
116 struct resource
*res
;
117 struct ssp_device
*ssp
;
118 struct device
*dev
= &pdev
->dev
;
120 ssp
= devm_kzalloc(dev
, sizeof(struct ssp_device
), GFP_KERNEL
);
126 ssp
->clk
= devm_clk_get(dev
, NULL
);
127 if (IS_ERR(ssp
->clk
))
128 return PTR_ERR(ssp
->clk
);
130 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
132 dev_err(dev
, "no memory resource defined\n");
136 res
= devm_request_mem_region(dev
, res
->start
, resource_size(res
),
139 dev_err(dev
, "failed to request memory resource\n");
143 ssp
->phys_base
= res
->start
;
145 ssp
->mmio_base
= devm_ioremap(dev
, res
->start
, resource_size(res
));
146 if (ssp
->mmio_base
== NULL
) {
147 dev_err(dev
, "failed to ioremap() registers\n");
151 ssp
->irq
= platform_get_irq(pdev
, 0);
153 dev_err(dev
, "no IRQ resource defined\n");
158 const struct of_device_id
*id
=
159 of_match_device(of_match_ptr(pxa_ssp_of_ids
), dev
);
160 ssp
->type
= (int) id
->data
;
162 const struct platform_device_id
*id
=
163 platform_get_device_id(pdev
);
164 ssp
->type
= (int) id
->driver_data
;
166 /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id
167 * starts from 0, do a translation here
169 ssp
->port_id
= pdev
->id
+ 1;
173 ssp
->of_node
= dev
->of_node
;
175 mutex_lock(&ssp_lock
);
176 list_add(&ssp
->node
, &ssp_list
);
177 mutex_unlock(&ssp_lock
);
179 platform_set_drvdata(pdev
, ssp
);
184 static int pxa_ssp_remove(struct platform_device
*pdev
)
186 struct resource
*res
;
187 struct ssp_device
*ssp
;
189 ssp
= platform_get_drvdata(pdev
);
193 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
194 release_mem_region(res
->start
, resource_size(res
));
198 mutex_lock(&ssp_lock
);
199 list_del(&ssp
->node
);
200 mutex_unlock(&ssp_lock
);
205 static const struct platform_device_id ssp_id_table
[] = {
206 { "pxa25x-ssp", PXA25x_SSP
},
207 { "pxa25x-nssp", PXA25x_NSSP
},
208 { "pxa27x-ssp", PXA27x_SSP
},
209 { "pxa3xx-ssp", PXA3xx_SSP
},
210 { "pxa168-ssp", PXA168_SSP
},
211 { "pxa910-ssp", PXA910_SSP
},
215 static struct platform_driver pxa_ssp_driver
= {
216 .probe
= pxa_ssp_probe
,
217 .remove
= pxa_ssp_remove
,
219 .name
= "pxa2xx-ssp",
220 .of_match_table
= of_match_ptr(pxa_ssp_of_ids
),
222 .id_table
= ssp_id_table
,
225 static int __init
pxa_ssp_init(void)
227 return platform_driver_register(&pxa_ssp_driver
);
230 static void __exit
pxa_ssp_exit(void)
232 platform_driver_unregister(&pxa_ssp_driver
);
235 arch_initcall(pxa_ssp_init
);
236 module_exit(pxa_ssp_exit
);
238 MODULE_DESCRIPTION("PXA SSP driver");
239 MODULE_AUTHOR("Liam Girdwood");
240 MODULE_LICENSE("GPL");