Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932499AbcDTHUN (ORCPT ); Wed, 20 Apr 2016 03:20:13 -0400 Received: from mail-bl2nam02on0047.outbound.protection.outlook.com ([104.47.38.47]:40416 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932256AbcDTHUK (ORCPT ); Wed, 20 Apr 2016 03:20:10 -0400 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; From: Kedareswara rao Appana To: , , , , , , , , , , , , , , CC: , , , Subject: [PATCH 2/2] dmaengine: vdma: Add clock support Date: Wed, 20 Apr 2016 12:50:00 +0530 Message-ID: <1461136800-20334-2-git-send-email-appanad@xilinx.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1461136800-20334-1-git-send-email-appanad@xilinx.com> References: <1461136800-20334-1-git-send-email-appanad@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-22272.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.100;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(103686003)(50226001)(1220700001)(106466001)(19580405001)(19580395003)(1096002)(42186005)(5003940100001)(5008740100001)(36386004)(87936001)(189998001)(33646002)(5001770100001)(2201001)(229853001)(92566002)(6806005)(81166005)(48376002)(2950100001)(50466002)(45336002)(4326007)(63266004)(46386002)(586003)(2906002)(86362001)(76176999)(36756003)(11100500001)(52956003)(50986999)(4001450100002)(90966002)(107986001)(921003)(2101003)(83996005)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:BL2NAM02HT155;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ad5515d0-c9c1-4da2-8b7d-08d368ec33fb X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(8251501002);SRVR:BL2NAM02HT155; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521026)(601004)(2401047)(13024025)(8121501046)(13015025)(13018025)(13017025)(13023025)(5005006)(3002001)(10201501046);SRVR:BL2NAM02HT155;BCL:0;PCL:0;RULEID:;SRVR:BL2NAM02HT155; X-Forefront-PRVS: 0918748D70 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 07:20:08.0721 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.100];Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2NAM02HT155 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3497 Lines: 126 Added basic clock support. The clocks are requested at probe and released at remove. Signed-off-by: Kedareswara rao Appana --- drivers/dma/xilinx/xilinx_vdma.c | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/dma/xilinx/xilinx_vdma.c b/drivers/dma/xilinx/xilinx_vdma.c index 70caea6..d526029 100644 --- a/drivers/dma/xilinx/xilinx_vdma.c +++ b/drivers/dma/xilinx/xilinx_vdma.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "../dmaengine.h" @@ -352,6 +353,8 @@ struct xilinx_dma_chan { * @flush_on_fsync: Flush on frame sync * @ext_addr: Indicates 64 bit addressing is supported by dma device * @dmatype: DMA ip type + * @clks: pointer to array of clocks + * @numclks: number of clocks available */ struct xilinx_dma_device { void __iomem *regs; @@ -362,6 +365,8 @@ struct xilinx_dma_device { u32 flush_on_fsync; bool ext_addr; enum xdma_ip_type dmatype; + struct clk **clks; + int numclks; }; /* Macros */ @@ -1731,6 +1736,26 @@ int xilinx_vdma_channel_set_config(struct dma_chan *dchan, } EXPORT_SYMBOL(xilinx_vdma_channel_set_config); +static int xdma_clk_init(struct xilinx_dma_device *xdev, bool enable) +{ + int i = 0, ret; + + for (i = 0; i < xdev->numclks; i++) { + if (enable) { + ret = clk_prepare_enable(xdev->clks[i]); + if (ret) { + dev_err(xdev->dev, + "failed to enable the axidma clock\n"); + return ret; + } + } else { + clk_disable_unprepare(xdev->clks[i]); + } + } + + return 0; +} + /* ----------------------------------------------------------------------------- * Probe and remove */ @@ -1919,6 +1944,7 @@ static int xilinx_dma_probe(struct platform_device *pdev) struct resource *io; u32 num_frames, addr_width; int i, err; + const char *str; /* Allocate and initialize the DMA engine structure */ xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); @@ -1965,6 +1991,32 @@ static int xilinx_dma_probe(struct platform_device *pdev) /* Set the dma mask bits */ dma_set_mask(xdev->dev, DMA_BIT_MASK(addr_width)); + xdev->numclks = of_property_count_strings(pdev->dev.of_node, + "clock-names"); + if (xdev->numclks > 0) { + xdev->clks = devm_kmalloc_array(&pdev->dev, xdev->numclks, + sizeof(struct clk *), + GFP_KERNEL); + if (!xdev->clks) + return -ENOMEM; + + for (i = 0; i < xdev->numclks; i++) { + of_property_read_string_index(pdev->dev.of_node, + "clock-names", i, &str); + xdev->clks[i] = devm_clk_get(xdev->dev, str); + if (IS_ERR(xdev->clks[i])) { + if (PTR_ERR(xdev->clks[i]) == -ENOENT) + xdev->clks[i] = NULL; + else + return PTR_ERR(xdev->clks[i]); + } + } + + err = xdma_clk_init(xdev, true); + if (err) + return err; + } + /* Initialize the DMA engine */ xdev->common.dev = &pdev->dev; @@ -2025,6 +2077,8 @@ static int xilinx_dma_probe(struct platform_device *pdev) return 0; error: + if (xdev->numclks > 0) + xdma_clk_init(xdev, false); for (i = 0; i < XILINX_DMA_MAX_CHANS_PER_DEVICE; i++) if (xdev->chan[i]) xilinx_dma_chan_remove(xdev->chan[i]); @@ -2050,6 +2104,8 @@ static int xilinx_dma_remove(struct platform_device *pdev) for (i = 0; i < XILINX_DMA_MAX_CHANS_PER_DEVICE; i++) if (xdev->chan[i]) xilinx_dma_chan_remove(xdev->chan[i]); + if (xdev->numclks > 0) + xdma_clk_init(xdev, false); return 0; } -- 2.1.2