LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Liam Beguin <liambeguin@gmail.com>
To: liambeguin@gmail.com, lars@metafoo.de,
	Michael.Hennerich@analog.com, jic23@kernel.org,
	charles-antoine.couret@essensium.com, Nuno.Sa@analog.com
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, robh+dt@kernel.org
Subject: [PATCH v1 0/4] AD7949 Fixes
Date: Fri,  9 Jul 2021 11:58:52 -0400	[thread overview]
Message-ID: <20210709155856.1732245-1-liambeguin@gmail.com> (raw)

While working on another series[1] I ran into issues where my SPI
controller would fail to handle 14-bit and 16-bit SPI messages. This
addresses that issue and adds support for selecting a different voltage
reference source from the devicetree.

This is base on a series[2] that seems to not have made it all the way,
and was tested on an ad7689.

[1] https://patchwork.kernel.org/project/linux-iio/list/?series=511545
[2] https://patchwork.kernel.org/project/linux-iio/list/?series=116971&state=%2A&archive=both

Changes since v1:
- add default case in read/write size cases
- drop of_node change as the core already takes care of it
- check dt user input in probe
- move description at the top of dt-binding definition
- drop AllOf block in dt-binding

Thanks for your time,
Liam

Liam Beguin (4):
  iio: adc: ad7949: define and use bitfield names
  iio: adc: ad7949: fix spi messages on non 14-bit controllers
  iio: adc: ad7949: add support for internal vref
  dt-bindings: iio: adc: ad7949: add adi,reference-source

 .../bindings/iio/adc/adi,ad7949.yaml          |  21 ++
 drivers/iio/adc/ad7949.c                      | 201 +++++++++++++++---
 2 files changed, 192 insertions(+), 30 deletions(-)

Range-diff against v1:
-:  ------------ > 1:  b8577e93229f iio: adc: ad7949: define and use bitfield names
1:  86bab3bedcf8 ! 2:  a8468391e3d0 iio: adc: ad7949: fix spi messages on non 14-bit controllers
    @@ drivers/iio/adc/ad7949.c: struct ad7949_adc_chip {
     +		ad7949_adc->buffer = ad7949_adc->cfg;
     +		break;
     +	case 8:
    ++	default:
     +		/* Pack 14-bit value into 2 bytes, MSB first */
     +		ad7949_adc->buf8[0] = FIELD_GET(GENMASK(13, 6), ad7949_adc->cfg);
     +		ad7949_adc->buf8[1] = FIELD_GET(GENMASK(5, 0), ad7949_adc->cfg);
    @@ drivers/iio/adc/ad7949.c: static int ad7949_spi_read_channel(struct ad7949_adc_c
     +		*val = ad7949_adc->buffer & GENMASK(13, 0);
     +		break;
     +	case 8:
    ++	default:
     +		/* Convert byte array to u16, MSB first */
     +		*val = (ad7949_adc->buf8[0] << 8) | ad7949_adc->buf8[1];
     +		/* Shift-out padding bits */
2:  5f4dbdd51e1f ! 3:  4b0c11c9a748 iio: adc: ad7949: add support for internal vref
    @@ drivers/iio/adc/ad7949.c: static int ad7949_spi_init(struct ad7949_adc_chip *ad7
      	const struct ad7949_adc_spec *spec;
      	struct ad7949_adc_chip *ad7949_adc;
      	struct iio_dev *indio_dev;
    -@@ drivers/iio/adc/ad7949.c: static int ad7949_spi_probe(struct spi_device *spi)
    - 		return -ENOMEM;
    - 	}
    - 
    -+	indio_dev->dev.of_node = np;
    - 	indio_dev->info = &ad7949_spi_info;
    - 	indio_dev->name = spi_get_device_id(spi)->name;
    - 	indio_dev->modes = INDIO_DIRECT_MODE;
     @@ drivers/iio/adc/ad7949.c: static int ad7949_spi_probe(struct spi_device *spi)
      	ad7949_adc->resolution = spec->resolution;
      	ad7949_set_bits_per_word(ad7949_adc);
    @@ drivers/iio/adc/ad7949.c: static int ad7949_spi_probe(struct spi_device *spi)
     -	if (IS_ERR(ad7949_adc->vref)) {
     -		dev_err(dev, "fail to request regulator\n");
     -		return PTR_ERR(ad7949_adc->vref);
    --	}
     +	/* Set default devicetree parameters */
     +	ad7949_adc->refsel = AD7949_REF_EXT_BUF;
     +	of_property_read_u32(np, "adi,reference-select", &ad7949_adc->refsel);
    ++	switch (ad7949_adc->refsel) {
    ++	case AD7949_REF_INT_2500:
    ++	case AD7949_REF_INT_4096:
    ++	case AD7949_REF_EXT_TEMP:
    ++	case AD7949_REF_EXT_TEMP_BUF:
    ++	case AD7949_REF_EXT:
    ++	case AD7949_REF_EXT_BUF:
    ++		break;
    ++	default:
    ++		dev_err(dev, "invalid adi,reference-select value (%d)\n",
    ++			ad7949_adc->refsel);
    ++		return -EINVAL;
    + 	}
      
     -	ret = regulator_enable(ad7949_adc->vref);
     -	if (ret < 0) {
3:  99367ba6e5f9 ! 4:  a3b6a6ef15fd dt-bindings: iio: adc: ad7949: add adi,reference-source
    @@ Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml: properties:
          const: 1
      
     +  adi,reference-select:
    -+    allOf:
    -+      - $ref: /schemas/types.yaml#/definitions/uint32
    -+      - enum: [0, 1, 2, 3, 6, 7]
    -+
    -+    default: 7
     +    description: |
     +      Select the reference voltage source to use when converting samples.
     +      Acceptable values are:
    @@ Documentation/devicetree/bindings/iio/adc/adi,ad7949.yaml: properties:
     +           disabled.
     +      - 7: Use external reference, internal buffer enabled.
     +           Internal reference and temperature sensor disabled.
    ++
    ++    $ref: /schemas/types.yaml#/definitions/uint32
    ++    enum: [0, 1, 2, 3, 6, 7]
    ++    default: 7
     +
      required:
        - compatible

base-commit: 6cbb3aa0f9d5d23221df787cf36f74d3866fdb78
-- 
2.30.1.489.g328c10930387


             reply	other threads:[~2021-07-09 15:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 15:58 Liam Beguin [this message]
2021-07-09 15:58 ` [PATCH v2 1/4] iio: adc: ad7949: define and use bitfield names Liam Beguin
2021-07-10 16:08   ` Jonathan Cameron
2021-07-10 18:17     ` Liam Beguin
2021-07-09 15:58 ` [PATCH v2 2/4] iio: adc: ad7949: fix spi messages on non 14-bit controllers Liam Beguin
2021-07-10 16:39   ` Jonathan Cameron
2021-07-11 19:58     ` Liam Beguin
2021-07-12 10:12       ` Jonathan Cameron
2021-07-09 15:58 ` [PATCH v2 3/4] iio: adc: ad7949: add support for internal vref Liam Beguin
2021-07-10 17:03   ` Jonathan Cameron
2021-07-09 15:58 ` [PATCH v2 4/4] dt-bindings: iio: adc: ad7949: add adi,reference-source Liam Beguin
2021-07-10 17:00   ` Jonathan Cameron
2021-07-12 17:05     ` Liam Beguin
2021-07-13  9:16       ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2021-07-08 23:56 [PATCH v1 0/4] AD7949 Fixes Liam Beguin
2021-07-09  8:12 ` Sa, Nuno

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=20210709155856.1732245-1-liambeguin@gmail.com \
    --to=liambeguin@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=Nuno.Sa@analog.com \
    --cc=charles-antoine.couret@essensium.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --subject='Re: [PATCH v1 0/4] AD7949 Fixes' \
    /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

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).