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

iio: adc: qcom-spmi-vadc: Propagate fw node label to userspace

Set the read_label() callback to return a friendly name provided in DT
(firmware), in order to make in_{therm,voltage}X_label attributes show
up in sysfs for userspace to consume a channel name. This is
particularly useful for custom thermistors being attached to otherwise
generically named GPIOs, where the name is known by the board DT.

If the channel name isn't set in DT, use the datasheet_name hardcoded in
the driver instead.

Note that this doesn't fall back to fwnode_get_name() as that provides
suboptimally readable names, with an @xx address suffix from board DT.

Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20230502-iio-adc-propagate-fw-node-label-v3-5-6be5db6e6b5a@somainline.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Marijn Suijten and committed by
Jonathan Cameron
3d0b1260 ac0abf75

+18 -1
+18 -1
drivers/iio/adc/qcom-spmi-vadc.c
··· 84 84 * that is an average of multiple measurements. 85 85 * @scale_fn_type: Represents the scaling function to convert voltage 86 86 * physical units desired by the client for the channel. 87 + * @channel_name: Channel name used in device tree. 87 88 */ 88 89 struct vadc_channel_prop { 89 90 unsigned int channel; ··· 94 93 unsigned int hw_settle_time; 95 94 unsigned int avg_samples; 96 95 enum vadc_scale_fn_type scale_fn_type; 96 + const char *channel_name; 97 97 }; 98 98 99 99 /** ··· 497 495 return -EINVAL; 498 496 } 499 497 498 + static int vadc_read_label(struct iio_dev *indio_dev, 499 + struct iio_chan_spec const *chan, char *label) 500 + { 501 + struct vadc_priv *vadc = iio_priv(indio_dev); 502 + const char *name = vadc->chan_props[chan->address].channel_name; 503 + 504 + return sysfs_emit(label, "%s\n", name); 505 + } 506 + 500 507 static const struct iio_info vadc_info = { 501 508 .read_raw = vadc_read_raw, 509 + .read_label = vadc_read_label, 502 510 .fwnode_xlate = vadc_fwnode_xlate, 503 511 }; 504 512 ··· 664 652 struct vadc_channel_prop *prop, 665 653 struct fwnode_handle *fwnode) 666 654 { 667 - const char *name = fwnode_get_name(fwnode); 655 + const char *name = fwnode_get_name(fwnode), *label; 668 656 u32 chan, value, varr[2]; 669 657 int ret; 670 658 ··· 678 666 dev_err(dev, "%s invalid channel number %d\n", name, chan); 679 667 return -EINVAL; 680 668 } 669 + 670 + ret = fwnode_property_read_string(fwnode, "label", &label); 671 + if (ret) 672 + label = vadc_chans[chan].datasheet_name; 673 + prop->channel_name = label; 681 674 682 675 /* the channel has DT description */ 683 676 prop->channel = chan;