mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-13 01:08:50 +00:00
iio: industrialio-core: iio_write_channel_info accept IIO_VAL_INT_PLUS_NANO
Allow iio_write_channel_info() to accept IIO_VAL_INT_PLUS_NANO Changes since V1: use callback to query expected format/precision Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
43a4360ea8
commit
5c04af0483
@ -220,6 +220,9 @@ struct iio_trigger; /* forward declaration */
|
|||||||
* contain the elements making up the returned value.
|
* contain the elements making up the returned value.
|
||||||
* @write_raw: function to write a value to the device.
|
* @write_raw: function to write a value to the device.
|
||||||
* Parameters are the same as for read_raw.
|
* Parameters are the same as for read_raw.
|
||||||
|
* @write_raw_get_fmt: callback function to query the expected
|
||||||
|
* format/precision. If not set by the driver, write_raw
|
||||||
|
* returns IIO_VAL_INT_PLUS_MICRO.
|
||||||
* @read_event_config: find out if the event is enabled.
|
* @read_event_config: find out if the event is enabled.
|
||||||
* @write_event_config: set if the event is enabled.
|
* @write_event_config: set if the event is enabled.
|
||||||
* @read_event_value: read a value associated with the event. Meaning
|
* @read_event_value: read a value associated with the event. Meaning
|
||||||
@ -247,6 +250,10 @@ struct iio_info {
|
|||||||
int val2,
|
int val2,
|
||||||
long mask);
|
long mask);
|
||||||
|
|
||||||
|
int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
|
||||||
|
struct iio_chan_spec const *chan,
|
||||||
|
long mask);
|
||||||
|
|
||||||
int (*read_event_config)(struct iio_dev *indio_dev,
|
int (*read_event_config)(struct iio_dev *indio_dev,
|
||||||
int event_code);
|
int event_code);
|
||||||
|
|
||||||
|
@ -412,25 +412,40 @@ static ssize_t iio_write_channel_info(struct device *dev,
|
|||||||
{
|
{
|
||||||
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
||||||
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
||||||
int ret, integer = 0, micro = 0, micro_mult = 100000;
|
int ret, integer = 0, fract = 0, fract_mult = 100000;
|
||||||
bool integer_part = true, negative = false;
|
bool integer_part = true, negative = false;
|
||||||
|
|
||||||
/* Assumes decimal - precision based on number of digits */
|
/* Assumes decimal - precision based on number of digits */
|
||||||
if (!indio_dev->info->write_raw)
|
if (!indio_dev->info->write_raw)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (indio_dev->info->write_raw_get_fmt)
|
||||||
|
switch (indio_dev->info->write_raw_get_fmt(indio_dev,
|
||||||
|
this_attr->c, this_attr->address)) {
|
||||||
|
case IIO_VAL_INT_PLUS_MICRO:
|
||||||
|
fract_mult = 100000;
|
||||||
|
break;
|
||||||
|
case IIO_VAL_INT_PLUS_NANO:
|
||||||
|
fract_mult = 100000000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (buf[0] == '-') {
|
if (buf[0] == '-') {
|
||||||
negative = true;
|
negative = true;
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*buf) {
|
while (*buf) {
|
||||||
if ('0' <= *buf && *buf <= '9') {
|
if ('0' <= *buf && *buf <= '9') {
|
||||||
if (integer_part)
|
if (integer_part)
|
||||||
integer = integer*10 + *buf - '0';
|
integer = integer*10 + *buf - '0';
|
||||||
else {
|
else {
|
||||||
micro += micro_mult*(*buf - '0');
|
fract += fract_mult*(*buf - '0');
|
||||||
if (micro_mult == 1)
|
if (fract_mult == 1)
|
||||||
break;
|
break;
|
||||||
micro_mult /= 10;
|
fract_mult /= 10;
|
||||||
}
|
}
|
||||||
} else if (*buf == '\n') {
|
} else if (*buf == '\n') {
|
||||||
if (*(buf + 1) == '\0')
|
if (*(buf + 1) == '\0')
|
||||||
@ -448,11 +463,11 @@ static ssize_t iio_write_channel_info(struct device *dev,
|
|||||||
if (integer)
|
if (integer)
|
||||||
integer = -integer;
|
integer = -integer;
|
||||||
else
|
else
|
||||||
micro = -micro;
|
fract = -fract;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = indio_dev->info->write_raw(indio_dev, this_attr->c,
|
ret = indio_dev->info->write_raw(indio_dev, this_attr->c,
|
||||||
integer, micro, this_attr->address);
|
integer, fract, this_attr->address);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user