diff options
author | Joachim Eastwood <manabian@gmail.com> | 2015-07-11 08:12:06 -0400 |
---|---|---|
committer | Vinod Koul <vinod.koul@intel.com> | 2015-08-18 12:42:14 -0400 |
commit | e5f4ae84be7421010780984bdc121eac15997327 (patch) | |
tree | a1b95956d57b0a659b50b3361d39b21bacee98f6 /drivers/dma | |
parent | fbd7e41005a4daa676e3f516d07aeff0a81dca2b (diff) |
dmaengine: add driver for lpc18xx dmamux
Add support for DMA on NXP LPC18xx/43xx platforms which has
a multiplexer in front of the PL080 dma request lines.
The mux is a single register in the LPC18xx/43xx CREG block
and can multiplex up to 4 request lines to each of the 16
lines on the PL080.
Signed-off-by: Joachim Eastwood <manabian@gmail.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Diffstat (limited to 'drivers/dma')
-rw-r--r-- | drivers/dma/Kconfig | 9 | ||||
-rw-r--r-- | drivers/dma/Makefile | 1 | ||||
-rw-r--r-- | drivers/dma/lpc18xx-dmamux.c | 183 |
3 files changed, 193 insertions, 0 deletions
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index 88d474b78076..9d5a77cb9715 100644 --- a/drivers/dma/Kconfig +++ b/drivers/dma/Kconfig | |||
@@ -63,6 +63,15 @@ config AMBA_PL08X | |||
63 | Platform has a PL08x DMAC device | 63 | Platform has a PL08x DMAC device |
64 | which can provide DMA engine support | 64 | which can provide DMA engine support |
65 | 65 | ||
66 | config LPC18XX_DMAMUX | ||
67 | bool "NXP LPC18xx/43xx DMA MUX for PL080" | ||
68 | depends on ARCH_LPC18XX || COMPILE_TEST | ||
69 | depends on OF && AMBA_PL08X | ||
70 | select MFD_SYSCON | ||
71 | help | ||
72 | Enable support for DMA on NXP LPC18xx/43xx platforms | ||
73 | with PL080 and multiplexed DMA request lines. | ||
74 | |||
66 | config INTEL_IOATDMA | 75 | config INTEL_IOATDMA |
67 | tristate "Intel I/OAT DMA support" | 76 | tristate "Intel I/OAT DMA support" |
68 | depends on PCI && X86 | 77 | depends on PCI && X86 |
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile index 6a4d6f2827da..800cb2d20be8 100644 --- a/drivers/dma/Makefile +++ b/drivers/dma/Makefile | |||
@@ -32,6 +32,7 @@ obj-$(CONFIG_TI_EDMA) += edma.o | |||
32 | obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o | 32 | obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o |
33 | obj-$(CONFIG_TEGRA20_APB_DMA) += tegra20-apb-dma.o | 33 | obj-$(CONFIG_TEGRA20_APB_DMA) += tegra20-apb-dma.o |
34 | obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o | 34 | obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o |
35 | obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o | ||
35 | obj-$(CONFIG_PL330_DMA) += pl330.o | 36 | obj-$(CONFIG_PL330_DMA) += pl330.o |
36 | obj-$(CONFIG_PCH_DMA) += pch_dma.o | 37 | obj-$(CONFIG_PCH_DMA) += pch_dma.o |
37 | obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o | 38 | obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o |
diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c new file mode 100644 index 000000000000..761f32687055 --- /dev/null +++ b/drivers/dma/lpc18xx-dmamux.c | |||
@@ -0,0 +1,183 @@ | |||
1 | /* | ||
2 | * DMA Router driver for LPC18xx/43xx DMA MUX | ||
3 | * | ||
4 | * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com> | ||
5 | * | ||
6 | * Based on TI DMA Crossbar driver by: | ||
7 | * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com | ||
8 | * Author: Peter Ujfalusi <peter.ujfalusi@ti.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/err.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/mfd/syscon.h> | ||
19 | #include <linux/of_device.h> | ||
20 | #include <linux/of_dma.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | |||
24 | /* CREG register offset and macros for mux manipulation */ | ||
25 | #define LPC18XX_CREG_DMAMUX 0x11c | ||
26 | #define LPC18XX_DMAMUX_VAL(v, n) ((v) << (n * 2)) | ||
27 | #define LPC18XX_DMAMUX_MASK(n) (0x3 << (n * 2)) | ||
28 | #define LPC18XX_DMAMUX_MAX_VAL 0x3 | ||
29 | |||
30 | struct lpc18xx_dmamux { | ||
31 | u32 value; | ||
32 | bool busy; | ||
33 | }; | ||
34 | |||
35 | struct lpc18xx_dmamux_data { | ||
36 | struct dma_router dmarouter; | ||
37 | struct lpc18xx_dmamux *muxes; | ||
38 | u32 dma_master_requests; | ||
39 | u32 dma_mux_requests; | ||
40 | struct regmap *reg; | ||
41 | spinlock_t lock; | ||
42 | }; | ||
43 | |||
44 | static void lpc18xx_dmamux_free(struct device *dev, void *route_data) | ||
45 | { | ||
46 | struct lpc18xx_dmamux_data *dmamux = dev_get_drvdata(dev); | ||
47 | struct lpc18xx_dmamux *mux = route_data; | ||
48 | unsigned long flags; | ||
49 | |||
50 | spin_lock_irqsave(&dmamux->lock, flags); | ||
51 | mux->busy = false; | ||
52 | spin_unlock_irqrestore(&dmamux->lock, flags); | ||
53 | } | ||
54 | |||
55 | static void *lpc18xx_dmamux_reserve(struct of_phandle_args *dma_spec, | ||
56 | struct of_dma *ofdma) | ||
57 | { | ||
58 | struct platform_device *pdev = of_find_device_by_node(ofdma->of_node); | ||
59 | struct lpc18xx_dmamux_data *dmamux = platform_get_drvdata(pdev); | ||
60 | unsigned long flags; | ||
61 | unsigned mux; | ||
62 | |||
63 | if (dma_spec->args_count != 3) { | ||
64 | dev_err(&pdev->dev, "invalid number of dma mux args\n"); | ||
65 | return ERR_PTR(-EINVAL); | ||
66 | } | ||
67 | |||
68 | mux = dma_spec->args[0]; | ||
69 | if (mux >= dmamux->dma_master_requests) { | ||
70 | dev_err(&pdev->dev, "invalid mux number: %d\n", | ||
71 | dma_spec->args[0]); | ||
72 | return ERR_PTR(-EINVAL); | ||
73 | } | ||
74 | |||
75 | if (dma_spec->args[1] > LPC18XX_DMAMUX_MAX_VAL) { | ||
76 | dev_err(&pdev->dev, "invalid dma mux value: %d\n", | ||
77 | dma_spec->args[1]); | ||
78 | return ERR_PTR(-EINVAL); | ||
79 | } | ||
80 | |||
81 | /* The of_node_put() will be done in the core for the node */ | ||
82 | dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0); | ||
83 | if (!dma_spec->np) { | ||
84 | dev_err(&pdev->dev, "can't get dma master\n"); | ||
85 | return ERR_PTR(-EINVAL); | ||
86 | } | ||
87 | |||
88 | spin_lock_irqsave(&dmamux->lock, flags); | ||
89 | if (dmamux->muxes[mux].busy) { | ||
90 | spin_unlock_irqrestore(&dmamux->lock, flags); | ||
91 | dev_err(&pdev->dev, "dma request %u busy with %u.%u\n", | ||
92 | mux, mux, dmamux->muxes[mux].value); | ||
93 | of_node_put(dma_spec->np); | ||
94 | return ERR_PTR(-EBUSY); | ||
95 | } | ||
96 | |||
97 | dmamux->muxes[mux].busy = true; | ||
98 | dmamux->muxes[mux].value = dma_spec->args[1]; | ||
99 | |||
100 | regmap_update_bits(dmamux->reg, LPC18XX_CREG_DMAMUX, | ||
101 | LPC18XX_DMAMUX_MASK(mux), | ||
102 | LPC18XX_DMAMUX_VAL(dmamux->muxes[mux].value, mux)); | ||
103 | spin_unlock_irqrestore(&dmamux->lock, flags); | ||
104 | |||
105 | dma_spec->args[1] = dma_spec->args[2]; | ||
106 | dma_spec->args_count = 2; | ||
107 | |||
108 | dev_dbg(&pdev->dev, "mapping dmamux %u.%u to dma request %u\n", mux, | ||
109 | dmamux->muxes[mux].value, mux); | ||
110 | |||
111 | return &dmamux->muxes[mux]; | ||
112 | } | ||
113 | |||
114 | static int lpc18xx_dmamux_probe(struct platform_device *pdev) | ||
115 | { | ||
116 | struct device_node *dma_np, *np = pdev->dev.of_node; | ||
117 | struct lpc18xx_dmamux_data *dmamux; | ||
118 | int ret; | ||
119 | |||
120 | dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL); | ||
121 | if (!dmamux) | ||
122 | return -ENOMEM; | ||
123 | |||
124 | dmamux->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg"); | ||
125 | if (IS_ERR(dmamux->reg)) { | ||
126 | dev_err(&pdev->dev, "syscon lookup failed\n"); | ||
127 | return PTR_ERR(dmamux->reg); | ||
128 | } | ||
129 | |||
130 | ret = of_property_read_u32(np, "dma-requests", | ||
131 | &dmamux->dma_mux_requests); | ||
132 | if (ret) { | ||
133 | dev_err(&pdev->dev, "missing dma-requests property\n"); | ||
134 | return ret; | ||
135 | } | ||
136 | |||
137 | dma_np = of_parse_phandle(np, "dma-masters", 0); | ||
138 | if (!dma_np) { | ||
139 | dev_err(&pdev->dev, "can't get dma master\n"); | ||
140 | return -ENODEV; | ||
141 | } | ||
142 | |||
143 | ret = of_property_read_u32(dma_np, "dma-requests", | ||
144 | &dmamux->dma_master_requests); | ||
145 | of_node_put(dma_np); | ||
146 | if (ret) { | ||
147 | dev_err(&pdev->dev, "missing master dma-requests property\n"); | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | dmamux->muxes = devm_kcalloc(&pdev->dev, dmamux->dma_master_requests, | ||
152 | sizeof(struct lpc18xx_dmamux), | ||
153 | GFP_KERNEL); | ||
154 | if (!dmamux->muxes) | ||
155 | return -ENOMEM; | ||
156 | |||
157 | spin_lock_init(&dmamux->lock); | ||
158 | platform_set_drvdata(pdev, dmamux); | ||
159 | dmamux->dmarouter.dev = &pdev->dev; | ||
160 | dmamux->dmarouter.route_free = lpc18xx_dmamux_free; | ||
161 | |||
162 | return of_dma_router_register(np, lpc18xx_dmamux_reserve, | ||
163 | &dmamux->dmarouter); | ||
164 | } | ||
165 | |||
166 | static const struct of_device_id lpc18xx_dmamux_match[] = { | ||
167 | { .compatible = "nxp,lpc1850-dmamux" }, | ||
168 | {}, | ||
169 | }; | ||
170 | |||
171 | static struct platform_driver lpc18xx_dmamux_driver = { | ||
172 | .probe = lpc18xx_dmamux_probe, | ||
173 | .driver = { | ||
174 | .name = "lpc18xx-dmamux", | ||
175 | .of_match_table = lpc18xx_dmamux_match, | ||
176 | }, | ||
177 | }; | ||
178 | |||
179 | static int __init lpc18xx_dmamux_init(void) | ||
180 | { | ||
181 | return platform_driver_register(&lpc18xx_dmamux_driver); | ||
182 | } | ||
183 | arch_initcall(lpc18xx_dmamux_init); | ||