From patchwork Fri Oct 30 11:03:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yao yuan X-Patchwork-Id: 7526251 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 00F09BEEA4 for ; Fri, 30 Oct 2015 11:12:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE470207CF for ; Fri, 30 Oct 2015 11:12:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB6AC2078B for ; Fri, 30 Oct 2015 11:12:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zs7aZ-0004Je-5l; Fri, 30 Oct 2015 11:11:19 +0000 Received: from mail-bl2on0140.outbound.protection.outlook.com ([65.55.169.140] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zs7aL-00043Y-FX for linux-arm-kernel@lists.infradead.org; Fri, 30 Oct 2015 11:11:08 +0000 Received: from BN3PR0301CA0044.namprd03.prod.outlook.com (10.160.152.140) by SN2PR03MB096.namprd03.prod.outlook.com (10.255.175.160) with Microsoft SMTP Server (TLS) id 15.1.306.13; Fri, 30 Oct 2015 11:10:42 +0000 Received: from BL2FFO11FD028.protection.gbl (2a01:111:f400:7c09::157) by BN3PR0301CA0044.outlook.office365.com (2a01:111:e400:401e::12) with Microsoft SMTP Server (TLS) id 15.1.312.18 via Frontend Transport; Fri, 30 Oct 2015 11:10:41 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; lists.infradead.org; dkim=none (message not signed) header.d=none;lists.infradead.org; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD028.mail.protection.outlook.com (10.173.161.107) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Fri, 30 Oct 2015 11:10:40 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t9UBAZ7p031155; Fri, 30 Oct 2015 04:10:36 -0700 From: Yuan Yao To: , , Subject: [PATCH v4] dmaengine: fsl-edma: add PM suspend/resume support Date: Fri, 30 Oct 2015 19:03:58 +0800 Message-ID: <1446203038-5323-1-git-send-email-yao.yuan@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD028; 1:Yh8m8h06KPgW8+L4Ou5cT1d+oiI52gJKdCPCvJy6gyJQc9PmTdzAsC//RuUoJtl3fIjJqaap3fof2GtmOMpvzo9WGRfqzsc8GYNn3WR+jKAkcUhELSIPdX+/lFEQ4xfeteW/F6VSPweZKgrS638wY8zIcQzWSvCHzWvqciMgYNBTN/yWWF304ICBAbnbGxOlxkHnJZBsKRGn8+ZD8FSCO6cSjUAjs5Yj9aKWpaOJivmDQJX5FTspyili//ILVpWOTxZipSHuhn7kKwylyHX2Mcq1/IstqqzYE76zPqQBvL/LmBFXPjBLCvCXlNtjZE/AfJRSKANgwLUWSt4uC79lUlJb5ifVxO6G7YsIJfQtn3S96ow3JGNE4j5bOQ55B8TvgJQ2bUqkCvfXmWGYfnGQ4Q== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(5001960100002)(92566002)(229853001)(87936001)(106466001)(50466002)(97736004)(81156007)(5008740100001)(33646002)(5001770100001)(189998001)(86362001)(105606002)(50986999)(48376002)(47776003)(85426001)(77096005)(2201001)(19580405001)(6806005)(5007970100001)(19580395003)(104016004)(36756003)(5003940100001)(50226001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN2PR03MB096; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB096; 2:KwaUARCxDPRh2o+BCn3CUEWFaraBKx041bwelJyEBU0SR/62vmuyuwMaGVBubWHtLvsX71eFDxd0vMU++/gRVjVe/Mhb8e5Imb3EjP6CDFbmlsdptSQVUVW0a5pRH6mZiURe+iB+OPjLKoQeU4xRw1gOqRfV0U4M5IbXz8pJE8U=; 3:cZHIZ/GlSsgOmE1IbQeZALeAEzcnnOiDQD/DjaW3fer8WlCnIMkxECs/iy97yVoZh66AJNMM8LCG3W3nHNXiyc1vQkPud498muwBbbss5U0VJX07errVO7Zh0yvKh/rTnProOiR3JB3F/o1xTTxM+Al6yx1z164KYAHRAU8ADhdT3jK7LLVFu2/0gNr/6s6J0B+MswYEqjGw+CrfnlUm/O5sRtwQ++8b8mly9oAy+0M=; 25:89x8mGnImM/PPKpBAW1VyB3uEiyoXIVS1muC86He9vlStwAzsibZdK+zDlf6aNnazmV/lfPb9NxiFByGkTaKtfJRAM3XbJiTa72yQ7baPQlTCGZVuYMEBzWFQaia+2DATYjaMNI+i4TknxDFvEM4kUepUNR54AvsL77buqSnf4jKmYBVn2YM+Zl53pRxNXIXlUTD9qQ8Zkic4cSL9avwDXOQVPVWPVAk48RNZH33KotYKWkb8lB48OIfF9Ii4ZiE X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB096; X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB096; 20:kV0BG9Wmw/BCp/Q4fQfkf21HUXsWQvRfGkIPStP8EOXZOLEZCSKJkuM/MfTuTvcjOQ6gd9//Nfjnlihi3zDZygEYIQlsDuvPfTUFl6DTNBBMFqLDHsStOJ15ZxlLpYsXXAp5szvttGPbxX6CjRtw4+7U1rBP0PHmiDGXuDK/GOB6sB8GKIeFXrw0lXHLTLA3H1xPvOZ8VPd1UtnNdNsBrboDtKMW7xpGi7XURYO4vj2GmZf4wIj1mQtVxAeYJEhiGF/X/px4NLMcVnQY+cacto/MFic+pKjjzj7u3/ccwCBuf4xGfb7tiFGTkTJ62g2OkQGwsYxrCvGXWM7EwdeSG4m0qCTVaQp1BhSIIjroH0I=; 4:SPMYkZYiENjdjRZqoa0E3pLn0Inb2HlHYwH/+YUWR6zcOBhqtl0XQc/hZOKvFTKxWwwUiUO/9njiZhhScYrsNs9CrTqactQMKjfU2u/7gTpnSpmp7wAP7IkiuA7AANM8rRdTjtKFGsjVGEkUr0asyCQR29f1xCFI7+4tA/BOHdUeb2O8shxVtEFajxRQygkp/kZHr6U1KW794Z9ft/ctibzUbyi9CnqSnI5zY0Cr0fl2g3xNy08Om087yv39NxW5SWU4haNe7qY4FzrQ+OEAPKK9nbMwY9N1Wm6nSdqYuwU4x2DkBGboxFxjV18GGrf0cTzMwSQMNEGyDxuDy0ebFt2hD7EV9ctk1bH1bphrZk9Jxn4qYtRgq3bBK0XFr22OITOtttgtNjy8AXOHxYOW8w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(10201501046)(3002001)(102215026); SRVR:SN2PR03MB096; BCL:0; PCL:0; RULEID:; SRVR:SN2PR03MB096; X-Forefront-PRVS: 07459438AA X-Microsoft-Exchange-Diagnostics: =?us-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lz+34Kf1?= =?us-ascii?Q?Ta9ZUDxkfXbBm4nmR1EA4ADMHf/QqnCPX2PkdJ986iYUEv5fPEXD0Ni3rJtw?= =?us-ascii?Q?SuJjFq9/FH7XASPcsdiFG4iQ/jrbF142grtK1qPw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB096; 5:Dee5EKxGs15YCOa0I9Xu60FAq6NTpkxOoiIF7PH132yGU0snUWK9XDBPWgPHTgOxcr2D6PkQe7CrqDtkrfnaN9ACPrqijLNc5lzSUOq02deAlX/PUmZieyL1PZc2H4M4gRbRrvsyJkdXpIl5kDNCVA==; 24:BFsLfeqF4dsvlJaf0OClYVY36VpVSSJ/gFFQ9DKFJylntTlhJ9WEZRDnuCGzJhwgebOO0QVe23TSW1ipwb7To6nOI8kkhZUWPb+MvUcdMRY=; 20:SZ+YIvgsuDYZ2RGHfIyASse81eEF4htLxcuKLtQ7kTIAogxItnRc7b0Ng7TOwyhwxRFZ8PylngScYWxP4nohpQ== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2015 11:10:40.8443 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB096 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151030_041106_077698_5E76C13E X-CRM114-Status: GOOD ( 28.00 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dmaengine@vger.kernel.org, dan.j.williams@intel.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This add power management suspend/resume support for the fsl-edma driver. eDMA acted as a basic function used by others. What it needs to do is the two steps below to support power management. In fsl_edma_suspend_late: Check whether the DMA chan is idle, if it is not idle disable DMA request. In fsl_edma_resume_early: Enable the eDMA and wait for being used. Signed-off-by: Yuan Yao --- Changes in v4: - Add comments for why use suspend_late and resume_early; Changes in v3: - Force terminate the active channels in suspend if the channel is not idle. Changes in v2: None --- drivers/dma/fsl-edma.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c index 915eec3..be2e62b 100644 --- a/drivers/dma/fsl-edma.c +++ b/drivers/dma/fsl-edma.c @@ -116,6 +116,10 @@ BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \ BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | \ BIT(DMA_SLAVE_BUSWIDTH_8_BYTES) +enum fsl_edma_pm_state { + RUNNING = 0, + SUSPENDED, +}; struct fsl_edma_hw_tcd { __le32 saddr; @@ -147,6 +151,9 @@ struct fsl_edma_slave_config { struct fsl_edma_chan { struct virt_dma_chan vchan; enum dma_status status; + enum fsl_edma_pm_state pm_state; + bool idle; + u32 slave_id; struct fsl_edma_engine *edma; struct fsl_edma_desc *edesc; struct fsl_edma_slave_config fsc; @@ -298,6 +305,7 @@ static int fsl_edma_terminate_all(struct dma_chan *chan) spin_lock_irqsave(&fsl_chan->vchan.lock, flags); fsl_edma_disable_request(fsl_chan); fsl_chan->edesc = NULL; + fsl_chan->idle = true; vchan_get_all_descriptors(&fsl_chan->vchan, &head); spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); vchan_dma_desc_free_list(&fsl_chan->vchan, &head); @@ -313,6 +321,7 @@ static int fsl_edma_pause(struct dma_chan *chan) if (fsl_chan->edesc) { fsl_edma_disable_request(fsl_chan); fsl_chan->status = DMA_PAUSED; + fsl_chan->idle = true; } spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); return 0; @@ -327,6 +336,7 @@ static int fsl_edma_resume(struct dma_chan *chan) if (fsl_chan->edesc) { fsl_edma_enable_request(fsl_chan); fsl_chan->status = DMA_IN_PROGRESS; + fsl_chan->idle = false; } spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); return 0; @@ -648,6 +658,7 @@ static void fsl_edma_xfer_desc(struct fsl_edma_chan *fsl_chan) fsl_edma_set_tcd_regs(fsl_chan, fsl_chan->edesc->tcd[0].vtcd); fsl_edma_enable_request(fsl_chan); fsl_chan->status = DMA_IN_PROGRESS; + fsl_chan->idle = false; } static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id) @@ -676,6 +687,7 @@ static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id) vchan_cookie_complete(&fsl_chan->edesc->vdesc); fsl_chan->edesc = NULL; fsl_chan->status = DMA_COMPLETE; + fsl_chan->idle = true; } else { vchan_cyclic_callback(&fsl_chan->edesc->vdesc); } @@ -704,6 +716,7 @@ static irqreturn_t fsl_edma_err_handler(int irq, void *dev_id) edma_writeb(fsl_edma, EDMA_CERR_CERR(ch), fsl_edma->membase + EDMA_CERR); fsl_edma->chans[ch].status = DMA_ERROR; + fsl_edma->chans[ch].idle = true; } } return IRQ_HANDLED; @@ -724,6 +737,12 @@ static void fsl_edma_issue_pending(struct dma_chan *chan) spin_lock_irqsave(&fsl_chan->vchan.lock, flags); + if (unlikely(fsl_chan->pm_state != RUNNING)) { + spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); + /* cannot submit due to suspend */ + return; + } + if (vchan_issue_pending(&fsl_chan->vchan) && !fsl_chan->edesc) fsl_edma_xfer_desc(fsl_chan); @@ -735,6 +754,7 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, { struct fsl_edma_engine *fsl_edma = ofdma->of_dma_data; struct dma_chan *chan, *_chan; + struct fsl_edma_chan *fsl_chan; unsigned long chans_per_mux = fsl_edma->n_chans / DMAMUX_NR; if (dma_spec->args_count != 2) @@ -748,8 +768,10 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, chan = dma_get_slave_channel(chan); if (chan) { chan->device->privatecnt++; - fsl_edma_chan_mux(to_fsl_edma_chan(chan), - dma_spec->args[1], true); + fsl_chan = to_fsl_edma_chan(chan); + fsl_chan->slave_id = dma_spec->args[1]; + fsl_edma_chan_mux(fsl_chan, fsl_chan->slave_id, + true); mutex_unlock(&fsl_edma->fsl_edma_mutex); return chan; } @@ -888,7 +910,9 @@ static int fsl_edma_probe(struct platform_device *pdev) struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i]; fsl_chan->edma = fsl_edma; - + fsl_chan->pm_state = RUNNING; + fsl_chan->slave_id = 0; + fsl_chan->idle = true; fsl_chan->vchan.desc_free = fsl_edma_free_desc; vchan_init(&fsl_chan->vchan, &fsl_edma->dma_dev); @@ -959,6 +983,60 @@ static int fsl_edma_remove(struct platform_device *pdev) return 0; } +static int fsl_edma_suspend_late(struct device *dev) +{ + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); + struct fsl_edma_chan *fsl_chan; + unsigned long flags; + int i; + + for (i = 0; i < fsl_edma->n_chans; i++) { + fsl_chan = &fsl_edma->chans[i]; + spin_lock_irqsave(&fsl_chan->vchan.lock, flags); + /* Make sure chan is idle or will force disable. */ + if (unlikely(!fsl_chan->idle)) { + dev_warn(dev, "WARN: There is non-idle channel."); + fsl_edma_disable_request(fsl_chan); + fsl_edma_chan_mux(fsl_chan, 0, false); + } + + fsl_chan->pm_state = SUSPENDED; + spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); + } + + return 0; +} + +static int fsl_edma_resume_early(struct device *dev) +{ + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); + struct fsl_edma_chan *fsl_chan; + int i; + + for (i = 0; i < fsl_edma->n_chans; i++) { + fsl_chan = &fsl_edma->chans[i]; + fsl_chan->pm_state = RUNNING; + edma_writew(fsl_edma, 0x0, fsl_edma->membase + EDMA_TCD_CSR(i)); + if (fsl_chan->slave_id != 0) + fsl_edma_chan_mux(fsl_chan, fsl_chan->slave_id, true); + } + + edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, + fsl_edma->membase + EDMA_CR); + + return 0; +} + +/* + * eDMA provides the service to others, so it should be suspend late + * and resume early. When eDMA suspend, all of the clients should stop + * the DMA data transmission and let the channel idle. + */ +static const struct dev_pm_ops fsl_edma_pm_ops = { + .suspend_late = fsl_edma_suspend_late, + .resume_early = fsl_edma_resume_early, +}; + static const struct of_device_id fsl_edma_dt_ids[] = { { .compatible = "fsl,vf610-edma", }, { /* sentinel */ } @@ -969,6 +1047,7 @@ static struct platform_driver fsl_edma_driver = { .driver = { .name = "fsl-edma", .of_match_table = fsl_edma_dt_ids, + .pm = &fsl_edma_pm_ops, }, .probe = fsl_edma_probe, .remove = fsl_edma_remove,