Message ID | 20200318134042.30133-6-alexandru.ardelean@analog.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ad7780,ad7791,ad7793: localize all IIO channel macro defs | expand |
On 3/18/20 2:40 PM, Alexandru Ardelean wrote: > This change uses the read_avail and '.info_mask_shared_by_type_available' > modifier to set the available scale. > Essentially, nothing changes to the driver's ABI. > > The main idea for this patch is to remove the AD7793 driver from > checkpatch's radar. There have been about ~3 attempts to fix/break the > 'in_voltage-voltage_scale_available' attribute, because checkpatch assumed > it to be an arithmetic operation and people were trying to change that. Yeah, probably a good idea! > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> > --- > drivers/iio/adc/ad7793.c | 53 +++++++++++++++++++++++++++------------- > 1 file changed, 36 insertions(+), 17 deletions(-) > > diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c > index 5592ae573e6b..fad98f1801db 100644 > --- a/drivers/iio/adc/ad7793.c > +++ b/drivers/iio/adc/ad7793.c > @@ -354,29 +354,28 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( > static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797, > sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4"); > > -static ssize_t ad7793_show_scale_available(struct device *dev, > - struct device_attribute *attr, char *buf) > +static int ad7793_read_avail(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + const int **vals, int *type, int *length, > + long mask) > { > - struct iio_dev *indio_dev = dev_to_iio_dev(dev); > struct ad7793_state *st = iio_priv(indio_dev); > - int i, len = 0; > > - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) > - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], > - st->scale_avail[i][1]); > + switch (mask) { > + case IIO_CHAN_INFO_SCALE: > + *vals = (int *)st->scale_avail; Can you change the type of scale_avail to int so we don't need the cast? > + *type = IIO_VAL_INT_PLUS_NANO; > + /* Values are stored in a 2D matrix */ > + *length = ARRAY_SIZE(st->scale_avail) * 2; > > - len += sprintf(buf + len, "\n"); > + return IIO_AVAIL_LIST; > + } > > - return len; > + return -EINVAL; > }
On Wed, 2020-03-18 at 16:10 +0100, Lars-Peter Clausen wrote: > On 3/18/20 2:40 PM, Alexandru Ardelean wrote: > > This change uses the read_avail and '.info_mask_shared_by_type_available' > > modifier to set the available scale. > > Essentially, nothing changes to the driver's ABI. > > > > The main idea for this patch is to remove the AD7793 driver from > > checkpatch's radar. There have been about ~3 attempts to fix/break the > > 'in_voltage-voltage_scale_available' attribute, because checkpatch assumed > > it to be an arithmetic operation and people were trying to change that. > > Yeah, probably a good idea! > > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> > > --- > > drivers/iio/adc/ad7793.c | 53 +++++++++++++++++++++++++++------------- > > 1 file changed, 36 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c > > index 5592ae573e6b..fad98f1801db 100644 > > --- a/drivers/iio/adc/ad7793.c > > +++ b/drivers/iio/adc/ad7793.c > > @@ -354,29 +354,28 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( > > static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797, > > sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4"); > > > > -static ssize_t ad7793_show_scale_available(struct device *dev, > > - struct device_attribute *attr, char *buf) > > +static int ad7793_read_avail(struct iio_dev *indio_dev, > > + struct iio_chan_spec const *chan, > > + const int **vals, int *type, int *length, > > + long mask) > > { > > - struct iio_dev *indio_dev = dev_to_iio_dev(dev); > > struct ad7793_state *st = iio_priv(indio_dev); > > - int i, len = 0; > > > > - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) > > - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], > > - st->scale_avail[i][1]); > > + switch (mask) { > > + case IIO_CHAN_INFO_SCALE: > > + *vals = (int *)st->scale_avail; > > Can you change the type of scale_avail to int so we don't need the cast? > So, I don't want to come-up as looking lazy. [I mean, I am lazy, but I don't want to look lazy.] I took a look at what it means to change this to a simple array. The rework feels to me like a bit more noise than is probably worth it. I mean, if the purpose of the rework is to just get rid of this cast, then it feels noisy [to me]. That being said, if you insist, I can take a look and do a patch [before this one] to convert it to a simple array. > > + *type = IIO_VAL_INT_PLUS_NANO; > > + /* Values are stored in a 2D matrix */ > > + *length = ARRAY_SIZE(st->scale_avail) * 2; > > > > - len += sprintf(buf + len, "\n"); > > + return IIO_AVAIL_LIST; > > + } > > > > - return len; > > + return -EINVAL; > > }
On 3/19/20 8:58 AM, Ardelean, Alexandru wrote: > On Wed, 2020-03-18 at 16:10 +0100, Lars-Peter Clausen wrote: >> On 3/18/20 2:40 PM, Alexandru Ardelean wrote: >>> This change uses the read_avail and '.info_mask_shared_by_type_available' >>> modifier to set the available scale. >>> Essentially, nothing changes to the driver's ABI. >>> >>> The main idea for this patch is to remove the AD7793 driver from >>> checkpatch's radar. There have been about ~3 attempts to fix/break the >>> 'in_voltage-voltage_scale_available' attribute, because checkpatch assumed >>> it to be an arithmetic operation and people were trying to change that. >> >> Yeah, probably a good idea! >> >>> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> >>> --- >>> drivers/iio/adc/ad7793.c | 53 +++++++++++++++++++++++++++------------- >>> 1 file changed, 36 insertions(+), 17 deletions(-) >>> >>> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c >>> index 5592ae573e6b..fad98f1801db 100644 >>> --- a/drivers/iio/adc/ad7793.c >>> +++ b/drivers/iio/adc/ad7793.c >>> @@ -354,29 +354,28 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( >>> static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797, >>> sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4"); >>> >>> -static ssize_t ad7793_show_scale_available(struct device *dev, >>> - struct device_attribute *attr, char *buf) >>> +static int ad7793_read_avail(struct iio_dev *indio_dev, >>> + struct iio_chan_spec const *chan, >>> + const int **vals, int *type, int *length, >>> + long mask) >>> { >>> - struct iio_dev *indio_dev = dev_to_iio_dev(dev); >>> struct ad7793_state *st = iio_priv(indio_dev); >>> - int i, len = 0; >>> >>> - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) >>> - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], >>> - st->scale_avail[i][1]); >>> + switch (mask) { >>> + case IIO_CHAN_INFO_SCALE: >>> + *vals = (int *)st->scale_avail; >> >> Can you change the type of scale_avail to int so we don't need the cast? >> > > So, I don't want to come-up as looking lazy. > [I mean, I am lazy, but I don't want to look lazy.] > > I took a look at what it means to change this to a simple array. > The rework feels to me like a bit more noise than is probably worth it. > I mean, if the purpose of the rework is to just get rid of this cast, then it > feels noisy [to me]. > > That being said, if you insist, I can take a look and do a patch [before this > one] to convert it to a simple array. Hm, ok, looks like is more complicated to get rid of the cast than I though. So keep it.
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index 5592ae573e6b..fad98f1801db 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -354,29 +354,28 @@ static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( static IIO_CONST_ATTR_NAMED(sampling_frequency_available_ad7797, sampling_frequency_available, "123 62 50 33 17 16 12 10 8 6 4"); -static ssize_t ad7793_show_scale_available(struct device *dev, - struct device_attribute *attr, char *buf) +static int ad7793_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) { - struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ad7793_state *st = iio_priv(indio_dev); - int i, len = 0; - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) - len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], - st->scale_avail[i][1]); + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals = (int *)st->scale_avail; + *type = IIO_VAL_INT_PLUS_NANO; + /* Values are stored in a 2D matrix */ + *length = ARRAY_SIZE(st->scale_avail) * 2; - len += sprintf(buf + len, "\n"); + return IIO_AVAIL_LIST; + } - return len; + return -EINVAL; } -static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available, - in_voltage-voltage_scale_available, S_IRUGO, - ad7793_show_scale_available, NULL, 0); - static struct attribute *ad7793_attributes[] = { &iio_const_attr_sampling_frequency_available.dev_attr.attr, - &iio_dev_attr_in_m_in_scale_available.dev_attr.attr, NULL }; @@ -534,6 +533,7 @@ static const struct iio_info ad7793_info = { .read_raw = &ad7793_read_raw, .write_raw = &ad7793_write_raw, .write_raw_get_fmt = &ad7793_write_raw_get_fmt, + .read_avail = ad7793_read_avail, .attrs = &ad7793_attribute_group, .validate_trigger = ad_sd_validate_trigger, }; @@ -547,7 +547,7 @@ static const struct iio_info ad7797_info = { }; #define __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ - _storagebits, _shift, _extend_name, _type, _mask_all) \ + _storagebits, _shift, _extend_name, _type, _mask_type_av, _mask_all) \ { \ .type = (_type), \ .differential = (_channel2 == -1 ? 0 : 1), \ @@ -559,6 +559,7 @@ static const struct iio_info ad7797_info = { .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_OFFSET), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = (_mask_type_av), \ .info_mask_shared_by_all = _mask_all, \ .scan_index = (_si), \ .scan_type = { \ @@ -574,23 +575,41 @@ static const struct iio_info ad7797_info = { _storagebits, _shift) \ __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ _storagebits, _shift, NULL, IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SCALE), \ BIT(IIO_CHAN_INFO_SAMP_FREQ)) #define AD7793_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ _storagebits, _shift) \ __AD7793_CHANNEL(_si, _channel, _channel, _address, _bits, \ _storagebits, _shift, "shorted", IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SCALE), \ BIT(IIO_CHAN_INFO_SAMP_FREQ)) #define AD7793_TEMP_CHANNEL(_si, _address, _bits, _storagebits, _shift) \ __AD7793_CHANNEL(_si, 0, -1, _address, _bits, \ _storagebits, _shift, NULL, IIO_TEMP, \ + 0, \ BIT(IIO_CHAN_INFO_SAMP_FREQ)) #define AD7793_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \ _shift) \ __AD7793_CHANNEL(_si, _channel, -1, _address, _bits, \ _storagebits, _shift, "supply", IIO_VOLTAGE, \ + 0, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7797_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift) \ + __AD7793_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + 0, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7797_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7793_CHANNEL(_si, _channel, _channel, _address, _bits, \ + _storagebits, _shift, "shorted", IIO_VOLTAGE, \ + 0, \ BIT(IIO_CHAN_INFO_SAMP_FREQ)) #define DECLARE_AD7793_CHANNELS(_name, _b, _sb, _s) \ @@ -620,8 +639,8 @@ const struct iio_chan_spec _name##_channels[] = { \ #define DECLARE_AD7797_CHANNELS(_name, _b, _sb) \ const struct iio_chan_spec _name##_channels[] = { \ - AD7793_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ - AD7793_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ + AD7797_DIFF_CHANNEL(0, 0, 0, AD7793_CH_AIN1P_AIN1M, (_b), (_sb), 0), \ + AD7797_SHORTED_CHANNEL(1, 0, AD7793_CH_AIN1M_AIN1M, (_b), (_sb), 0), \ AD7793_TEMP_CHANNEL(2, AD7793_CH_TEMP, (_b), (_sb), 0), \ AD7793_SUPPLY_CHANNEL(3, 3, AD7793_CH_AVDD_MONITOR, (_b), (_sb), 0), \ IIO_CHAN_SOFT_TIMESTAMP(4), \
This change uses the read_avail and '.info_mask_shared_by_type_available' modifier to set the available scale. Essentially, nothing changes to the driver's ABI. The main idea for this patch is to remove the AD7793 driver from checkpatch's radar. There have been about ~3 attempts to fix/break the 'in_voltage-voltage_scale_available' attribute, because checkpatch assumed it to be an arithmetic operation and people were trying to change that. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> --- drivers/iio/adc/ad7793.c | 53 +++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-)