From patchwork Mon May 10 04:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 12246759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C39ACC433B4 for ; Mon, 10 May 2021 03:32:34 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 020AB6142D for ; Mon, 10 May 2021 03:32:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 020AB6142D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oss.nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AbVMzDewEweN8SglQ6hQlogcZWiGzzlekbHEVRHl9Es=; b=d8MA4eg9LPKtgH+OuiO5ekfj1 hs4pIEuH5GpG1OE1K2rQhX6KV1fjZHUz7FoE1EAU7yy1lzH6yKfD8PIUVqHMpB9afUvNIy4m42sJB wo/1KJNWFaWjQ95whoOzHSlIueCVZ+PUcjZmzvgaDJqvyZWsdtS8r7nHp6TInknHV1Nl6TAZxYmKX c7mT0i+5D7oKPqMqqn+Un40LWa2TdSQQCripuwAze2HZJnjdfTn3kjtJuz1Kl5U9luMh2+I2V2VqT Dvc0u0K+AlLzIX7HZzt4ZdheTlKYC6nHlu15mKEWEtGPou53Yiju9AxlqQBnCL2nihBT/yIp+XRQ2 UP811InYg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lfwcd-00CyDu-EV; Mon, 10 May 2021 03:30:19 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lfwbo-00Cxzn-NP for linux-arm-kernel@desiato.infradead.org; Mon, 10 May 2021 03:29:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=GF6MauPmT4g0ZYZibgloyB+h6HZUfn7M6Sivd5kwauk=; b=ZfKZcYr+yOE+Wz7e6LCi+0tqLT b4VEvX0GDUceABgXGtHD+QEnUlH5laAiY9HP6jTAJEwFfU0izIgg3b7xIe68aoYuqQ3fxhnKGzfjV Hs2zcD3/TyMAv3/9iu/DlZn6TTBo9/XfU8h1SnBsC/8YOlJ1zF9F1avZf7zL9T4NB7IEqq9QFWQdd pzkDdQjgSRwwP7o/RuVA1rkr6MkM0rsLXzw/mz5GMWJa4YvGc6HBU4CKYFUZ6NkrfI2KxOpZihxwF b+wIm2I7rI/1qne/a0TTiJV0DqqZiITUZIu0MgtKHO9lFrUpDnSk2926cqZUdilDy5nio+mbnMIf0 EVmHVmmA==; Received: from mail-eopbgr40063.outbound.protection.outlook.com ([40.107.4.63] helo=EUR03-DB5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lfwbl-008Ejy-O4 for linux-arm-kernel@lists.infradead.org; Mon, 10 May 2021 03:29:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PpRDtPS0HeWnQ8RuSIW+U6lwvaNu7rIUKxE9aqvfr9I2Jy+89P+Ef0ZQz6TMrbCU8WgR+ge0ubMx+R2b1el+2VtSqXKe0kz5Iqfh9qC0vqyXzwyFkIsS9rqiebSN+2nZ1iYKvQwHc/giOMAIy31j9SBOnq93HXRT50yxS7/6xgB4E0qPPK0wnYphjRDn89evKH/2DVzy57w8awi+f/tj8Rdb4Ra9wIlZYlTNKmeNAOJmBSiqFfnHA+rmY7zLacCrFVEDyDtoy8ERDjiJ5wURfUPbRfR43HLv/EqaCMVZwNf20+is4UE+BIpUQqqff/CG/Ne50hAEDHpnxRaNR8rekg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GF6MauPmT4g0ZYZibgloyB+h6HZUfn7M6Sivd5kwauk=; b=bJ8mc8REv041PvC9cJxMQWvoUpGZxWxvd/ygmMI+FVFTQG6RqwW9q3o9y2YWT1vVeoWj38SwLTMH9piYckb6MVRZIWMipOwl5ZXmFWKG4aOP8fSrKB8MjzidE85c6SLAUcZLU2B/8QX+10IYN1QjEcvwACMt5YqeEt1/kJvkePWDUMBPBRbAx+F/Obd9tdg2X49aHR8ueYzidl4kv85sFoPoE/ArCvQU9XOqKagwK+CScfqDcxf63IOlrCVOkOCoXpzDvGZfYL+Swfu3PWYwpfsu1d3TkJBZhdnuIMbwnfVjLiJ7FOdzczqKkwrPfTpkcp2CRJj25pTmaHd1LahOKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GF6MauPmT4g0ZYZibgloyB+h6HZUfn7M6Sivd5kwauk=; b=bOMaaDF/LjTbbkGWcAucTovtIiK1i/yqm167n7zASP1/gmb/ScSr0HNw8wwVRSkSykkJbz3Tk/mGkF/QdyfCOHpOi8WElupYZK/Ot4zBoVMfZ7DjCVjJBAZwmefA3RNy/p3GmMX4PZgcI71WdxYrSwU2D0DW1dd01PlHU6mQpps= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=oss.nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB7PR04MB4091.eurprd04.prod.outlook.com (2603:10a6:5:1e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.26; Mon, 10 May 2021 03:29:21 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::45b9:c993:87ec:9a64]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::45b9:c993:87ec:9a64%8]) with mapi id 15.20.4108.031; Mon, 10 May 2021 03:29:21 +0000 From: "Peng Fan (OSS)" To: robh+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, p.zabel@pengutronix.de, l.stach@pengutronix.de, krzk@kernel.org, agx@sigxcpu.org, marex@denx.de, andrew.smirnov@gmail.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ping.bai@nxp.com, frieder.schrempf@kontron.de, aford173@gmail.com, abel.vesa@nxp.com, Peng Fan Subject: [PATCH V3 04/13] soc: imx: gpcv2: split power up and power down sequence control Date: Mon, 10 May 2021 12:00:36 +0800 Message-Id: <20210510040045.13225-5-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210510040045.13225-1-peng.fan@oss.nxp.com> References: <20210510040045.13225-1-peng.fan@oss.nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: SG2PR04CA0184.apcprd04.prod.outlook.com (2603:1096:4:14::22) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by SG2PR04CA0184.apcprd04.prod.outlook.com (2603:1096:4:14::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 10 May 2021 03:29:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 86df4415-80f3-4ee5-daba-08d91363cd12 X-MS-TrafficTypeDiagnostic: DB7PR04MB4091: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kPqKYQ/5DKUs4bDDRIEYNpd1lkKCO8IoUoIi78BwCS/OQT3+cD3Tg6MtRjACOAq3Mb3t4Ll4RdddBO+PmNb66pH/0ur0bSo/XKgBSi48fkTRDp4ssKY886Ritia+AKyzcvhau7TCwkWDpEOTmThf+N859pGT0T/AZ6wgDMqIKBF06j67NchRFjVukIxPpZ7/FwTbGb1ma7nt/ezPgnIL/VOfdAAMpk1egxd2xqwokzS2UVVbarNtO+v2C661VydklLa2jdKDF2n3xS4CpZ2r1i3O1XXYBFwdUo5lWPv2GDl+glZDJ7S1coUXCGfgGQYjrw802TmiD8xVMd4N+CjSqbOkf0WrKxSNcHgDuX7OviG2heisRr81iwCF5y8iqnTStFf+AbJJqpHyZHOER7mZ4rah/TCrLVoSyOnNLmL3qpqza+kHTkypVh14R3CWEoRzTB1M4QQC5YnTu61yCGqX5flN0SMN7yV9wR1wz/qLgfmTJb3hWHry2DmBaEdPlwzMooOdZZixZ35zNaQp1e8Pelc79RTPMIWSuf9qfGItqUTVNJSA4Sdg/ayI3jg0jFsTA7kkOpXvAB7hZg8Lr+UWJpx3RTFfQXVmQoG+3P6F+yr5YVdwk4Ov7V2r4tqEAfQEcbu10useh4FCau8Qmsd/1NB1/iLDerruqp+070474tY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0402MB2760.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(316002)(86362001)(478600001)(4326008)(1076003)(2616005)(956004)(5660300002)(16526019)(6666004)(7416002)(66476007)(38100700002)(83380400001)(6506007)(52116002)(26005)(2906002)(38350700002)(6512007)(6486002)(66556008)(8936002)(186003)(8676002)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3K0QkR7V2u1fQlyuNeVHeuzCnprKfjuN5g8qV78gf9ZRSzxoSztJ8ZO7cI9TCsttpwgJLPFDh5/44eD1P+yFCcEcBOeAB5mIirRsWNNVod0yHyPRYTDAQNkJehwDDOlm2Qmi17tAmW819v8MrQ/Wqbgs+EGbmLXrfK02wk3u+wmbPjhsv60vup1zRKx3QY5tcgjIPgEUsqUZRV+XL/hOoat1CeXVRMQyzdjO6vzM7iyVYi7sMJb6lepS/PX8N+H1b9hm5Pn1ficNc9uy0NozdDmJ3SUNvBr+EKCqZPnHVoJsMI474OWoxhL46UjtWM9MjHGI5Q42idDvlH0ibLYu6E4hiGYnFAAbnAL6SFjW6nRn1jEtFRmuAibXjWvNbJw7is55VQmCEbds3lwCP0Tp+4pbCc1S18Mc7GMBtvCMYsIII5+dNgrQvmG8Po2f+a3ZQ4URcgNfVX+l5x36cA7YTID4QQbOksh5dYJi54W7DRKv0KVGepMxgyyjWnSN7Klw1ap2u/9brJi2sSsoqBUuCKRQnVRx69WQjpmEo/cbzg7u17bmy7uY1Dl68ggUXomdDzYBBWqCwuVVX92Azx5QbZsQ4l9VsbQaOZNzYrChagN5EMAroGc5NLtL8dn651++/DdXA2s7dzvhxc8cuRke/TBPI9aXO7GHXbrrtdDTh2a7O2Ak0OnQRPKg5MOlltPXxO0Bza6jjUCijEcY6+VQ0Z/p8RO+WvBjxIj/R0dLs9rQdCSCHwJ4sSPUFvGKhxagkU5EKZMPuhiLUuJSs+xw9kjPXzdwOGNVEAF170z+pUoVDsD6e9XTmqB7OnSLV388CvUJCqOHKzFsfEjvpxNH7fqQTGX8TNaV8Vg57t/fsOCb9xiyQ3S3A7zEVjw55/+/vvsKFqEZCEMV1DKZ2C4vcH91VSybQDdrR5tmlvg6x0Mm0JCHm2LGEH8WQp6ltF39ShDEXU01ySq3ep+4BPVfaSmUWcG0aMfZRVLPnVKW7hQbPgRcpLm9iOLcw93zs52sCU/ArKE0B+VySt6CUdPObi4gLd3LYE4gVKup143XXqTGjfl7zT1Rn10D4ZYzkLw7QqYjxZHJ+nOW9C0jvz8lEnHeTlxRA0+17+hGY6x+BRFfxtECNI8aFXj69QBW/hQ4bff3DTqFU0woTKsMM3e6ySC20TuQhCWjapJpMOG66wbFWrg9z2wS/Ngct5RVWDn+ENO/u92ZaTy5aB/NMIOxLEJ3eO6G4aSZBKkeFFk0Da3DzoC2GklhFucbnMYUEKWnuvzpE95imKEm9XtA/wdVrZH/0yMIhJeKAop3FXq/zst4TkInkY2PZgCLr54y+vii X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86df4415-80f3-4ee5-daba-08d91363cd12 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2021 03:29:21.5069 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NkKy91GS6+uj6S0etGCl6jsvXA25jQgpezcUjuuX0UD1Wj+KTi8knpGLuadq8ZK6QkHLZPp/JvfMNnIYVCTenw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4091 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210509_202925_815593_63649A64 X-CRM114-Status: GOOD ( 23.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Lucas Stach The current mixed function to control both power up and power down sequences is very hard to follow and already contains some sequence errors like triggering the ADB400 handshake at the wrong time due to this. Split the function into two, which results in slightly more code, but is way easier to get right. Tested-by: Frieder Schrempf Reviewed-by: Frieder Schrempf Signed-off-by: Lucas Stach Signed-off-by: Peng Fan --- drivers/soc/imx/gpcv2.c | 141 ++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 55 deletions(-) diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c index 4222b6e87e7c..bcf1f338b0bf 100644 --- a/drivers/soc/imx/gpcv2.c +++ b/drivers/soc/imx/gpcv2.c @@ -125,20 +125,19 @@ struct imx_pgc_domain_data { const struct regmap_access_table *reg_access_table; }; -static int imx_gpc_pu_pgc_sw_pxx_req(struct generic_pm_domain *genpd, - bool on) +static inline struct imx_pgc_domain * +to_imx_pgc_domain(struct generic_pm_domain *genpd) { - struct imx_pgc_domain *domain = container_of(genpd, - struct imx_pgc_domain, - genpd); - unsigned int offset = on ? - GPC_PU_PGC_SW_PUP_REQ : GPC_PU_PGC_SW_PDN_REQ; - const bool enable_power_control = !on; - const bool has_regulator = !IS_ERR(domain->regulator); - int i, ret = 0; - u32 pxx_req; - - if (has_regulator && on) { + return container_of(genpd, struct imx_pgc_domain, genpd); +} + +static int imx_pgc_power_up(struct generic_pm_domain *genpd) +{ + struct imx_pgc_domain *domain = to_imx_pgc_domain(genpd); + u32 reg_val; + int ret; + + if (!IS_ERR(domain->regulator)) { ret = regulator_enable(domain->regulator); if (ret) { dev_err(domain->dev, "failed to enable regulator\n"); @@ -150,69 +149,101 @@ static int imx_gpc_pu_pgc_sw_pxx_req(struct generic_pm_domain *genpd, ret = clk_bulk_prepare_enable(domain->num_clks, domain->clks); if (ret) { dev_err(domain->dev, "failed to enable reset clocks\n"); - regulator_disable(domain->regulator); - return ret; + goto out_regulator_disable; } - if (enable_power_control) - regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc), - GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR); - - if (domain->bits.hsk) - regmap_update_bits(domain->regmap, GPC_PU_PWRHSK, - domain->bits.hsk, on ? domain->bits.hsk : 0); - - regmap_update_bits(domain->regmap, offset, + /* request the domain to power up */ + regmap_update_bits(domain->regmap, GPC_PU_PGC_SW_PUP_REQ, domain->bits.pxx, domain->bits.pxx); - /* * As per "5.5.9.4 Example Code 4" in IMX7DRM.pdf wait * for PUP_REQ/PDN_REQ bit to be cleared */ - ret = regmap_read_poll_timeout(domain->regmap, offset, pxx_req, - !(pxx_req & domain->bits.pxx), + ret = regmap_read_poll_timeout(domain->regmap, GPC_PU_PGC_SW_PUP_REQ, + reg_val, !(reg_val & domain->bits.pxx), 0, USEC_PER_MSEC); if (ret) { dev_err(domain->dev, "failed to command PGC\n"); - /* - * If we were in a process of enabling a - * domain and failed we might as well disable - * the regulator we just enabled. And if it - * was the opposite situation and we failed to - * power down -- keep the regulator on - */ - on = !on; + goto out_clk_disable; } - if (enable_power_control) - regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc), - GPC_PGC_CTRL_PCR, 0); + /* disable power control */ + regmap_clear_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc), + GPC_PGC_CTRL_PCR); + + /* request the ADB400 to power up */ + if (domain->bits.hsk) + regmap_update_bits(domain->regmap, GPC_PU_PWRHSK, + domain->bits.hsk, domain->bits.hsk); /* Disable reset clocks for all devices in the domain */ clk_bulk_disable_unprepare(domain->num_clks, domain->clks); - if (has_regulator && !on) { - int err; + return 0; - err = regulator_disable(domain->regulator); - if (err) - dev_err(domain->dev, - "failed to disable regulator: %d\n", err); - /* Preserve earlier error code */ - ret = ret ?: err; - } +out_clk_disable: + clk_bulk_disable_unprepare(domain->num_clks, domain->clks); +out_regulator_disable: + if (!IS_ERR(domain->regulator)) + regulator_disable(domain->regulator); return ret; } -static int imx_gpc_pu_pgc_sw_pup_req(struct generic_pm_domain *genpd) +static int imx_pgc_power_down(struct generic_pm_domain *genpd) { - return imx_gpc_pu_pgc_sw_pxx_req(genpd, true); -} + struct imx_pgc_domain *domain = to_imx_pgc_domain(genpd); + u32 reg_val; + int ret; -static int imx_gpc_pu_pgc_sw_pdn_req(struct generic_pm_domain *genpd) -{ - return imx_gpc_pu_pgc_sw_pxx_req(genpd, false); + /* Enable reset clocks for all devices in the domain */ + ret = clk_bulk_prepare_enable(domain->num_clks, domain->clks); + if (ret) { + dev_err(domain->dev, "failed to enable reset clocks\n"); + return ret; + } + + /* request the ADB400 to power down */ + if (domain->bits.hsk) + regmap_clear_bits(domain->regmap, GPC_PU_PWRHSK, + domain->bits.hsk); + + /* enable power control */ + regmap_update_bits(domain->regmap, GPC_PGC_CTRL(domain->pgc), + GPC_PGC_CTRL_PCR, GPC_PGC_CTRL_PCR); + + /* request the domain to power down */ + regmap_update_bits(domain->regmap, GPC_PU_PGC_SW_PDN_REQ, + domain->bits.pxx, domain->bits.pxx); + /* + * As per "5.5.9.4 Example Code 4" in IMX7DRM.pdf wait + * for PUP_REQ/PDN_REQ bit to be cleared + */ + ret = regmap_read_poll_timeout(domain->regmap, GPC_PU_PGC_SW_PDN_REQ, + reg_val, !(reg_val & domain->bits.pxx), + 0, USEC_PER_MSEC); + if (ret) { + dev_err(domain->dev, "failed to command PGC\n"); + goto out_clk_disable; + } + + /* Disable reset clocks for all devices in the domain */ + clk_bulk_disable_unprepare(domain->num_clks, domain->clks); + + if (!IS_ERR(domain->regulator)) { + ret = regulator_disable(domain->regulator); + if (ret) { + dev_err(domain->dev, "failed to disable regulator\n"); + return ret; + } + } + + return 0; + +out_clk_disable: + clk_bulk_disable_unprepare(domain->num_clks, domain->clks); + + return ret; } static const struct imx_pgc_domain imx7_pgc_domains[] = { @@ -590,8 +621,8 @@ static int imx_gpcv2_probe(struct platform_device *pdev) domain = pd_pdev->dev.platform_data; domain->regmap = regmap; - domain->genpd.power_on = imx_gpc_pu_pgc_sw_pup_req; - domain->genpd.power_off = imx_gpc_pu_pgc_sw_pdn_req; + domain->genpd.power_on = imx_pgc_power_up; + domain->genpd.power_off = imx_pgc_power_down; pd_pdev->dev.parent = dev; pd_pdev->dev.of_node = np;