Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2523335rdg; Mon, 14 Aug 2023 05:30:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbPnqlFG3X9oXaI4WrJFI2JzLRvsL96bEtouA/NLJm953g+4JFn0PT6q8a3ShYjVfholNy X-Received: by 2002:a17:907:7615:b0:99b:c2b2:e4ac with SMTP id jx21-20020a170907761500b0099bc2b2e4acmr7625096ejc.33.1692016228338; Mon, 14 Aug 2023 05:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692016228; cv=none; d=google.com; s=arc-20160816; b=BHrUnB/Ed5YXMDL/7auRbow6uYlji2T5DVZo14cDrZ+8voacOTvDb/hxIHaiAxh64m 1AdCBLg5ykElhhZgI7QOwbDm4o4/946XzBAAGu/fhl7d3twCqLPDsennesdXCVTMdWKI pbTI9/6s0eYcTXKcCSYsnLyCyDWF0fIyXn33PIZMXfos07lh/EvvpvWWv0xYZt/INqy1 ram0G/E4HyknXc4OOrZx1L+TYy0V+tWqFF08TGUHIEiWT9IhqcTxUKjhb3Zmpz66Lgxj 9rFDLEinQqz7NEJiTUV+zSwNFRPQ2uaoRezEz1MZEWMmw08U5d2iOXams7J9DTDtR9T2 OJIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KS7KVcgftVL37t1n9Che7EJW3j0iqYnMxaJ13obaF6g=; fh=Qm+lGNHm9v2i6bwPXB3sKYVAqvqNn7+Jbnv8pSjzGVw=; b=cDzZA1sQxbWS1X7GAU7Bqo2p1ygsN+cqy8RCm2Mo0gAq86nGWrmrQxY8QpRFq5o0Mx G05ciUEaVI/paQzQyE04nq4vxFt5N64f8LtluQNjDJb+EUe0eXtqUPkbf6IYoeUxRI6r SEhpE9X3zH1MypC2JAOPGRWQUBmOBMh/oUdA7UPd/DRtX8mPGbZvtaG9Ym9oIfvprT8w xB2sxpRpkElkse4evJvwcDV6F2HU1ZB4/zcoJZgLa0hu/Nt72E86fQMRH18BmovVAkbU twRPDCSvpeZ0IEZrjdCfWjCMvawxXftDpf326rdfcNmCzq0If1r38juC5aO/VjJmEHTB pqcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pGZf4oMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lm21-20020a170906981500b00992acfe04b8si8341912ejb.150.2023.08.14.05.30.02; Mon, 14 Aug 2023 05:30:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pGZf4oMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbjHNL0E (ORCPT + 99 others); Mon, 14 Aug 2023 07:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233736AbjHNLZe (ORCPT ); Mon, 14 Aug 2023 07:25:34 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFE59E61 for ; Mon, 14 Aug 2023 04:25:32 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-58c4e337357so2043737b3.0 for ; Mon, 14 Aug 2023 04:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692012332; x=1692617132; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KS7KVcgftVL37t1n9Che7EJW3j0iqYnMxaJ13obaF6g=; b=pGZf4oMW7KC/g9GiLfwbb7+ZOWIZRij69MhybRVywOgC7Ni84ZUKWxbJZ4K1lwHBKW wUBBrLoHl0RB/t9AgOQ/IpvjGHh8orLDgkhjrWvDIw0JYqo6ilxSo5UVrVK3Kk5ZCI8q rV5R4DziiIAq+HgsTvv7gQdWnofFck99BSICcWnPSizyjgH0WSIudWNomIy/fEcgx8lS CF1h+9FDMrAv9vJ4nmq3AvWQ7DRKgUj1UZnirx7L9+lYxqkipu08SvxK0tw42uni+8GW 3Y1fpOT6eobDpkq7KInwApKGjoj9btgJmThWI/yIF1M99vr9v6XhCsmhnq900gcMQxhO AcUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692012332; x=1692617132; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KS7KVcgftVL37t1n9Che7EJW3j0iqYnMxaJ13obaF6g=; b=Yl34WgR5uHcxQ8hxpYjmdUDvW5ItT+Q7/neSpgYSF/t7vgvAQWaak3mUP88ccDcHzK xpLjmt6eLm8OSQig6imwwzIoFvRQlMc9ji44qH1YAbjv2ZHy/ECTsumLFrKdt4/HLy+h rjwUO6plMika6UA6LBlNCWoKVdFUWbo5cbKADkb6O7vBRxMb/ksfFs2iaemb15ucyaYC cHKwFHWa2UPYEIBPIP/OK47N8hBc5+mY57lqEiyy2PcBwy+RtNkPnISKaTV8HKAAmufX pjT82Lh4Y0n0Alj8rjHMXpqfgNIiyv/m9MM8h8KxkkB3+QMKNjWkgyXUvWT9rPZocG7h zGlA== X-Gm-Message-State: AOJu0Ywr9jzktV+caQUkyrP2kpi8CbrN2A2lP3+gT3yy88sB57D7B8hW /KYaNNEtj5iYxM89zS5JknOu40p6B52OFLuWNPOF78Majnv/3UcZiCI= X-Received: by 2002:a81:a542:0:b0:583:c917:7ff0 with SMTP id v2-20020a81a542000000b00583c9177ff0mr8563710ywg.51.1692012332124; Mon, 14 Aug 2023 04:25:32 -0700 (PDT) MIME-Version: 1.0 References: <20230814104127.1929-1-peng.fan@oss.nxp.com> <20230814104127.1929-8-peng.fan@oss.nxp.com> In-Reply-To: <20230814104127.1929-8-peng.fan@oss.nxp.com> From: Ulf Hansson Date: Mon, 14 Aug 2023 13:24:56 +0200 Message-ID: Subject: Re: [PATCH V4 7/8] genpd: imx: scu-pd: add multi states support To: "Peng Fan (OSS)" Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Peng Fan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 14 Aug 2023 at 12:37, Peng Fan (OSS) wrote: > > From: Peng Fan > > Add multi states support, this is to support devices could run in LP mode > when runtime suspend, and OFF mode when system suspend. For my understanding, is there a functional problem to support OFF at runtime suspend too? > > Signed-off-by: Peng Fan > --- > drivers/genpd/imx/scu-pd.c | 48 ++++++++++++++++++++++++++++++++++++-- > 1 file changed, 46 insertions(+), 2 deletions(-) > > diff --git a/drivers/genpd/imx/scu-pd.c b/drivers/genpd/imx/scu-pd.c > index 2f693b67ddb4..30da101119eb 100644 > --- a/drivers/genpd/imx/scu-pd.c > +++ b/drivers/genpd/imx/scu-pd.c > @@ -65,6 +65,12 @@ > #include > #include > > +enum { > + PD_STATE_LP, > + PD_STATE_OFF, > + PD_STATE_MAX > +}; > + > /* SCU Power Mode Protocol definition */ > struct imx_sc_msg_req_set_resource_power_mode { > struct imx_sc_rpc_msg hdr; > @@ -368,7 +374,8 @@ static int imx_sc_pd_power(struct generic_pm_domain *domain, bool power_on) > hdr->size = 2; > > msg.resource = pd->rsrc; > - msg.mode = power_on ? IMX_SC_PM_PW_MODE_ON : IMX_SC_PM_PW_MODE_LP; > + msg.mode = power_on ? IMX_SC_PM_PW_MODE_ON : pd->pd.state_idx ? > + IMX_SC_PM_PW_MODE_OFF : IMX_SC_PM_PW_MODE_LP; > > /* keep uart console power on for no_console_suspend */ > if (imx_con_rsrc == pd->rsrc && !console_suspend_enabled && !power_on) > @@ -412,11 +419,33 @@ static struct generic_pm_domain *imx_scu_pd_xlate(struct of_phandle_args *spec, > return domain; > } > > +static bool imx_sc_pd_suspend_ok(struct device *dev) > +{ > + /* Always true */ > + return true; > +} > + > +static bool imx_sc_pd_power_down_ok(struct dev_pm_domain *pd) > +{ > + struct generic_pm_domain *genpd = pd_to_genpd(pd); > + > + /* For runtime suspend, choose LP mode */ > + genpd->state_idx = 0; > + > + return true; > +} I am wondering if we couldn't use the simple_qos_governor here instead. In principle it looks like we want a QoS latency constraint to be set during runtime, to prevent the OFF state. During system wide suspend, the deepest state is always selected by genpd. > + > +struct dev_power_governor imx_sc_pd_qos_governor = { > + .suspend_ok = imx_sc_pd_suspend_ok, > + .power_down_ok = imx_sc_pd_power_down_ok, > +}; > + > static struct imx_sc_pm_domain * > imx_scu_add_pm_domain(struct device *dev, int idx, > const struct imx_sc_pd_range *pd_ranges) > { > struct imx_sc_pm_domain *sc_pd; > + struct genpd_power_state *states; > bool is_off; > int mode, ret; > > @@ -427,9 +456,22 @@ imx_scu_add_pm_domain(struct device *dev, int idx, > if (!sc_pd) > return ERR_PTR(-ENOMEM); > > + states = devm_kcalloc(dev, PD_STATE_MAX, sizeof(*states), GFP_KERNEL); > + if (!states) { > + devm_kfree(dev, sc_pd); > + return ERR_PTR(-ENOMEM); > + } > + > sc_pd->rsrc = pd_ranges->rsrc + idx; > sc_pd->pd.power_off = imx_sc_pd_power_off; > sc_pd->pd.power_on = imx_sc_pd_power_on; > + states[PD_STATE_LP].power_off_latency_ns = 25000; > + states[PD_STATE_LP].power_on_latency_ns = 25000; > + states[PD_STATE_OFF].power_off_latency_ns = 2500000; > + states[PD_STATE_OFF].power_on_latency_ns = 2500000; We should probably describe these in DT instead? The domain-idle-states bindings allows us to do this. See Documentation/devicetree/bindings/power/domain-idle-state.yaml. Then we have of_genpd_parse_idle_states(), a helper that parses the values. > + > + sc_pd->pd.states = states; > + sc_pd->pd.state_count = PD_STATE_MAX; > > if (pd_ranges->postfix) > snprintf(sc_pd->name, sizeof(sc_pd->name), > @@ -455,14 +497,16 @@ imx_scu_add_pm_domain(struct device *dev, int idx, > sc_pd->name, sc_pd->rsrc); > > devm_kfree(dev, sc_pd); > + devm_kfree(dev, states); > return NULL; > } > > - ret = pm_genpd_init(&sc_pd->pd, NULL, is_off); > + ret = pm_genpd_init(&sc_pd->pd, &imx_sc_pd_qos_governor, is_off); > if (ret) { > dev_warn(dev, "failed to init pd %s rsrc id %d", > sc_pd->name, sc_pd->rsrc); > devm_kfree(dev, sc_pd); > + devm_kfree(dev, states); > return NULL; > } > > -- > 2.37.1 > Kind regards Uffe