Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Chris Morgan <macroalpha82@gmail.com>
Cc: linux-sunxi@lists.linux.dev, linux-pm@vger.kernel.org,
	devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
	broonie@kernel.org, lee@kernel.org, samuel@sholland.org,
	jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org,
	conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org,
	lars@metafoo.de, Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH 5/8] iio: adc: axp20x_adc: add support for AXP717 ADC
Date: Sun, 23 Jun 2024 17:30:15 +0100	[thread overview]
Message-ID: <20240623173015.555584b6@jic23-huawei> (raw)
In-Reply-To: <20240617220535.359021-6-macroalpha82@gmail.com>

On Mon, 17 Jun 2024 17:05:32 -0500
Chris Morgan <macroalpha82@gmail.com> wrote:

> From: Chris Morgan <macromorgan@hotmail.com>
> 
> Add support for the AXP717 ADC. The AXP717 differs from other ADCs
> in this series by utilizing a 14 bit ADC for all channels (a full 16
> bits with the first 2 digits reserved). It also differs by lacking a
> battery discharge current channel.
> 
> Note that while the current charge channel itself is included in this
> driver for the AXP717 and listed in the datasheet, no scale or offset
> was given for this channel. For now no scale or offset is provided in
> this driver.
> 
> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
Hi Chris

A few minor comments inline,

Thanks,

Jonathan

> ---
>  drivers/iio/adc/axp20x_adc.c | 167 +++++++++++++++++++++++++++++++++--
>  1 file changed, 160 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c
> index d6c51b0f48e3..f35ba2c11e1b 100644
> --- a/drivers/iio/adc/axp20x_adc.c
> +++ b/drivers/iio/adc/axp20x_adc.c
> @@ -5,6 +5,7 @@
>   *	Quentin Schulz <quentin.schulz@free-electrons.com>
>   */
>  
> +#include <asm/unaligned.h>
>  #include <linux/bitfield.h>
>  #include <linux/completion.h>
>  #include <linux/interrupt.h>
> @@ -27,6 +28,8 @@
>  
>  #define AXP22X_ADC_EN1_MASK			(GENMASK(7, 5) | BIT(0))
>  
> +#define AXP717_ADC_EN1_MASK			GENMASK(5, 0)
> +
>  #define AXP20X_GPIO10_IN_RANGE_GPIO0		BIT(0)
>  #define AXP20X_GPIO10_IN_RANGE_GPIO1		BIT(1)
>  
> @@ -35,6 +38,11 @@
>  
>  #define AXP22X_ADC_RATE_HZ(x)			((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK)
>  
> +#define AXP717_ADC_DATA_TS			0x00
> +#define AXP717_ADC_DATA_TEMP			0x01
> +
> +#define AXP717_ADC_DATA_MASK			0x3fff

GENMASK()

> +static int axp717_adc_raw(struct iio_dev *indio_dev,
> +			  struct iio_chan_spec const *chan, int *val)
> +{
> +	struct axp20x_adc_iio *info = iio_priv(indio_dev);
> +	u8 bulk_reg[2];
> +	int ret;
> +
> +	/*
> +	 * A generic "ADC data" channel is used for TS, tdie, vmid,
> +	 * and vbackup. This channel must both first be enabled and
> +	 * also selected before it can be read.
> +	 */
> +	switch (chan->channel) {
> +	case AXP717_TS_IN:
> +		regmap_write(info->regmap, AXP717_ADC_DATA_SEL,
> +			     AXP717_ADC_DATA_TS);
> +		break;
> +	case AXP717_DIE_TEMP_V:
> +		regmap_write(info->regmap, AXP717_ADC_DATA_SEL,
> +			     AXP717_ADC_DATA_TEMP);
> +		break;
> +
> +	default:
> +		break;
> +	}
> +
> +	/*
> +	 * All channels are 14 bits, with the first 2 bits on the high
> +	 * register reserved and the remaining bits as the ADC value.
> +	 */
> +	ret = regmap_bulk_read(info->regmap, chan->address, bulk_reg, 2);
> +	if (ret < 0)
> +		return ret;
> +
> +	*val = get_unaligned_be16(bulk_reg) & AXP717_ADC_DATA_MASK;

FIELD_GET() preferred as then I don't have to check if DATA_MASK includes
the 0th bit.

> +	return IIO_VAL_INT;
> +}
> +


  parent reply	other threads:[~2024-06-23 16:30 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17 22:05 [PATCH 0/8] Add Battery and USB Supply for AXP717 Chris Morgan
2024-06-17 22:05 ` [PATCH 1/8] dt-bindings: iio: adc: Add AXP717 compatible Chris Morgan
2024-06-18  6:41   ` Krzysztof Kozlowski
2024-06-23  5:17   ` Chen-Yu Tsai
2024-06-17 22:05 ` [PATCH 2/8] power: supply: axp20x_usb_power: Add support for AXP717 Chris Morgan
2024-06-18  6:40   ` Krzysztof Kozlowski
2024-06-23  5:02   ` Chen-Yu Tsai
2024-06-17 22:05 ` [PATCH 3/8] power: supply: axp20x_battery: add " Chris Morgan
2024-06-18  6:41   ` Krzysztof Kozlowski
2024-06-23  5:05   ` Chen-Yu Tsai
2024-06-17 22:05 ` [PATCH 4/8] mfd: axp20x: Add ADC, BAT, and USB cells " Chris Morgan
2024-06-20 17:25   ` Lee Jones
2024-06-23  5:55   ` Chen-Yu Tsai
2024-06-17 22:05 ` [PATCH 5/8] iio: adc: axp20x_adc: add support for AXP717 ADC Chris Morgan
2024-06-23  5:27   ` Chen-Yu Tsai
2024-07-30 19:11     ` Chris Morgan
2024-06-23 16:30   ` Jonathan Cameron [this message]
2024-06-17 22:05 ` [PATCH 6/8] power: supply: axp20x_usb_power: Add support for AXP717 Chris Morgan
2024-06-22 23:49   ` Ryan Walklin
2024-06-23  5:42   ` Chen-Yu Tsai
2024-07-30 19:14     ` Chris Morgan
2024-06-24 18:00   ` Philippe Simons
2024-06-17 22:05 ` [PATCH 7/8] power: supply: axp20x_battery: add " Chris Morgan
2024-06-22 23:51   ` Ryan Walklin
2024-06-23  6:19   ` Chen-Yu Tsai
2024-07-30 19:38     ` Chris Morgan
2024-06-24 17:56   ` Philippe Simons
2024-06-17 22:05 ` [PATCH 8/8] arm64: dts: allwinner: h700: Add charger for Anbernic RG35XX Chris Morgan

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=20240623173015.555584b6@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lee@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=macroalpha82@gmail.com \
    --cc=macromorgan@hotmail.com \
    --cc=robh@kernel.org \
    --cc=samuel@sholland.org \
    --cc=sre@kernel.org \
    --cc=wens@csie.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