From: Adam Michaelis <adam.michaelis@rockwellcollins.com>
To: linux-iio@vger.kernel.org
Cc: lars@metafoo.de, michael.hennerich@analog.com, jic23@kernel.org,
knaack.h@gmx.de, pmeerw@pmeerw.net, robh+dt@kernel.org,
mark.rutland@arm.com, charles-antoine.couret@essensium.com,
devicetree@vger.kernel.org, brandon.maier@rockwellcollins.com,
clayton.shotwell@rockwellcollins.com,
Adam Michaelis <adam.michaelis@rockwellcollins.com>
Subject: [PATCH v2 6/6] iio: ad7949: Fix dummy read cycle placement
Date: Thu, 2 May 2019 11:14:32 -0500 [thread overview]
Message-ID: <1556813672-49861-6-git-send-email-adam.michaelis@rockwellcollins.com> (raw)
In-Reply-To: <1556813672-49861-1-git-send-email-adam.michaelis@rockwellcollins.com>
The AD7949 requires two conversion cycles following any configuration
change (including changing the analog channel being sampled). Therefore,
adding a dummy read cycle when config is changed and removing the extra
cycles at initial configuration.
Signed-off-by: Adam Michaelis <adam.michaelis@rockwellcollins.com>
---
V2: Add some defines to reduce use of magic numbers.
---
drivers/iio/adc/ad7949.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c
index cba152151908..5a6fe522c931 100644
--- a/drivers/iio/adc/ad7949.c
+++ b/drivers/iio/adc/ad7949.c
@@ -144,6 +144,25 @@ static int ad7949_spi_write_cfg(struct ad7949_adc_chip *ad7949_adc, u16 val,
* time to send a new command to the device
*/
udelay(2);
+
+ /*
+ * Perform extra read cycle to allow configuration, acquisition,
+ * and conversion sequences to complete for new configuration.
+ */
+ (void)memset(&tx, 0, sizeof(tx));
+ (void)memset(ad7949_adc->buffer, 0, AD7949_BUFFER_LEN);
+
+ tx.rx_buf = ad7949_adc->buffer;
+ tx.len = ad7949_message_len(ad7949_adc);
+
+ spi_message_init_with_transfers(&msg, &tx, 1);
+ ret = spi_sync(ad7949_adc->spi, &msg);
+
+ /*
+ * This delay is to avoid a new request before the required time
+ * to send a new command to the device.
+ */
+ udelay(2);
}
return ret;
@@ -276,7 +295,6 @@ static int ad7949_spi_reg_access(struct iio_dev *indio_dev,
static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc)
{
int ret;
- int val;
u16 adc_config = 0;
ad7949_adc->current_channel = 0;
@@ -309,13 +327,6 @@ static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc)
adc_config,
AD7949_CFG_MASK_TOTAL);
- /*
- * Do two dummy conversions to apply the first configuration setting.
- * Required only after the start up of the device.
- */
- ad7949_spi_read_channel(ad7949_adc, &val, ad7949_adc->current_channel);
- ad7949_spi_read_channel(ad7949_adc, &val, ad7949_adc->current_channel);
-
return ret;
}
--
1.9.1
next prev parent reply other threads:[~2019-05-02 16:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 16:14 [PATCH v2 1/6] iio: ad7949: Support internal Vref Adam Michaelis
2019-05-02 16:14 ` [PATCH v2 2/6] dt-bindings: iio: ad7949: Add adi,reference-select Adam Michaelis
2019-05-05 14:33 ` Jonathan Cameron
2019-05-02 16:14 ` [PATCH v2 3/6] iio: ad7949: Support configuration read-back Adam Michaelis
2019-05-05 14:42 ` Jonathan Cameron
2019-05-06 19:32 ` Adam Michaelis
2019-05-07 19:53 ` Adam Michaelis
2019-05-11 10:31 ` Jonathan Cameron
2019-05-13 10:04 ` Popa, Stefan Serban
2019-05-13 14:52 ` [External] " Adam Michaelis
2019-05-24 12:02 ` Couret Charles-Antoine
2019-05-02 16:14 ` [PATCH v2 4/6] dt-bindings: iio: ad7949: Add cfg-readback option Adam Michaelis
2019-05-02 16:14 ` [PATCH v2 5/6] iio: ad7949: Fix SPI interfacing for 14-bit messages Adam Michaelis
2019-05-05 15:06 ` Jonathan Cameron
2019-05-02 16:14 ` Adam Michaelis [this message]
2019-05-05 15:08 ` [PATCH v2 6/6] iio: ad7949: Fix dummy read cycle placement Jonathan Cameron
2019-05-05 14:39 ` [PATCH v2 1/6] iio: ad7949: Support internal Vref Jonathan Cameron
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=1556813672-49861-6-git-send-email-adam.michaelis@rockwellcollins.com \
--to=adam.michaelis@rockwellcollins.com \
--cc=brandon.maier@rockwellcollins.com \
--cc=charles-antoine.couret@essensium.com \
--cc=clayton.shotwell@rockwellcollins.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=michael.hennerich@analog.com \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.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;
as well as URLs for NNTP newsgroup(s).