Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad7944: Consolidate spi_sync() wrapper

Since commit 6020ca4de8e5 ("iio: adc: ad7944: use spi_optimize_message()"),
The helper functions wrapping spi_sync() for 3-wire and 4-wire modes are
virtually identical. Since gpiod_set_value_cansleep() does a NULL check
internally, we can consolidate the two functions into one and avoid
switch statements at the call sites.

The default cases of the removed switch statement were just to make the
compiler happy and are not reachable since the mode is validated in the
probe function. So removing those should be safe.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20240412-ad7944-consolidate-msg-v1-1-7fdeff89172f@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
61c8031a d9dd38cb

+13 -54
+13 -54
drivers/iio/adc/ad7944.c
··· 214 214 return devm_add_action_or_reset(dev, ad7944_unoptimize_msg, &adc->msg); 215 215 } 216 216 217 - /* 218 - * ad7944_3wire_cs_mode_conversion - Perform a 3-wire CS mode conversion and 219 - * acquisition 217 + /** 218 + * ad7944_convert_and_acquire - Perform a single conversion and acquisition 220 219 * @adc: The ADC device structure 221 220 * @chan: The channel specification 222 221 * Return: 0 on success, a negative error code on failure 223 222 * 224 - * This performs a conversion and reads data when the chip is wired in 3-wire 225 - * mode with the CNV line on the ADC tied to the CS line on the SPI controller. 223 + * Perform a conversion and acquisition of a single sample using the 224 + * pre-optimized adc->msg. 226 225 * 227 226 * Upon successful return adc->sample.raw will contain the conversion result. 228 227 */ 229 - static int ad7944_3wire_cs_mode_conversion(struct ad7944_adc *adc, 230 - const struct iio_chan_spec *chan) 231 - { 232 - return spi_sync(adc->spi, &adc->msg); 233 - } 234 - 235 - /* 236 - * ad7944_4wire_mode_conversion - Perform a 4-wire mode conversion and acquisition 237 - * @adc: The ADC device structure 238 - * @chan: The channel specification 239 - * Return: 0 on success, a negative error code on failure 240 - * 241 - * Upon successful return adc->sample.raw will contain the conversion result. 242 - */ 243 - static int ad7944_4wire_mode_conversion(struct ad7944_adc *adc, 244 - const struct iio_chan_spec *chan) 228 + static int ad7944_convert_and_acquire(struct ad7944_adc *adc, 229 + const struct iio_chan_spec *chan) 245 230 { 246 231 int ret; 247 232 248 233 /* 249 234 * In 4-wire mode, the CNV line is held high for the entire conversion 250 - * and acquisition process. 235 + * and acquisition process. In other modes adc->cnv is NULL and is 236 + * ignored (CS is wired to CNV in those cases). 251 237 */ 252 238 gpiod_set_value_cansleep(adc->cnv, 1); 253 239 ret = spi_sync(adc->spi, &adc->msg); ··· 248 262 { 249 263 int ret; 250 264 251 - switch (adc->spi_mode) { 252 - case AD7944_SPI_MODE_DEFAULT: 253 - ret = ad7944_4wire_mode_conversion(adc, chan); 254 - if (ret) 255 - return ret; 256 - 257 - break; 258 - case AD7944_SPI_MODE_SINGLE: 259 - ret = ad7944_3wire_cs_mode_conversion(adc, chan); 260 - if (ret) 261 - return ret; 262 - 263 - break; 264 - default: 265 - return -EOPNOTSUPP; 266 - } 265 + ret = ad7944_convert_and_acquire(adc, chan); 266 + if (ret) 267 + return ret; 267 268 268 269 if (chan->scan_type.storagebits > 16) 269 270 *val = adc->sample.raw.u32; ··· 311 338 struct ad7944_adc *adc = iio_priv(indio_dev); 312 339 int ret; 313 340 314 - switch (adc->spi_mode) { 315 - case AD7944_SPI_MODE_DEFAULT: 316 - ret = ad7944_4wire_mode_conversion(adc, &indio_dev->channels[0]); 317 - if (ret) 318 - goto out; 319 - 320 - break; 321 - case AD7944_SPI_MODE_SINGLE: 322 - ret = ad7944_3wire_cs_mode_conversion(adc, &indio_dev->channels[0]); 323 - if (ret) 324 - goto out; 325 - 326 - break; 327 - default: 328 - /* not supported */ 341 + ret = ad7944_convert_and_acquire(adc, &indio_dev->channels[0]); 342 + if (ret) 329 343 goto out; 330 - } 331 344 332 345 iio_push_to_buffers_with_timestamp(indio_dev, &adc->sample.raw, 333 346 pf->timestamp);