Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp220816ybv; Wed, 5 Feb 2020 04:28:19 -0800 (PST) X-Google-Smtp-Source: APXvYqznByNcOHCq1nZbaw6xXQdzrp1zrAIu0xi/0HyweA8a+JPTdq8b2Qu05WndvkVb4eMfVw1A X-Received: by 2002:a9d:12cf:: with SMTP id g73mr24370635otg.329.1580905699242; Wed, 05 Feb 2020 04:28:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580905699; cv=none; d=google.com; s=arc-20160816; b=Nkq2FbjmbrKBZCisYV3T4Ae0u3+m93C9A+gGW4i51d/sYJWqQiMVAe6dTHf1qlbxzr NmL7gAY2w06tPnfaQy8Wja4txIz72izOnGMqPUKIxZTaet1bY8SToclolcoaaf9JoP+b 9CiuJqX7mH8PUFb5DRkAvZIktDb3Xt4xlclE5XveIAjGXUUTWVX7cO/HTXrhiYaHQKbq F85Ao4X8ngwIsdSo36SbYuUKN3ChAm6Lf6rR795KbXJubYEUqI8nXEDWTBTctwTrii80 Na0yFzWvT6b6WLd+8CFSJqQynTq4GojvAdnMVb7+FegW1eEsEIJJWi56oxlqaD8azJKC q18w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature; bh=3oBp+GQXIvHz9eMsTaJ9GKjk778UhbK5cdSMUYMH/24=; b=IrXEPlaS0MSJsZ5lhH5zAblfYZRPq998uEob05I6b4Ul9cQ9bPkbRy7agzKbtZb+cz ETNRmTHVXFoqklyGnzHF/iNx2VB9jabtTK+wQNRU6j5mZxicxXXfAGQLBM0eka2XJjU8 XgOH16LAivfp5sijysJOZsfikrIHQcUYCxThXBdDGc21rAsosd9PtoXL9Osbhxmoaemx bG6yweYMZnkMm8mqBO4qnvWkXhncjF1TpMwWPLwJfVKRiDHbrWWP89QtLAHCp8xE1PC9 XW1gje1GR3E/8/O9uloPH0AQ6vh+kcBWvxz0nButh3by5aO/u6yKL69zgu3l/PF7RweR HGig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=FTQjFBm3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si13134411otq.121.2020.02.05.04.28.07; Wed, 05 Feb 2020 04:28:19 -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=fail header.i=@mg.codeaurora.org header.s=smtp header.b=FTQjFBm3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728114AbgBEM07 (ORCPT + 99 others); Wed, 5 Feb 2020 07:26:59 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:37284 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbgBEM07 (ORCPT ); Wed, 5 Feb 2020 07:26:59 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1580905618; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=3oBp+GQXIvHz9eMsTaJ9GKjk778UhbK5cdSMUYMH/24=; b=FTQjFBm3ow3wpRkBW8j5n6oHAVXnftuRDZWpRsW1Cmj9tCUOpnZyhEBwrL9NzgU+pQ1ekT4K pWXgqz89a/yO6ubGCSNkj8+eWW0UFUZoa+GEKkOJGXzhxw+ebb1zNpYEFQRksmXqR4DvKeOn 88BfTN7GUOeNHOK7iFgLtyNywWo= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e3ab491.7fdf29c96f48-smtp-out-n02; Wed, 05 Feb 2020 12:26:57 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 2566BC447A5; Wed, 5 Feb 2020 12:26:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mkshah-linux.qualcomm.com (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mkshah) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7E851C447A1; Wed, 5 Feb 2020 12:26:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7E851C447A1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=mkshah@codeaurora.org From: Maulik Shah To: swboyd@chromium.org, agross@kernel.org, david.brown@linaro.org, sudeep.holla@arm.com, Lorenzo.Pieralisi@arm.com Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bjorn.andersson@linaro.org, evgreen@chromium.org, dianders@chromium.org, rnayak@codeaurora.org, ilina@codeaurora.org, lsrao@codeaurora.org, ulf.hansson@linaro.org, rjw@rjwysocki.net, Maulik Shah Subject: [PATCH v4 4/6] drivers: qcom: rpmh-rsc: Add RSC power domain support Date: Wed, 5 Feb 2020 17:56:10 +0530 Message-Id: <1580905572-22712-5-git-send-email-mkshah@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1580905572-22712-1-git-send-email-mkshah@codeaurora.org> References: <1580905572-22712-1-git-send-email-mkshah@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add RSC power domain support. RSC is top level power domain in hireachical CPU LPM modes. Once the rsc domain is down flush all cached sleep and wake votes from controller. Signed-off-by: Maulik Shah --- drivers/soc/qcom/rpmh-internal.h | 2 + drivers/soc/qcom/rpmh-rsc.c | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h index 6eec32b..3736c14 100644 --- a/drivers/soc/qcom/rpmh-internal.h +++ b/drivers/soc/qcom/rpmh-internal.h @@ -8,6 +8,7 @@ #define __RPM_INTERNAL_H__ #include +#include #include #define TCS_TYPE_NR 4 @@ -102,6 +103,7 @@ struct rsc_drv { DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR); spinlock_t lock; struct rpmh_ctrlr client; + struct generic_pm_domain rsc_pd; }; int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg); diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index e278fc1..92bca4c 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -499,6 +499,32 @@ static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg) } /** + * rpmh_rsc_ctrlr_is_idle: Check if any of the AMCs are busy. + * + * @drv: The controller + * + * Return: false if the TCSes are engaged in handling requests, True otherwise. + */ +static bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv) +{ + int m; + struct tcs_group *tcs = get_tcs_of_type(drv, ACTIVE_TCS); + bool ret = true; + unsigned long flags; + + spin_lock_irqsave(&drv->lock, flags); + for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) { + if (!tcs_is_free(drv, m)) { + ret = false; + break; + } + } + spin_unlock_irqrestore(&drv->lock, flags); + + return ret; +} + +/** * rpmh_rsc_write_ctrl_data: Write request to the controller * * @drv: the controller @@ -521,6 +547,50 @@ int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, const struct tcs_request *msg) return tcs_ctrl_write(drv, msg); } +static int rpmh_domain_power_off(struct generic_pm_domain *rsc_pd) +{ + struct rsc_drv *drv = container_of(rsc_pd, struct rsc_drv, rsc_pd); + + /* + * RPMh domain can not be powered off when there is pending ACK for + * ACTIVE_TCS request. Exit when controller is busy. + */ + if (!rpmh_rsc_ctrlr_is_idle(drv)) + return -EBUSY; + + return rpmh_flush(&drv->client); +} + +static int rpmh_probe_power_domain(struct platform_device *pdev, + struct rsc_drv *drv) +{ + int ret; + struct generic_pm_domain *rsc_pd = &drv->rsc_pd; + struct device_node *dn = pdev->dev.of_node; + + rsc_pd->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s", dn->name); + if (!rsc_pd->name) + return -ENOMEM; + + rsc_pd->name = kbasename(rsc_pd->name); + rsc_pd->power_off = rpmh_domain_power_off; + rsc_pd->flags |= GENPD_FLAG_IRQ_SAFE; + + ret = pm_genpd_init(rsc_pd, NULL, false); + if (ret) + return ret; + + ret = of_genpd_add_provider_simple(dn, rsc_pd); + if (ret) + goto remove_pd; + + return ret; + +remove_pd: + pm_genpd_remove(rsc_pd); + return ret; +} + static int rpmh_probe_tcs_config(struct platform_device *pdev, struct rsc_drv *drv) { @@ -663,6 +733,17 @@ static int rpmh_rsc_probe(struct platform_device *pdev) if (ret) return ret; + /* + * Power domain is not required for controllers that support 'solver' + * mode where they can be in autonomous mode executing low power mode + * to power down. + */ + if (of_property_read_bool(dn, "#power-domain-cells")) { + ret = rpmh_probe_power_domain(pdev, drv); + if (ret) + return ret; + } + /* Enable the active TCS to send requests immediately */ write_tcs_reg(drv, RSC_DRV_IRQ_ENABLE, 0, drv->tcs[ACTIVE_TCS].mask); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation