Skip to content

Commit 70a1012

Browse files
Smankusorsjic23
authored andcommitted
iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels
Implement the .read_label callback to allow userspace to identify ADC channels via the "label" property in the device tree. The name field in pm8xxx_chan_info is renamed to label to better reflect its purpose. If no label is provided in the device tree, it defaults to the hardware datasheet name. The change has been tested on Sony Xperia SP (PM8921). Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent fcec89d commit 70a1012

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

drivers/iio/adc/qcom-pm8xxx-xoadc.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,15 @@ static const struct xoadc_channel pm8921_xoadc_channels[] = {
369369

370370
/**
371371
* struct pm8xxx_chan_info - ADC channel information
372-
* @name: name of this channel
372+
* @label: label of this channel from device tree (defaults to datasheet name if not specified)
373373
* @hwchan: pointer to hardware channel information (muxing & scaling settings)
374374
* @calibration: whether to use absolute or ratiometric calibration
375375
* @decimation: 0,1,2,3
376376
* @amux_ip_rsv: ratiometric scale value if using ratiometric
377377
* calibration: 0, 1, 2, 4, 5.
378378
*/
379379
struct pm8xxx_chan_info {
380-
const char *name;
380+
const char *label;
381381
const struct xoadc_channel *hwchan;
382382
enum vadc_calibration calibration;
383383
u8 decimation:2;
@@ -446,7 +446,7 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc,
446446
u8 lsb, msb;
447447

448448
dev_dbg(adc->dev, "read channel \"%s\", amux %d, prescale/mux: %d, rsv %d\n",
449-
ch->name, ch->hwchan->amux_channel, ch->hwchan->pre_scale_mux, rsv);
449+
ch->label, ch->hwchan->amux_channel, ch->hwchan->pre_scale_mux, rsv);
450450

451451
mutex_lock(&adc->lock);
452452

@@ -716,8 +716,21 @@ static int pm8xxx_fwnode_xlate(struct iio_dev *indio_dev,
716716
return -EINVAL;
717717
}
718718

719+
static int pm8xxx_read_label(struct iio_dev *indio_dev,
720+
struct iio_chan_spec const *chan, char *label)
721+
{
722+
struct pm8xxx_xoadc *adc = iio_priv(indio_dev);
723+
const struct pm8xxx_chan_info *ch;
724+
725+
ch = pm8xxx_get_channel(adc, chan->address);
726+
if (!ch)
727+
return -EINVAL;
728+
return sysfs_emit(label, "%s\n", ch->label);
729+
}
730+
719731
static const struct iio_info pm8xxx_xoadc_info = {
720732
.fwnode_xlate = pm8xxx_fwnode_xlate,
733+
.read_label = pm8xxx_read_label,
721734
.read_raw = pm8xxx_read_raw,
722735
};
723736

@@ -761,7 +774,8 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev,
761774
pre_scale_mux, amux_channel);
762775
return -EINVAL;
763776
}
764-
ch->name = name;
777+
ch->label = hwchan->datasheet_name;
778+
fwnode_property_read_string(fwnode, "label", &ch->label);
765779
ch->hwchan = hwchan;
766780
/* Everyone seems to use absolute calibration except in special cases */
767781
ch->calibration = VADC_CALIB_ABSOLUTE;
@@ -803,7 +817,7 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev,
803817

804818
dev_dbg(dev,
805819
"channel [PRESCALE/MUX: %02x AMUX: %02x] \"%s\" ref voltage: %d, decimation %d prescale %d/%d, scale function %d\n",
806-
hwchan->pre_scale_mux, hwchan->amux_channel, ch->name,
820+
hwchan->pre_scale_mux, hwchan->amux_channel, ch->label,
807821
ch->amux_ip_rsv, ch->decimation, hwchan->prescale.numerator,
808822
hwchan->prescale.denominator, hwchan->scale_fn_type);
809823

0 commit comments

Comments
 (0)