Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp792598ybl; Wed, 28 Aug 2019 05:30:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6ZgtUkwl63msGkj5MtE57YVen4T2568nL3TfT9WFcTU4dIdAl1PZNDl7iTcKrXOn9iNxq X-Received: by 2002:a17:90a:380a:: with SMTP id w10mr3966322pjb.138.1566995438824; Wed, 28 Aug 2019 05:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566995438; cv=none; d=google.com; s=arc-20160816; b=0TziAKvC9iZ/yT7DmIgIOVBPX9oCzldiBBywvK3NGRGHWabLaTIpMbfyzEdpeP+eCA 2XTOO3W5ZIcNnvxYsmg92qc/A4XMJ93wmox1PLAdAo+38+Yw4nnUj5VYSVfhCOggigh5 TwlIlkV7XRsaQdHW4iX4+xVEUQuiEmnk9X5x8oPpTh8Q/S2ZvrQar5GZGhulj4xJUNO+ cO3s4WU9f9+YIPtrp/gtOXu62nPHjz4mr4QRzUGkRSVyAKXEe0XpKIVUKdMmSDoLFgm/ WfM8hcTgMAZ9tJ40tnsM//LMVyo3+x/zNmqPs9Z+ly7yRn3EzHzaXBDRMsTTw3WMGrOn bXuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=6/ahTJOMF+LAJ2E2CTeoSowG9FOKL1W4YT/8KuLBNMY=; b=zRXxFu/nSjBMXo7lTerHsHflp5pzTFpiQetTObo89IgGG3Ul1uK64UPQ04T99r1ipD JZGd5lhGepGj+E8l7xOOopA6Tza06l+BBxkRSGtJfCNNQgkoA5FrDJ/lTueVaD5LeJFm i4FTxwlJO89vr5LP+AFarDvbLbBCXUVW4BksXhvuJWawz540mV9OxRcirme+yS66T3sP 9t77eUKYeYOG4XuagaBTPBsJWYw728GmtcDx8BbY1fITupr4qczTm48CdMg8iuI7Jldy RVbZlVBqAMUVx2Glv7muOrv9fFFtwLEDI1NLPSpQaWhgp9aSjQ94w278kShUzcOUqzRq Itzg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si1782632plr.431.2019.08.28.05.30.23; Wed, 28 Aug 2019 05:30:38 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726817AbfH1M3Q (ORCPT + 99 others); Wed, 28 Aug 2019 08:29:16 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:46449 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726566AbfH1M3E (ORCPT ); Wed, 28 Aug 2019 08:29:04 -0400 X-UUID: aa0007ba038d434086a15393bb0e0ce8-20190828 X-UUID: aa0007ba038d434086a15393bb0e0ce8-20190828 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 762124500; Wed, 28 Aug 2019 20:28:53 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 28 Aug 2019 20:28:58 +0800 Received: from mtksdaap41.mediatek.inc (172.21.77.4) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 28 Aug 2019 20:28:58 +0800 From: Henry Chen To: Georgi Djakov , Rob Herring , Matthias Brugger , Viresh Kumar , Stephen Boyd , Ryan Case CC: Nicolas Boichat , Fan Chen , James Liao , Weiyi Lu , , , , , Henry Chen Subject: [PATCH V3 03/10] soc: mediatek: add support for the performance state Date: Wed, 28 Aug 2019 20:28:41 +0800 Message-ID: <1566995328-15158-4-git-send-email-henryc.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1566995328-15158-1-git-send-email-henryc.chen@mediatek.com> References: <1566995328-15158-1-git-send-email-henryc.chen@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support power domain performance state, add header file for scp event. Signed-off-by: Henry Chen --- drivers/soc/mediatek/mtk-scpsys.c | 58 +++++++++++++++++++++++++++++++++++++++ drivers/soc/mediatek/mtk-scpsys.h | 22 +++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-scpsys.h diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c index e072810..50bc254 100644 --- a/drivers/soc/mediatek/mtk-scpsys.c +++ b/drivers/soc/mediatek/mtk-scpsys.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include @@ -21,6 +23,7 @@ #include #include #include +#include "mtk-scpsys.h" #define MTK_POLL_DELAY_US 10 #define MTK_POLL_TIMEOUT USEC_PER_SEC @@ -187,6 +190,18 @@ struct scp_soc_data { bool bus_prot_reg_update; }; +static BLOCKING_NOTIFIER_HEAD(scpsys_notifier_list); + +int register_scpsys_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&scpsys_notifier_list, nb); +} + +int unregister_scpsys_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&scpsys_notifier_list, nb); +} + static int scpsys_domain_is_on(struct scp_domain *scpd) { struct scp *scp = scpd->scp; @@ -505,6 +520,41 @@ static void init_clks(struct platform_device *pdev, struct clk **clk) clk[i] = devm_clk_get(&pdev->dev, clk_names[i]); } +static int mtk_pd_set_performance(struct generic_pm_domain *genpd, + unsigned int state) +{ + int i; + struct scp_domain *scpd = + container_of(genpd, struct scp_domain, genpd); + struct scp_event_data scpe; + struct scp *scp = scpd->scp; + struct genpd_onecell_data *pd_data = &scp->pd_data; + + for (i = 0; i < pd_data->num_domains; i++) { + if (genpd == pd_data->domains[i]) { + dev_dbg(scp->dev, "%d. %s = %d\n", + i, genpd->name, state); + break; + } + } + + if (i == pd_data->num_domains) + return 0; + + scpe.event_type = MTK_SCPSYS_PSTATE; + scpe.genpd = genpd; + scpe.domain_id = i; + blocking_notifier_call_chain(&scpsys_notifier_list, state, &scpe); + + return 0; +} + +static unsigned int mtk_pd_get_performance(struct generic_pm_domain *genpd, + struct dev_pm_opp *opp) +{ + return dev_pm_opp_get_level(opp); +} + static struct scp *init_scp(struct platform_device *pdev, const struct scp_domain_data *scp_domain_data, int num, const struct scp_ctrl_reg *scp_ctrl_reg, @@ -630,6 +680,14 @@ static struct scp *init_scp(struct platform_device *pdev, genpd->power_on = scpsys_power_on; if (MTK_SCPD_CAPS(scpd, MTK_SCPD_ACTIVE_WAKEUP)) genpd->flags |= GENPD_FLAG_ACTIVE_WAKEUP; + + /* Add opp table check first to avoid OF runtime parse failed */ + if (of_count_phandle_with_args(pdev->dev.of_node, + "operating-points-v2", NULL) > 0) { + genpd->set_performance_state = mtk_pd_set_performance; + genpd->opp_to_performance_state = + mtk_pd_get_performance; + } } return scp; diff --git a/drivers/soc/mediatek/mtk-scpsys.h b/drivers/soc/mediatek/mtk-scpsys.h new file mode 100644 index 0000000..c1e8325 --- /dev/null +++ b/drivers/soc/mediatek/mtk-scpsys.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2018 MediaTek Inc. + */ + +#ifndef __MTK_SCPSYS_H__ +#define __MTK_SCPSYS_H__ + +struct scp_event_data { + int event_type; + int domain_id; + struct generic_pm_domain *genpd; +}; + +enum scp_event_type { + MTK_SCPSYS_PSTATE, +}; + +int register_scpsys_notifier(struct notifier_block *nb); +int unregister_scpsys_notifier(struct notifier_block *nb); + +#endif /* __MTK_SCPSYS_H__ */ -- 1.9.1