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

power: supply: ab8500: Use iio_read_channel_processed_scale()

Instead of rescaling current or voltage channels after the fact, use the
dedicated scaling API. This should reduce any inaccuracies resulting from
the scaling.

This is also slightly more efficient as it saves a function call and a
multiplication.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/5668d73b92eb6318c7f094a9a8fa914c909485ca.1719037737.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Christophe JAILLET and committed by
Sebastian Reichel
dc6ce568 32887570

+16 -12
+16 -12
drivers/power/supply/ab8500_charger.c
··· 487 487 488 488 /* Only measure voltage if the charger is connected */ 489 489 if (di->ac.charger_connected) { 490 - ret = iio_read_channel_processed(di->adc_main_charger_v, &vch); 490 + /* Convert to microvolt, IIO returns millivolt */ 491 + ret = iio_read_channel_processed_scale(di->adc_main_charger_v, 492 + &vch, 1000); 491 493 if (ret < 0) { 492 494 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 493 495 return ret; ··· 497 495 } else { 498 496 vch = 0; 499 497 } 500 - /* Convert to microvolt, IIO returns millivolt */ 501 - return vch * 1000; 498 + return vch; 502 499 } 503 500 504 501 /** ··· 542 541 543 542 /* Only measure voltage if the charger is connected */ 544 543 if (di->usb.charger_connected) { 545 - ret = iio_read_channel_processed(di->adc_vbus_v, &vch); 544 + /* Convert to microvolt, IIO returns millivolt */ 545 + ret = iio_read_channel_processed_scale(di->adc_vbus_v, 546 + &vch, 1000); 546 547 if (ret < 0) { 547 548 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 548 549 return ret; ··· 552 549 } else { 553 550 vch = 0; 554 551 } 555 - /* Convert to microvolt, IIO returns millivolt */ 556 - return vch * 1000; 552 + return vch; 557 553 } 558 554 559 555 /** ··· 568 566 569 567 /* Only measure current if the charger is online */ 570 568 if (di->usb.charger_online) { 571 - ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich); 569 + /* Return microamperes */ 570 + ret = iio_read_channel_processed_scale(di->adc_usb_charger_c, 571 + &ich, 1000); 572 572 if (ret < 0) { 573 573 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 574 574 return ret; ··· 578 574 } else { 579 575 ich = 0; 580 576 } 581 - /* Return microamperes */ 582 - return ich * 1000; 577 + return ich; 583 578 } 584 579 585 580 /** ··· 594 591 595 592 /* Only measure current if the charger is online */ 596 593 if (di->ac.charger_online) { 597 - ret = iio_read_channel_processed(di->adc_main_charger_c, &ich); 594 + /* Return microamperes */ 595 + ret = iio_read_channel_processed_scale(di->adc_main_charger_c, 596 + &ich, 1000); 598 597 if (ret < 0) { 599 598 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 600 599 return ret; ··· 604 599 } else { 605 600 ich = 0; 606 601 } 607 - /* Return microamperes */ 608 - return ich * 1000; 602 + return ich; 609 603 } 610 604 611 605 /**