Skip to content

Commit 5d318b5

Browse files
pwojtaszczyk-tsvinodkoul
authored andcommitted
dmaengine: Add dma router for pl08x in LPC32XX SoC
LPC32XX connects few of its peripherals to pl08x DMA thru a multiplexer, this driver allows to route a signal request line thru the multiplexer for given peripheral. Signed-off-by: Piotr Wojtaszczyk <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 9542961 commit 5d318b5

File tree

5 files changed

+207
-0
lines changed

5 files changed

+207
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,7 @@ T: git git://github.com/vzapolskiy/linux-lpc32xx.git
24422442
F: Documentation/devicetree/bindings/i2c/nxp,pnx-i2c.yaml
24432443
F: arch/arm/boot/dts/nxp/lpc/lpc32*
24442444
F: arch/arm/mach-lpc32xx/
2445+
F: drivers/dma/lpc32xx-dmamux.c
24452446
F: drivers/i2c/busses/i2c-pnx.c
24462447
F: drivers/net/ethernet/nxp/lpc_eth.c
24472448
F: drivers/usb/host/ohci-nxp.c

arch/arm/mach-lpc32xx/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ config ARCH_LPC32XX
88
select CLKSRC_LPC32XX
99
select CPU_ARM926T
1010
select GPIOLIB
11+
select LPC32XX_DMAMUX if AMBA_PL08X
1112
help
1213
Support for the NXP LPC32XX family of processors

drivers/dma/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ config LPC18XX_DMAMUX
387387
Enable support for DMA on NXP LPC18xx/43xx platforms
388388
with PL080 and multiplexed DMA request lines.
389389

390+
config LPC32XX_DMAMUX
391+
bool "NXP LPC32xx DMA MUX for PL080"
392+
depends on ARCH_LPC32XX || COMPILE_TEST
393+
depends on OF && AMBA_PL08X
394+
select MFD_SYSCON
395+
help
396+
Support for PL080 multiplexed DMA request lines on
397+
LPC32XX platrofm.
398+
390399
config LS2X_APB_DMA
391400
tristate "Loongson LS2X APB DMA support"
392401
depends on LOONGARCH || COMPILE_TEST

drivers/dma/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ obj-y += idxd/
5151
obj-$(CONFIG_K3_DMA) += k3dma.o
5252
obj-$(CONFIG_LOONGSON1_APB_DMA) += loongson1-apb-dma.o
5353
obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o
54+
obj-$(CONFIG_LPC32XX_DMAMUX) += lpc32xx-dmamux.o
5455
obj-$(CONFIG_LS2X_APB_DMA) += ls2x-apb-dma.o
5556
obj-$(CONFIG_MILBEAUT_HDMAC) += milbeaut-hdmac.o
5657
obj-$(CONFIG_MILBEAUT_XDMAC) += milbeaut-xdmac.o

drivers/dma/lpc32xx-dmamux.c

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
//
3+
// Copyright 2024 Timesys Corporation <[email protected]>
4+
//
5+
// Based on TI DMA Crossbar driver by:
6+
// Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
7+
// Author: Peter Ujfalusi <[email protected]>
8+
9+
#include <linux/err.h>
10+
#include <linux/init.h>
11+
#include <linux/mfd/syscon.h>
12+
#include <linux/of.h>
13+
#include <linux/of_dma.h>
14+
#include <linux/of_platform.h>
15+
#include <linux/platform_device.h>
16+
#include <linux/regmap.h>
17+
#include <linux/spinlock.h>
18+
19+
#define LPC32XX_SSP_CLK_CTRL 0x78
20+
#define LPC32XX_I2S_CLK_CTRL 0x7c
21+
22+
struct lpc32xx_dmamux {
23+
int signal;
24+
char *name_sel0;
25+
char *name_sel1;
26+
int muxval;
27+
int muxreg;
28+
int bit;
29+
bool busy;
30+
};
31+
32+
struct lpc32xx_dmamux_data {
33+
struct dma_router dmarouter;
34+
struct regmap *reg;
35+
spinlock_t lock; /* protects busy status flag */
36+
};
37+
38+
/* From LPC32x0 User manual "3.2.1 DMA request signals" */
39+
static struct lpc32xx_dmamux lpc32xx_muxes[] = {
40+
{
41+
.signal = 3,
42+
.name_sel0 = "spi2-rx-tx",
43+
.name_sel1 = "ssp1-rx",
44+
.muxreg = LPC32XX_SSP_CLK_CTRL,
45+
.bit = 5,
46+
},
47+
{
48+
.signal = 10,
49+
.name_sel0 = "uart7-rx",
50+
.name_sel1 = "i2s1-dma1",
51+
.muxreg = LPC32XX_I2S_CLK_CTRL,
52+
.bit = 4,
53+
},
54+
{
55+
.signal = 11,
56+
.name_sel0 = "spi1-rx-tx",
57+
.name_sel1 = "ssp1-tx",
58+
.muxreg = LPC32XX_SSP_CLK_CTRL,
59+
.bit = 4,
60+
},
61+
{
62+
.signal = 14,
63+
.name_sel0 = "none",
64+
.name_sel1 = "ssp0-rx",
65+
.muxreg = LPC32XX_SSP_CLK_CTRL,
66+
.bit = 3,
67+
},
68+
{
69+
.signal = 15,
70+
.name_sel0 = "none",
71+
.name_sel1 = "ssp0-tx",
72+
.muxreg = LPC32XX_SSP_CLK_CTRL,
73+
.bit = 2,
74+
},
75+
};
76+
77+
static void lpc32xx_dmamux_release(struct device *dev, void *route_data)
78+
{
79+
struct lpc32xx_dmamux_data *dmamux = dev_get_drvdata(dev);
80+
struct lpc32xx_dmamux *mux = route_data;
81+
82+
dev_dbg(dev, "releasing dma request signal %d routed to %s\n",
83+
mux->signal, mux->muxval ? mux->name_sel1 : mux->name_sel1);
84+
85+
guard(spinlock)(&dmamux->lock);
86+
87+
mux->busy = false;
88+
}
89+
90+
static void *lpc32xx_dmamux_reserve(struct of_phandle_args *dma_spec,
91+
struct of_dma *ofdma)
92+
{
93+
struct platform_device *pdev = of_find_device_by_node(ofdma->of_node);
94+
struct device *dev = &pdev->dev;
95+
struct lpc32xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
96+
unsigned long flags;
97+
struct lpc32xx_dmamux *mux = NULL;
98+
int i;
99+
100+
if (dma_spec->args_count != 3) {
101+
dev_err(&pdev->dev, "invalid number of dma mux args\n");
102+
return ERR_PTR(-EINVAL);
103+
}
104+
105+
for (i = 0; i < ARRAY_SIZE(lpc32xx_muxes); i++) {
106+
if (lpc32xx_muxes[i].signal == dma_spec->args[0]) {
107+
mux = &lpc32xx_muxes[i];
108+
break;
109+
}
110+
}
111+
if (!mux) {
112+
dev_err(&pdev->dev, "invalid mux request number: %d\n",
113+
dma_spec->args[0]);
114+
return ERR_PTR(-EINVAL);
115+
}
116+
117+
if (dma_spec->args[2] > 1) {
118+
dev_err(&pdev->dev, "invalid dma mux value: %d\n",
119+
dma_spec->args[1]);
120+
return ERR_PTR(-EINVAL);
121+
}
122+
123+
/* The of_node_put() will be done in the core for the node */
124+
dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0);
125+
if (!dma_spec->np) {
126+
dev_err(&pdev->dev, "can't get dma master\n");
127+
return ERR_PTR(-EINVAL);
128+
}
129+
130+
spin_lock_irqsave(&dmamux->lock, flags);
131+
if (mux->busy) {
132+
spin_unlock_irqrestore(&dmamux->lock, flags);
133+
dev_err(dev, "dma request signal %d busy, routed to %s\n",
134+
mux->signal, mux->muxval ? mux->name_sel1 : mux->name_sel1);
135+
of_node_put(dma_spec->np);
136+
return ERR_PTR(-EBUSY);
137+
}
138+
139+
mux->busy = true;
140+
mux->muxval = dma_spec->args[2] ? BIT(mux->bit) : 0;
141+
142+
regmap_update_bits(dmamux->reg, mux->muxreg, BIT(mux->bit), mux->muxval);
143+
spin_unlock_irqrestore(&dmamux->lock, flags);
144+
145+
dma_spec->args[2] = 0;
146+
dma_spec->args_count = 2;
147+
148+
dev_dbg(dev, "dma request signal %d routed to %s\n",
149+
mux->signal, mux->muxval ? mux->name_sel1 : mux->name_sel1);
150+
151+
return mux;
152+
}
153+
154+
static int lpc32xx_dmamux_probe(struct platform_device *pdev)
155+
{
156+
struct device_node *np = pdev->dev.of_node;
157+
struct lpc32xx_dmamux_data *dmamux;
158+
159+
dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL);
160+
if (!dmamux)
161+
return -ENOMEM;
162+
163+
dmamux->reg = syscon_node_to_regmap(np->parent);
164+
if (IS_ERR(dmamux->reg)) {
165+
dev_err(&pdev->dev, "syscon lookup failed\n");
166+
return PTR_ERR(dmamux->reg);
167+
}
168+
169+
spin_lock_init(&dmamux->lock);
170+
platform_set_drvdata(pdev, dmamux);
171+
dmamux->dmarouter.dev = &pdev->dev;
172+
dmamux->dmarouter.route_free = lpc32xx_dmamux_release;
173+
174+
return of_dma_router_register(np, lpc32xx_dmamux_reserve,
175+
&dmamux->dmarouter);
176+
}
177+
178+
static const struct of_device_id lpc32xx_dmamux_match[] = {
179+
{ .compatible = "nxp,lpc3220-dmamux" },
180+
{},
181+
};
182+
183+
static struct platform_driver lpc32xx_dmamux_driver = {
184+
.probe = lpc32xx_dmamux_probe,
185+
.driver = {
186+
.name = "lpc32xx-dmamux",
187+
.of_match_table = lpc32xx_dmamux_match,
188+
},
189+
};
190+
191+
static int __init lpc32xx_dmamux_init(void)
192+
{
193+
return platform_driver_register(&lpc32xx_dmamux_driver);
194+
}
195+
arch_initcall(lpc32xx_dmamux_init);

0 commit comments

Comments
 (0)