[PATCH] iio: hmc5843 Add channel attribute for bias configuration
Daniel Baluta
daniel.baluta at gmail.com
Wed Feb 3 00:13:06 EET 2016
On Tue, Feb 2, 2016 at 11:52 PM, Cristina Moraru
<cristina.moraru09 at gmail.com> wrote:
> Replace static device attribute with channel shared attribute
> for bias configuration in order to comply with IIO ABI.
Commit message here should be more clear. That is:
Replace non standard meas_conf attribute with the standard IIO
calibbias attribute.
Calibbias can have one of the following values:
0 - Normal measurement configuration (Default) [TODO: add here
description from datasheet, page 12]
1 - Positive bias configuration for X, Y, and Z axes. In this configuration,
a positive current is forced across the resistive load for all three axe
2 - Negative bias configuration for X, Y and Z axes [TODO: add here
the entire description from datasheet]
With this in place, we can think of moving this driver out of staging.
===
also we should add an attribute called calibbias_available similar
with samp_freq_available.
>
> Signed-off-by: Cristina Moraru <cristina.moraru09 at gmail.com>
> ---
> drivers/staging/iio/magnetometer/hmc5843_core.c | 61 ++++++-------------------
> 1 file changed, 15 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/staging/iio/magnetometer/hmc5843_core.c b/drivers/staging/iio/magnetometer/hmc5843_core.c
> index 4aab022..9ec1a9e 100644
> --- a/drivers/staging/iio/magnetometer/hmc5843_core.c
> +++ b/drivers/staging/iio/magnetometer/hmc5843_core.c
> @@ -205,50 +205,6 @@ static int hmc5843_set_meas_conf(struct hmc5843_data *data, u8 meas_conf)
> }
>
> static
> -ssize_t hmc5843_show_measurement_configuration(struct device *dev,
> - struct device_attribute *attr,
> - char *buf)
> -{
> - struct hmc5843_data *data = iio_priv(dev_to_iio_dev(dev));
> - unsigned int val;
> - int ret;
> -
> - ret = regmap_read(data->regmap, HMC5843_CONFIG_REG_A, &val);
> - if (ret)
> - return ret;
> - val &= HMC5843_MEAS_CONF_MASK;
> -
> - return sprintf(buf, "%d\n", val);
> -}
> -
> -static
> -ssize_t hmc5843_set_measurement_configuration(struct device *dev,
> - struct device_attribute *attr,
> - const char *buf,
> - size_t count)
> -{
> - struct hmc5843_data *data = iio_priv(dev_to_iio_dev(dev));
> - unsigned long meas_conf = 0;
> - int ret;
> -
> - ret = kstrtoul(buf, 10, &meas_conf);
> - if (ret)
> - return ret;
> - if (meas_conf >= HMC5843_MEAS_CONF_MASK)
> - return -EINVAL;
> -
> - ret = hmc5843_set_meas_conf(data, meas_conf);
> -
> - return (ret < 0) ? ret : count;
> -}
> -
> -static IIO_DEVICE_ATTR(meas_conf,
> - S_IWUSR | S_IRUGO,
> - hmc5843_show_measurement_configuration,
> - hmc5843_set_measurement_configuration,
> - 0);
> -
> -static
Hmm, not sure if 'static' here should be removed. It's part of
hmc5843_show_samp_freq_avail definition.
> ssize_t hmc5843_show_samp_freq_avail(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> @@ -371,6 +327,13 @@ static int hmc5843_read_raw(struct iio_dev *indio_dev,
> *val = data->variant->regval_to_samp_freq[rval][0];
> *val2 = data->variant->regval_to_samp_freq[rval][1];
> return IIO_VAL_INT_PLUS_MICRO;
> + case IIO_CHAN_INFO_CALIBBIAS:
> + ret = regmap_read(data->regmap, HMC5843_CONFIG_REG_A, &rval);
> + if (ret)
> + return ret;
> + rval &= HMC5843_MEAS_CONF_MASK;
> + *val = rval;
> + return IIO_VAL_INT;
> }
> return -EINVAL;
> }
> @@ -395,6 +358,11 @@ static int hmc5843_write_raw(struct iio_dev *indio_dev,
> return -EINVAL;
>
> return hmc5843_set_range_gain(data, range);
> + case IIO_CHAN_INFO_CALIBBIAS:
> + if (val >= HMC5843_MEAS_CONF_MASK)
> + return -EINVAL;
> +
> + return hmc5843_set_meas_conf(data, val);
> default:
> return -EINVAL;
> }
> @@ -409,6 +377,8 @@ static int hmc5843_write_raw_get_fmt(struct iio_dev *indio_dev,
> return IIO_VAL_INT_PLUS_MICRO;
> case IIO_CHAN_INFO_SCALE:
> return IIO_VAL_INT_PLUS_NANO;
> + case IIO_CHAN_INFO_CALIBBIAS:
> + return IIO_VAL_INT;
> default:
> return -EINVAL;
> }
> @@ -451,7 +421,7 @@ done:
> .channel2 = IIO_MOD_##axis, \
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
> - BIT(IIO_CHAN_INFO_SAMP_FREQ), \
> + BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_CALIBBIAS), \
> .scan_index = idx, \
> .scan_type = { \
> .sign = 's', \
> @@ -477,7 +447,6 @@ static const struct iio_chan_spec hmc5883_channels[] = {
> };
>
> static struct attribute *hmc5843_attributes[] = {
> - &iio_dev_attr_meas_conf.dev_attr.attr,
> &iio_dev_attr_scale_available.dev_attr.attr,
> &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
> NULL
> --
> 1.9.1
>
More information about the firefly
mailing list