From: Ricardo Rivera-Matos <r-rivera-matos@ti.com>
To: "Andrew F. Davis" <afd@ti.com>, <sre@kernel.org>,
<pali@kernel.org>, <robh@kernel.org>
Cc: <dmurphy@ti.com>, <linux-pm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
<sspatil@android.com>
Subject: Re: [PATCH v11 4/4] power: supply: bq25150 introduce the bq25150
Date: Thu, 28 May 2020 17:20:27 -0500 [thread overview]
Message-ID: <5792b63e-37cc-7110-4767-df300385eb7b@ti.com> (raw)
In-Reply-To: <95fcf5ae-cf49-4618-08cc-da7487450e53@ti.com>
On 5/28/20 9:43 AM, Andrew F. Davis wrote:
> On 5/28/20 10:05 AM, Ricardo Rivera-Matos wrote:
>> +static int bq2515x_set_precharge_current(struct bq2515x_device *bq2515x,
>> + int val)
>> +{
>> + int ret;
>> + unsigned int pchrgctrl;
>> + unsigned int icharge_range;
>> + unsigned int precharge_reg_code;
>> + u16 precharge_multiplier = BQ2515X_ICHG_RNG_1B0_UA;
>> + u16 precharge_max_ua = BQ2515X_PRECHRG_ICHRG_RNGE_1875_UA;
>
> Why u16? looks like it gets promoted everywhere it's used anyway.
ACK
>
>
>> +
>> + ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl);
>> + if (ret)
>> + return ret;
>> +
>> + icharge_range = pchrgctrl & BQ2515X_ICHARGE_RANGE;
>> +
>> + if (icharge_range) {
>> + precharge_max_ua = BQ2515X_PRECHRG_ICHRG_RNGE_3750_UA;
>> + precharge_multiplier = BQ2515X_ICHG_RNG_1B1_UA;
> This is a little hard to read when we have a default value overwritten
> in an if, it basically hides the else logic, suggest:
>
>
> if (icharge_range) {
> precharge_max_ua = BQ2515X_PRECHRG_ICHRG_RNGE_3750_UA;
> precharge_multiplier = BQ2515X_ICHG_RNG_1B1_UA;
> } else {
> precharge_max_ua = BQ2515X_PRECHRG_ICHRG_RNGE_1875_UA;
> precharge_multiplier = BQ2515X_ICHG_RNG_1B0_UA;
> }
ACK. I originally had it as an if/else deal, but I got feedback it was
too verbose. It will stay verbose.
>
>
>> + }
>> + if (val > precharge_max_ua || val < BQ2515X_ICHG_MIN_UA)
>> + return -EINVAL;
>> +
>> + precharge_reg_code = val / precharge_multiplier;
>> +
>> + ret = bq2515x_set_charge_disable(bq2515x, 1);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL,
>> + BQ2515X_PRECHARGE_MASK, precharge_reg_code);
>> + if (ret)
>> + return ret;
>> +
>> + return bq2515x_set_charge_disable(bq2515x, 0);
>> +}
> [snip]
>
>> +
>> +static int bq2515x_set_ilim_lvl(struct bq2515x_device *bq2515x, int val)
>> +{
>> + int i = 0;
>> + unsigned int array_size = ARRAY_SIZE(bq2515x_ilim_lvl_values);
>> +
>> + if (val >= bq2515x_ilim_lvl_values[array_size - 1]) {
>
> Isn't this check the same as is done in first iteration of the below loop?
>
> Andrew
ACK
>
>
>> + i = array_size - 1;
>> + } else {
>> + for (i = array_size - 1; i > 0; i--) {
>> + if (val >= bq2515x_ilim_lvl_values[i])
>> + break;
>> + }
>> + }
>> + return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i);
>> +}
>> +
prev parent reply other threads:[~2020-05-28 22:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-28 14:05 [PATCH v11 0/4] Add JEITA properties and introduce the bq2515x charger Ricardo Rivera-Matos
2020-05-28 14:05 ` [PATCH v11 1/4] power_supply: Add additional health properties to the header Ricardo Rivera-Matos
2020-05-28 14:16 ` Andrew F. Davis
2020-05-28 22:42 ` Ricardo Rivera-Matos
2020-05-28 14:05 ` [PATCH v11 2/4] dt-bindings: power: Convert battery.txt to battery.yaml Ricardo Rivera-Matos
2020-05-28 14:05 ` [PATCH v11 3/4] dt-bindings: power: Add the bindings for the bq2515x family of chargers Ricardo Rivera-Matos
2020-05-28 14:05 ` [PATCH v11 4/4] power: supply: bq25150 introduce the bq25150 Ricardo Rivera-Matos
2020-05-28 14:43 ` Andrew F. Davis
2020-05-28 22:20 ` Ricardo Rivera-Matos [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5792b63e-37cc-7110-4767-df300385eb7b@ti.com \
--to=r-rivera-matos@ti.com \
--cc=afd@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=dmurphy@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pali@kernel.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=sspatil@android.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox