From patchwork Tue Jul 21 08:56:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yao yuan X-Patchwork-Id: 6834041 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3EEA99F358 for ; Tue, 21 Jul 2015 09:45:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2F09C2047B for ; Tue, 21 Jul 2015 09:44:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3C9B20453 for ; Tue, 21 Jul 2015 09:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754546AbbGUJep (ORCPT ); Tue, 21 Jul 2015 05:34:45 -0400 Received: from mail-bl2on0133.outbound.protection.outlook.com ([65.55.169.133]:13969 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754445AbbGUJeg (ORCPT ); Tue, 21 Jul 2015 05:34:36 -0400 Received: from BN3PR0301CA0020.namprd03.prod.outlook.com (10.160.180.158) by BL2PR03MB273.namprd03.prod.outlook.com (10.255.231.11) with Microsoft SMTP Server (TLS) id 15.1.225.13; Tue, 21 Jul 2015 09:01:47 +0000 Received: from BL2FFO11OLC014.protection.gbl (2a01:111:f400:7c09::154) by BN3PR0301CA0020.outlook.office365.com (2a01:111:e400:4000::30) with Microsoft SMTP Server (TLS) id 15.1.219.17 via Frontend Transport; Tue, 21 Jul 2015 09:01:48 +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; 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 BL2FFO11OLC014.mail.protection.outlook.com (10.173.160.144) with Microsoft SMTP Server (TLS) id 15.1.213.8 via Frontend Transport; Tue, 21 Jul 2015 09:01:47 +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 t6L91e6v006594; Tue, 21 Jul 2015 02:01:41 -0700 From: Yuan Yao To: , , CC: , , , Subject: [PATCH v2] dmaengine: fsl-edma: add PM suspend/resume support Date: Tue, 21 Jul 2015 16:56:45 +0800 Message-ID: <1437469005-3162-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; BL2FFO11OLC014; 1:qXXbqZDM1N2g18FIWr3fj/+cC1tzH8DIFewMyUxq7BdDR+91qQVOIirOQvyCSK93AlKBYn4EWBlaDOterDzZkdt2CM33uZs/sTlBksXJs4RmkXdsR7OMqG1+Pg/FQtcVOXrZg1e/V5sprdj+qdCWbkSVJFhT51rfrSbrNgvOctVquYQfxo5YhpWwuTQ1PDS1ZLsMxFt/RXaPk/sOvVG4MiuwHczqfFqkDng2+ZPDwwhmW/FEMvkIinzB6JSznn1DRSfZGAVoEsbeQwq9Wz1jSr4sUxiqgWosAqsU1hMjaSj7m6UoMYebYoNRphW2TEFgF7BYV+4W0hNfdvb2hg4Kg9pTj6flTeU2p+/R8XdBAdg+RJHqiLahhPpuLze5/LkoheRQGSHGNQ+0PRteW5GPX6solTs3BsdV/Ej17B4KQgId62B3HNDKK1FWvt+kIZdJ X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(189998001)(50986999)(50466002)(87936001)(19580395003)(46102003)(5001960100002)(36756003)(62966003)(77156002)(85426001)(50226001)(5003940100001)(105606002)(19580405001)(6806004)(106466001)(47776003)(229853001)(77096005)(104016003)(33646002)(48376002)(2201001)(5001770100001)(86362001)(92566002); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR03MB273; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB273; 2:UYC66PEotC5fByRyKoMI3olFHOj2aAD/AGV35hNIoYXncjMp6zQFMLSkyVwIJVunXJp37BLj6o4/Fi/jdZprCU+jhF0bz4KAF7PPI4zIjC0814TzEoOfBRB5tUNK+XOflvlkvRKJ9hiFja0n5CENVuipv/SMJQb4t+1FpoE09ss=; 3:UJWZmi461rkXw/y+zNmK5Y0nL6hwu2l6Vkn3iMZzv3HehY7TW5QlOJoUiNAbTTE9z2X5IUPiZ4dKlDctl4Nt7fwrgEEuuAjhXMpOUuUg6+Aw48ndenG4eoPncqUwfD/HW3bC/7VFNwJdkmuuttfN7k23f8MTkqRy28cnLuoU0roC+ohEVBB7vxL7lGmyMrHP1jOrJ/z4Rc4smCckvIderMPrrvbIwX6Dn2HUYB/XSI0=; 25:7hxkF54N1vNBEXzyOFSchCHMlltti8wwPU4mym4qywW9ZeYWYDrM5L48P8duvuRGly+9VCvnHmmN9UT3ZULWQV4Doc/Xuo0ODlTfFT/50ToBwtjG8SCjfVwYf59jgsqTHpljxMcM37Id+8khvfq1ws9RrV9JflON9rKhHmO9rDqXbBuDtQKlPcPlORTwno3csgx0XMlG2/VHm2NPsB8k/dNa8fcXJdaW3hlErc0YCtqkWVkdiBVwj6X8aMjkgFje X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB273; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB273; 20:hBP7f0z9ODPw0gvLtniTfhzpI5lvBHXuLxo4Q+3reiQwmKgeK/+6NCHYpUQnOkbk93ZIYx9aal43wrgn85/TVPMyCo2RYShw1DzqWQkn3KB4RD4H9aDywcAtZsSE8Kq83ZK5aMXoYXzUu/HUMHIRLRz32EWfJiCk9m70VwW7AFW0IXx5BVHWXACwF3AS+Gbw7jjoEP1O+1a8vGKhK9wtNppCNiFJx++CSTNfbo6nO+uNR2SaCy37rMuJQOBMUU/k7hYl5Vx/nGX3AYt0xIaDLR/0G28OxppzCZomr5RLSLeEZjJ1s4lAt+BOql3yUUwl/PkuMZJTJvmV02Fv9Nvmo9JURc9RHgXpXMWera0qF+U=; 4:GTXJ7OWmXx87Ir6a8S9THd+dbT5D9L9rQmO43AaBgJSJXffmpkptjT6Ki8LAIyznDemg9uc8dYOjfslfF+NQiTPEqDjHsM2F+al9SMtWQYNfendbEV1E5Lw/0MQiitHJWMXDCz3OOG3RoxWOBUNCl7Kj+pjjEn/TGm8K6Xut9sCT3ZNNa3DzdoSfxwJu58toZ/p72Z6YFwnifWpfIlsWcH4VfUsuJXp7Bfdw6LTjglAdJJE7KDbdob9riV4+d6rAJ3Hvp1Y+XVa+9GZBHtnYBbvwOlt1wwx+gP8bccDF5Dg= BL2PR03MB273: X-MS-Exchange-Organization-RulesExecuted 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:BL2PR03MB273; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB273; X-Forefront-PRVS: 0644578634 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB273; 23:mxPbBkbRRq/dp0Bs6JMzWpBbtUL2/V0zlsoupIq1K4cAbmzL0MbsQghrvqBrJ7oQ2/0i2EAibxkIhJ9Gj2+QpifrMUZhIp8WwKefZRWqOyLO72VFY6z46BeTQstoArErqPCu9BcVXwFIiMLyhf3Y64yi8I0RCPAscP3ZjT1thA4oMqzOMyHqjNy2Jww7C0XrgCRugimDf8Z5d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Fgw== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2015 09:01:47.8734 (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: BL2PR03MB273 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 and if it is not idle, stop PM operation. In fsl_edma_resume_early: Enable the eDMA and wait for being used. Signed-off-by: Yuan Yao --- drivers/dma/fsl-edma.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c index 915eec3..cf8b06c 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,58 @@ 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 can not into suspend. */ + if (unlikely(!fsl_chan->idle)) + goto out; + fsl_chan->pm_state = SUSPENDED; + spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); + } + return 0; + +out: + for (; i >= 0; i--) { + fsl_chan = &fsl_edma->chans[i]; + fsl_chan->pm_state = RUNNING; + spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); + } + return -EBUSY; +} + +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; +} + +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 +1045,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,