~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/plat-pxa/ssp.c

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.15 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.73 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.144 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.193 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.193 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.73 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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/spi/pxa2xx_spi.h>
 32 #include <linux/io.h>
 33 #include <linux/of.h>
 34 #include <linux/of_device.h>
 35 
 36 #include <asm/irq.h>
 37 #include <mach/hardware.h>
 38 
 39 static DEFINE_MUTEX(ssp_lock);
 40 static LIST_HEAD(ssp_list);
 41 
 42 struct ssp_device *pxa_ssp_request(int port, const char *label)
 43 {
 44         struct ssp_device *ssp = NULL;
 45 
 46         mutex_lock(&ssp_lock);
 47 
 48         list_for_each_entry(ssp, &ssp_list, node) {
 49                 if (ssp->port_id == port && ssp->use_count == 0) {
 50                         ssp->use_count++;
 51                         ssp->label = label;
 52                         break;
 53                 }
 54         }
 55 
 56         mutex_unlock(&ssp_lock);
 57 
 58         if (&ssp->node == &ssp_list)
 59                 return NULL;
 60 
 61         return ssp;
 62 }
 63 EXPORT_SYMBOL(pxa_ssp_request);
 64 
 65 struct ssp_device *pxa_ssp_request_of(const struct device_node *of_node,
 66                                       const char *label)
 67 {
 68         struct ssp_device *ssp = NULL;
 69 
 70         mutex_lock(&ssp_lock);
 71 
 72         list_for_each_entry(ssp, &ssp_list, node) {
 73                 if (ssp->of_node == of_node && ssp->use_count == 0) {
 74                         ssp->use_count++;
 75                         ssp->label = label;
 76                         break;
 77                 }
 78         }
 79 
 80         mutex_unlock(&ssp_lock);
 81 
 82         if (&ssp->node == &ssp_list)
 83                 return NULL;
 84 
 85         return ssp;
 86 }
 87 EXPORT_SYMBOL(pxa_ssp_request_of);
 88 
 89 void pxa_ssp_free(struct ssp_device *ssp)
 90 {
 91         mutex_lock(&ssp_lock);
 92         if (ssp->use_count) {
 93                 ssp->use_count--;
 94                 ssp->label = NULL;
 95         } else
 96                 dev_err(&ssp->pdev->dev, "device already free\n");
 97         mutex_unlock(&ssp_lock);
 98 }
 99 EXPORT_SYMBOL(pxa_ssp_free);
100 
101 #ifdef CONFIG_OF
102 static const struct of_device_id pxa_ssp_of_ids[] = {
103         { .compatible = "mrvl,pxa25x-ssp",      .data = (void *) PXA25x_SSP },
104         { .compatible = "mvrl,pxa25x-nssp",     .data = (void *) PXA25x_NSSP },
105         { .compatible = "mrvl,pxa27x-ssp",      .data = (void *) PXA27x_SSP },
106         { .compatible = "mrvl,pxa3xx-ssp",      .data = (void *) PXA3xx_SSP },
107         { .compatible = "mvrl,pxa168-ssp",      .data = (void *) PXA168_SSP },
108         { .compatible = "mrvl,pxa910-ssp",      .data = (void *) PXA910_SSP },
109         { .compatible = "mrvl,ce4100-ssp",      .data = (void *) CE4100_SSP },
110         { },
111 };
112 MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids);
113 #endif
114 
115 static int pxa_ssp_probe(struct platform_device *pdev)
116 {
117         struct resource *res;
118         struct ssp_device *ssp;
119         struct device *dev = &pdev->dev;
120 
121         ssp = devm_kzalloc(dev, sizeof(struct ssp_device), GFP_KERNEL);
122         if (ssp == NULL)
123                 return -ENOMEM;
124 
125         ssp->pdev = pdev;
126 
127         ssp->clk = devm_clk_get(dev, NULL);
128         if (IS_ERR(ssp->clk))
129                 return PTR_ERR(ssp->clk);
130 
131         if (dev->of_node) {
132                 struct of_phandle_args dma_spec;
133                 struct device_node *np = dev->of_node;
134                 int ret;
135 
136                 /*
137                  * FIXME: we should allocate the DMA channel from this
138                  * context and pass the channel down to the ssp users.
139                  * For now, we lookup the rx and tx indices manually
140                  */
141 
142                 /* rx */
143                 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells",
144                                                  0, &dma_spec);
145 
146                 if (ret) {
147                         dev_err(dev, "Can't parse dmas property\n");
148                         return -ENODEV;
149                 }
150                 ssp->drcmr_rx = dma_spec.args[0];
151                 of_node_put(dma_spec.np);
152 
153                 /* tx */
154                 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells",
155                                                  1, &dma_spec);
156                 if (ret) {
157                         dev_err(dev, "Can't parse dmas property\n");
158                         return -ENODEV;
159                 }
160                 ssp->drcmr_tx = dma_spec.args[0];
161                 of_node_put(dma_spec.np);
162         } else {
163                 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
164                 if (res == NULL) {
165                         dev_err(dev, "no SSP RX DRCMR defined\n");
166                         return -ENODEV;
167                 }
168                 ssp->drcmr_rx = res->start;
169 
170                 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
171                 if (res == NULL) {
172                         dev_err(dev, "no SSP TX DRCMR defined\n");
173                         return -ENODEV;
174                 }
175                 ssp->drcmr_tx = res->start;
176         }
177 
178         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
179         if (res == NULL) {
180                 dev_err(dev, "no memory resource defined\n");
181                 return -ENODEV;
182         }
183 
184         res = devm_request_mem_region(dev, res->start, resource_size(res),
185                                       pdev->name);
186         if (res == NULL) {
187                 dev_err(dev, "failed to request memory resource\n");
188                 return -EBUSY;
189         }
190 
191         ssp->phys_base = res->start;
192 
193         ssp->mmio_base = devm_ioremap(dev, res->start, resource_size(res));
194         if (ssp->mmio_base == NULL) {
195                 dev_err(dev, "failed to ioremap() registers\n");
196                 return -ENODEV;
197         }
198 
199         ssp->irq = platform_get_irq(pdev, 0);
200         if (ssp->irq < 0) {
201                 dev_err(dev, "no IRQ resource defined\n");
202                 return -ENODEV;
203         }
204 
205         if (dev->of_node) {
206                 const struct of_device_id *id =
207                         of_match_device(of_match_ptr(pxa_ssp_of_ids), dev);
208                 ssp->type = (int) id->data;
209         } else {
210                 const struct platform_device_id *id =
211                         platform_get_device_id(pdev);
212                 ssp->type = (int) id->driver_data;
213 
214                 /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id
215                  * starts from 0, do a translation here
216                  */
217                 ssp->port_id = pdev->id + 1;
218         }
219 
220         ssp->use_count = 0;
221         ssp->of_node = dev->of_node;
222 
223         mutex_lock(&ssp_lock);
224         list_add(&ssp->node, &ssp_list);
225         mutex_unlock(&ssp_lock);
226 
227         platform_set_drvdata(pdev, ssp);
228 
229         return 0;
230 }
231 
232 static int pxa_ssp_remove(struct platform_device *pdev)
233 {
234         struct resource *res;
235         struct ssp_device *ssp;
236 
237         ssp = platform_get_drvdata(pdev);
238         if (ssp == NULL)
239                 return -ENODEV;
240 
241         iounmap(ssp->mmio_base);
242 
243         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
244         release_mem_region(res->start, resource_size(res));
245 
246         clk_put(ssp->clk);
247 
248         mutex_lock(&ssp_lock);
249         list_del(&ssp->node);
250         mutex_unlock(&ssp_lock);
251 
252         kfree(ssp);
253         return 0;
254 }
255 
256 static const struct platform_device_id ssp_id_table[] = {
257         { "pxa25x-ssp",         PXA25x_SSP },
258         { "pxa25x-nssp",        PXA25x_NSSP },
259         { "pxa27x-ssp",         PXA27x_SSP },
260         { "pxa3xx-ssp",         PXA3xx_SSP },
261         { "pxa168-ssp",         PXA168_SSP },
262         { "pxa910-ssp",         PXA910_SSP },
263         { },
264 };
265 
266 static struct platform_driver pxa_ssp_driver = {
267         .probe          = pxa_ssp_probe,
268         .remove         = pxa_ssp_remove,
269         .driver         = {
270                 .name           = "pxa2xx-ssp",
271                 .of_match_table = of_match_ptr(pxa_ssp_of_ids),
272         },
273         .id_table       = ssp_id_table,
274 };
275 
276 static int __init pxa_ssp_init(void)
277 {
278         return platform_driver_register(&pxa_ssp_driver);
279 }
280 
281 static void __exit pxa_ssp_exit(void)
282 {
283         platform_driver_unregister(&pxa_ssp_driver);
284 }
285 
286 arch_initcall(pxa_ssp_init);
287 module_exit(pxa_ssp_exit);
288 
289 MODULE_DESCRIPTION("PXA SSP driver");
290 MODULE_AUTHOR("Liam Girdwood");
291 MODULE_LICENSE("GPL");
292 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp