Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp884461pxb; Wed, 27 Oct 2021 14:26:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGwbOZzcbIf7G9GbrJYxd/4HXEVAxLix7uFhH287cAcjErWiBcHghTU/dqOA9gRu85I3t1 X-Received: by 2002:a17:907:608c:: with SMTP id ht12mr127478ejc.78.1635370005340; Wed, 27 Oct 2021 14:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635370005; cv=none; d=google.com; s=arc-20160816; b=YLxmgtoFmtT+KBNpGjJXPQGxCcl8akrvQbllFxDM1HGolgLiYBuXe/O5WMQjp9+BZY qZpHXxwFsv06+WrZCEWGR8jmrP+k95g0MZebMbgOfc+Z+yW3eUKkpBj02HUJ6eGLY5bB eebWZ71Q8+RxRl1L/TglfWrvRx7y9AGKS1qeA/VI+5/LwwVRkotCt5KviTA7gpJyMubl QGGy2AI/haLP1ieF3QW1DBaDe5APFSk+NgDNF5S6qV7yyoY+oafha+K4R5+9Xu4YOgM7 QlUsT3/9Gm8hEguAqpPe4idgslVrDIoSD/43nMDwAAl9QiY3Nfgczwy4YUvePhaQUMqp rHBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=emfK6MCmU8mBdNVw+dRXfYWzqv456o8C2DzZkJfc+GQ=; b=yPHHFa33yi3T1CkSW6Du9iz8XgY3WAFfWPvcxwAhhGx/8f9aR/vsm2MrMLoixc86qA 8YueNLar72q4Dpdfda8r0+mllz0hjI08IpL+jVZlrP+43K7hrQYApe+lf6TcDl44OffK hHS2Ehbk4LQNWhEjPnMytTE+lS/bFdz3RksWn47VM1aAHQeh3a7b0FzURUVjkOHsFGKO tNCS/d+PGlgMDB1N0k1fbPzW9vJnH/l4N6p2isrd//Rdu/k5yztbgyDKTy8CLsoT9cTm gT5DS/Oqr6aKHDaNYhUnkVGybCHHDeh2U/56505KMBEDAtZG4gVi+DeY+4KbRzXFcAKy FFUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=YE3U3u0j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si808778edt.481.2021.10.27.14.26.22; Wed, 27 Oct 2021 14:26:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=YE3U3u0j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242177AbhJ0Nmo (ORCPT + 97 others); Wed, 27 Oct 2021 09:42:44 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:42658 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232335AbhJ0Nmn (ORCPT ); Wed, 27 Oct 2021 09:42:43 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1635342018; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=emfK6MCmU8mBdNVw+dRXfYWzqv456o8C2DzZkJfc+GQ=; b=YE3U3u0jK3xp0VI4OzmaPQBFIH6bDBGVYfcGPwoS4xo3v49UAYWX97LiZv9vw/FR6JHmGw+E bngQUge/P1fZMXBrQcIESnkuQ+OIcskIT5myEAHTOXI7LhAZ1zse4aJYNANe1xwdXJbeNZBO JuBpH0G347irIxRJR0R/3RjNav0= X-Mailgun-Sending-Ip: 198.61.254.9 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 smtp-out-n05.prod.us-west-2.postgun.com with SMTP id 617956b1648aeeca5c37a37c (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 27 Oct 2021 13:40:01 GMT Sender: skakit=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 31ECDC43618; Wed, 27 Oct 2021 13:40:01 +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=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: skakit) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2DA55C4360C; Wed, 27 Oct 2021 13:40:00 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 27 Oct 2021 19:10:00 +0530 From: skakit@codeaurora.org To: Stephen Boyd Cc: Bjorn Andersson , Rob Herring , Lee Jones , Liam Girdwood , Mark Brown , Das Srinagesh , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, mka@chromium.org, collinsd@codeaurora.org, subbaram@codeaurora.org, kgunda@codeaurora.org Subject: Re: [PATCH V2 3/4] regulator: Add a regulator driver for the PM8008 PMIC In-Reply-To: References: <1633060859-22969-1-git-send-email-skakit@codeaurora.org> <1633060859-22969-4-git-send-email-skakit@codeaurora.org> <168101fa5937d841d7073e94db246df9@codeaurora.org> Message-ID: <0fc33d57fe929cef3681cafd78e40a6a@codeaurora.org> X-Sender: skakit@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-10-26 01:16, Stephen Boyd wrote: > Quoting skakit@codeaurora.org (2021-10-22 05:28:34) >> On 2021-10-06 00:05, Stephen Boyd wrote: >> > Quoting Satya Priya (2021-09-30 21:00:58) >> >> diff --git a/drivers/regulator/qcom-pm8008-regulator.c >> >> b/drivers/regulator/qcom-pm8008-regulator.c >> >> new file mode 100644 >> >> index 0000000..5dacaa4 >> >> --- /dev/null >> >> +++ b/drivers/regulator/qcom-pm8008-regulator.c >> >> @@ -0,0 +1,320 @@ >> >> +// SPDX-License-Identifier: GPL-2.0-only >> >> +/* Copyright (c) 2021, The Linux Foundation. All rights reserved. */ >> >> + >> >> +#include > [...] >> >> + >> >> +static int pm8008_regulator_get_voltage(struct regulator_dev *rdev) >> >> +{ >> >> + struct pm8008_regulator *pm8008_reg = rdev_get_drvdata(rdev); >> >> + u8 vset_raw[2]; >> >> + int rc; >> >> + >> >> + rc = pm8008_read(pm8008_reg->regmap, >> >> + LDO_VSET_LB_REG(pm8008_reg->base), >> >> + vset_raw, 2); >> > >> > Can this be an __le16 mV? >> > >> >> Below is the diff after changing as per your suggestion, Please >> correct >> me if wrong. >> >> - u8 vset_raw[2]; >> + __le16 mV; >> int rc; >> >> - rc = pm8008_read(pm8008_reg->regmap, >> - LDO_VSET_LB_REG(pm8008_reg->base), >> - vset_raw, 2); >> + rc = regmap_bulk_read(pm8008_reg->regmap, >> + LDO_VSET_LB_REG(pm8008_reg->base), &mV, 2); >> if (rc < 0) { >> dev_err(pm8008_reg->dev, "failed to read regulator >> voltage rc=%d\n", rc); >> return rc; >> } >> >> - return (vset_raw[1] << 8 | vset_raw[0]) * 1000; >> + return le16_to_cpu(mV) * 1000; > > Looks good. Does mV need to be casted when passed to > regmap_bulk_read()? > >> >> Below is the diff: >> >> - int rc = 0, mv; >> - u8 vset_raw[2]; >> + int rc, mv; >> + u16 vset_raw; >> [...] >> - vset_raw[0] = mv & 0xff; >> - vset_raw[1] = (mv & 0xff00) >> 8; >> - rc = pm8008_write(pm8008_reg->regmap, >> LDO_VSET_LB_REG(pm8008_reg->base), >> - vset_raw, 2); >> + vset_raw = cpu_to_le16(mv); >> + >> + rc = regmap_bulk_write(pm8008_reg->regmap, >> + LDO_VSET_LB_REG(pm8008_reg->base), &vset_raw, >> + sizeof(vset_raw)); >> > > Ok, thanks > >> >> + dev_err(dev, "%s: failed to get regulator data\n", >> >> name); >> >> + return -ENODATA; >> >> + } >> >> + >> >> + init_data->constraints.input_uV = >> >> init_data->constraints.max_uV; >> >> + reg_config.dev = dev; >> >> + reg_config.init_data = init_data; >> >> + reg_config.driver_data = pm8008_reg; >> >> + reg_config.of_node = reg_node; >> >> + >> >> + pm8008_reg->rdesc.type = REGULATOR_VOLTAGE; >> >> + pm8008_reg->rdesc.ops = &pm8008_regulator_ops; >> >> + pm8008_reg->rdesc.name = init_data->constraints.name; >> >> + pm8008_reg->rdesc.supply_name = reg_data[i].supply_name; >> >> + pm8008_reg->rdesc.uV_step = VSET_STEP_UV; >> >> + pm8008_reg->rdesc.min_uV = reg_data[i].min_uv; >> >> + pm8008_reg->rdesc.n_voltages >> >> + = ((reg_data[i].max_uv - reg_data[i].min_uv) >> >> + / pm8008_reg->rdesc.uV_step) + 1; >> >> + >> >> + pm8008_reg->rdesc.enable_reg = LDO_ENABLE_REG(base); >> >> + pm8008_reg->rdesc.enable_mask = ENABLE_BIT; >> >> + pm8008_reg->rdesc.min_dropout_uV = reg_data[i].min_dropout_uv; >> >> + of_property_read_u32(reg_node, "qcom,min-dropout-voltage", >> >> + &pm8008_reg->rdesc.min_dropout_uV); >> > >> > Why do we allow DT to override this? Isn't it a property of the >> > hardware >> > that doesn't change? So the driver can hardcode the knowledge about the >> > dropout. >> > >> >> The headroom values change with targets. We are adding some default >> headroom values in the driver and later overwriting them with the >> actual >> values specified in the DT. > > What do you mean by "targets"? Is that the SoC the PMIC is paired with? Yes I meant the SoC/board on which the pmic is present. > I'd prefer it be a standard regulator property instead of qcom specific > if it actually needs to be different based on different devices. > Ok, I'll drop the qcom prefix. >> >> >> + >> >> + pm8008_reg->rdev = devm_regulator_register(dev, >> >> &pm8008_reg->rdesc, >> > >> > Is this assignment ever used? Seems like it would be better to merely >> > >> > return PTR_ERR_OR_ZERO(devm_regulator_register(dev, ...)); >> > >> >> Okay. >> >> >> + ®_config); >> >> + if (IS_ERR(pm8008_reg->rdev)) { >> >> + rc = PTR_ERR(pm8008_reg->rdev); >> >> + dev_err(dev, "%s: failed to register regulator >> >> rc=%d\n", >> >> + pm8008_reg->rdesc.name, rc); >> >> + return rc; >> >> + } >> >> + >> >> + dev_dbg(dev, "%s regulator registered\n", name); >> >> + >> >> + return 0; >> >> +} >> >> + >> >> +static int pm8008_parse_regulator(struct regmap *regmap, struct >> >> device *dev) >> >> +{ >> >> + int rc = 0; >> > >> > Drop initialization. >> > >> >> Okay. >> >> >> + const char *name; >> >> + struct device_node *child; >> >> + struct pm8008_regulator *pm8008_reg; >> >> + >> >> + /* parse each subnode and register regulator for regulator >> >> child */ >> >> + for_each_available_child_of_node(dev->of_node, child) { >> >> + pm8008_reg = devm_kzalloc(dev, sizeof(*pm8008_reg), >> >> GFP_KERNEL); >> >> + >> >> + pm8008_reg->regmap = regmap; >> >> + pm8008_reg->of_node = child; >> >> + pm8008_reg->dev = dev; >> >> + >> >> + rc = of_property_read_string(child, "regulator-name", >> >> &name); >> >> + if (rc) >> >> + continue; >> >> + >> >> + rc = pm8008_register_ldo(pm8008_reg, name); >> > >> > Can we use the of_parse_cb similar to qcom_spmi-regulator.c? >> > >> >> Are you suggesting to remove the pm8008_register_ldo API and add its >> contents in probe itself and then use of_parse_cb callback like in >> qcom_spmi-regulator.c? > > Yes > Okay. >> >> Do we have any advantage using that here? Also I am not exactly sure >> what all contents to put in that. Seems like we can put the step rate >> and min-dropout-voltage configurations in there. > > Right. The regulator code is setup to do "DT parsing stuff" for each > regulator node already, so you don't need to duplicate that logic in > this driver. That's the main goal, consolidate regulator matching and > iteration into the core. Maybe Mark has more info. Okay.