iio: st_sensors: add debugfs register read hook
authorLinus Walleij <linus.walleij@linaro.org>
Wed, 12 Aug 2015 08:22:41 +0000 (10:22 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sun, 16 Aug 2015 09:51:25 +0000 (10:51 +0100)
This adds a debugfs hook to read/write registers in the ST
sensors using debugfs. Proved to be awesome help when trying
to debug why IRQs do not arrive.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Denis Ciocca <denis.ciocca@st.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
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 ff30f880688019fa099d79d7fce3f53b28cfb828..dab8b76c14270564efa0eae3665bfa9d716765dc 100644 (file)
@@ -618,6 +618,7 @@ static const struct iio_info accel_info = {
        .attrs = &st_accel_attribute_group,
        .read_raw = &st_accel_read_raw,
        .write_raw = &st_accel_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index 2e7fdb502645b66f7042220c7d06df7166bde5c4..25258e2c1a82dec3958de9dc92e0ee9f60bdfde2 100644 (file)
@@ -44,6 +44,28 @@ st_sensors_write_data_with_mask_error:
        return err;
 }
 
+int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
+                                 unsigned reg, unsigned writeval,
+                                 unsigned *readval)
+{
+       struct st_sensor_data *sdata = iio_priv(indio_dev);
+       u8 readdata;
+       int err;
+
+       if (!readval)
+               return sdata->tf->write_byte(&sdata->tb, sdata->dev,
+                                            (u8)reg, (u8)writeval);
+
+       err = sdata->tf->read_byte(&sdata->tb, sdata->dev, (u8)reg, &readdata);
+       if (err < 0)
+               return err;
+
+       *readval = (unsigned)readdata;
+
+       return 0;
+}
+EXPORT_SYMBOL(st_sensors_debugfs_reg_access);
+
 static int st_sensors_match_odr(struct st_sensor_settings *sensor_settings,
                        unsigned int odr, struct st_sensor_odr_avl *odr_out)
 {
index 4b993a5bc9a1196dab5ff91bfa6084ed006ed89b..02eddcebeea3e97fd38c5a9bfa60e427bd9f1ac9 100644 (file)
@@ -383,6 +383,7 @@ static const struct iio_info gyro_info = {
        .attrs = &st_gyro_attribute_group,
        .read_raw = &st_gyro_read_raw,
        .write_raw = &st_gyro_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index f8dc4b85d70c60858f26b18aba3e3be8ffe43c92..b27f0146647bb14996dda61d0a11bd31fc2de6cc 100644 (file)
@@ -560,6 +560,7 @@ static const struct iio_info magn_info = {
        .attrs = &st_magn_attribute_group,
        .read_raw = &st_magn_read_raw,
        .write_raw = &st_magn_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index eb41d2b92c24048ce2c65918bc7d42e03640f19d..b39a2fb0671cd15638c0db19c2f068a52a02f8b6 100644 (file)
@@ -400,6 +400,7 @@ static const struct iio_info press_info = {
        .attrs = &st_press_attribute_group,
        .read_raw = &st_press_read_raw,
        .write_raw = &st_press_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index 3c17cd7fdf06f08b9c8a85c502f592e4124e6053..2fe939c73cd241c6a24eabea83abf8761fb1de0a 100644 (file)
@@ -271,6 +271,10 @@ void st_sensors_power_enable(struct iio_dev *indio_dev);
 
 void st_sensors_power_disable(struct iio_dev *indio_dev);
 
+int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
+                                 unsigned reg, unsigned writeval,
+                                 unsigned *readval);
+
 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
 
 int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);