Skip to content

Commit d382496

Browse files
TonyHan11vinodkoul
authored andcommitted
dmaengine: at_xdmac: get the number of DMA channels from device tree
In case of kernel runs in non-secure mode, the number of DMA channels can be got from device tree since the value read from GTYPE register is "0" as it's always secured. As the number of channels can never be negative, update them to the type "unsigned". This is required for LAN969x. Signed-off-by: Tony Han <tony.han@microchip.com> Signed-off-by: Robert Marko <robert.marko@sartura.hr> Link: https://patch.msgid.link/20251203121208.1269487-1-robert.marko@sartura.hr Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent c47422f commit d382496

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

drivers/dma/at_xdmac.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,12 +2247,29 @@ static int __maybe_unused atmel_xdmac_runtime_resume(struct device *dev)
22472247
return clk_enable(atxdmac->clk);
22482248
}
22492249

2250+
static inline int at_xdmac_get_channel_number(struct platform_device *pdev,
2251+
u32 reg, u32 *pchannels)
2252+
{
2253+
int ret;
2254+
2255+
if (reg) {
2256+
*pchannels = AT_XDMAC_NB_CH(reg);
2257+
return 0;
2258+
}
2259+
2260+
ret = of_property_read_u32(pdev->dev.of_node, "dma-channels", pchannels);
2261+
if (ret)
2262+
dev_err(&pdev->dev, "can't get number of channels\n");
2263+
2264+
return ret;
2265+
}
2266+
22502267
static int at_xdmac_probe(struct platform_device *pdev)
22512268
{
22522269
struct at_xdmac *atxdmac;
2253-
int irq, nr_channels, i, ret;
2270+
int irq, ret;
22542271
void __iomem *base;
2255-
u32 reg;
2272+
u32 nr_channels, i, reg;
22562273

22572274
irq = platform_get_irq(pdev, 0);
22582275
if (irq < 0)
@@ -2268,7 +2285,10 @@ static int at_xdmac_probe(struct platform_device *pdev)
22682285
* of channels to do the allocation.
22692286
*/
22702287
reg = readl_relaxed(base + AT_XDMAC_GTYPE);
2271-
nr_channels = AT_XDMAC_NB_CH(reg);
2288+
ret = at_xdmac_get_channel_number(pdev, reg, &nr_channels);
2289+
if (ret)
2290+
return ret;
2291+
22722292
if (nr_channels > AT_XDMAC_MAX_CHAN) {
22732293
dev_err(&pdev->dev, "invalid number of channels (%u)\n",
22742294
nr_channels);

0 commit comments

Comments
 (0)