Skip to content

Commit a0175b9

Browse files
Linus Walleijjic23
authored andcommitted
iio: st_sensors: add debugfs register read hook
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>
1 parent 8d96fc2 commit a0175b9

6 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎drivers/iio/accel/st_accel_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ static const struct iio_info accel_info = {
618618
.attrs = &st_accel_attribute_group,
619619
.read_raw = &st_accel_read_raw,
620620
.write_raw = &st_accel_write_raw,
621+
.debugfs_reg_access = &st_sensors_debugfs_reg_access,
621622
};
622623

623624
#ifdef CONFIG_IIO_TRIGGER

‎drivers/iio/common/st_sensors/st_sensors_core.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
4444
return err;
4545
}
4646

47+
int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
48+
unsigned reg, unsigned writeval,
49+
unsigned *readval)
50+
{
51+
struct st_sensor_data *sdata = iio_priv(indio_dev);
52+
u8 readdata;
53+
int err;
54+
55+
if (!readval)
56+
return sdata->tf->write_byte(&sdata->tb, sdata->dev,
57+
(u8)reg, (u8)writeval);
58+
59+
err = sdata->tf->read_byte(&sdata->tb, sdata->dev, (u8)reg, &readdata);
60+
if (err < 0)
61+
return err;
62+
63+
*readval = (unsigned)readdata;
64+
65+
return 0;
66+
}
67+
EXPORT_SYMBOL(st_sensors_debugfs_reg_access);
68+
4769
static int st_sensors_match_odr(struct st_sensor_settings *sensor_settings,
4870
unsigned int odr, struct st_sensor_odr_avl *odr_out)
4971
{

‎drivers/iio/gyro/st_gyro_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ static const struct iio_info gyro_info = {
383383
.attrs = &st_gyro_attribute_group,
384384
.read_raw = &st_gyro_read_raw,
385385
.write_raw = &st_gyro_write_raw,
386+
.debugfs_reg_access = &st_sensors_debugfs_reg_access,
386387
};
387388

388389
#ifdef CONFIG_IIO_TRIGGER

‎drivers/iio/magnetometer/st_magn_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ static const struct iio_info magn_info = {
560560
.attrs = &st_magn_attribute_group,
561561
.read_raw = &st_magn_read_raw,
562562
.write_raw = &st_magn_write_raw,
563+
.debugfs_reg_access = &st_sensors_debugfs_reg_access,
563564
};
564565

565566
#ifdef CONFIG_IIO_TRIGGER

‎drivers/iio/pressure/st_pressure_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static const struct iio_info press_info = {
400400
.attrs = &st_press_attribute_group,
401401
.read_raw = &st_press_read_raw,
402402
.write_raw = &st_press_write_raw,
403+
.debugfs_reg_access = &st_sensors_debugfs_reg_access,
403404
};
404405

405406
#ifdef CONFIG_IIO_TRIGGER

‎include/linux/iio/common/st_sensors.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ void st_sensors_power_enable(struct iio_dev *indio_dev);
271271

272272
void st_sensors_power_disable(struct iio_dev *indio_dev);
273273

274+
int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
275+
unsigned reg, unsigned writeval,
276+
unsigned *readval);
277+
274278
int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
275279

276280
int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);

0 commit comments

Comments
 (0)