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: chemical: bme680: generalize read_*() functions

Remove the IIO specific scaling measurement units from the read functions
and add them inside the ->read_raw() function to keep the read_*() generic.
This way they can be used in other parts of the driver.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Link: https://patch.msgid.link/20241021195316.58911-8-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Vasileios Amoiridis and committed by
Jonathan Cameron
27f8b05b 7adfc348

+40 -28
+40 -28
drivers/iio/chemical/bme680_core.c
··· 647 647 return ret; 648 648 } 649 649 650 - static int bme680_read_temp(struct bme680_data *data, int *val) 650 + static int bme680_read_temp(struct bme680_data *data, s16 *comp_temp) 651 651 { 652 652 int ret; 653 653 u32 adc_temp; 654 - s16 comp_temp; 655 654 656 655 ret = bme680_read_temp_adc(data, &adc_temp); 657 656 if (ret) 658 657 return ret; 659 658 660 - comp_temp = bme680_compensate_temp(data, adc_temp); 661 - *val = comp_temp * 10; /* Centidegrees to millidegrees */ 662 - return IIO_VAL_INT; 659 + *comp_temp = bme680_compensate_temp(data, adc_temp); 660 + return 0; 663 661 } 664 662 665 - static int bme680_read_press(struct bme680_data *data, 666 - int *val, int *val2) 663 + static int bme680_read_press(struct bme680_data *data, u32 *comp_press) 667 664 { 668 665 int ret; 669 666 u32 adc_press; ··· 674 677 if (ret) 675 678 return ret; 676 679 677 - *val = bme680_compensate_press(data, adc_press, t_fine); 678 - *val2 = 1000; 679 - return IIO_VAL_FRACTIONAL; 680 + *comp_press = bme680_compensate_press(data, adc_press, t_fine); 681 + return 0; 680 682 } 681 683 682 - static int bme680_read_humid(struct bme680_data *data, 683 - int *val, int *val2) 684 + static int bme680_read_humid(struct bme680_data *data, u32 *comp_humidity) 684 685 { 685 686 int ret; 686 - u32 adc_humidity, comp_humidity; 687 + u32 adc_humidity; 687 688 s32 t_fine; 688 689 689 690 ret = bme680_get_t_fine(data, &t_fine); ··· 692 697 if (ret) 693 698 return ret; 694 699 695 - comp_humidity = bme680_compensate_humid(data, adc_humidity, t_fine); 696 - 697 - *val = comp_humidity; 698 - *val2 = 1000; 699 - return IIO_VAL_FRACTIONAL; 700 + *comp_humidity = bme680_compensate_humid(data, adc_humidity, t_fine); 701 + return 0; 700 702 } 701 703 702 - static int bme680_read_gas(struct bme680_data *data, 703 - int *val) 704 + static int bme680_read_gas(struct bme680_data *data, int *comp_gas_res) 704 705 { 705 706 struct device *dev = regmap_get_device(data->regmap); 706 707 int ret; ··· 731 740 } 732 741 733 742 gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); 734 - 735 - *val = bme680_compensate_gas(data, adc_gas_res, gas_range); 736 - return IIO_VAL_INT; 743 + *comp_gas_res = bme680_compensate_gas(data, adc_gas_res, gas_range); 744 + return 0; 737 745 } 738 746 739 747 static int bme680_read_raw(struct iio_dev *indio_dev, ··· 740 750 int *val, int *val2, long mask) 741 751 { 742 752 struct bme680_data *data = iio_priv(indio_dev); 743 - int ret; 753 + int chan_val, ret; 744 754 745 755 guard(mutex)(&data->lock); 746 756 ··· 757 767 case IIO_CHAN_INFO_PROCESSED: 758 768 switch (chan->type) { 759 769 case IIO_TEMP: 760 - return bme680_read_temp(data, val); 770 + ret = bme680_read_temp(data, (s16 *)&chan_val); 771 + if (ret) 772 + return ret; 773 + 774 + *val = chan_val * 10; 775 + return IIO_VAL_INT; 761 776 case IIO_PRESSURE: 762 - return bme680_read_press(data, val, val2); 777 + ret = bme680_read_press(data, &chan_val); 778 + if (ret) 779 + return ret; 780 + 781 + *val = chan_val; 782 + *val2 = 1000; 783 + return IIO_VAL_FRACTIONAL; 763 784 case IIO_HUMIDITYRELATIVE: 764 - return bme680_read_humid(data, val, val2); 785 + ret = bme680_read_humid(data, &chan_val); 786 + if (ret) 787 + return ret; 788 + 789 + *val = chan_val; 790 + *val2 = 1000; 791 + return IIO_VAL_FRACTIONAL; 765 792 case IIO_RESISTANCE: 766 - return bme680_read_gas(data, val); 793 + ret = bme680_read_gas(data, &chan_val); 794 + if (ret) 795 + return ret; 796 + 797 + *val = chan_val; 798 + return IIO_VAL_INT; 767 799 default: 768 800 return -EINVAL; 769 801 }