1// SPDX-License-Identifier: GPL-2.0 2/* 3 * SHDMA Device Tree glue 4 * 5 * Copyright (C) 2013 Renesas Electronics Inc. 6 * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de> 7 */ 8 9#include <linux/dmaengine.h> 10#include <linux/module.h> 11#include <linux/of.h> 12#include <linux/of_dma.h> 13#include <linux/of_platform.h> 14#include <linux/platform_device.h> 15#include <linux/shdma-base.h> 16 17#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan) 18 19static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec, 20 struct of_dma *ofdma) 21{ 22 u32 id = dma_spec->args[0]; 23 dma_cap_mask_t mask; 24 struct dma_chan *chan; 25 26 if (dma_spec->args_count != 1) 27 return NULL; 28 29 dma_cap_zero(mask); 30 /* Only slave DMA channels can be allocated via DT */ 31 dma_cap_set(DMA_SLAVE, mask); 32 33 chan = dma_request_channel(mask, shdma_chan_filter, 34 (void *)(uintptr_t)id); 35 if (chan) 36 to_shdma_chan(chan)->hw_req = id; 37 38 return chan; 39} 40 41static int shdma_of_probe(struct platform_device *pdev) 42{ 43 const struct of_dev_auxdata *lookup = dev_get_platdata(&pdev->dev); 44 int ret; 45 46 ret = of_dma_controller_register(pdev->dev.of_node, 47 shdma_of_xlate, pdev); 48 if (ret < 0) 49 return ret; 50 51 ret = of_platform_populate(pdev->dev.of_node, NULL, lookup, &pdev->dev); 52 if (ret < 0) 53 of_dma_controller_free(pdev->dev.of_node); 54 55 return ret; 56} 57 58static const struct of_device_id shdma_of_match[] = { 59 { .compatible = "renesas,shdma-mux", }, 60 { } 61}; 62MODULE_DEVICE_TABLE(of, sh_dmae_of_match); 63 64static struct platform_driver shdma_of = { 65 .driver = { 66 .name = "shdma-of", 67 .of_match_table = shdma_of_match, 68 }, 69 .probe = shdma_of_probe, 70}; 71 72module_platform_driver(shdma_of); 73 74MODULE_LICENSE("GPL v2"); 75MODULE_DESCRIPTION("SH-DMA driver DT glue"); 76MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>"); 77