linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wens@csie.org>
To: Quentin Schulz <quentin.schulz@free-electrons.com>
Cc: "Chen-Yu Tsai" <wens@csie.org>,
	"Jonathan Cameron" <jic23@kernel.org>,
	knaack.h@gmx.de, "Lars-Peter Clausen" <lars@metafoo.de>,
	"Peter Meerwald-Stadler" <pmeerw@pmeerw.net>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Russell King" <linux@armlinux.org.uk>,
	"Maxime Ripard" <maxime.ripard@free-electrons.com>,
	"Lee Jones" <lee.jones@linaro.org>,
	linux-iio@vger.kernel.org,
	devicetree <devicetree@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"open list:THERMAL" <linux-pm@vger.kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	"Thomas Petazzoni" <thomas.petazzoni@free-electrons.com>,
	"Icenowy Zheng" <icenowy@aosc.xyz>,
	"Bruno Prémont" <bonbons@linux-vserver.org>
Subject: Re: [PATCH 03/22] iio: adc: add support for X-Powers AXP20X and AXP22X PMICs ADCs
Date: Thu, 5 Jan 2017 16:27:50 +0800	[thread overview]
Message-ID: <CAGb2v66n46KQAzQBUrDwx7sYADkRm3_XyCHf9imN+FiDkHfP1w@mail.gmail.com> (raw)
In-Reply-To: <9acfe5e0-dc56-bd63-02b4-7bf34d49d62c@free-electrons.com>

On Thu, Jan 5, 2017 at 4:06 PM, Quentin Schulz
<quentin.schulz@free-electrons.com> wrote:
> Hi Chen-Yu,
>
> On 05/01/2017 06:42, Chen-Yu Tsai wrote:
>> On Tue, Jan 3, 2017 at 12:37 AM, Quentin Schulz
>> <quentin.schulz@free-electrons.com> wrote:
> [...]
>>> +
>>> +#define AXP20X_ADC_RATE_MASK                   (3 << 6)
>>> +#define AXP20X_ADC_RATE_25HZ                   (0 << 6)
>>> +#define AXP20X_ADC_RATE_50HZ                   BIT(6)
>>
>> Please be consistent with the format.
>>
>>> +#define AXP20X_ADC_RATE_100HZ                  (2 << 6)
>>> +#define AXP20X_ADC_RATE_200HZ                  (3 << 6)
>>> +
>>> +#define AXP22X_ADC_RATE_100HZ                  (0 << 6)
>>> +#define AXP22X_ADC_RATE_200HZ                  BIT(6)
>>> +#define AXP22X_ADC_RATE_400HZ                  (2 << 6)
>>> +#define AXP22X_ADC_RATE_800HZ                  (3 << 6)
>>
>> These are power-of-2 multiples of some base rate. May I suggest
>> a formula macro instead. Either way, you seem to be using only
>> one value. Will this be made configurable in the future?
>>
>
> Yes, I could use a formula macro instead. No plan to make it
> configurable, should I make it configurable?

I don't see a use case for that atm.

>>> +
>>> +#define AXP20X_ADC_CHANNEL(_channel, _name, _type, _reg)       \
>>> +       {                                                       \
>>> +               .type = _type,                                  \
>>> +               .indexed = 1,                                   \
>>> +               .channel = _channel,                            \
>>> +               .address = _reg,                                \
>>> +               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
>>> +                                     BIT(IIO_CHAN_INFO_SCALE), \
>>> +               .datasheet_name = _name,                        \
>>> +       }
>>> +
>>> +#define AXP20X_ADC_CHANNEL_OFFSET(_channel, _name, _type, _reg) \
>>> +       {                                                       \
>>> +               .type = _type,                                  \
>>> +               .indexed = 1,                                   \
>>> +               .channel = _channel,                            \
>>> +               .address = _reg,                                \
>>> +               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
>>> +                                     BIT(IIO_CHAN_INFO_SCALE) |\
>>> +                                     BIT(IIO_CHAN_INFO_OFFSET),\
>>> +               .datasheet_name = _name,                        \
>>> +       }
>>> +
>>> +struct axp20x_adc_iio {
>>> +       struct iio_dev          *indio_dev;
>>> +       struct regmap           *regmap;
>>> +};
>>> +
>>> +enum axp20x_adc_channel {
>>> +       AXP20X_ACIN_V = 0,
>>> +       AXP20X_ACIN_I,
>>> +       AXP20X_VBUS_V,
>>> +       AXP20X_VBUS_I,
>>> +       AXP20X_TEMP_ADC,
>>
>> PMIC_TEMP would be better. And please save a slot for TS input.
>>
>
> ACK.
>
> Hum.. I'm wondering what should be the IIO type of the TS input channel
> then? The TS Pin can be used in two modes: either to monitor the
> temperature of the battery or as an external ADC, at least that's what I
> understand from the datasheet.

AFAIK the battery charge/discharge high/low temperature threshold
registers take values in terms of voltage, not actual temperature.
And the temperature readout kind of depends on the thermoresistor
one is using. So I think "voltage" would be the proper type.

>
>>> +       AXP20X_GPIO0_V,
>>> +       AXP20X_GPIO1_V,
>>
>> Please skip a slot for "battery instantaneous power".
>>
>>> +       AXP20X_BATT_V,
>>> +       AXP20X_BATT_CHRG_I,
>>> +       AXP20X_BATT_DISCHRG_I,
>>> +       AXP20X_IPSOUT_V,
>>> +};
>>> +
>>> +enum axp22x_adc_channel {
>>> +       AXP22X_TEMP_ADC = 0,
>>
>> Same comments as AXP20X_TEMP_ADC.
>>
>>> +       AXP22X_BATT_V,
>>> +       AXP22X_BATT_CHRG_I,
>>> +       AXP22X_BATT_DISCHRG_I,
>>> +};
>>
>> Shouldn't these channel numbers be exported as part of the device tree
>> bindings? At the very least, they shouldn't be changed.
>>
>
> I don't understand what you mean by that. Do you mean you want a
> consistent numbering between the AXP20X and the AXP22X, so that
> AXP22X_BATT_V would have the same channel number than AXP20X_BATT_V?
>
> Could you explain a bit more your thoughts on the channel numbers being
> exported as part of the device tree bindings?

What I meant was that, since you are referencing the channels in the
device tree, the numbering scheme would be part of the device tree
binding, and should never be changed. So either these would be macros
in include/dt-bindings/, or a big warning should be put before it.

But see my reply on patch 7, about do we actually need to expose this
in the device tree.

>> Also please add a comment saying that the channels are numbered
>> in the order of their respective registers, and not the table
>> describing the ADCs in the datasheet (9.7 Signal Capture for AXP209
>> and 9.5 E-Gauge for AXP221).
>>
>
> Yes I can.
>
> What about Rob wanting channel numbers to start at zero for each
> different IIO type (i.e., today we have AXP22X_BATT_CHRG_I being
> exported as in_current1_raw whereas he wants in_current0_raw).

Hmm... I missed this. Are you talking about IIO or hwmon? IIRC
hwmon numbers things starting at 1.

> [...]
>>> +static int axp22x_adc_read_raw(struct iio_dev *indio_dev,
>>> +                              struct iio_chan_spec const *channel, int *val,
>>> +                              int *val2)
>>> +{
>>> +       struct axp20x_adc_iio *info = iio_priv(indio_dev);
>>> +       int size = 12, ret;
>>> +
>>> +       switch (channel->channel) {
>>> +       case AXP22X_BATT_DISCHRG_I:
>>> +               size = 13;
>>> +       case AXP22X_TEMP_ADC:
>>> +       case AXP22X_BATT_V:
>>> +       case AXP22X_BATT_CHRG_I:
>>
>> According to the datasheet, AXP22X_BATT_CHRG_I is also 13 bits wide.
>>
>
> Where did you get that?
>
> Also, the datasheet is inconsistent:
>  - 9.5 E-Gauge Fuel Gauge system => the min value is at 0x0 and the max
> value at 0xfff for all channels, that's 12 bits.
>  - 10.1.4 ADC Data => all channels except battery discharge current are
> on 12 bits (8 high, 4 low).

My datasheets (AXP221 v1.6, AXP221s v1.2, AXP223 v1.1, all Chinese) say
in 10.1.4:

  - 7A: battery charge current high 5 bits
  - 7B: battery charge current low 8 bits
  - 7C: battery discharge current high 5 bits
  - 7D: battery discharge current low 8 bits

>
> [...]
>>> +static int axp22x_read_raw(struct iio_dev *indio_dev,
>>> +                          struct iio_chan_spec const *chan, int *val,
>>> +                          int *val2, long mask)
>>> +{
>>> +       switch (mask) {
>>> +       case IIO_CHAN_INFO_OFFSET:
>>> +               *val = -2667;
>>
>> Datasheet says -267.7 C, or -2677 here.
>>
>
> The formula in the datasheet is (in milli Celsius):
>  processed = raw * 100 - 266700;
>
> while the IIO framework asks for a scale and an offset which are then
> applied as:
>  processed = (raw + offset) * scale;
>
> Thus by factorizing, we get:
>  processed = (raw - 2667) * 100;

What I meant was that your lower end value is off by one degree,
-266.7 in your code vs -267.7 in the datasheet.

>
> [...]
>>> +static int axp20x_remove(struct platform_device *pdev)
>>> +{
>>> +       struct axp20x_adc_iio *info;
>>> +       struct iio_dev *indio_dev = platform_get_drvdata(pdev);
>>> +
>>> +       info = iio_priv(indio_dev);
>>
>> Nit: you could just reverse the 2 declarations above and join this
>> line after struct axp20x_adc_iio *info;
>>
>>> +       regmap_write(info->regmap, AXP20X_ADC_EN1, 0);
>>> +       regmap_write(info->regmap, AXP20X_ADC_EN2, 0);
>>
>> The existing VBUS power supply driver enables the VBUS ADC bits itself,
>> and does not check them later on. This means if one were to remove this
>> axp20x-adc module, the voltage/current readings in the VBUS power supply
>> would be invalid. Some sort of workaround would be needed here in this
>> driver of the VBUS driver.
>>
>
> That would be one reason to migrate the VBUS driver to use the IIO
> channels, wouldn't it?

It is, preferably without changing the device tree.

Regards
ChenYu

>
> But ACK, I'll think about something to work around this issue.
>
>>> +
>>> +       return 0;
>>> +}
>>> +
>>> +static struct platform_driver axp20x_adc_driver = {
>>> +       .driver = {
>>> +               .name = "axp20x-adc",
>>> +               .of_match_table = axp20x_adc_of_match,
>>> +       },
>>> +       .probe = axp20x_probe,
>>> +       .remove = axp20x_remove,
>>> +};
>>> +
>>> +module_platform_driver(axp20x_adc_driver);
>>> +
>>> +MODULE_DESCRIPTION("ADC driver for AXP20X and AXP22X PMICs");
>>> +MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");
>>> +MODULE_LICENSE("GPL");
>>> diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h
>>> index a4860bc..650c6f6 100644
>>> --- a/include/linux/mfd/axp20x.h
>>> +++ b/include/linux/mfd/axp20x.h
>>> @@ -150,6 +150,10 @@ enum {
>>>  #define AXP20X_VBUS_I_ADC_L            0x5d
>>>  #define AXP20X_TEMP_ADC_H              0x5e
>>>  #define AXP20X_TEMP_ADC_L              0x5f
>>> +
>>> +#define AXP22X_TEMP_ADC_H              0x56
>>> +#define AXP22X_TEMP_ADC_L              0x57
>>> +
>>
>> This is in the wrong patch. Also we already have
>>
>> /* AXP22X specific registers */
>> #define AXP22X_PMIC_ADC_H               0x56
>> #define AXP22X_PMIC_ADC_L               0x57
>> #define AXP22X_TS_ADC_H                 0x58
>> #define AXP22X_TS_ADC_L                 0x59
>>
>> If you want, you could just rename them to be consistent.
>>
>
> ACK.
>
> Thanks,
> Quentin
>
> --
> Quentin Schulz, Free Electrons
> Embedded Linux and Kernel engineering
> http://free-electrons.com

  reply	other threads:[~2017-01-05  8:28 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-02 16:37 [PATCH 00/22] add support for AXP20X and AXP22X power supply drivers Quentin Schulz
2017-01-02 16:37 ` [PATCH 01/22] dt-bindings: iio: adc: add AXP20X/AXP22X ADC DT binding Quentin Schulz
2017-01-03 23:20   ` Rob Herring
2017-01-05  4:05     ` Chen-Yu Tsai
2017-01-05 16:40   ` Maxime Ripard
2017-01-02 16:37 ` [PATCH 02/22] mfd: axp20x: add ADC data regs to volatile regs for AXP22X Quentin Schulz
2017-01-04 11:55   ` Lee Jones
2017-01-05  4:12   ` Chen-Yu Tsai
2017-01-02 16:37 ` [PATCH 03/22] iio: adc: add support for X-Powers AXP20X and AXP22X PMICs ADCs Quentin Schulz
2017-01-05  5:42   ` Chen-Yu Tsai
2017-01-05  8:06     ` Quentin Schulz
2017-01-05  8:27       ` Chen-Yu Tsai [this message]
2017-01-05  9:50         ` Quentin Schulz
2017-01-05 10:28           ` Chen-Yu Tsai
2017-01-07 19:23             ` Jonathan Cameron
2017-01-05 16:46           ` Maxime Ripard
2017-01-07 19:20           ` Jonathan Cameron
2017-01-05 16:51   ` Maxime Ripard
2017-01-07 19:13   ` Jonathan Cameron
2017-01-02 16:37 ` [PATCH 04/22] mfd: axp20x: add ADC cells for AXP20X and AXP22X PMICs Quentin Schulz
2017-01-04 11:56   ` Lee Jones
2017-01-04 11:56     ` Lee Jones
2017-01-05  5:51       ` Chen-Yu Tsai
2017-01-02 16:37 ` [PATCH 05/22] ARM: dtsi: axp209: add AXP209 ADC subnode Quentin Schulz
2017-01-05  5:51   ` Chen-Yu Tsai
2017-01-05  8:08     ` Quentin Schulz
2017-01-05  8:16       ` Chen-Yu Tsai
2017-01-02 16:37 ` [PATCH 06/22] ARM: dtsi: axp22x: add AXP22X " Quentin Schulz
2017-01-05  5:52   ` Chen-Yu Tsai
2017-01-02 16:37 ` [PATCH 07/22] dt-bindings: power: supply: add AXP20X/AXP22X AC power supply Quentin Schulz
2017-01-04 13:14   ` Rob Herring
2017-01-05  6:17     ` Chen-Yu Tsai
2017-01-07 19:26       ` Jonathan Cameron
2017-01-02 16:37 ` [PATCH 08/22] power: supply: add AC power supply driver for AXP20X and AXP22X PMICs Quentin Schulz
2017-01-07 19:31   ` Jonathan Cameron
2017-01-08 10:41     ` Quentin Schulz
2017-01-17  3:00   ` Sebastian Reichel
2017-01-26 13:32     ` Quentin Schulz
2017-01-27  8:20       ` Maxime Ripard
2017-01-28 14:30         ` Jonathan Cameron
2017-01-29 15:16           ` Sebastian Reichel
2017-01-02 16:37 ` [PATCH 09/22] mfd: axp20x: add AC power supply cells for " Quentin Schulz
2017-01-04 11:57   ` Lee Jones
2017-01-02 16:37 ` [PATCH 10/22] ARM: dtsi: axp209: add AC power supply subnode Quentin Schulz
2017-01-02 16:37 ` [PATCH 11/22] ARM: dtsi: axp22x: " Quentin Schulz
2017-01-02 16:37 ` [PATCH 12/22] ARM: dts: sun8i: sina33: enable ACIN " Quentin Schulz
2017-01-02 16:37 ` [PATCH 13/22] ARM: sun5i: chip: " Quentin Schulz
2017-01-02 16:37 ` [PATCH 14/22] dt-bindings: power: supply: add AXP20X/AXP22X battery DT binding Quentin Schulz
2017-01-04 13:21   ` Rob Herring
2017-01-07 19:33     ` Jonathan Cameron
2017-01-08 10:48       ` Quentin Schulz
2017-01-08 10:59         ` Jonathan Cameron
2017-01-02 16:37 ` [PATCH 15/22] mfd: axp20x: add CHRG_CTRL1 to writeable regs for AXP20X/AXP22X Quentin Schulz
2017-01-04 11:57   ` Lee Jones
2017-01-05  6:10   ` Chen-Yu Tsai
2017-01-05  8:10     ` Quentin Schulz
2017-01-02 16:37 ` [PATCH 16/22] mfd: axp20x: add V_OFF to writeable regs for AXP20X and AXP22X Quentin Schulz
2017-01-04 11:57   ` Lee Jones
2017-01-05  6:02     ` Chen-Yu Tsai
2017-01-02 16:37 ` [PATCH 17/22] power: supply: add battery driver for AXP20X and AXP22X PMICs Quentin Schulz
2017-01-05 17:02   ` Maxime Ripard
2017-01-05 17:34   ` Ezequiel Garcia
2017-01-06  2:46     ` Sebastian Reichel
2017-01-06  3:39   ` Chen-Yu Tsai
2017-01-06  8:29     ` Quentin Schulz
2017-01-17  3:46   ` Sebastian Reichel
2017-01-02 16:37 ` [PATCH 18/22] mfd: axp20x: add MFD cells for AXP20X and AXP22X battery driver Quentin Schulz
2017-01-04 11:57   ` Lee Jones
2017-01-02 16:37 ` [PATCH 19/22] ARM: dtsi: axp209: add battery power supply subnode Quentin Schulz
2017-01-02 16:37 ` [PATCH 20/22] ARM: dtsi: axp22x: " Quentin Schulz
2017-01-02 16:37 ` [PATCH 21/22] ARM: dts: sun8i: sina33: enable " Quentin Schulz
2017-01-02 16:37 ` [PATCH 22/22] ARM: sun5i: chip: " Quentin Schulz

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=CAGb2v66n46KQAzQBUrDwx7sYADkRm3_XyCHf9imN+FiDkHfP1w@mail.gmail.com \
    --to=wens@csie.org \
    --cc=bonbons@linux-vserver.org \
    --cc=devicetree@vger.kernel.org \
    --cc=icenowy@aosc.xyz \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=pmeerw@pmeerw.net \
    --cc=quentin.schulz@free-electrons.com \
    --cc=robh+dt@kernel.org \
    --cc=sre@kernel.org \
    --cc=thomas.petazzoni@free-electrons.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;
as well as URLs for NNTP newsgroup(s).