From: Dumitru Ceclan <mitrutzceclan@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>,
Stefan Popa <stefan.popa@analog.com>,
Alexandru Tachici <alexandru.tachici@analog.com>
Cc: Dumitru Ceclan <mitrutzceclan@gmail.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Dumitru Ceclan <dumitru.ceclan@analog.com>
Subject: [PATCH 3/4] iio: adc: ad7124: reduce the number of SPI transfers
Date: Wed, 31 Jul 2024 15:37:24 +0300 [thread overview]
Message-ID: <20240731-ad7124-fix-v1-3-46a76aa4b9be@analog.com> (raw)
In-Reply-To: <20240731-ad7124-fix-v1-0-46a76aa4b9be@analog.com>
The ad7124_init_config_vref() function writes the AD7124_ADC_CONTROL
register for each channel that is configured to use the internal
reference.
The ad7124_write_config()function performs 7 SPI transfers for
configuring 2 registers: config_x and filter_x.
Reduce the number of SPI transfers:
-during the probe by only setting the st->adc_control value in
ad7124_init_config_vref() and writing to the device only at the end of
ad7124_setup().
-in ad7124_write_config() by grouping writes to the same register.
Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com>
---
drivers/iio/adc/ad7124.c | 31 ++++++++++++-------------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index bd323c6bd756..4d63cd5c9d04 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -382,8 +382,7 @@ static int ad7124_init_config_vref(struct ad7124_state *st, struct ad7124_channe
cfg->vref_mv = 2500;
st->adc_control &= ~AD7124_ADC_CTRL_REF_EN_MSK;
st->adc_control |= AD7124_ADC_CTRL_REF_EN(1);
- return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL,
- 2, st->adc_control);
+ return 0;
default:
dev_err(&st->sd.spi->dev, "Invalid reference %d\n", refsel);
return -EINVAL;
@@ -401,24 +400,17 @@ static int ad7124_write_config(struct ad7124_state *st, struct ad7124_channel_co
tmp = (cfg->buf_positive << 1) + cfg->buf_negative;
val = AD7124_CONFIG_BIPOLAR(cfg->bipolar) | AD7124_CONFIG_REF_SEL(cfg->refsel) |
- AD7124_CONFIG_IN_BUFF(tmp);
- ret = ad_sd_write_reg(&st->sd, AD7124_CONFIG(cfg->cfg_slot), 2, val);
- if (ret < 0)
- return ret;
+ AD7124_CONFIG_IN_BUFF(tmp) | AD7124_CONFIG_PGA(cfg->pga_bits);
- tmp = AD7124_FILTER_TYPE_SEL(cfg->filter_type);
- ret = ad7124_spi_write_mask(st, AD7124_FILTER(cfg->cfg_slot), AD7124_FILTER_TYPE_MSK,
- tmp, 3);
- if (ret < 0)
- return ret;
-
- ret = ad7124_spi_write_mask(st, AD7124_FILTER(cfg->cfg_slot), AD7124_FILTER_FS_MSK,
- AD7124_FILTER_FS(cfg->odr_sel_bits), 3);
+ ret = ad_sd_write_reg(&st->sd, AD7124_CONFIG(cfg->cfg_slot), 2, val);
if (ret < 0)
return ret;
- return ad7124_spi_write_mask(st, AD7124_CONFIG(cfg->cfg_slot), AD7124_CONFIG_PGA_MSK,
- AD7124_CONFIG_PGA(cfg->pga_bits), 2);
+ tmp = AD7124_FILTER_TYPE_SEL(cfg->filter_type) |
+ AD7124_FILTER_FS(cfg->odr_sel_bits);
+ return ad7124_spi_write_mask(st, AD7124_FILTER(cfg->cfg_slot),
+ AD7124_FILTER_TYPE_MSK | AD7124_FILTER_FS_MSK,
+ tmp, 3);
}
static struct ad7124_channel_config *ad7124_pop_config(struct ad7124_state *st)
@@ -906,9 +898,6 @@ static int ad7124_setup(struct ad7124_state *st)
/* Set the power mode */
st->adc_control &= ~AD7124_ADC_CTRL_PWR_MSK;
st->adc_control |= AD7124_ADC_CTRL_PWR(power_mode);
- ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);
- if (ret < 0)
- return ret;
mutex_init(&st->cfgs_lock);
INIT_KFIFO(st->live_cfgs_fifo);
@@ -926,6 +915,10 @@ static int ad7124_setup(struct ad7124_state *st)
ad7124_set_channel_odr(st, i, 10);
}
+ ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);
+ if (ret < 0)
+ return ret;
+
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2024-07-31 12:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 12:37 [PATCH 0/4] ad7124 fixes and improvements Dumitru Ceclan
2024-07-31 12:37 ` [PATCH 1/4] iio: adc: ad7124: fix chip ID mismatch Dumitru Ceclan
2024-08-03 15:03 ` Jonathan Cameron
2024-07-31 12:37 ` [PATCH 2/4] iio: adc: ad7124: fix config comparison Dumitru Ceclan
2024-08-03 15:04 ` Jonathan Cameron
2024-07-31 12:37 ` Dumitru Ceclan [this message]
2024-08-03 15:07 ` [PATCH 3/4] iio: adc: ad7124: reduce the number of SPI transfers Jonathan Cameron
2024-07-31 12:37 ` [PATCH 4/4] iio: adc: ad7124: set initial ADC mode to idle Dumitru Ceclan
2024-08-01 8:36 ` [PATCH 0/4] ad7124 fixes and improvements Nuno Sá
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=20240731-ad7124-fix-v1-3-46a76aa4b9be@analog.com \
--to=mitrutzceclan@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=alexandru.tachici@analog.com \
--cc=dumitru.ceclan@analog.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stefan.popa@analog.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