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

iio: adc: ti-adc12138: Simplify with devm_clk_get_enabled()

Driver is getting clock and almost immediately enabling it, with the
devm_request_irq() as the only relevant code executed between, thus the
probe path and cleanups can be simplified with devm_clk_get_enabled().

Move devm_request_irq() earlier, so the interrupt handler will be
registered before clock is enabled. This might be important in case
regulator supplies are enabled by other device driver and this device
raises interrupt immediately after clock sarts ticking.

The change does not reverse cleanup paths - first regulator will be
disabled, then clock and finally interrupt handler freed.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20250713-iio-clk-get-enabled-v1-1-70abc1f9ce6c@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Krzysztof Kozlowski and committed by
Jonathan Cameron
9ae68c9b 49baeed7

+11 -19
+11 -19
drivers/iio/adc/ti-adc12138.c
··· 38 38 struct adc12138 { 39 39 struct spi_device *spi; 40 40 unsigned int id; 41 - /* conversion clock */ 42 - struct clk *cclk; 43 41 /* positive analog voltage reference */ 44 42 struct regulator *vref_p; 45 43 /* negative analog voltage reference */ 46 44 struct regulator *vref_n; 47 45 struct mutex lock; 48 46 struct completion complete; 49 - /* The number of cclk periods for the S/H's acquisition time */ 47 + /* The number of conversion clock periods for the S/H's acquisition time */ 50 48 unsigned int acquisition_time; 51 49 /* 52 50 * Maximum size needed: 16x 2 bytes ADC data + 8 bytes timestamp. ··· 398 400 { 399 401 struct iio_dev *indio_dev; 400 402 struct adc12138 *adc; 403 + struct clk *cclk; 401 404 int ret; 402 405 403 406 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); ··· 434 435 if (ret) 435 436 adc->acquisition_time = 10; 436 437 437 - adc->cclk = devm_clk_get(&spi->dev, NULL); 438 - if (IS_ERR(adc->cclk)) 439 - return PTR_ERR(adc->cclk); 438 + ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, 439 + IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); 440 + if (ret) 441 + return ret; 442 + 443 + cclk = devm_clk_get_enabled(&spi->dev, NULL); 444 + if (IS_ERR(cclk)) 445 + return PTR_ERR(cclk); 440 446 441 447 adc->vref_p = devm_regulator_get(&spi->dev, "vref-p"); 442 448 if (IS_ERR(adc->vref_p)) ··· 458 454 return ret; 459 455 } 460 456 461 - ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, 462 - IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); 463 - if (ret) 464 - return ret; 465 - 466 - ret = clk_prepare_enable(adc->cclk); 467 - if (ret) 468 - return ret; 469 - 470 457 ret = regulator_enable(adc->vref_p); 471 458 if (ret) 472 - goto err_clk_disable; 459 + return ret; 473 460 474 461 if (!IS_ERR(adc->vref_n)) { 475 462 ret = regulator_enable(adc->vref_n); ··· 491 496 regulator_disable(adc->vref_n); 492 497 err_vref_p_disable: 493 498 regulator_disable(adc->vref_p); 494 - err_clk_disable: 495 - clk_disable_unprepare(adc->cclk); 496 499 497 500 return ret; 498 501 } ··· 505 512 if (!IS_ERR(adc->vref_n)) 506 513 regulator_disable(adc->vref_n); 507 514 regulator_disable(adc->vref_p); 508 - clk_disable_unprepare(adc->cclk); 509 515 } 510 516 511 517 static const struct of_device_id adc12138_dt_ids[] = {