iio:st sensors: remove custom sampling frequence attribute in favour of core support.
authorJonathan Cameron <jic23@kernel.org>
Sun, 22 Jun 2014 19:59:00 +0000 (20:59 +0100)
committerJonathan Cameron <jic23@kernel.org>
Mon, 7 Jul 2014 08:39:57 +0000 (09:39 +0100)
This allows in kernel client drivers to access this

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Cc: Denis Ciocca <denis.ciocca@st.com>
Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
drivers/iio/accel/st_accel_core.c
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/gyro/st_gyro_core.c
drivers/iio/magnetometer/st_magn_core.c
drivers/iio/pressure/st_pressure_core.c
include/linux/iio/common/st_sensors.h

index a2abf7c2ce3be4cbd0cdcbb8dd2481035651d3bc..087864854c613e02cf1c58bdfb75c6650d0bcabc 100644 (file)
@@ -393,6 +393,9 @@ static int st_accel_read_raw(struct iio_dev *indio_dev,
                *val = 0;
                *val2 = adata->current_fullscale->gain;
                return IIO_VAL_INT_PLUS_MICRO;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = adata->odr;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -410,6 +413,13 @@ static int st_accel_write_raw(struct iio_dev *indio_dev,
        case IIO_CHAN_INFO_SCALE:
                err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
                break;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               if (val2)
+                       return -EINVAL;
+               mutex_lock(&indio_dev->mlock);
+               err = st_sensors_set_odr(indio_dev, val);
+               mutex_unlock(&indio_dev->mlock);
+               return err;
        default:
                return -EINVAL;
        }
@@ -417,14 +427,12 @@ static int st_accel_write_raw(struct iio_dev *indio_dev,
        return err;
 }
 
-static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
 static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_accel_scale_available);
 
 static struct attribute *st_accel_attributes[] = {
        &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
        &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
-       &iio_dev_attr_sampling_frequency.dev_attr.attr,
        NULL,
 };
 
index e8b932fed70ecb4b97ac5eeb044a6fb0c41cfcdd..30fb6407fad01ba3e832bc2bad856e37b25bed4d 100644 (file)
@@ -463,35 +463,6 @@ read_wai_error:
 }
 EXPORT_SYMBOL(st_sensors_check_device_support);
 
-ssize_t st_sensors_sysfs_get_sampling_frequency(struct device *dev,
-                               struct device_attribute *attr, char *buf)
-{
-       struct st_sensor_data *adata = iio_priv(dev_get_drvdata(dev));
-
-       return sprintf(buf, "%d\n", adata->odr);
-}
-EXPORT_SYMBOL(st_sensors_sysfs_get_sampling_frequency);
-
-ssize_t st_sensors_sysfs_set_sampling_frequency(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size)
-{
-       int err;
-       unsigned int odr;
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
-
-       err = kstrtoint(buf, 10, &odr);
-       if (err < 0)
-               goto conversion_error;
-
-       mutex_lock(&indio_dev->mlock);
-       err = st_sensors_set_odr(indio_dev, odr);
-       mutex_unlock(&indio_dev->mlock);
-
-conversion_error:
-       return err < 0 ? err : size;
-}
-EXPORT_SYMBOL(st_sensors_sysfs_set_sampling_frequency);
-
 ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
index ed74a906998953de9c97461a7f137323eb30ed5f..f156fc6c5c6c11be88770b29cf11bfc78cd645e4 100644 (file)
@@ -245,6 +245,9 @@ static int st_gyro_read_raw(struct iio_dev *indio_dev,
                *val = 0;
                *val2 = gdata->current_fullscale->gain;
                return IIO_VAL_INT_PLUS_MICRO;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = gdata->odr;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -262,6 +265,13 @@ static int st_gyro_write_raw(struct iio_dev *indio_dev,
        case IIO_CHAN_INFO_SCALE:
                err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
                break;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               if (val2)
+                       return -EINVAL;
+               mutex_lock(&indio_dev->mlock);
+               err = st_sensors_set_odr(indio_dev, val);
+               mutex_unlock(&indio_dev->mlock);
+               return err;
        default:
                err = -EINVAL;
        }
@@ -269,14 +279,12 @@ static int st_gyro_write_raw(struct iio_dev *indio_dev,
        return err;
 }
 
-static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
 static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_anglvel_scale_available);
 
 static struct attribute *st_gyro_attributes[] = {
        &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
        &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr,
-       &iio_dev_attr_sampling_frequency.dev_attr.attr,
        NULL,
 };
 
index 240a21dd0c6111457ce171d37b5d43fa9b5b0316..a4b64130ac2f862996aa28522176bcee8ef904e3 100644 (file)
@@ -299,6 +299,9 @@ static int st_magn_read_raw(struct iio_dev *indio_dev,
                else
                        *val2 = mdata->current_fullscale->gain;
                return IIO_VAL_INT_PLUS_MICRO;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = mdata->odr;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -316,6 +319,13 @@ static int st_magn_write_raw(struct iio_dev *indio_dev,
        case IIO_CHAN_INFO_SCALE:
                err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
                break;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               if (val2)
+                       return -EINVAL;
+               mutex_lock(&indio_dev->mlock);
+               err = st_sensors_set_odr(indio_dev, val);
+               mutex_unlock(&indio_dev->mlock);
+               return err;
        default:
                err = -EINVAL;
        }
@@ -323,14 +333,12 @@ static int st_magn_write_raw(struct iio_dev *indio_dev,
        return err;
 }
 
-static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
 static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_magn_scale_available);
 
 static struct attribute *st_magn_attributes[] = {
        &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
        &iio_dev_attr_in_magn_scale_available.dev_attr.attr,
-       &iio_dev_attr_sampling_frequency.dev_attr.attr,
        NULL,
 };
 
index cd7e01f3a93b5fbfd59ade63de23fc8b11f436cc..473d914ef470482dda3d3d95bbb1f8e0e4a0c738 100644 (file)
@@ -307,6 +307,27 @@ static const struct st_sensors st_press_sensors[] = {
        },
 };
 
+static int st_press_write_raw(struct iio_dev *indio_dev,
+                             struct iio_chan_spec const *ch,
+                             int val,
+                             int val2,
+                             long mask)
+{
+       int err;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               if (val2)
+                       return -EINVAL;
+               mutex_lock(&indio_dev->mlock);
+               err = st_sensors_set_odr(indio_dev, val);
+               mutex_unlock(&indio_dev->mlock);
+               return err;
+       default:
+               return -EINVAL;
+       }
+}
+
 static int st_press_read_raw(struct iio_dev *indio_dev,
                        struct iio_chan_spec const *ch, int *val,
                                                        int *val2, long mask)
@@ -349,6 +370,9 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
                }
 
                return IIO_VAL_FRACTIONAL;
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = pdata->odr;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -357,12 +381,10 @@ read_error:
        return err;
 }
 
-static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
 
 static struct attribute *st_press_attributes[] = {
        &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
-       &iio_dev_attr_sampling_frequency.dev_attr.attr,
        NULL,
 };
 
@@ -374,6 +396,7 @@ static const struct iio_info press_info = {
        .driver_module = THIS_MODULE,
        .attrs = &st_press_attribute_group,
        .read_raw = &st_press_read_raw,
+       .write_raw = &st_press_write_raw,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index 96f51f0e00961c894c1a38b85f89873ea19d31af..d8257ab60bacdc932b05dd1333a2218b00e257d4 100644 (file)
@@ -47,6 +47,7 @@
        .type = device_type, \
        .modified = mod, \
        .info_mask_separate = mask, \
+       .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
        .scan_index = index, \
        .channel2 = ch2, \
        .address = addr, \
        }, \
 }
 
-#define ST_SENSOR_DEV_ATTR_SAMP_FREQ() \
-               IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, \
-                       st_sensors_sysfs_get_sampling_frequency, \
-                       st_sensors_sysfs_set_sampling_frequency)
-
 #define ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL() \
                IIO_DEV_ATTR_SAMP_FREQ_AVAIL( \
                        st_sensors_sysfs_sampling_frequency_avail)
@@ -285,12 +281,6 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
 int st_sensors_check_device_support(struct iio_dev *indio_dev,
                        int num_sensors_list, const struct st_sensors *sensors);
 
-ssize_t st_sensors_sysfs_get_sampling_frequency(struct device *dev,
-                               struct device_attribute *attr, char *buf);
-
-ssize_t st_sensors_sysfs_set_sampling_frequency(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size);
-
 ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
                                struct device_attribute *attr, char *buf);
 
This page took 0.032334 seconds and 5 git commands to generate.