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: rzg2l_adc: Use read_poll_timeout()

Replace the driver-specific implementation with the read_poll_timeout()
function. This change simplifies the code and improves maintainability by
leveraging the standardized helper.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Link: https://patch.msgid.link/20241206111337.726244-7-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Claudiu Beznea and committed by
Jonathan Cameron
b7549624 7842ef74

+10 -19
+10 -19
drivers/iio/adc/rzg2l_adc.c
··· 13 13 #include <linux/iio/iio.h> 14 14 #include <linux/interrupt.h> 15 15 #include <linux/io.h> 16 + #include <linux/iopoll.h> 16 17 #include <linux/mod_devicetable.h> 17 18 #include <linux/module.h> 18 19 #include <linux/platform_device.h> ··· 113 112 114 113 static void rzg2l_adc_start_stop(struct rzg2l_adc *adc, bool start) 115 114 { 116 - int timeout = 5; 115 + int ret; 117 116 u32 reg; 118 117 119 118 reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); ··· 126 125 if (start) 127 126 return; 128 127 129 - do { 130 - usleep_range(100, 200); 131 - reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); 132 - timeout--; 133 - if (!timeout) { 134 - pr_err("%s stopping ADC timed out\n", __func__); 135 - break; 136 - } 137 - } while (((reg & RZG2L_ADM0_ADBSY) || (reg & RZG2L_ADM0_ADCE))); 128 + ret = read_poll_timeout(rzg2l_adc_readl, reg, !(reg & (RZG2L_ADM0_ADBSY | RZG2L_ADM0_ADCE)), 129 + 200, 1000, true, adc, RZG2L_ADM(0)); 130 + if (ret) 131 + pr_err("%s stopping ADC timed out\n", __func__); 138 132 } 139 133 140 134 static void rzg2l_set_trigger(struct rzg2l_adc *adc) ··· 335 339 336 340 static int rzg2l_adc_hw_init(struct device *dev, struct rzg2l_adc *adc) 337 341 { 338 - int timeout = 5; 339 342 u32 reg; 340 343 int ret; 341 344 ··· 347 352 reg |= RZG2L_ADM0_SRESB; 348 353 rzg2l_adc_writel(adc, RZG2L_ADM(0), reg); 349 354 350 - while (!(rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_SRESB)) { 351 - if (!timeout) { 352 - ret = -EBUSY; 353 - goto exit_hw_init; 354 - } 355 - timeout--; 356 - usleep_range(100, 200); 357 - } 355 + ret = read_poll_timeout(rzg2l_adc_readl, reg, reg & RZG2L_ADM0_SRESB, 356 + 200, 1000, false, adc, RZG2L_ADM(0)); 357 + if (ret) 358 + goto exit_hw_init; 358 359 359 360 /* Only division by 4 can be set */ 360 361 reg = rzg2l_adc_readl(adc, RZG2L_ADIVC);