From patchwork Fri Dec 17 13:09:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 12684583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A160C433EF for ; Fri, 17 Dec 2021 13:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=V1E+KnKhPbGphATQ3Fp01VTUvq9ZuBRl8iGzQpf9Sak=; b=OelpMfRnyHZbOt mJuoUn/9W1gYebqWzFPdCL4ZAtFRbIW7Lt8c2kX1upW2txktmbx8qsrCoVIAuKyxZ6Koq7MPQ7uSd YPUS210eCr9Q1ssnK0Ba+XZBGqZReKdGPZPkNIQSBU9cH+V3brTmX1M3Yp8OoTkRmi2e+yP3JD2NQ wbbunimS+hI0fLZ/ESlOHTyl7c9ZXwvsL7E8HGatZ0IPM6opY7ZOYWjEMh1awXJQtvLlKt04mjzPy z6kgNCAfc8ncekBi0uWxabQBDYpoJDao48Vmd+OIDdXD/O55EdAOe4b/L7Tk8Y5g28HoCNmW/OjX/ OhAuz0VpULkNbDX/oKKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzy-00AJ97-En; Fri, 17 Dec 2021 13:10:10 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzO-00AIoh-NK for linux-rockchip@lists.infradead.org; Fri, 17 Dec 2021 13:09:41 +0000 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myCzF-0004Up-9K; Fri, 17 Dec 2021 14:09:25 +0100 Received: from sha by dude02.hi.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1myCzD-00Cjq0-Vg; Fri, 17 Dec 2021 14:09:23 +0100 From: Sascha Hauer To: linux-rockchip@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Heiko Stuebner , Michael Riesch , kernel@pengutronix.de, Sascha Hauer Subject: [PATCH 1/4] soc: rockchip: power-domain: register device for each domain Date: Fri, 17 Dec 2021 14:09:16 +0100 Message-Id: <20211217130919.3035788-2-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211217130919.3035788-1-s.hauer@pengutronix.de> References: <20211217130919.3035788-1-s.hauer@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_050935_131768_DECDCC01 X-CRM114-Status: GOOD ( 31.08 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This patch prepares the rockchip power domain driver for regulator support. When a switchable regulator supplies a power domain the logical place to put the regulator is into the device node of that domain. In Linux we can get a regulator from a device node only when a device is attached to it. With this patch we register a device for each domain. Signed-off-by: Sascha Hauer --- drivers/soc/rockchip/pm_domains.c | 275 ++++++++++++++---------------- 1 file changed, 127 insertions(+), 148 deletions(-) diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index 0868b7d406fba..d2f71437c73a9 100644 --- a/drivers/soc/rockchip/pm_domains.c +++ b/drivers/soc/rockchip/pm_domains.c @@ -29,6 +29,8 @@ #include #include +struct rockchip_pmu; + struct rockchip_domain_info { const char *name; int pwr_mask; @@ -39,6 +41,10 @@ struct rockchip_domain_info { bool active_wakeup; int pwr_w_mask; int req_w_mask; + + struct rockchip_pmu *pmu; + struct generic_pm_domain *parent_domain; + int id; }; struct rockchip_pmu_info { @@ -81,6 +87,7 @@ struct rockchip_pmu { struct regmap *regmap; const struct rockchip_pmu_info *info; struct mutex mutex; /* mutex lock for pmu */ + atomic_t missing; struct genpd_onecell_data genpd_data; struct generic_pm_domain *domains[]; }; @@ -387,12 +394,11 @@ static void rockchip_pd_detach_dev(struct generic_pm_domain *genpd, } static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, - struct device_node *node) + struct device_node *node, + struct generic_pm_domain *parent_domain) { - const struct rockchip_domain_info *pd_info; - struct rockchip_pm_domain *pd; - struct device_node *qos_node; - int i, j; + struct platform_device *pd_pdev; + struct rockchip_domain_info *domain_info; u32 id; int error; @@ -410,28 +416,98 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, return -EINVAL; } - pd_info = &pmu->info->domain_info[id]; - if (!pd_info) { - dev_err(pmu->dev, "%pOFn: undefined domain id %d\n", - node, id); - return -EINVAL; + pd_pdev = platform_device_alloc("rk-power-domain", id); + if (!pd_pdev) { + dev_err(pmu->dev, "Failed to allocate platform device\n"); + return -ENOMEM; } - pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); + error = platform_device_add_data(pd_pdev, + &pmu->info->domain_info[id], + sizeof(pmu->info->domain_info[id])); + if (error) + goto err_put; + + domain_info = pd_pdev->dev.platform_data; + domain_info->parent_domain = parent_domain; + domain_info->pmu = pmu; + domain_info->id = id; + + pd_pdev->dev.parent = pmu->dev; + pd_pdev->dev.of_node = node; + + atomic_inc(&pmu->missing); + + error = platform_device_add(pd_pdev); + if (error) + goto err_put; + + return 0; + +err_put: + platform_device_put(pd_pdev); + + return error; +} + +static void rockchip_pm_add_domains(struct rockchip_pmu *pmu, + struct device_node *parent, + struct generic_pm_domain *parent_domain) +{ + struct device_node *np; + int error; + + /* + * We may only register the genpd provider when we have registered all + * domains that are specified in the device tree. We count the missing + * domains in rockchip_pmu::missing. + * The rockchip pm_domains may have subdomains which means we can be + * called here recursively. Give it one extra count here to prevent + * the counter dropping to zero when we are called recursively. + */ + atomic_inc(&pmu->missing); + + for_each_child_of_node(parent, np) { + error = rockchip_pm_add_one_domain(pmu, np, parent_domain); + if (error) + dev_err(pmu->dev, "failed to handle node %pOFn: %d\n", + np, error); + } + + if (!atomic_dec_and_test(&pmu->missing)) + return; + + error = of_genpd_add_provider_onecell(pmu->dev->of_node, &pmu->genpd_data); + if (error) + dev_err(pmu->dev, "failed to add provider: %d\n", error); +} + +static int rockchip_domain_probe(struct platform_device *pdev) +{ + struct rockchip_domain_info *pd_info = pdev->dev.platform_data; + struct rockchip_pm_domain *pd; + struct device_node *node = pdev->dev.of_node; + struct device_node *qos_node; + struct rockchip_pmu *pmu = pd_info->pmu; + struct generic_pm_domain *parent_domain; + int i, j; + int error; + + pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL); if (!pd) return -ENOMEM; pd->info = pd_info; - pd->pmu = pmu; + pd->pmu = pd_info->pmu; pd->num_clks = of_clk_get_parent_count(node); if (pd->num_clks > 0) { - pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, + pd->clks = devm_kcalloc(&pdev->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); if (!pd->clks) return -ENOMEM; } else { - dev_dbg(pmu->dev, "%pOFn: doesn't have clocks: %d\n", + dev_dbg(&pdev->dev, "%pOFn: doesn't have clocks: %d\n", node, pd->num_clks); pd->num_clks = 0; } @@ -440,7 +516,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->clks[i].clk = of_clk_get(node, i); if (IS_ERR(pd->clks[i].clk)) { error = PTR_ERR(pd->clks[i].clk); - dev_err(pmu->dev, + dev_err(&pdev->dev, "%pOFn: failed to get clk at index %d: %d\n", node, i, error); return error; @@ -455,7 +531,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, NULL); if (pd->num_qos > 0) { - pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, + pd->qos_regmap = devm_kcalloc(&pdev->dev, pd->num_qos, sizeof(*pd->qos_regmap), GFP_KERNEL); if (!pd->qos_regmap) { @@ -464,7 +540,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, } for (j = 0; j < MAX_QOS_REGS_NUM; j++) { - pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, + pd->qos_save_regs[j] = devm_kcalloc(&pdev->dev, pd->num_qos, sizeof(u32), GFP_KERNEL); @@ -490,7 +566,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, } } - error = rockchip_pd_power(pd, true); + error = rockchip_pd_power_on(&pd->genpd); if (error) { dev_err(pmu->dev, "failed to power on domain '%pOFn': %d\n", @@ -507,13 +583,33 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->genpd.attach_dev = rockchip_pd_attach_dev; pd->genpd.detach_dev = rockchip_pd_detach_dev; pd->genpd.flags = GENPD_FLAG_PM_CLK; - if (pd_info->active_wakeup) + if (pd->info->active_wakeup) pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; pm_genpd_init(&pd->genpd, NULL, false); - pmu->genpd_data.domains[id] = &pd->genpd; + parent_domain = pd_info->parent_domain; + if (parent_domain) { + error = pm_genpd_add_subdomain(parent_domain, &pd->genpd); + if (error) { + dev_err(pmu->dev, "%s failed to add subdomain %s: %d\n", + parent_domain->name, pd->genpd.name, error); + goto out_genpd_remove; + } else { + dev_dbg(pmu->dev, "%s add subdomain: %s\n", + parent_domain->name, pd->genpd.name); + } + } + + pmu->genpd_data.domains[pd->info->id] = &pd->genpd; + + atomic_dec(&pmu->missing); + + rockchip_pm_add_domains(pmu, node, &pd->genpd); + return 0; +out_genpd_remove: + pm_genpd_remove(&pd->genpd); err_unprepare_clocks: clk_bulk_unprepare(pd->num_clks, pd->clks); err_put_clocks: @@ -521,46 +617,19 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, return error; } -static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd) +static int rockchip_domain_remove(struct platform_device *pdev) { - int ret; - - /* - * We're in the error cleanup already, so we only complain, - * but won't emit another error on top of the original one. - */ - ret = pm_genpd_remove(&pd->genpd); - if (ret < 0) - dev_err(pd->pmu->dev, "failed to remove domain '%s' : %d - state may be inconsistent\n", - pd->genpd.name, ret); - - clk_bulk_unprepare(pd->num_clks, pd->clks); - clk_bulk_put(pd->num_clks, pd->clks); - - /* protect the zeroing of pm->num_clks */ - mutex_lock(&pd->pmu->mutex); - pd->num_clks = 0; - mutex_unlock(&pd->pmu->mutex); - - /* devm will free our memory */ + return 0; } -static void rockchip_pm_domain_cleanup(struct rockchip_pmu *pmu) -{ - struct generic_pm_domain *genpd; - struct rockchip_pm_domain *pd; - int i; - - for (i = 0; i < pmu->genpd_data.num_domains; i++) { - genpd = pmu->genpd_data.domains[i]; - if (genpd) { - pd = to_rockchip_pd(genpd); - rockchip_pm_remove_one_domain(pd); - } - } - - /* devm will free our memory */ -} +static struct platform_driver rockchip_domain_driver = { + .driver = { + .name = "rk-power-domain", + }, + .probe = rockchip_domain_probe, + .remove = rockchip_domain_remove, +}; +builtin_platform_driver(rockchip_domain_driver) static void rockchip_configure_pd_cnt(struct rockchip_pmu *pmu, u32 domain_reg_offset, @@ -572,71 +641,14 @@ static void rockchip_configure_pd_cnt(struct rockchip_pmu *pmu, regmap_write(pmu->regmap, domain_reg_offset + 4, count); } -static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu, - struct device_node *parent) -{ - struct device_node *np; - struct generic_pm_domain *child_domain, *parent_domain; - int error; - - for_each_child_of_node(parent, np) { - u32 idx; - - error = of_property_read_u32(parent, "reg", &idx); - if (error) { - dev_err(pmu->dev, - "%pOFn: failed to retrieve domain id (reg): %d\n", - parent, error); - goto err_out; - } - parent_domain = pmu->genpd_data.domains[idx]; - - error = rockchip_pm_add_one_domain(pmu, np); - if (error) { - dev_err(pmu->dev, "failed to handle node %pOFn: %d\n", - np, error); - goto err_out; - } - - error = of_property_read_u32(np, "reg", &idx); - if (error) { - dev_err(pmu->dev, - "%pOFn: failed to retrieve domain id (reg): %d\n", - np, error); - goto err_out; - } - child_domain = pmu->genpd_data.domains[idx]; - - error = pm_genpd_add_subdomain(parent_domain, child_domain); - if (error) { - dev_err(pmu->dev, "%s failed to add subdomain %s: %d\n", - parent_domain->name, child_domain->name, error); - goto err_out; - } else { - dev_dbg(pmu->dev, "%s add subdomain: %s\n", - parent_domain->name, child_domain->name); - } - - rockchip_pm_add_subdomain(pmu, np); - } - - return 0; - -err_out: - of_node_put(np); - return error; -} - static int rockchip_pm_domain_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - struct device_node *node; struct device *parent; struct rockchip_pmu *pmu; const struct of_device_id *match; const struct rockchip_pmu_info *pmu_info; - int error; if (!np) { dev_err(dev, "device tree node not found\n"); @@ -688,42 +700,9 @@ static int rockchip_pm_domain_probe(struct platform_device *pdev) rockchip_configure_pd_cnt(pmu, pmu_info->gpu_pwrcnt_offset, pmu_info->gpu_power_transition_time); - error = -ENODEV; - - for_each_available_child_of_node(np, node) { - error = rockchip_pm_add_one_domain(pmu, node); - if (error) { - dev_err(dev, "failed to handle node %pOFn: %d\n", - node, error); - of_node_put(node); - goto err_out; - } - - error = rockchip_pm_add_subdomain(pmu, node); - if (error < 0) { - dev_err(dev, "failed to handle subdomain node %pOFn: %d\n", - node, error); - of_node_put(node); - goto err_out; - } - } - - if (error) { - dev_dbg(dev, "no power domains defined\n"); - goto err_out; - } - - error = of_genpd_add_provider_onecell(np, &pmu->genpd_data); - if (error) { - dev_err(dev, "failed to add provider: %d\n", error); - goto err_out; - } + rockchip_pm_add_domains(pmu, np, NULL); return 0; - -err_out: - rockchip_pm_domain_cleanup(pmu); - return error; } static const struct rockchip_domain_info px30_pm_domains[] = { From patchwork Fri Dec 17 13:09:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 12684577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 207E9C433EF for ; Fri, 17 Dec 2021 13:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=MxwJ8C93zIUty2tzaccVoejyx2zR8HajogO1ihej8SI=; b=YzWIfRqQ7XK6+d NOpjdSKBRXrFncEiH8wNzlKsHWduheYt45GIDg9WKkamcEFw1JblsP/8VoIRPah4P1EmlL5mUWS7K D6RqlBkg/nbwXIhMp2nMSgolKroCYN0r0y8M6F5MNPq6q7aYSJw+VFSNaW5+489lCkpF7Qev1KGqt JtL09+N2VvMqxERwIwPg62O0g5cT3TFfLghOq880gYJavZQU2305zkMsdeGs9pSf2B7muaPX6J7eH FwqKEJCHMn/nGE+6elfXmXiMfqtvnTbhDpdlyYrjw3kNozfxUimYALT5EGuJW2ews4ljD0c1u2RvK f/FownUVanl76ko4Q0bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzL-00AIo6-DU; Fri, 17 Dec 2021 13:09:31 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzI-00AIm9-Bm for linux-rockchip@lists.infradead.org; Fri, 17 Dec 2021 13:09:29 +0000 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myCzF-0004Uq-9K; Fri, 17 Dec 2021 14:09:25 +0100 Received: from sha by dude02.hi.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1myCzE-00Cjq3-06; Fri, 17 Dec 2021 14:09:24 +0100 From: Sascha Hauer To: linux-rockchip@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Heiko Stuebner , Michael Riesch , kernel@pengutronix.de, Sascha Hauer Subject: [PATCH 2/4] soc: rockchip: power-domain: Use devm_clk_bulk_get_all() Date: Fri, 17 Dec 2021 14:09:17 +0100 Message-Id: <20211217130919.3035788-3-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211217130919.3035788-1-s.hauer@pengutronix.de> References: <20211217130919.3035788-1-s.hauer@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_050928_424232_C1C9C4B3 X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Now that each power domain has its own device we no longer have to use of_clk_get(), but can instead simplify retrieving the clocks by using devm_clk_bulk_get_all(). Signed-off-by: Sascha Hauer --- drivers/soc/rockchip/pm_domains.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index d2f71437c73a9..dcfd3db649f58 100644 --- a/drivers/soc/rockchip/pm_domains.c +++ b/drivers/soc/rockchip/pm_domains.c @@ -490,7 +490,7 @@ static int rockchip_domain_probe(struct platform_device *pdev) struct device_node *qos_node; struct rockchip_pmu *pmu = pd_info->pmu; struct generic_pm_domain *parent_domain; - int i, j; + int j; int error; pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL); @@ -500,32 +500,13 @@ static int rockchip_domain_probe(struct platform_device *pdev) pd->info = pd_info; pd->pmu = pd_info->pmu; - pd->num_clks = of_clk_get_parent_count(node); - if (pd->num_clks > 0) { - pd->clks = devm_kcalloc(&pdev->dev, pd->num_clks, - sizeof(*pd->clks), GFP_KERNEL); - if (!pd->clks) - return -ENOMEM; - } else { - dev_dbg(&pdev->dev, "%pOFn: doesn't have clocks: %d\n", - node, pd->num_clks); - pd->num_clks = 0; - } - - for (i = 0; i < pd->num_clks; i++) { - pd->clks[i].clk = of_clk_get(node, i); - if (IS_ERR(pd->clks[i].clk)) { - error = PTR_ERR(pd->clks[i].clk); - dev_err(&pdev->dev, - "%pOFn: failed to get clk at index %d: %d\n", - node, i, error); - return error; - } - } + pd->num_clks = devm_clk_bulk_get_all(&pdev->dev, &pd->clks); + if (pd->num_clks < 0) + return pd->num_clks; error = clk_bulk_prepare(pd->num_clks, pd->clks); if (error) - goto err_put_clocks; + return error; pd->num_qos = of_count_phandle_with_args(node, "pm_qos", NULL); @@ -612,8 +593,6 @@ static int rockchip_domain_probe(struct platform_device *pdev) pm_genpd_remove(&pd->genpd); err_unprepare_clocks: clk_bulk_unprepare(pd->num_clks, pd->clks); -err_put_clocks: - clk_bulk_put(pd->num_clks, pd->clks); return error; } From patchwork Fri Dec 17 13:09:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 12684581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D5C0C433F5 for ; Fri, 17 Dec 2021 13:10:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=s1Wq8r8jh/sFs1u9JBYo3Fw/MF+Z88Z6rqfzn72ijFY=; b=TrN0twPXwVGWsO /R3aruOH/nm+rsI8II8NdedrUZNr6rEhHsJfA8P+7EFoHkpxYgUQY8492R+KFcUHZMHMpRsm2cUIR +Peb2A7zwnbdgjeRkucF5ck1Uxnz9EzX1P+GFAIGM8hr9RDETqh7IuY6MdGekxkvn8GXTBfWjs293 pknibqV+6m6DaECiXMapiycD14ia09RnPeJDBDmWtzlcFC9nOOJobv0R/eOLBJl4VxlnY6BX3ehrk IYaJPZjjHdz1ENqstHH4p2dTU6DeM7vvqEOkfJqrg2P330sJ4I80Jn22qmGwz3XFuWnFP0Px4PdIz SS96no6ENgaUXW/STpow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzk-00AIy6-Dg; Fri, 17 Dec 2021 13:09:56 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzI-00AImA-E6 for linux-rockchip@lists.infradead.org; Fri, 17 Dec 2021 13:09:31 +0000 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myCzF-0004Ur-9K; Fri, 17 Dec 2021 14:09:25 +0100 Received: from sha by dude02.hi.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1myCzE-00Cjq6-0c; Fri, 17 Dec 2021 14:09:24 +0100 From: Sascha Hauer To: linux-rockchip@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Heiko Stuebner , Michael Riesch , kernel@pengutronix.de, Sascha Hauer Subject: [PATCH 3/4] soc: rockchip: power-domain: Add regulator support Date: Fri, 17 Dec 2021 14:09:18 +0100 Message-Id: <20211217130919.3035788-4-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211217130919.3035788-1-s.hauer@pengutronix.de> References: <20211217130919.3035788-1-s.hauer@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_050928_484948_001C0A67 X-CRM114-Status: GOOD ( 16.62 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This patch allows to let a domain be supplied by a regulator which is needed for the GPU on the rk3568-EVB board. Signed-off-by: Sascha Hauer --- drivers/soc/rockchip/pm_domains.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index dcfd3db649f58..e7db888cc226c 100644 --- a/drivers/soc/rockchip/pm_domains.c +++ b/drivers/soc/rockchip/pm_domains.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,7 @@ struct rockchip_pm_domain { u32 *qos_save_regs[MAX_QOS_REGS_NUM]; int num_clks; struct clk_bulk_data *clks; + struct regulator *regulator; }; struct rockchip_pmu { @@ -344,6 +346,14 @@ static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on) static int rockchip_pd_power_on(struct generic_pm_domain *domain) { struct rockchip_pm_domain *pd = to_rockchip_pd(domain); + struct rockchip_pmu *pmu = pd->pmu; + int ret; + + ret = regulator_enable(pd->regulator); + if (ret) { + dev_err(pmu->dev, "failed to enable regulator: %d\n", ret); + return ret; + } return rockchip_pd_power(pd, true); } @@ -351,8 +361,15 @@ static int rockchip_pd_power_on(struct generic_pm_domain *domain) static int rockchip_pd_power_off(struct generic_pm_domain *domain) { struct rockchip_pm_domain *pd = to_rockchip_pd(domain); + int ret; - return rockchip_pd_power(pd, false); + ret = rockchip_pd_power(pd, false); + if (ret) + return ret; + + regulator_disable(pd->regulator); + + return 0; } static int rockchip_pd_attach_dev(struct generic_pm_domain *genpd, @@ -500,6 +517,11 @@ static int rockchip_domain_probe(struct platform_device *pdev) pd->info = pd_info; pd->pmu = pd_info->pmu; + pd->regulator = devm_regulator_get(&pdev->dev, "power"); + + if (IS_ERR(pd->regulator)) + return PTR_ERR(pd->regulator); + pd->num_clks = devm_clk_bulk_get_all(&pdev->dev, &pd->clks); if (pd->num_clks < 0) return pd->num_clks; From patchwork Fri Dec 17 13:09:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 12684587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB232C433EF for ; Fri, 17 Dec 2021 13:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=y/M0lcYkiAJg/9unn6onvBhNsLlfrjG7UmB7oZ/C0wU=; b=kSx2o+ngK2rogG aqiYBTI9OPvMwr6EHS2kfQbg0e/uZoZdhJGmlAGebhOAQxPxEKt5iskkh5HGwDYXgKtF1Fs+ViBBQ ushKuCtZ6WrfGaemAn/JDPNddc5Rlx2wCi5pBkqSof+9sGRHV9dp60gzmisztt0PJadVrsZUPx1r3 IDPzYqzQe+yPLiCAq4/qwJAjZTrS8Sjkp/SERdr6xGJ+LHpz2GplcITZH9tqD74lGO50f+vuREN49 tdGDypRM5SVY+mzNH8bo4X7LtXbDnd38uOV6I+Bk1Fw4pHO7V5T4qnO0GuxLMqPdH5L3nS0jOdUSx A5A+YWSFZmhWfn6pPRsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myD0S-00AJS6-Hv; Fri, 17 Dec 2021 13:10:40 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myCzW-00AIsD-LI for linux-rockchip@lists.infradead.org; Fri, 17 Dec 2021 13:09:43 +0000 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1myCzF-0004Us-9N; Fri, 17 Dec 2021 14:09:25 +0100 Received: from sha by dude02.hi.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1myCzE-00Cjq9-15; Fri, 17 Dec 2021 14:09:24 +0100 From: Sascha Hauer To: linux-rockchip@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Heiko Stuebner , Michael Riesch , kernel@pengutronix.de, Sascha Hauer Subject: [PATCH 4/4] dt-bindings: power: rockchip: Add power-supply to domain nodes Date: Fri, 17 Dec 2021 14:09:19 +0100 Message-Id: <20211217130919.3035788-5-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211217130919.3035788-1-s.hauer@pengutronix.de> References: <20211217130919.3035788-1-s.hauer@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_050942_756188_8D7A4A52 X-CRM114-Status: UNSURE ( 8.99 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Signed-off-by: Sascha Hauer --- .../bindings/power/rockchip,power-controller.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/power/rockchip,power-controller.yaml b/Documentation/devicetree/bindings/power/rockchip,power-controller.yaml index 9b9d710874663..f7e4b95fb6feb 100644 --- a/Documentation/devicetree/bindings/power/rockchip,power-controller.yaml +++ b/Documentation/devicetree/bindings/power/rockchip,power-controller.yaml @@ -71,6 +71,8 @@ patternProperties: "#size-cells": const: 0 + power-supply: true + patternProperties: "^power-domain@[0-9a-f]+$": @@ -85,6 +87,8 @@ patternProperties: "#size-cells": const: 0 + power-supply: true + patternProperties: "^power-domain@[0-9a-f]+$": @@ -96,6 +100,8 @@ patternProperties: "#power-domain-cells": const: 0 + power-supply: true + $defs: pd-node: type: object