Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3273440imu; Sun, 6 Jan 2019 23:49:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/XbEX523tQ/DHrNvl6fbLXjJPKrF5dlCGYqzD2MRRv0Tb2RlIhHU5wu0+9291mZYRduWwIA X-Received: by 2002:a62:399b:: with SMTP id u27mr64282222pfj.181.1546847352618; Sun, 06 Jan 2019 23:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546847352; cv=none; d=google.com; s=arc-20160816; b=MdLis4bHlYvmA1GMc+wMWr7RBOdPM+K7hpg9IbIQoExJyhgQnddbke6IC/o+5OPGko AzZ0KkLC6P0bXo+ojKOUOADpoZ09YSu7rD06TAxi0fIxFTnZA2xRtnde8NmBmwBek1z+ eoUUXqJYEMP6n+1VFmyhr9Qp+s3CE9OtwRMuUP4sydNXK20tt/d5SI66Y5yfuXONLnjy yIaV/2HEMVfv4zkxDNx+nbG710UTaP1aLbp4fHYB29RIv6w+qdlT9zSwyX1nrHVcD8Zz xFCQbx/Ooid6bOvcWOrcuhp5SY9vtgNJ0Fo8nBWunPF1ljOeBxziks55SFqWtpKITRNL M9JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=JJPwHRYlVspUwgQmgKQnn+doYE1eNZ/N9Xmkk3WcPrU=; b=gDZGRf6kR6x71XOvF1ycXxWLEu1bngLBOrTJHNMSeEyU2gdmxjCbeRs0wmJ1FfU5EC FS00UR6JJx34wNCSd28QiWFOMWk/CGe0Ljl01V93IF6jdUIaPkvJz8MbNdzresEisEYc P3yudm4pdMQ5Yl1d8ij7Y8lvPJ7ROi/3LzivZNm5FlkQZtDvmq78Ycv30tSa5zPEkzZP 4TpbfK2Xl1X7BsyNfsgFXM/AxrXaT24T73GqlGVRK1oF/Arn/sCiW69l+8+bDS4r4Xl0 Qas3sLT9UInke2KNHJ2UwgHBNajYnn9Jn+TSqwKm9vY0SRPb+PPn2sWj/GL7SS0T3Nac HCkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=wZMXnHBt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si16156383pgh.185.2019.01.06.23.48.56; Sun, 06 Jan 2019 23:49:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=wZMXnHBt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726590AbfAGHrm (ORCPT + 99 others); Mon, 7 Jan 2019 02:47:42 -0500 Received: from mail-eopbgr50060.outbound.protection.outlook.com ([40.107.5.60]:27839 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726441AbfAGHrk (ORCPT ); Mon, 7 Jan 2019 02:47:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JJPwHRYlVspUwgQmgKQnn+doYE1eNZ/N9Xmkk3WcPrU=; b=wZMXnHBt/3J3SU/sypGHy2yipeMoXNrb1gkdHg3eKbiFRO4xTqMFtTzCmCvfdkiuf+a8nnhFezxUkzLJnJNVaNDyVpUj2vzWY1I3B0I+bBSjsIOlkjnDocFv1qvZR17m7iU6sJLOWOf4HsUZPbRHsvb+CR83U8xHxa7QiVYAmf4= Received: from AM6PR04MB5016.eurprd04.prod.outlook.com (20.177.34.88) by AM6PR04MB5831.eurprd04.prod.outlook.com (20.179.2.223) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1495.6; Mon, 7 Jan 2019 07:47:36 +0000 Received: from AM6PR04MB5016.eurprd04.prod.outlook.com ([fe80::7c57:c2f3:1681:3fc4]) by AM6PR04MB5016.eurprd04.prod.outlook.com ([fe80::7c57:c2f3:1681:3fc4%6]) with mapi id 15.20.1495.011; Mon, 7 Jan 2019 07:47:36 +0000 From: Clark Wang To: "broonie@kernel.org" CC: "linux-spi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Clark Wang Subject: [PATCH 2/8] spi: lpspi: enable runtime pm for lpspi Thread-Topic: [PATCH 2/8] spi: lpspi: enable runtime pm for lpspi Thread-Index: AQHUpl1BvcWf5QFDhUyp/bfXx0Qxvg== Date: Mon, 7 Jan 2019 07:47:36 +0000 Message-ID: <20190107074639.6336-3-xiaoning.wang@nxp.com> References: <20190107074639.6336-1-xiaoning.wang@nxp.com> In-Reply-To: <20190107074639.6336-1-xiaoning.wang@nxp.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR02CA0087.apcprd02.prod.outlook.com (2603:1096:4:90::27) To AM6PR04MB5016.eurprd04.prod.outlook.com (2603:10a6:20b:9::24) authentication-results: spf=none (sender IP is ) smtp.mailfrom=xiaoning.wang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [92.121.68.129] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM6PR04MB5831;6:4+fJYUcqU+pBMd53b1ErUYTJxQy19TmCcj3vNbZKRSmZ62O00a6Co82m3fqjZkBTMYW8dXGeW//5sROQtzgQlye2ZBJK8ciHyGxyqDgA03qRKVRgNBLKtttUcA5NoOEJrYowH6vHO2zP8O/FShZ5hYSGpWu0K3yN/W7Dsz+7F16/H2h55owqDqcTE2eXJoZK8imjI5rUbdWe7/OQ/WlI3W79rQksro06ceyuG2A8khx2K6FPBMGwFGSWESQPYyWozCR6ZMqbUb0drlUtC5YgMWRJKEGM+4CbtxP+txDwdrAOl6+JaSWRgS2aidtmAV/vmEocqKU5WjRIuF1qlke6DG3QaNwx9TXD/Ydwu5aJUo15tJeqaSU8BwQCNpwiJ6VJMCEp06oiwMYkVyTcPQc4nTHq7S7+vXkxpY1eg+HBy5ZSwzlVxi60Iy8RBH14gqabgdL0+drhBSH36z+6Da55SQ==;5:SWFFV9//euQD7E29Vi8K7UJPFGUXkFVe0acfJKwr5LM6BvSezJY9OwGYSLXWFeWIyi9TOlrpx17lfQWOfzbklhywb2419bEpXjE/lZcrLWIsPpH11nMYnKG63FnKlROGBtF2pYXND0deioFqGpD3Ghc2rYjfD+8mdGRBDFFOwkzY1bFPdz0o4p0+WM50WVwGFH/KC7LWZZ1LmuzXPRepvA==;7:Kc44kyORJvW/eGvX9ZlpoXhGfuAcYWUsvMP9XRAkSVzClHhMBKwQFbB4G05HSdFz61U3zaAz5V/hB3Fc2kmdwchjTMsMdziR4Yp60tbZJy9Np0Rqn3fSZXpytFfdTaj5QEIFCUXd4wJ4sQTduHSBTg== x-ms-office365-filtering-correlation-id: 2f3d6413-61df-4dab-04d2-08d674746408 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM6PR04MB5831; x-ms-traffictypediagnostic: AM6PR04MB5831: x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(8220060)(2401047)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(6041310)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:AM6PR04MB5831;BCL:0;PCL:0;RULEID:;SRVR:AM6PR04MB5831; x-forefront-prvs: 0910AAF391 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(39860400002)(376002)(396003)(366004)(346002)(199004)(189003)(14444005)(256004)(8676002)(6436002)(97736004)(5640700003)(54906003)(6486002)(68736007)(316002)(6916009)(575784001)(86362001)(2351001)(105586002)(99286004)(66066001)(186003)(26005)(81166006)(2501003)(476003)(8936002)(446003)(36756003)(11346002)(50226002)(2616005)(7736002)(81156014)(106356001)(1730700003)(52116002)(305945005)(76176011)(6116002)(3846002)(102836004)(2906002)(386003)(6506007)(4326008)(1076003)(25786009)(71190400001)(71200400001)(14454004)(486006)(6512007)(478600001)(5660300001)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR04MB5831;H:AM6PR04MB5016.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: BJifp8H87lsUaTkALf1jB3u0GceLf1+rax/yYeER7B58mK7njqnlZI6ktuj4XrjM+mp7ge6Rld9oaf2PDupFnp2kkM5WJgVO5quX7GS/1YfiX2ZRNawtPag0FIE639aJ7Sz2w2At8Ft20dk1N329ItUBtzKX42slMexK5wYzM62QppN8S+ON/bOYOz1h1PjGoYl2rgNAv3MjBEjZThXl8K0cuMHdiRGuIWW84HQ4xZjD8Wl1vlXIJq85w7YNtzFPzyPW078GsCrdV9Eh+4CAiIp80xEa5ThjhJERlUwwUIZDiMwKQ9+S9oHtpgnW5W4y spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f3d6413-61df-4dab-04d2-08d674746408 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jan 2019 07:47:34.6588 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB5831 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Han Xu Enable the runtime power management for lpspi module. Do some adaptation work from kernel 4.9 to 4.14. Signed-off-by: Clark Wang Signed-off-by: Han Xu Reviewed-by: Frank Li --- drivers/spi/spi-fsl-lpspi.c | 117 ++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 25 deletions(-) diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 5802f188051b..3e935db5ff02 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -24,6 +26,8 @@ =20 #define DRIVER_NAME "fsl_lpspi" =20 +#define FSL_LPSPI_RPM_TIMEOUT 50 /* 50ms */ + /* i.MX7ULP LPSPI registers */ #define IMX7ULP_VERID 0x0 #define IMX7ULP_PARAM 0x4 @@ -150,13 +154,9 @@ static int lpspi_prepare_xfer_hardware(struct spi_cont= roller *controller) spi_controller_get_devdata(controller); int ret; =20 - ret =3D clk_prepare_enable(fsl_lpspi->clk_ipg); - if (ret) - return ret; - - ret =3D clk_prepare_enable(fsl_lpspi->clk_per); - if (ret) { - clk_disable_unprepare(fsl_lpspi->clk_ipg); + ret =3D pm_runtime_get_sync(fsl_lpspi->dev); + if (ret < 0) { + dev_err(fsl_lpspi->dev, "failed to enable clock\n"); return ret; } =20 @@ -168,8 +168,8 @@ static int lpspi_unprepare_xfer_hardware(struct spi_con= troller *controller) struct fsl_lpspi_data *fsl_lpspi =3D spi_controller_get_devdata(controller); =20 - clk_disable_unprepare(fsl_lpspi->clk_ipg); - clk_disable_unprepare(fsl_lpspi->clk_per); + pm_runtime_mark_last_busy(fsl_lpspi->dev); + pm_runtime_put_autosuspend(fsl_lpspi->dev); =20 return 0; } @@ -476,6 +476,45 @@ static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id= ) return IRQ_NONE; } =20 +int fsl_lpspi_runtime_resume(struct device *dev) +{ + struct fsl_lpspi_data *fsl_lpspi =3D dev_get_drvdata(dev); + int ret; + + ret =3D clk_prepare_enable(fsl_lpspi->clk_per); + if (ret) + return ret; + + ret =3D clk_prepare_enable(fsl_lpspi->clk_ipg); + if (ret) { + clk_disable_unprepare(fsl_lpspi->clk_per); + return ret; + } + + return 0; +} + +int fsl_lpspi_runtime_suspend(struct device *dev) +{ + struct fsl_lpspi_data *fsl_lpspi =3D dev_get_drvdata(dev); + + clk_disable_unprepare(fsl_lpspi->clk_per); + clk_disable_unprepare(fsl_lpspi->clk_ipg); + + return 0; +} + +static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi) +{ + struct device *dev =3D fsl_lpspi->dev; + + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, FSL_LPSPI_RPM_TIMEOUT); + pm_runtime_use_autosuspend(dev); + + return 0; +} + static int fsl_lpspi_probe(struct platform_device *pdev) { struct fsl_lpspi_data *fsl_lpspi; @@ -501,6 +540,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev= ) =20 fsl_lpspi =3D spi_controller_get_devdata(controller); fsl_lpspi->dev =3D &pdev->dev; + dev_set_drvdata(&pdev->dev, fsl_lpspi); fsl_lpspi->is_slave =3D of_property_read_bool((&pdev->dev)->of_node, "spi-slave"); =20 @@ -547,28 +587,21 @@ static int fsl_lpspi_probe(struct platform_device *pd= ev) goto out_controller_put; } =20 - ret =3D clk_prepare_enable(fsl_lpspi->clk_ipg); - if (ret) { - dev_err(&pdev->dev, - "can't enable lpspi ipg clock, ret=3D%d\n", ret); + /* enable the clock */ + ret =3D fsl_lpspi_init_rpm(fsl_lpspi); + if (ret) goto out_controller_put; - } =20 - ret =3D clk_prepare_enable(fsl_lpspi->clk_per); - if (ret) { - dev_err(&pdev->dev, - "can't enable lpspi per clock, ret=3D%d\n", ret); - clk_disable_unprepare(fsl_lpspi->clk_ipg); - goto out_controller_put; + ret =3D pm_runtime_get_sync(fsl_lpspi->dev); + if (ret < 0) { + dev_err(fsl_lpspi->dev, "failed to enable clock\n"); + return ret; } =20 temp =3D readl(fsl_lpspi->base + IMX7ULP_PARAM); fsl_lpspi->txfifosize =3D 1 << (temp & 0x0f); fsl_lpspi->rxfifosize =3D 1 << ((temp >> 8) & 0x0f); =20 - clk_disable_unprepare(fsl_lpspi->clk_per); - clk_disable_unprepare(fsl_lpspi->clk_ipg); - ret =3D devm_spi_register_controller(&pdev->dev, controller); if (ret < 0) { dev_err(&pdev->dev, "spi_register_controller error.\n"); @@ -589,16 +622,50 @@ static int fsl_lpspi_remove(struct platform_device *p= dev) struct fsl_lpspi_data *fsl_lpspi =3D spi_controller_get_devdata(controller); =20 - clk_disable_unprepare(fsl_lpspi->clk_per); - clk_disable_unprepare(fsl_lpspi->clk_ipg); + pm_runtime_disable(fsl_lpspi->dev); + + spi_master_put(controller); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int fsl_lpspi_suspend(struct device *dev) +{ + int ret; + + pinctrl_pm_select_sleep_state(dev); + ret =3D pm_runtime_force_suspend(dev); + return ret; +} + +static int fsl_lpspi_resume(struct device *dev) +{ + int ret; + + ret =3D pm_runtime_force_resume(dev); + if (ret) { + dev_err(dev, "Error in resume: %d\n", ret); + return ret; + } + + pinctrl_pm_select_default_state(dev); =20 return 0; } +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops fsl_lpspi_pm_ops =3D { + SET_RUNTIME_PM_OPS(fsl_lpspi_runtime_suspend, + fsl_lpspi_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(fsl_lpspi_suspend, fsl_lpspi_resume) +}; =20 static struct platform_driver fsl_lpspi_driver =3D { .driver =3D { .name =3D DRIVER_NAME, .of_match_table =3D fsl_lpspi_dt_ids, + .pm =3D &fsl_lpspi_pm_ops, }, .probe =3D fsl_lpspi_probe, .remove =3D fsl_lpspi_remove, --=20 2.17.1