Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756574AbbGGJxZ (ORCPT ); Tue, 7 Jul 2015 05:53:25 -0400 Received: from mail-bn1bon0119.outbound.protection.outlook.com ([157.56.111.119]:61962 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752443AbbGGJxS (ORCPT ); Tue, 7 Jul 2015 05:53:18 -0400 X-Greylist: delayed 1045 seconds by postgrey-1.27 at vger.kernel.org; Tue, 07 Jul 2015 05:53:18 EDT Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; From: Shengjiu Wang To: , CC: , Subject: [PATCH V2] dmaengine: imx-sdma: Add device to device support Date: Tue, 7 Jul 2015 17:20:04 +0800 Message-ID: X-Mailer: git-send-email 1.7.9.5 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD033;1:qkPrR5+yHQPW0njYJTMaT2HnufSvtuwSSUkJg/OKqp9vnGwpog+SwZt1tkbZlo8rELiUHC62WNDEhg1/noojNaeyn0H3AXcx2nVchWlgexJUQTKBPdYbi3lxRRuouPPPmNTRzXRsJ/yu0FHNQgHFui9wnW0zaM/JVp/MBBUKvjnRCdPZTIeC5NQDxk1VLrDAahyjuPsZDb2QIiC4Mq454RqYHuIZ4FD1z1iul6aK0pVvunnf+nRlcJRGV0Axfyo6lVMcXJWhcn/9Vudz4BUApX8JVtVELM8B78bH3ndYGUt2NfvxqDBYoFO0JN3LkOSoGlcQsiarLfyF3oJACXzTqg== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(92566002)(5001960100002)(87936001)(50226001)(6806004)(5003940100001)(189998001)(105606002)(106466001)(118296001)(77156002)(62966003)(36756003)(48376002)(85426001)(46102003)(50986999)(33646002)(229853001)(104016003)(77096005)(19580405001)(19580395003)(5001770100001)(86362001)(50466002)(47776003);DIR:OUT;SFP:1102;SCL:1;SRVR:CH1PR03MB612;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;2:Dx0f+O8gpKasUfb8tRtHobowe7n573hnHHusIgM0vAYXFkq4SGP7cx07w6qKAsRZ;3:wvRF53jXg25fhpgOVLeTJd7EuE7iBO+XR1tdi85ONfaBxBFPHypcLmQ+0sQ1dsKYeg6m1n06kbAoRb/8AfA1ju0t4CVXqvCHucoGltMyrSjDtZAMrGtVPg4X3zWTrizUEtOJnWUfHCR9TkNtuccPU4vXOxBDdqGxyTCLQvujbJDNzQGHL3+x2aT+arfdh0dRedLEOPHB4lLvul3xDf8y+ydjNmM+o8VUYpFq1BXlRjM=;25:0gjQ9dQEf+TJGuGNX+7h3ij8KMdpeZh+YLhVSx0Du4tHNhBoIDoAvFfPV3Zm8/aYcM90YoeutxApRZ4uZvA8jEWGaD1eesgYVwa1N9lZZKXLCHQjSAhjwH+oYT4PWM9iH4iS9kG4Z7DyqRSJ6VHwgNZVDJ89iGazIORI1GaXUm7OAUryAJSbUimPs+1z1uK2Ikol1PctNs9wWl8nRbNNiAtBX5YytWMv0AtwwvtA1oa9yd+HdsGyXeiK84k0YzZ4ya1pE829YfF5JRgD6oBcoA==;20:xkSArYCxOUd8nGlG8tc2mHJqA0ofWvlR57wZY13BYj4bvVGwHexWVRh7M0qB/UeB5n7TAJjSWdKw40NHoPAswtOglgwHZg3tzYPN54Zq723bDZqvkxIPrO/imwmtjZBrM5G+obJZnwbhkNzi7jfiLHvW4/lRdlff4gL8ISA+UCM8X7EWDqonm+DK7sKelBrTAKCvRwwRnJNYc8dMHEx6FVBOMwNXV9BLYVryJlS04/reNmn1iUvmwiiXIUUfm4T1hT2lpYxahHCCMsQsO65GD/BEy1+gW46eWOL9L3UBwwk6/WQn7Mown9Chjd0CbjqdvNOGZedGl/AciIZKwZKp1zOdMiAN4YgCqj2g6FOhPxg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CH1PR03MB612; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:CH1PR03MB612;BCL:0;PCL:0;RULEID:;SRVR:CH1PR03MB612; X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;4:bzd56M3Gz97ZfVAV/E4PhEncnrPLafrRX8D/cLElBI2u/EDQH1A79N2ipQ/yrvIaoLOpEiSxKjja/LepaHBH1NcMHnHUfCz3Tj+13QmSfUo4cYShqqUZBKzuGFGbc5I0TPbCMGeCtGaP5rMfqWR8tEVNRWkkCis5X55Y6sq3urHIqzu7U/UPxwyP6Mcu/BDFjAcrVZAXQ0KtHjF/Hf0z6/BZUyGJZmuouRStHe8Tx1wk5VV52kYKihv51bMOF7HvlsJ3zI/vpi2d20+yjManmFvG83Ll3QytHf5yFsLmENw= X-Forefront-PRVS: 0630013541 X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;23:0nO/6PuuCSStHKhbqhKdxndptYL/KyPNoezin2VCjQ+n9At1bM1niOWxnFWWob8T+j++uLDVtb4thAIMhedwVtoLZTgAmkJ8/58mzvm9lMh3k2JeGyTWD47eYSUZRynAQNALOnRzMrs6n6jxPgLT3NRDTAZelOjMkAQw7pP5s6ynBJj3t9ntB+8zk+qAhAtaY4A/A/GWaqhQZjMcPKqsp3pgfbnLZAaz3xWra+IM3rgBWBwLjoTWIvxOilcSqz88ZSMAk62ryK1yQyWZZDp1hYUKVLhvThNC1grddV2jxFdWvmn+xUY0tHnQJFEnsCjjdoS3e111hC3elupO5wXOPQboTmszPDZ4BI82cN1Cz43rdfarRAD3ldlklaJhgf515EB+7p5kny7az0HTktS5BbmTcWf5Xg+5vKPXmSOIwv6dQ6WU/Qrg4BbquPqvXlhkbtF086LDdX1eAoSbb/aRWyWccH3ojD94YuD357Jt5hH3nMTFuPUFuw/nW73/UGy1aiZDre9hJHCIbfCColgr4yoyyj+pBQ526UMvHOcaehZb/ZbVw6oR9FMQwZ86+n+K7nasVZGo5FoMwZcEpnqlhTMnsOVs5aQIA/uinncHpa5iGrQicqfmrZgfcF9cnAyheyNnEVM+QjePXofaWO6KWTeSWlJqYtpc61Ma1TtEvCuoJO9oumoBsD2jMWHodPvNVAAMgZbTq+b023zC4BkXLLY/n4AnhkNFxAT2i8gwCCntDIrMLVBzv2QjUUDyZ2x4BK0+HXh5tpHieIsCncuEm0I+COphkDDYsgvWaQleOnwOwpna3eq6nJ0QKVB/m0e1JasxqGD2J318B2dbgpsgN47ziwwx1ki63Fqar4KhgZUWFUeBUIw9JyrH/hA4OyLf X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;5:O3kW0xv16KdxW8DfdpXlZG9TewQkayX+lYl/FvqhlJ7lh9KoB7Qja0rUyrg/5kob0HBMTXgv67n79wMSHeb7VM/7myxiZX71G7/fg7O4cElP9UeTWoYshtjiTlFu9tvU4leSeL2cXzzAtPFjXBBVcg==;24:De3HAb4zdb4CHdU+l48hWMT+1qojiS9X9rujBdPsuh0GzfNHIZh7h5dMC/DmPN/2OFTb+IYgsBzDi984kYY1SyrP6zP4nRSzIaMbhlleSjQ=;20:3/eRLDdg5rr1flf9m5wi4McuHR1vE7iC+axD0K4uegczGZYG44oPPEaxdpAgzY85DstklCyKxT4gmNcaNv9Hvw== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2015 09:20:34.9109 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH1PR03MB612 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9434 Lines: 278 This patch adds DEV_TO_DEV support for i.MX SDMA driver to support data transfer between two peripheral FIFOs. The per_2_per script requires two peripheral addresses and two DMA requests, and it need to check the src addr and dst addr is in the SPBA bus space or in the AIPS bus space. Signed-off-by: Shengjiu Wang --- changes in V2 - refine the sdma_set_watermarklevel_for_p2p(), add description. - exchange the meaning of per_address, per_address2. per_address is dst_addr per_address2 is src_addr, which is align with not p2p case. drivers/dma/imx-sdma.c | 140 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 128 insertions(+), 12 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 77b6aab..845f200 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -259,8 +260,9 @@ struct sdma_channel { struct sdma_buffer_descriptor *bd; dma_addr_t bd_phys; unsigned int pc_from_device, pc_to_device; + unsigned int device_to_device; unsigned long flags; - dma_addr_t per_address; + dma_addr_t per_address, per_address2; unsigned long event_mask[2]; unsigned long watermark_level; u32 shp_addr, per_addr; @@ -328,6 +330,8 @@ struct sdma_engine { u32 script_number; struct sdma_script_start_addrs *script_addrs; const struct sdma_driver_data *drvdata; + u32 spba_start_addr; + u32 spba_end_addr; }; static struct sdma_driver_data sdma_imx31 = { @@ -705,6 +709,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac, sdmac->pc_from_device = 0; sdmac->pc_to_device = 0; + sdmac->device_to_device = 0; switch (peripheral_type) { case IMX_DMATYPE_MEMORY: @@ -780,6 +785,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac, sdmac->pc_from_device = per_2_emi; sdmac->pc_to_device = emi_2_per; + sdmac->device_to_device = per_2_per; } static int sdma_load_context(struct sdma_channel *sdmac) @@ -792,11 +798,12 @@ static int sdma_load_context(struct sdma_channel *sdmac) int ret; unsigned long flags; - if (sdmac->direction == DMA_DEV_TO_MEM) { + if (sdmac->direction == DMA_DEV_TO_MEM) load_address = sdmac->pc_from_device; - } else { + else if (sdmac->direction == DMA_DEV_TO_DEV) + load_address = sdmac->device_to_device; + else load_address = sdmac->pc_to_device; - } if (load_address < 0) return load_address; @@ -851,6 +858,84 @@ static int sdma_disable_channel(struct dma_chan *chan) return 0; } +/* + * p_2_p watermark_level description + * Bits Name Description + * 0-7 Lower WML Lower watermark level + * 8 PS 1: Pad Swallowing + * 0: No Pad Swallowing + * 9 PA 1: Pad Adding + * 0: No Pad Adding + * 10 SPDIF If this bit is set both source + * and destination are on SPBA + * 11 Source Bit(SP) 1: Source on SPBA + * 0: Source on AIPS + * 12 Destination Bit(DP) 1: Destination on SPBA + * 0: Destination on AIPS + * 13-15 --------- MUST BE 0 + * 16-23 Higher WML HWML + * 24-27 N Total number of samples after + * which Pad adding/Swallowing + * must be done. It must be odd. + * 28 Lower WML Event(LWE) SDMA events reg to check for + * LWML event mask + * 0: LWE in EVENTS register + * 1: LWE in EVENTS2 register + * 29 Higher WML Event(HWE) SDMA events reg to check for + * HWML event mask + * 0: HWE in EVENTS register + * 1: HWE in EVENTS2 register + * 30 --------- MUST BE 0 + * 31 CONT 1: Amount of samples to be + * transferred is unknown and + * script will keep on + * transferring samples as long as + * both events are detected and + * script must be manually stopped + * by the application + * 0: The amount of samples to be + * transferred is equal to the + * count field of mode word + */ +static void sdma_set_watermarklevel_for_p2p(struct sdma_channel *sdmac) +{ + struct sdma_engine *sdma = sdmac->sdma; + + int lwml = sdmac->watermark_level & 0xff; + int hwml = (sdmac->watermark_level >> 16) & 0xff; + + __set_bit(sdmac->event_id0 % 32, &sdmac->event_mask[1]); + __set_bit(sdmac->event_id1 % 32, &sdmac->event_mask[0]); + + if (sdmac->event_id0 > 31) + __set_bit(28, &sdmac->watermark_level); + + if (sdmac->event_id1 > 31) + __set_bit(29, &sdmac->watermark_level); + + /* + * If LWML(src_maxburst) > HWML(dst_maxburst), we need + * swap LWML and HWML of INFO(A.3.2.5.1), also need swap + * r0(event_mask[1]) and r1(event_mask[0]). + */ + if (lwml > hwml) { + sdmac->watermark_level &= ~0xff00ff; + sdmac->watermark_level |= hwml; + sdmac->watermark_level |= lwml << 16; + swap(sdmac->event_mask[0], sdmac->event_mask[1]); + } + + if (sdmac->per_address2 >= sdma->spba_start_addr && + sdmac->per_address2 <= sdma->spba_end_addr) + __set_bit(11, &sdmac->watermark_level); + + if (sdmac->per_address >= sdma->spba_start_addr && + sdmac->per_address <= sdma->spba_end_addr) + __set_bit(12, &sdmac->watermark_level); + + __set_bit(31, &sdmac->watermark_level); +} + static int sdma_config_channel(struct dma_chan *chan) { struct sdma_channel *sdmac = to_sdma_chan(chan); @@ -869,6 +954,12 @@ static int sdma_config_channel(struct dma_chan *chan) sdma_event_enable(sdmac, sdmac->event_id0); } + if (sdmac->event_id1) { + if (sdmac->event_id1 >= sdmac->sdma->drvdata->num_events) + return -EINVAL; + sdma_event_enable(sdmac, sdmac->event_id1); + } + switch (sdmac->peripheral_type) { case IMX_DMATYPE_DSP: sdma_config_ownership(sdmac, false, true, true); @@ -887,19 +978,17 @@ static int sdma_config_channel(struct dma_chan *chan) (sdmac->peripheral_type != IMX_DMATYPE_DSP)) { /* Handle multiple event channels differently */ if (sdmac->event_id1) { - sdmac->event_mask[1] = BIT(sdmac->event_id1 % 32); - if (sdmac->event_id1 > 31) - __set_bit(31, &sdmac->watermark_level); - sdmac->event_mask[0] = BIT(sdmac->event_id0 % 32); - if (sdmac->event_id0 > 31) - __set_bit(30, &sdmac->watermark_level); - } else { + if (sdmac->peripheral_type == IMX_DMATYPE_ASRC_SP || + sdmac->peripheral_type == IMX_DMATYPE_ASRC) + sdma_set_watermarklevel_for_p2p(sdmac); + } else __set_bit(sdmac->event_id0, sdmac->event_mask); - } + /* Watermark Level */ sdmac->watermark_level |= sdmac->watermark_level; /* Address */ sdmac->shp_addr = sdmac->per_address; + sdmac->per_addr = sdmac->per_address2; } else { sdmac->watermark_level = 0; /* FIXME: M3_BASE_ADDRESS */ } @@ -987,6 +1076,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan) sdmac->peripheral_type = data->peripheral_type; sdmac->event_id0 = data->dma_request; + sdmac->event_id1 = data->dma_request2; clk_enable(sdmac->sdma->clk_ipg); clk_enable(sdmac->sdma->clk_ahb); @@ -1221,6 +1311,14 @@ static int sdma_config(struct dma_chan *chan, sdmac->watermark_level = dmaengine_cfg->src_maxburst * dmaengine_cfg->src_addr_width; sdmac->word_size = dmaengine_cfg->src_addr_width; + } else if (dmaengine_cfg->direction == DMA_DEV_TO_DEV) { + sdmac->per_address2 = dmaengine_cfg->src_addr; + sdmac->per_address = dmaengine_cfg->dst_addr; + sdmac->watermark_level = + dmaengine_cfg->src_maxburst & 0xff; + sdmac->watermark_level |= + (dmaengine_cfg->dst_maxburst & 0xff) << 16; + sdmac->word_size = dmaengine_cfg->dst_addr_width; } else { sdmac->per_address = dmaengine_cfg->dst_addr; sdmac->watermark_level = dmaengine_cfg->dst_maxburst * @@ -1444,6 +1542,14 @@ static struct dma_chan *sdma_xlate(struct of_phandle_args *dma_spec, data.dma_request = dma_spec->args[0]; data.peripheral_type = dma_spec->args[1]; data.priority = dma_spec->args[2]; + /* + * init dma_request2 to zero, which is not used by the dts. + * For P2P, dma_request2 is init from dma_request_channel(), + * chan->private will point to the imx_dma_data, and in + * device_alloc_chan_resources(), imx_dma_data.dma_request2 will + * be set to sdmac->event_id1. + */ + data.dma_request2 = 0; return dma_request_channel(mask, sdma_filter_fn, &data); } @@ -1453,10 +1559,12 @@ static int sdma_probe(struct platform_device *pdev) const struct of_device_id *of_id = of_match_device(sdma_dt_ids, &pdev->dev); struct device_node *np = pdev->dev.of_node; + struct device_node *spba_bus; const char *fw_name; int ret; int irq; struct resource *iores; + struct resource spba_res; struct sdma_platform_data *pdata = dev_get_platdata(&pdev->dev); int i; struct sdma_engine *sdma; @@ -1608,6 +1716,14 @@ static int sdma_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to register controller\n"); goto err_register; } + + spba_bus = of_find_compatible_node(NULL, NULL, "fsl,spba-bus"); + ret = of_address_to_resource(spba_bus, 0, &spba_res); + if (!ret) { + sdma->spba_start_addr = spba_res.start; + sdma->spba_end_addr = spba_res.end; + } + of_node_put(spba_bus); } dev_info(sdma->dev, "initialized\n"); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/