From: thomas.petazzoni@free-electrons.com (Thomas Petazzoni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/10] power: supply: axp20x_usb_power: set min voltage and max current from sysfs
Date: Fri, 25 Nov 2016 10:48:18 +0100 [thread overview]
Message-ID: <20161125104818.597c0718@free-electrons.com> (raw)
In-Reply-To: <20161125090921.23138-3-quentin.schulz@free-electrons.com>
Quentin,
On Fri, 25 Nov 2016 10:09:13 +0100, Quentin Schulz wrote:
> +static int axp20x_usb_power_set_property(struct power_supply *psy,
> + enum power_supply_property psp,
> + const union power_supply_propval *val)
> +{
> + struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
> + int ret, val1;
> +
> + switch (psp) {
> + case POWER_SUPPLY_PROP_VOLTAGE_MIN:
> + switch (val->intval) {
This nested switch construct doesn't look very pretty. What about
instead:
switch(psp) {
case POWER_SUPPLY_PROP_VOLTAGE_MIN:
return axp20x_usb_power_set_prop_voltage_min(...);
case POWER_SUPPLY_PROP_CURRENT_MAX:
return axp20x_usb_power_set_prop_current_max(...);
default:
return -EINVAL;
}
> + case 4000000:
> + case 4100000:
> + case 4200000:
> + case 4300000:
> + case 4400000:
> + case 4500000:
> + case 4600000:
> + case 4700000:
> + val1 = (val->intval - 4000000) / 100000;
> + ret = regmap_update_bits(power->regmap,
> + AXP20X_VBUS_IPSOUT_MGMT,
> + AXP20X_VBUS_VHOLD_MASK,
> + val1 << 3);
> + if (ret)
> + return ret;
> +
> + return 0;
Just do:
return regmap_update_bits(...);
The dance to test ret is useless, since you anyway return ret when
non-zero, or return zero when ret was zero.
While you're at it, maybe make val1 a u32, since I guess it's written
to a 32-bit register (unless u32 is not commonly used in this driver
already, of course).
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
next prev parent reply other threads:[~2016-11-25 9:48 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-25 9:09 [PATCH 00/10] add support for VBUS max current and min voltage limits AXP20X and AXP22X PMICs Quentin Schulz
2016-11-25 9:09 ` [PATCH 01/10] power: supply: axp20x_usb_power: use of_device_id data field instead of device_is_compatible Quentin Schulz
2016-11-25 9:23 ` Chen-Yu Tsai
2016-11-25 10:52 ` kbuild test robot
2016-11-25 9:09 ` [PATCH 02/10] power: supply: axp20x_usb_power: set min voltage and max current from sysfs Quentin Schulz
2016-11-25 9:42 ` Chen-Yu Tsai
2016-11-25 9:48 ` Thomas Petazzoni [this message]
2016-11-25 9:09 ` [PATCH 03/10] Documentation: DT: binding: axp20x_usb_power: add axp223 compatible Quentin Schulz
2016-11-25 9:25 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 04/10] power: supply: axp20x_usb_power: add 100mA max current limit for AXP223 Quentin Schulz
2016-11-25 9:56 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 05/10] mfd: axp20x: add separate MFD cell " Quentin Schulz
2016-11-25 10:03 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 06/10] ARM: dtsi: add DTSI " Quentin Schulz
2016-11-25 10:04 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 07/10] ARM: dts: sun8i-a33-olinuxino: use AXP223 DTSI Quentin Schulz
2016-11-25 10:05 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 08/10] ARM: dts: sun8i-a33-sinlinx-sina33: " Quentin Schulz
2016-11-25 10:05 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 09/10] ARM: dts: sun8i-r16-parrot: " Quentin Schulz
2016-11-25 10:05 ` Chen-Yu Tsai
2016-11-25 9:09 ` [PATCH 10/10] ARM: dtsi: sun8i-reference-design-tablet: " Quentin Schulz
2016-11-25 10:06 ` Chen-Yu Tsai
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=20161125104818.597c0718@free-electrons.com \
--to=thomas.petazzoni@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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