linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Quentin Schulz <quentin.schulz@free-electrons.com>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 03/22] iio: adc: add support for X-Powers AXP20X and AXP22X PMICs ADCs
Date: Sat, 7 Jan 2017 14:06:59 -0500	[thread overview]
Message-ID: <eca48969-64dd-e032-7646-7d9d8183d41c@kernel.org> (raw)
In-Reply-To: <6c683088-1866-c372-d285-9f681c916971@free-electrons.com>

On 03/01/17 03:16, Quentin Schulz wrote:
> Hi Peter,
> 
> On 02/01/2017 19:37, Peter Meerwald-Stadler wrote:
>> On Mon, 2 Jan 2017, Quentin Schulz wrote:
>>
> [...]
>>> +#define AXP20X_ADC_RATE_MASK			(3 << 6)
>>
>> could use GENMASK()?
>>
>>> +#define AXP20X_ADC_RATE_25HZ			(0 << 6)
>>> +#define AXP20X_ADC_RATE_50HZ			BIT(6)
>>
>> BIT() doesn't really make sense here
>>
>>> +#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)
>>
>> BIT() doesn't really make sense here
>>
> 
> ACK.
> 
>>> +#define AXP22X_ADC_RATE_400HZ			(2 << 6)
>>> +#define AXP22X_ADC_RATE_800HZ			(3 << 6)
>>> +
>>> +#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,
>>> +	AXP20X_GPIO0_V,
>>> +	AXP20X_GPIO1_V,
>>> +	AXP20X_BATT_V,
>>> +	AXP20X_BATT_CHRG_I,
>>> +	AXP20X_BATT_DISCHRG_I,
>>> +	AXP20X_IPSOUT_V,
>>> +};
>>> +
>>> +enum axp22x_adc_channel {
>>> +	AXP22X_TEMP_ADC = 0,
>>> +	AXP22X_BATT_V,
>>> +	AXP22X_BATT_CHRG_I,
>>> +	AXP22X_BATT_DISCHRG_I,
>>> +};
>>> +
>>> +static const struct iio_chan_spec axp20x_adc_channels[] = {
>>
>> not sure if the channel indexing works out as expected;
>> axp20x_adc_channel/axp22x_adc_channel enumerate over all channels, but 
>> here we want to enumerate channels per type I think
>>
>> e.g. you have 6 IIO_VOLTAGE channels, they should have indices 0 to 5;
>> there is one IIO_TEMP channels, it should not be indexed or have index 0 
>>
> 
> Make sense, I'll just have to create enum for each type and have a call
> to different functions in read_raw depending on the requested channel
> type. ACK.
> 
> [...]
>>> +static int axp20x_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 AXP20X_BATT_DISCHRG_I:
>>> +		size = 13;
>>> +	case AXP20X_ACIN_V:
>>> +	case AXP20X_ACIN_I:
>>> +	case AXP20X_VBUS_V:
>>> +	case AXP20X_VBUS_I:
>>> +	case AXP20X_TEMP_ADC:
>>> +	case AXP20X_BATT_V:
>>> +	case AXP20X_BATT_CHRG_I:
>>> +	case AXP20X_IPSOUT_V:
>>> +	case AXP20X_GPIO0_V:
>>> +	case AXP20X_GPIO1_V:
>>> +		ret = axp20x_read_variable_width(info->regmap, channel->address,
>>> +						 size);
>>> +		if (ret < 0)
>>> +			return ret;
>>> +		*val = ret;
>>> +		return IIO_VAL_INT;
>>> +
>>> +	default:
>>> +		return -EINVAL;
>>> +	}
>>> +
>>> +	return -EINVAL;
>>
>> dead code? here and elsewhere
>>
> 
> Indeed. Will be removed.
> 
> [...]
>>> +
>>> +		/* Configure ADCs rate */
>>> +		regmap_update_bits(info->regmap, AXP20X_ADC_RATE,
>>> +				   AXP20X_ADC_RATE_MASK, AXP20X_ADC_RATE_50HZ);
>>
>> 100Hz would be a common rate for AXP209 and AXP221
>>
> 
> ACK.
> 
>>> +		break;
>>> +
>>> +	case AXP221_ID:
>>> +		indio_dev->info = &axp22x_adc_iio_info;
>>> +		indio_dev->num_channels = ARRAY_SIZE(axp22x_adc_channels);
>>> +		indio_dev->channels = axp22x_adc_channels;
>>> +
>>> +		/* Enable the ADCs on IP */
>>> +		regmap_write(info->regmap, AXP20X_ADC_EN1, AXP22X_ADC_EN1_MASK);
>>> +
>>> +		/* Configure ADCs rate */
>>> +		regmap_update_bits(info->regmap, AXP20X_ADC_RATE,
>>> +				   AXP20X_ADC_RATE_MASK, AXP22X_ADC_RATE_200HZ);
>>> +		break;
>>> +
>>> +	default:
>>> +		return -EINVAL;
>>> +	}
>>> +
>>> +	ret = devm_iio_device_register(&pdev->dev, indio_dev);
>>
>> if you need a _remove() -- which you do -- you must not use 
>> devm_iio_device_register()
>>
> 
> ACK. On the same topic, what about the devm_iio_device_alloc at the very
> beginning of the probe function?
That one is fine.  Key thing is that any devm stuff occurs after remove.  So to keep
the remove order the opposite of probe you are fine until you first have a step that needs
reversing that isn't via a managed interface.

In this case the upshot is you disable the hardware slightly before you remove the
userspace interface to access it.
> 
>>> +	if (ret < 0) {
>>> +		dev_err(&pdev->dev, "could not register the device\n");
>>> +		regmap_write(info->regmap, AXP20X_ADC_EN1, 0);
>>> +		regmap_write(info->regmap, AXP20X_ADC_EN2, 0);
>>
>> EN2 is not enabled for AXP221 above?
> 
> No. EN2 controls GPIO0/1 and internal temperature ADCs status and those
> ADCs are not supported in the AXP22X variants. The EN2 register is
> simply not existing in AXP22X documentation, I'll add an if condition on
> info->axp_id for resetting EN2 register.
> 
>> strictly, only certain EN2 bits are set for AXP209 -- here and in 
>> _remove()
>>
> 
> Yes. EN2 register has only bits for controlling GPIO 0/1 and internal
> temperature ADCs status, so setting all bits to zero is fine I guess.
> 
>>> +		return ret;
>>> +	}
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +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);
>>> +
>>> +	regmap_write(info->regmap, AXP20X_ADC_EN1, 0);
>>> +	regmap_write(info->regmap, AXP20X_ADC_EN2, 0);
>>> +
>>> +	return 0;
>>> +}
> [...]
> 
> Thanks,
> 
> Quentin
> 


  reply	other threads:[~2017-01-08  9:48 UTC|newest]

Thread overview: 75+ 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-02 18:37   ` Peter Meerwald-Stadler
2017-01-03  8:16     ` Quentin Schulz
2017-01-07 19:06       ` Jonathan Cameron [this message]
2017-01-05  5:42   ` Chen-Yu Tsai
2017-01-05  8:06     ` Quentin Schulz
2017-01-05  8:27       ` Chen-Yu Tsai
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=eca48969-64dd-e032-7646-7d9d8183d41c@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=quentin.schulz@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).