From patchwork Mon Oct 19 08:31:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yao yuan X-Patchwork-Id: 7434401 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 C9CAABEEA4 for ; Mon, 19 Oct 2015 08:39:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA923206E1 for ; Mon, 19 Oct 2015 08:39:37 +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 AC72920673 for ; Mon, 19 Oct 2015 08:39:36 +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 1Zo5xA-00048m-On; Mon, 19 Oct 2015 08:38:00 +0000 Received: from mail-bn1bn0103.outbound.protection.outlook.com ([157.56.110.103] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zo5x7-0003z1-TM for linux-arm-kernel@lists.infradead.org; Mon, 19 Oct 2015 08:37:59 +0000 Received: from CO2PR03CA0043.namprd03.prod.outlook.com (10.141.194.170) by BN3PR0301MB1267.namprd03.prod.outlook.com (10.161.209.147) with Microsoft SMTP Server (TLS) id 15.1.300.14; Mon, 19 Oct 2015 08:37:35 +0000 Received: from BL2FFO11OLC005.protection.gbl (2a01:111:f400:7c09::177) by CO2PR03CA0043.outlook.office365.com (2a01:111:e400:1414::42) with Microsoft SMTP Server (TLS) id 15.1.286.15 via Frontend Transport; Mon, 19 Oct 2015 08:37:35 +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 BL2FFO11OLC005.mail.protection.outlook.com (10.173.160.91) with Microsoft SMTP Server (TLS) id 15.1.300.4 via Frontend Transport; Mon, 19 Oct 2015 08:37:34 +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 t9J8bU3d027334; Mon, 19 Oct 2015 01:37:31 -0700 From: Yuan Yao To: , , Subject: [PATCH v3] dmaengine: fsl-edma: add PM suspend/resume support Date: Mon, 19 Oct 2015 16:31:05 +0800 Message-ID: <1445243465-7727-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; BL2FFO11OLC005; 1:ia84Vv+jEGmLB87SgyhaM3Ociadftmnu6go5R4/eQjKDF3uVKJdwt3knCGQ6lMJC9pJ/klqzKwS5HMUsHNNa+YZjA/Ji7tZhrkyWNyt+d6d5vO5MucImQhRQWvX1ty8KGbYAY950zyjb4WKCRZhwficAyohKOsCKns272FkE4r7etdLDqUY0mFY5t43wnAVUDoT1L7IAJMtfBnts8CIz6nC+yPAwUKOpiU2KdtGy+PyJ2VXL1FemOaHDw2KRqrG71YW+pjbveXat/mut/pBCzL9d0LD3TMR6PvVPNkj697Y0x8a5aTFCtfoWiCmdLntQZ33Fchhu6uii7lBxL5INXZY0jvh8+qTZrSFFmu7PFVS7AdJZ5A5f1jgI8WeokVMRQJwTuK1lH3+80ohIFi4yGw== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(19580395003)(85426001)(48376002)(86362001)(2201001)(87936001)(47776003)(6806005)(104016004)(189998001)(50466002)(11100500001)(5003940100001)(5001960100002)(81156007)(77096005)(97736004)(5001770100001)(5007970100001)(64706001)(229853001)(50226001)(50986999)(19580405001)(106466001)(36756003)(105606002)(33646002)(5008740100001)(46102003)(92566002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR0301MB1267; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1267; 2:PnkkR6+Dc+Td64MAuLDaCDE5dAt8rlvoEBn4FTDnOieeuh8berIVGM6opYaFXH4kex4Q4U8IgVA608LeVLbi9Dlw6A4pWrnnRjSzeyx8mTgpzOBw7T1rMCihDQpdEYy6uLG9UsE+y6PTzypEpyVuWnoBDD8NCUOJSGksA/9P/HI=; 3:NP9HDcCEqyqndqMcPSbY88VxTmtJCWgAc1UEicu/vbmWrPsnN2T88f3qhWDya6t+31vTWfw7C5QslNMk1ceji9Pqrg0qggbALC5hk2uFEU+lA6s6Q/imvK8SlKys123b1eI7YB2+y9yp/0m7Y2SlhU9JBSj4pjaH5CL3BL1Di8JPiAVpbhtIMRURv3Pu/uHB4vY9iJZNCWFfHu/K8JQQg3moTRIrw3+LUqAgCfz1Pg4=; 25:9dFyolCmuSBDvDC5rCEBeC3J4uu3vB3F+awABWgJuFDFDO0d1L3fPK287j2EZNDYzdQ23Ypjb/WUVCmcSfMc1c6Zz7U/wkWhxtkogFTpk4j/ZlnAvraUu2MxePToVSBZGpoVlyKee3JLQWeEDMby6pMAO2HdVYLsJM63xeD2ChW2w3Vf2vVKwflrzJuGINRScj5aj8FilMMSAeSl8oTK9TTLVLi3p45KnRGnPzx15AuSgmcFoMXhHcCoVvU6Ik2T X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0301MB1267; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1267; 20:clsLFGlE7bhb3RnlrR5gf0Q2649BD5MH3Oz1C4oJRVyDvWgZ/UpWc6cGbjTXQ9yjRR8+yjbTj/jMf0VfoZo/Hm97PQfFauBMXDjopCHAtmxdxWHl5R1u6p6f+j+XMrkCnfn+4ysKKgib8WPd6o2u8kDlQr3U/aouTMsWIGKdcx6XAzBVgveg+mtMlAviciy7yxC7MvOpH3O2qV2FuKuJTBwAjkPej7IrE9E7iC849OuNqWh+zLMau57aet61htokTRgs5PCRNtK0F0aGL5HpCNz36gTox8s5kmyr4NDD9Q8MXTV97RqBjWALO+pW3bNrwGY9KTfCdGCp0MqRL7/uAC7+8hIL7fHXYaSS+SoD3+o=; 4:xkImvbhX5bI0pyIEiXWvjlqcI/XjhmJ/eAb6lEQ3NDKL4xzlUhD8wjHIER/UexXzfT2Tk4ClRcNfRa/iRbUoFgw6u4KXq5+DeL08l/6vqLWhvn6BtuwRO/CcbnBYfspBsaaGLpE1hXk4Baxf5EHTXiwmQop5EefpjCGQ5BKI9NGvV9HJ3hbbeinMFpZl82XKeivR1rGBQKFYZNpL88GqV8IemO5sWbWdwZj1ygBnJdIrSzvw0QSCzRGAZyaSavE5RI0tiCRApILb7QMchNEoUxFVnDov0gSmz+Fifa0BSnYAYKFzklcYQGRz4LXFOzugI5pYJryV+p1YKPpb/iaw+5iyGHnweSaSXeVo7YMoXak= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001); SRVR:BN3PR0301MB1267; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0301MB1267; X-Forefront-PRVS: 07349BFAD2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0301MB1267; 23:1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p?= =?us-ascii?Q?28BpLVZz+qqV0CYpVQFBp8KWoawTTcMADxLaLEwMRxNEPEbwDE31N1Xe0m2A?= =?us-ascii?Q?+wyQNInKzrpc6N3OAFrL4CDNG/S5/pnpEqxKtBb5FVCAkOCYh2jwrt2K5PsG?= =?us-ascii?Q?h4l94lt7ZnwKohGDqn+MGHwJywXJPJv444cCVeZltp4Qxog=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1267; 5:BSuRd7CDZKDq3D+aKp/MIO8XDY4Q6g2Io5nZqqQnyKXc7kB7VPWIrwilxQ3VIUH3bLEmBid3PH+Io1obwtjIIf0Nr0694xd/KKgl3PUCA95arhHQKXkc6Nhyc8+Ht29Tq74PPSTiGI4v7zfprf2hCw==; 24:sWLBYId+6K3YQ3agKQgW8C61BlnghRIzvY38yl+hZKUrQ1PLCGZ1fZpjsbzuvdM5UtdIfZPC4O1m22GDUyR4IvoYsO3qmHOCOKN75PmqkH0=; 20:kr7VMynefR17HzdNwD5q45G6mvVxiiy3jx8zPSPCg2NCph3RzJDTIfJoj4fGSSBK+PvdGRewmME7NJJWoWbZAA== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2015 08:37:34.3392 (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: BN3PR0301MB1267 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151019_013758_328201_C377E6E4 X-CRM114-Status: GOOD ( 26.43 ) 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=-4.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 --- drivers/dma/fsl-edma.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c index 915eec3..6e28e57 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,55 @@ 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; +} + +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 +1042,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,