iio: accel: adxl345: add FIFO operating with IRQ triggered watermark events
Subsystems (4)
v3 cover iio: accel: adxl345: add FIFO operating with IRQ triggered watermark events
The adxl345 sensor offers several features. Most of them are based on using the hardware FIFO and reacting on events coming in on an interrupt line. Add access to configure and read out the FIFO, handling of interrupts and configuration and application of the watermark feature on that FIFO.
---
Although I tried to implement most of the requested changes, now the code is simplified and clearer, I still encounter some issues.
1) Unsure if my way reading out the FIFO elements with a regmap_noinc_read() is supposed to be like that. TBH, isn't there a better way, say, to configure the channel correctly and this is handled by the iio API internally? As I understood from v2 there might be a way using available data, also in iio_info I see now as buffer attributes an available data field. Where can I find information how to use it or did I get this wrong?
2) Overrun handling: I'm trying to reset the FIFO and registers. Unsure, if this is the correct dealing here.
3) I can see the IRQs coming in, and with a watch -n 0.1 iio_info I can see the correct fields changing. I tried the follwoing down below, but the iio_readdev shows me the following result. I don't quite understand if I still have an issue here, or if this is a calibration thing?
# iio_info Library version: 0.23 (git tag: v0.23) Compiled with backends: local xml ip usb IIO context created with local backend. Backend version: 0.23 (git tag: v0.23) Backend description string: Linux dut1138 6.6.21-lothar02 #3 SMP PREEMPT Wed Nov 6 21:21:14 UTC 2024 aarch64 IIO context has 2 attributes: local,kernel: 6.6.21-lothar02 uri: local: IIO context has 1 devices: iio:device0: adxl345 (buffer capable) 3 channels found: accel_x: (input, index: 0, format: le:s13/16>>0) 4 channel-specific attributes found: attr 0: calibbias value: 0 attr 1: raw value: -14 <--- CHANGES attr 2: sampling_frequency value: 100.000000000 attr 3: scale value: 0.038300 accel_y: (input, index: 1, format: le:s13/16>>0) 4 channel-specific attributes found: attr 0: calibbias value: 0 attr 1: raw value: 6 <--- CHANGES attr 2: sampling_frequency value: 100.000000000 attr 3: scale value: 0.038300 accel_z: (input, index: 2, format: le:s13/16>>0) 4 channel-specific attributes found: attr 0: calibbias value: 0 attr 1: raw value: 247 <--- CHANGES attr 2: sampling_frequency value: 100.000000000 attr 3: scale value: 0.038300 2 device-specific attributes found: attr 0: sampling_frequency_available value: 0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200 attr 1: waiting_for_supplier value: 0 3 buffer-specific attributes found: attr 0: data_available value: 13 attr 1: direction value: in attr 2: watermark value: 15 No trigger on this device
Above I marked what keeps changing with "CHANGES", that's what I expect. Then with readdev I obtain the following result.
# iio_attr -c adxl345 dev 'adxl345', channel 'accel_x' (input, index: 0, format: le:s13/16>>0), found 4 channel-specific attributes dev 'adxl345', channel 'accel_y' (input, index: 1, format: le:s13/16>>0), found 4 channel-specific attributes dev 'adxl345', channel 'accel_z' (input, index: 2, format: le:s13/16>>0), found 4 channel-specific attributes # echo 1 > ./scan_elements/in_accel_x_en # echo 1 > ./scan_elements/in_accel_y_en # echo 1 > ./scan_elements/in_accel_z_en # echo 32 > ./buffer0/length # echo 15 > ./buffer0/watermark # echo 1 > ./buffer0/enable # iio_readdev -b 16 -s 21 adxl345 > samples.dat # hexdump -d ./samples.dat 0000000 65523 00006 00248 65523 00005 00235 65522 00006 0000010 00248 65522 00006 00248 65521 00005 00247 65522 0000020 00007 00249 65523 00005 00249 65521 00006 00248 0000030 65522 00006 00248 65522 00006 00250 65522 00006 0000040 00249 65522 00005 00248 65523 00005 00248 65521 0000050 00007 00248 65521 00006 00250 65522 00005 00248 0000060 65521 00006 00248 65522 00007 00247 65522 00006 0000070 00248 65522 00006 00248 65521 00004 00250 000007e
Am I doing this actually correctly?
---
v2 -> v3: Implementation reworked and simplified
- INT lines are defined by binding
- kfifo is prepared by devm_iio_kfifo_buffer_setup()
- event handler is registered w/ devm_request_threaded_irq()
v1 -> v2: Fix comments according to Documentation/doc-guide/kernel-doc.rst
and missing static declaration of function.
---
Lothar Rubusch (10):
iio: accel: adxl345: fix comment on probe
iio: accel: adxl345: rename variable data to st
iio: accel: adxl345: measure right-justified
iio: accel: adxl345: add function to switch measuring
iio: accel: adxl345: extend list of defines
dt-bindings: iio: accel: add interrupt-names
iio: accel: adxl345: initialize IRQ number
iio: accel: adxl345: initialize FIFO delay value for SPI
iio: accel: adxl345: prepare channel for scan_index
iio: accel: adxl345: add kfifo with watermark
.../bindings/iio/accel/adi,adxl345.yaml | 13 + drivers/iio/accel/adxl345.h | 90 +++- drivers/iio/accel/adxl345_core.c | 427 ++++++++++++++++-- drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +- 5 files changed, 484 insertions(+), 55 deletions(-)
Signature · 1 line
2.39.5
PATCH v3 1/10 iio: accel: adxl345: fix comment on probe
Fix comment on the probe function. Add covered sensors and fix typo.
--- drivers/iio/accel/adxl345_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/accel/adxl345_core.c +1 -2
@@ -169,8 +169,7 @@ static void adxl345_powerdown(void *regmap) }/** -* adxl345_core_probe() - probe and setup for the adxl345 accelerometer, -* also covers the adlx375 accelerometer +* adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device * @setup: Setup routine to be executed right before the standard device
Signature · 1 line
2.39.5
PATCH v3 2/10 iio: accel: adxl345: rename variable data to st
In reply to Lothar RubuschRename the locally used variable data to st. The st refers to "state", representing the internal state of the driver object. Further it prepares the usage of an internal data pointer needed for the implementation of the sensor features.
--- drivers/iio/accel/adxl345_core.c | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/iio/accel/adxl345_core.c +22 -22
@@ -17,7 +17,7 @@#include "adxl345.h" -struct adxl345_data { +struct adxl345_state {const struct adxl345_chip_info *info;struct regmap *regmap; };
@@ -43,7 +43,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_state *st = iio_priv(indio_dev);__le16 accel;long long samp_freq_nhz;unsigned int regval;
@@ -56,7 +56,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,* ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte */ - ret =regmap_bulk_read (data->regmap, + ret =regmap_bulk_read (st->regmap,ADXL345_REG_DATA_AXIS (chan->address), &accel,sizeof (accel));if (ret <0 )
@@ -66,10 +66,10 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : *val =0 ; - *val2 = data->info->uscale; + *val2 = st->info->uscale;return IIO_VAL_INT_PLUS_MICRO ;case IIO_CHAN_INFO_CALIBBIAS : - ret =regmap_read (data->regmap, + ret =regmap_read (st->regmap,ADXL345_REG_OFS_AXIS (chan->address), ®val);if (ret <0 )return ret;
@@ -81,7 +81,7 @@ static int adxl345_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ;case IIO_CHAN_INFO_SAMP_FREQ : - ret =regmap_read (data->regmap,ADXL345_REG_BW_RATE , ®val); + ret =regmap_read (st->regmap,ADXL345_REG_BW_RATE , ®val);if (ret <0 )return ret;
@@ -99,7 +99,7 @@ static int adxl345_write_raw(struct iio_dev *indio_dev,struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct adxl345_data *data = iio_priv(indio_dev); + struct adxl345_state *st = iio_priv(indio_dev);s64 n;switch (mask) {
@@ -108,14 +108,14 @@ static int adxl345_write_raw(struct iio_dev *indio_dev,* 8-bit resolution at +/- 2g, that is 4x accel data scale * factor */ -return regmap_write (data->regmap, +return regmap_write (st->regmap,ADXL345_REG_OFS_AXIS (chan->address), val /4 );case IIO_CHAN_INFO_SAMP_FREQ : n =div_s64 (val *NANOHZ_PER_HZ + val2,ADXL345_BASE_RATE_NANO_HZ ); -return regmap_update_bits (data->regmap,ADXL345_REG_BW_RATE , +return regmap_update_bits (st->regmap,ADXL345_REG_BW_RATE ,ADXL345_BW_RATE ,clamp_val (ilog2 (n),0 ,ADXL345_BW_RATE ));
@@ -180,7 +180,7 @@ static void adxl345_powerdown(void *regmap)int adxl345_core_probe (struct device *dev,struct regmap *regmap,int (*setup)(struct device *,struct regmap *)) { -struct adxl345_data *data; +struct adxl345_state *st;struct iio_dev *indio_dev;u32 regval; unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE |
@@ -189,17 +189,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ADXL345_DATA_FORMAT_SELF_TEST);int ret; - indio_dev =devm_iio_device_alloc (dev,sizeof (*data)); + indio_dev =devm_iio_device_alloc (dev,sizeof (*st));if (!indio_dev)return -ENOMEM ; - data =iio_priv (indio_dev); - data->regmap = regmap; - data->info =device_get_match_data (dev); -if (!data->info) + st =iio_priv (indio_dev); + st->regmap = regmap; + st->info =device_get_match_data (dev); +if (!st->info)return -ENODEV ; - indio_dev->name = data->info->name; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->channels = adxl345_channels;
@@ -207,12 +207,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,if (setup) {/* Perform optional initial bus specific configuration */ - ret =setup (dev, data->regmap); + ret =setup (dev, st->regmap);if (ret)return ret;/* Enable full-resolution mode */ - ret =regmap_update_bits (data->regmap,ADXL345_REG_DATA_FORMAT , + ret =regmap_update_bits (st->regmap,ADXL345_REG_DATA_FORMAT , data_format_mask,ADXL345_DATA_FORMAT_FULL_RES );if (ret)
@@ -221,14 +221,14 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, }else {/* Enable full-resolution mode (init all data_format bits) */ - ret =regmap_write (data->regmap,ADXL345_REG_DATA_FORMAT , + ret =regmap_write (st->regmap,ADXL345_REG_DATA_FORMAT ,ADXL345_DATA_FORMAT_FULL_RES );if (ret)return dev_err_probe (dev, ret,"Failed to set data range\n" ); } - ret =regmap_read (data->regmap,ADXL345_REG_DEVID , ®val); + ret =regmap_read (st->regmap,ADXL345_REG_DEVID , ®val);if (ret <0 )return dev_err_probe (dev, ret,"Error reading device ID\n" );
@@ -237,11 +237,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID);/* Enable measurement mode */ - ret =adxl345_powerup (data->regmap); + ret =adxl345_powerup (st->regmap);if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable measurement mode\n" ); - ret =devm_add_action_or_reset (dev, adxl345_powerdown, data->regmap); + ret =devm_add_action_or_reset (dev, adxl345_powerdown, st->regmap);if (ret <0 )return ret;
Signature · 1 line
2.39.5
PATCH v3 3/10 iio: accel: adxl345: measure right-justified
In reply to Lothar RubuschMake measurements right-justified, since it is the default for the driver and sensor. By not setting the ADXL345_DATA_FORMAT_JUSTIFY bit, the data becomes right-judstified. This was the original setting, there is no reason to change it to left-justified, where right-justified simplifies working on the registers.
--- drivers/iio/accel/adxl345_core.c | 1 - 1 file changed, 1 deletion(-)
drivers/iio/accel/adxl345_core.c +0 -1
@@ -184,7 +184,6 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,struct iio_dev *indio_dev;u32 regval;unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE | -ADXL345_DATA_FORMAT_JUSTIFY |ADXL345_DATA_FORMAT_FULL_RES |ADXL345_DATA_FORMAT_SELF_TEST );int ret;
Signature · 1 line
2.39.5
PATCH v3 4/10 iio: accel: adxl345: add function to switch measuring
In reply to Lothar RubuschReplace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. This is needed for several features of the accelerometer. It allows to change e.g. FIFO settings.
--- drivers/iio/accel/adxl345_core.c | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-)
drivers/iio/accel/adxl345_core.c +31 -13
@@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** +* adxl345_set_measure_en() - Enable and disable measuring. +* +* @st: The device data. +* @en: Enable measurements, else standby mode. +* +* For lowest power operation, standby mode can be used. In standby mode, +* current consumption is supposed to be reduced to 0.1uA (typical). In this +* mode no measurements are made. Placing the device into standby mode +* preserves the contents of FIFO. +* +* Return: Returns 0 if successful, or a negative error value. +*/ +static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ; + + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ; +return regmap_write (st->regmap,ADXL345_REG_POWER_CTL , val); +} + +static void adxl345_powerdown (void *ptr) +{ +struct adxl345_state *st = ptr; + +adxl345_set_measure_en (st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" );
@@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup (void *regmap) -{ -return regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_MEASURE ); -} - -static void adxl345_powerdown (void *regmap) -{ -regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); -} -/** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device
@@ -236,13 +254,13 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID);/* Enable measurement mode */ - ret =adxl345_powerup (st->regmap); + ret =adxl345_set_measure_en (st, true);if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable measurement mode\n" ); - ret =devm_add_action_or_reset (dev, adxl345_powerdown, st->regmap); + ret =devm_add_action_or_reset (dev, adxl345_powerdown, st);if (ret <0 ) -return ret; +return dev_err_probe (dev, ret,"Failed to add action or reset\n" );return devm_iio_device_register (dev, indio_dev); }
Signature · 1 line
2.39.5
PATCH v3 5/10 iio: accel: adxl345: extend list of defines
In reply to Lothar RubuschExtend the list of constants. Keep them the header file for readability. The constants allow the implementation of events like FIFO-watermark, single tap, double tap, freefall, etc.
--- drivers/iio/accel/adxl345.h | 89 ++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-)
drivers/iio/accel/adxl345.h +77 -12
@@ -9,37 +9,102 @@#define _ADXL345_H_#define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D#define ADXL345_REG_OFSX 0x1E#define ADXL345_REG_OFSY 0x1F#define ADXL345_REG_OFSZ 0x20 -#define ADXL345_REG_OFS_AXIS (index) (ADXL345_REG_OFSX + (index)) +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C#define ADXL345_REG_POWER_CTL 0x2D +#define ADXL345_REG_INT_ENABLE 0x2E +#define ADXL345_REG_INT_MAP 0x2F +#define ADXL345_REG_INT_SOURCE 0x30#define ADXL345_REG_DATA_FORMAT 0x31 -#define ADXL345_REG_DATAX0 0x32 -#define ADXL345_REG_DATAY0 0x34 -#define ADXL345_REG_DATAZ0 0x36 -#define ADXL345_REG_DATA_AXIS (index) \ - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) +#define ADXL345_REG_XYZ_BASE 0x32 +#define ADXL345_REG_DATA_AXIS (index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) + +#define ADXL345_REG_FIFO_CTL 0x38 +#define ADXL345_REG_FIFO_STATUS 0x39 + +#define ADXL345_DEVID 0xE5 + +#define ADXL345_FIFO_CTL_SAMLPES (x) (0x1f & (x)) +#define ADXL345_FIFO_CTL_TRIGGER (x) (0x20 & ((x) << 5))/* 0: INT1, 1: INT2 */ +#define ADXL345_FIFO_CTL_MODE (x) (0xc0 & ((x) << 6)) +#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2) +#define ADXL345_INT_WATERMARK BIT(1) +#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 + +/* +* BW_RATE bits - Bandwidth and output data rate. The default value is +* 0x0A, which translates to a 100 Hz output data rate +*/ #define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4)#define ADXL345_BASE_RATE_NANO_HZ 97656250LL -#define ADXL345_POWER_CTL_MEASURE BIT(3)#define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2) +#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5)#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0)/* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2)/* Left-justified (MSB) mode */ +#define ADXL345_DATA_FORMAT_IS_LEFT_JUSTIFIED BIT(2)#define ADXL345_DATA_FORMAT_FULL_RES BIT(3)/* Up to 13-bits resolution */ -#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6)/* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)/* Enable a self test */ - +#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)#define ADXL345_DATA_FORMAT_2G 0#define ADXL345_DATA_FORMAT_4G 1#define ADXL345_DATA_FORMAT_8G 2#define ADXL345_DATA_FORMAT_16G 3 -#define ADXL345_DEVID 0xE5 +#define ADXL345_REG_OFS_AXIS (index) (ADXL345_REG_OFSX + (index)) + +/* +* FIFO stores a maximum of 32 entries, which equates to a maximum of 33 entries +* available at any given time because an additional entry is available at the +* output filter of the device. +* +* (see datasheet FIFO_STATUS description on "Entries Bits") +*/ +#define ADXL345_FIFO_SIZE 33/* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB
Signature · 1 line
2.39.5
PATCH v3 6/10 dt-bindings: iio: accel: add interrupt-names
In reply to Lothar RubuschAdd interrupt-names INT1 and INT2 for the two interrupt lines of the sensor. Only one line will be connected for incoming events. The driver needs to be configured accordingly. If no interrupt line is set up, the sensor will still measure, but no events are possible.
--- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +13 -0
@@ -37,6 +37,17 @@ properties: interrupts: maxItems: 1 + interrupt-names: + Data ready is only available on INT1, but events can use either or + both pins. If not specified, first element assumed to correspond + to INT1 and second (where present) to INT2. + minItems: 1 + maxItems: 2 + items: + enum: + - INT1 + - INT2 + required: - compatible - reg
@@ -61,6 +72,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - |
@@ -79,5 +91,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; };
Signature · 1 line
2.39.5
Rob Herring (Arm)
maintainerRe: [PATCH v3 06/10] dt-bindings: iio: accel: add interrupt-names
Quoted 10 lines · Lothar Rubusch
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor. Only one line will be connected for incoming events. The driver needs to be configured accordingly. If no interrupt line is set up, the sensor will still measure, but no events are possible.
Signed-off-by Lothar Rubusch <[email protected]>--- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: ignoring, error in schema: properties: maxItems
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties:minItems: 1 is not of type 'object', 'boolean'
from schema $id: http://json-schema.org/draft-07/schema#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties:maxItems: 2 is not of type 'object', 'boolean'
from schema $id: http://json-schema.org/draft-07/schema#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties:interrupt-names: 'Data ready is only available on INT1, but events can use either or both pins. If not specified, first element assumed to correspond to INT1 and second (where present) to INT2.' is not of type 'object', 'boolean'
from schema $id: http://json-schema.org/draft-07/schema#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties: 'minItems' should not be valid under {'$ref': '#/definitions/json-schema-prop-names'}
hint: A json-schema keyword was found instead of a DT property name.
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties: 'maxItems' should not be valid under {'$ref': '#/definitions/json-schema-prop-names'}
hint: A json-schema keyword was found instead of a DT property name.
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties: 'items' should not be valid under {'$ref': '#/definitions/json-schema-prop-names'}
hint: A json-schema keyword was found instead of a DT property name.
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties:minItems: 1 is not of type 'object', 'boolean'
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties:maxItems: 2 is not of type 'object', 'boolean'
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml: properties:interrupt-names: 'Data ready is only available on INT1, but events can use either or both pins. If not specified, first element assumed to correspond to INT1 and second (where present) to INT2.' is not of type 'object', 'boolean'
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#Documentation/devicetree/bindings/iio/accel/adi,adxl345.example.dtb: /example-0/i2c/accelerometer@2a: failed to match any schema with compatible: ['adi,adxl345']Documentation/devicetree/bindings/iio/accel/adi,adxl345.example.dtb: /example-1/spi/accelerometer@0: failed to match any schema with compatible: ['adi,adxl345']
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v3 06/10] dt-bindings: iio: accel: add interrupt-names
In reply to Lothar RubuschQuoted 15 lines · Lothar Rubusch
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor. Only one line will be connected for incoming events. The driver needs to be configured accordingly. If no interrupt line is set up, the sensor will still measure, but no events are possible.
Signed-off-by Lothar Rubusch <[email protected]>--- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+)Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +0
-0
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml properties: · line 45
Quoted 9 lines
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +6
-0@@ -37,6 +37,17 @@ properties: interrupts: maxItems: 1 + interrupt-names: + Data ready is only available on INT1, but events can use either or + both pins. If not specified, first element assumed to correspond + to INT1 and second (where present) to INT2. + minItems: 1 + maxItems: 2
This does not match your interrupts property.
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml properties: · line 49
Quoted 4 lines
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +4
-0+ items: + enum: + - INT1 + - INT2
Best regards,
Krzysztof
PATCH v3 7/10 iio: accel: adxl345: initialize IRQ number
In reply to Lothar RubuschAdd the possibility to claim an interrupt and init the state structure with interrupt number and interrupt line to use. The adxl345 can use two different interrupt lines, mainly to signal FIFO watermark events, single or double tap, activity, etc. Hence, having the interrupt line available is crucial to implement such features.
--- drivers/iio/accel/adxl345_core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/iio/accel/adxl345_core.c +14 -0
@@ -11,6 +11,7 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/units.h> +#include <linux/interrupt.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -18,8 +19,10 @@#include "adxl345.h" struct adxl345_state { +int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +u8 intio; };#define ADXL345_CHANNEL (index, axis) { \
@@ -212,6 +215,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st =iio_priv (indio_dev); st->regmap = regmap; + + st->intio =-1 ; + st->irq =fwnode_irq_get_byname (dev_fwnode (dev),"INT1" ); +if (st->irq >0 ) + st->intio =ADXL345_INT1 ; +else { + st->irq =fwnode_irq_get_byname (dev_fwnode (dev),"INT2" ); +if (st->irq >0 ) + st->intio =ADXL345_INT2 ; + } + st->info =device_get_match_data (dev);if (!st->info)return -ENODEV ;
Signature · 1 line
2.39.5
PATCH v3 8/10 iio: accel: adxl345: initialize FIFO delay value for SPI
In reply to Lothar RubuschAdd the possibility to delay FIFO access when SPI is used. According to the datasheet this is needed for the adxl345. When initialization happens over SPI the need for delay is to be signalized, and the delay will be used.
--- drivers/iio/accel/adxl345.h | 1 + drivers/iio/accel/adxl345_core.c | 12 ++++++++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +++++-- 4 files changed, 19 insertions(+), 3 deletions(-)
drivers/iio/accel/adxl345.h +1 -0
@@ -127,6 +127,7 @@ struct adxl345_chip_info { };int adxl345_core_probe (struct device *dev,struct regmap *regmap, +bool fifo_delay_default,int (*setup)(struct device *,struct regmap *));#endif /* _ADXL345_H_ */
drivers/iio/accel/adxl345_core.c +12 -0
@@ -22,6 +22,7 @@ struct adxl345_state {int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +bool fifo_delay;/* delay: delay is needed for SPI */ u8 intio; };
@@ -193,12 +194,21 @@ static const struct iio_info adxl345_info = {* adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device +* @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * +* For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS +* pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient. +* The total delay necessary for 5 MHz operation is at most 3.4 us. This is not +* a concern when using I2C mode because the communication rate is low enough +* to ensure a sufficient delay between FIFO reads. +* Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G +* * Return: 0 on success, negative errno on error */ int adxl345_core_probe (struct device *dev,struct regmap *regmap, +bool fifo_delay_default,int (*setup)(struct device *,struct regmap *)) {struct adxl345_state *st;
@@ -230,6 +240,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,if (!st->info)return -ENODEV ; + st->fifo_delay = fifo_delay_default; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes =INDIO_DIRECT_MODE ;
drivers/iio/accel/adxl345_i2c.c +1 -1
@@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client)if (IS_ERR (regmap))return dev_err_probe (&client->dev,PTR_ERR (regmap),"Error initializing regmap\n" ); -return adxl345_core_probe (&client->dev, regmap,NULL ); +return adxl345_core_probe (&client->dev, regmap, false,NULL ); }static const struct adxl345_chip_info adxl345_i2c_info = {
drivers/iio/accel/adxl345_spi.c +5 -2
@@ -12,6 +12,7 @@#include "adxl345.h" #define ADXL345_MAX_SPI_FREQ_HZ 5000000 +#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000static const struct regmap_config adxl345_spi_regmap_config = { .reg_bits =8 ,
@@ -28,6 +29,7 @@ static int adxl345_spi_setup(struct device *dev, struct regmap *regmap)static int adxl345_spi_probe (struct spi_device *spi) {struct regmap *regmap; +bool needs_delay;/* Bail out if max_speed_hz exceeds 5 MHz */ if (spi->max_speed_hz >ADXL345_MAX_SPI_FREQ_HZ )
@@ -38,10 +40,11 @@ static int adxl345_spi_probe(struct spi_device *spi)if (IS_ERR (regmap))return dev_err_probe (&spi->dev,PTR_ERR (regmap),"Error initializing regmap\n" ); + needs_delay = (spi->max_speed_hz >ADXL345_MAX_FREQ_NO_FIFO_DELAY );if (spi->mode &SPI_3WIRE ) -return adxl345_core_probe (&spi->dev, regmap, adxl345_spi_setup); +return adxl345_core_probe (&spi->dev, regmap, needs_delay, adxl345_spi_setup);else -return adxl345_core_probe (&spi->dev, regmap,NULL ); +return adxl345_core_probe (&spi->dev, regmap, needs_delay,NULL ); }static const struct adxl345_chip_info adxl345_spi_info = {
Signature · 1 line
2.39.5
PATCH v3 9/10 iio: accel: adxl345: prepare channel for scan_index
In reply to Lothar RubuschAdd separate fields for register and index to the channel definition. The scan_index is set up with the kfifo in the follow up patches.
--- drivers/iio/accel/adxl345_core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/iio/accel/adxl345_core.c +10 -5
@@ -26,21 +26,26 @@ struct adxl345_state {u8 intio; }; -#define ADXL345_CHANNEL (index, axis) { \ +#define ADXL345_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ - .address = index, \ + .address = (reg), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = (index), \ } +enum adxl345_chans { + chan_x, chan_y, chan_z, +}; +static const struct iio_chan_spec adxl345_channels[] = { -ADXL345_CHANNEL (0 ,X ), -ADXL345_CHANNEL (1 ,Y ), -ADXL345_CHANNEL (2 ,Z ), +ADXL345_CHANNEL (0 , chan_x,X ), +ADXL345_CHANNEL (1 , chan_y,Y ), +ADXL345_CHANNEL (2 , chan_z,Z ), }; static int adxl345_read_raw(struct iio_dev *indio_dev,
Signature · 1 line
2.39.5
PATCH v3 10/10 iio: accel: adxl345: add kfifo with watermark
In reply to Lothar RubuschAdd a basic setup for kfifo with configurable watermark, add a handler for watermark interrupt events and extend the channel for the scan_index needed for the kfifo. The sensor is configurable to use a FIFO_BYPASSED mode or a FIFO_STREAM mode. For the FIFO_STREAM mode a watermark can be configured, or disabled by setting 0. Further features are based on the FIFO setup.
--- drivers/iio/accel/adxl345_core.c | 300 +++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+)
drivers/iio/accel/adxl345_core.c +300 -0
@@ -15,15 +15,28 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> +#include <linux/iio/buffer.h> +#include <linux/iio/events.h> +#include <linux/iio/kfifo_buf.h> #include "adxl345.h" +#define ADXL345_FIFO_BYPASS 0 +#define ADXL345_FIFO_FIFO 1 +#define ADXL345_FIFO_STREAM 2 + +#define ADXL345_DIRS 3 +struct adxl345_state {int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +__le16 fifo_buf[ADXL345_DIRS *ADXL345_FIFO_SIZE ];bool fifo_delay;/* delay: delay is needed for SPI */ u8 intio; +u8 int_map; +u8 watermark; +u8 fifo_mode; };#define ADXL345_CHANNEL (index, reg, axis) { \
@@ -36,6 +49,13 @@ struct adxl345_state { .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index = (index), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 13, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_LE, \ + }, \ }enum adxl345_chans {
@@ -48,6 +68,25 @@ static const struct iio_chan_spec adxl345_channels[] = { ADXL345_CHANNEL(2, chan_z, Z), }; +static int adxl345_set_interrupts (struct adxl345_state *st) +{ +int ret; +unsigned int int_enable = st->int_map; +unsigned int int_map; + +/* Any bits set to 0 in the INT map register send their respective +* interrupts to the INT1 pin, whereas bits set to 1 send their respective +* interrupts to the INT2 pin. The intio shall convert this accordingly. +*/ + int_map =0xFF & (st->intio ? st->int_map : ~st->int_map); + + ret =regmap_write (st->regmap,ADXL345_REG_INT_MAP , int_map); +if (ret) +return ret; + +return regmap_write (st->regmap,ADXL345_REG_INT_ENABLE , int_enable); +} +static int adxl345_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)
@@ -133,6 +172,31 @@ static int adxl345_write_raw(struct iio_dev *indio_dev,return -EINVAL ; } +static int adxl345_set_watermark (struct iio_dev *indio_dev,unsigned int value) +{ +struct adxl345_state *st =iio_priv (indio_dev); +unsigned int fifo_mask =0x1F ; +int ret; + +if (value ==0 ) { + st->int_map &= ~ADXL345_INT_WATERMARK ; +return 0 ; + } + +if (value >ADXL345_FIFO_SIZE ) + value =ADXL345_FIFO_SIZE ; + + ret =regmap_update_bits (st->regmap,ADXL345_REG_FIFO_CTL , + fifo_mask, value); +if (ret) +return ret; + + st->watermark = value; + st->int_map |=ADXL345_INT_WATERMARK ; + +return 0 ; +} +static int adxl345_write_raw_get_fmt (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,long mask)
@@ -188,11 +252,224 @@ static const struct attribute_group adxl345_attrs_group = { .attrs = adxl345_attrs, }; +static int adxl345_set_fifo (struct adxl345_state *st) +{ +u8 fifo_ctl; +int ret; + +/* FIFO should only be configured while in standby mode */ + ret =adxl345_set_measure_en (st, false); +if (ret <0 ) +return ret; + + fifo_ctl =ADXL345_FIFO_CTL_SAMLPES (st->watermark) | +ADXL345_FIFO_CTL_TRIGGER (st->intio) | +ADXL345_FIFO_CTL_MODE (st->fifo_mode); + + ret =regmap_write (st->regmap,ADXL345_REG_FIFO_CTL , fifo_ctl); +if (ret <0 ) +return ret; + +return adxl345_set_measure_en (st, true); +} + +/** +* adxl345_get_samples() - Read number of FIFO entries. +* @st: The initialized state instance of this driver. +* +* The sensor does not support treating any axis individually, or exclude them +* from measuring. +* +* Return: negative error, or value. +*/ +static int adxl345_get_samples (struct adxl345_state *st) +{ +unsigned int regval =0 ; +int ret; + + ret =regmap_read (st->regmap,ADXL345_REG_FIFO_STATUS , ®val); +if (ret <0 ) +return ret; + +return 0x3f & regval; +} + +/** +* adxl345_fifo_transfer() - Read samples number of elements. +* @st: The instance of the state object of this sensor. +* @samples: The number of lines in the FIFO referred to as fifo_entry, +* a fifo_entry has 3 elements for X, Y and Z direction of 2 bytes each. +* +* It is recommended that a multiple-byte read of all registers be performed to +* prevent a change in data between reads of sequential registers. That is to +* read out the data registers X0, X1, Y0, Y1, Z0, Z1 at once. +* +* Return: 0 or error value. +*/ +static int adxl345_fifo_transfer (struct adxl345_state *st,int samples) +{ +size_t count; +int i, ret; + + count =sizeof (st->fifo_buf[0 ]) *ADXL345_DIRS ; +for (i =0 ; i < samples; i++) { + ret =regmap_noinc_read (st->regmap,ADXL345_REG_XYZ_BASE , + st->fifo_buf + (i * count /2 ), count); +if (ret <0 ) +return ret; + } +return ret; +} + +/** +* adxl345_fifo_reset() - Empty the FIFO in error condition. +* @st: The instance to the state object of the sensor. +* +* Read all elements of the FIFO. Reading the interrupt source register +* resets the sensor. +*/ +static void adxl345_fifo_reset (struct adxl345_state *st) +{ +int regval; +int samples; + +adxl345_set_measure_en (st, false); + + samples =adxl345_get_samples (st); +if (samples >0 ) +adxl345_fifo_transfer (st, samples); + +regmap_read (st->regmap,ADXL345_REG_INT_SOURCE , ®val); + +adxl345_set_measure_en (st, true); +} + +static int adxl345_buffer_postenable (struct iio_dev *indio_dev) +{ +struct adxl345_state *st =iio_priv (indio_dev); +int ret; + + ret =adxl345_set_interrupts (st); +if (ret <0 ) +return ret; + + st->fifo_mode =ADXL345_FIFO_STREAM ; +return adxl345_set_fifo (st); +} + +static int adxl345_buffer_predisable (struct iio_dev *indio_dev) +{ +struct adxl345_state *st =iio_priv (indio_dev); +int ret; + + st->int_map =0x00 ; + + ret =adxl345_set_interrupts (st); +if (ret <0 ) +return ret; + + st->fifo_mode =ADXL345_FIFO_BYPASS ; +return adxl345_set_fifo (st); +} + +static const struct iio_buffer_setup_ops adxl345_buffer_ops = { + .postenable = adxl345_buffer_postenable, + .predisable = adxl345_buffer_predisable, +}; + +static int adxl345_get_status (struct adxl345_state *st) +{ +int ret; +unsigned int regval; + + ret =regmap_read (st->regmap,ADXL345_REG_INT_SOURCE , ®val); +if (ret <0 ) +return ret; + +return (0xff & regval); +} + +static int adxl345_fifo_push (struct iio_dev *indio_dev, +int samples) +{ +struct adxl345_state *st =iio_priv (indio_dev); +int i, ret; + +if (samples <=0 ) +return -EINVAL ; + + ret =adxl345_fifo_transfer (st, samples); +if (ret) +return ret; + +for (i =0 ; i <ADXL345_DIRS * samples; i +=ADXL345_DIRS ) { +/* +* To ensure that the FIFO has completely popped, there must be at least 5 +* us between the end of reading the data registers, signified by the +* transition to register 0x38 from 0x37 or the CS pin going high, and the +* start of new reads of the FIFO or reading the FIFO_STATUS register. For +* SPI operation at 1.5 MHz or lower, the register addressing portion of the +* transmission is sufficient delay to ensure the FIFO has completely +* popped. It is necessary for SPI operation greater than 1.5 MHz to +* de-assert the CS pin to ensure a total of 5 us, which is at most 3.4 us +* at 5 MHz operation. +*/ +if (st->fifo_delay && (samples >1 )) +udelay (3 ); + +iio_push_to_buffers (indio_dev, &st->fifo_buf[i]); + } + +return 0 ; +} + +/** +* irqreturn_t adxl345_event_handler() - Handle events of the ADXL345. +* @irq: The irq being handled. +* @p: The struct iio_device pointer for the device. +* +* Return: The interrupt was handled. +*/ +static irqreturn_t adxl345_event_handler (int irq,void *p) +{ +struct iio_dev *indio_dev = p; +struct adxl345_state *st =iio_priv (indio_dev); +u8 int_stat; +int samples; + + int_stat =adxl345_get_status (st); +if (int_stat <0 ) +return IRQ_NONE ; + +if (int_stat ==0x0 ) + goto err; + +if (int_stat &ADXL345_INT_OVERRUN ) + goto err; + +if (int_stat & (ADXL345_INT_DATA_READY |ADXL345_INT_WATERMARK )) { + samples =adxl345_get_samples (st); +if (samples <0 ) + goto err; + +if (adxl345_fifo_push (indio_dev, samples) <0 ) + goto err; + + } +return IRQ_HANDLED ; + +err: +adxl345_fifo_reset (st); + +return IRQ_HANDLED ; +} +static const struct iio_info adxl345_info = { .attrs = &adxl345_attrs_group, .read_raw = adxl345_read_raw, .write_raw = adxl345_write_raw, .write_raw_get_fmt = adxl345_write_raw_get_fmt, + .hwfifo_set_watermark = adxl345_set_watermark, };/**
@@ -222,6 +499,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE |ADXL345_DATA_FORMAT_FULL_RES |ADXL345_DATA_FORMAT_SELF_TEST ); +u8 fifo_ctl;int ret; indio_dev =devm_iio_device_alloc (dev,sizeof (*st));
@@ -293,6 +571,28 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,if (ret <0 )return dev_err_probe (dev, ret,"Failed to add action or reset\n" ); +if (st->irq >0 ) { +dev_dbg (dev,"initialize for FIFO_STREAM mode\n" ); + + ret =devm_iio_kfifo_buffer_setup (dev, indio_dev, &adxl345_buffer_ops); +if (ret) +return ret; + + ret =devm_request_threaded_irq (dev, st->irq,NULL , &adxl345_event_handler, +IRQF_SHARED |IRQF_ONESHOT , + indio_dev->name, indio_dev); +if (ret) +return dev_err_probe (dev, ret,"Failed to setup triggered buffer\n" ); + + }else { +dev_dbg (dev,"initialize for FIFO_BYPASS mode (fallback)\n" ); + + fifo_ctl =ADXL345_FIFO_CTL_MODE (ADXL345_FIFO_BYPASS ); + + ret =regmap_write (st->regmap,ADXL345_REG_FIFO_CTL , fifo_ctl); +if (ret <0 ) +return ret; + }return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_NS_GPL (adxl345_core_probe,"IIO_ADXL345" );
Signature · 1 line
2.39.5
kernel test robot
build botRe: [PATCH v3 10/10] iio: accel: adxl345: add kfifo with watermark
kernel test robot noticed the following build warnings:
Hi Lothar,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.13-rc1 next-20241203]
[cannot apply to jic23-iio/togreg v6.13-rc1 v6.12 v6.12-rc7 next-20241128] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Lothar-Rubusch/iio-accel-adxl345-fix-comment-on-probe/20241204-121629 base: linus/master patch link: https://lore.kernel.org/r/20241203205241.48077-11-l.rubusch%40gmail.com patch subject: [PATCH v3 10/10] iio: accel: adxl345: add kfifo with watermark config: i386-buildonly-randconfig-004 (https://download.01.org/0day-ci/archive/20241204/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241204/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/iio/accel/adxl345_core.c:434: warning: expecting prototype for irqreturn_t adxl345_event_handler()(). Prototype was for adxl345_event_handler() instead
vim +434 drivers/iio/accel/adxl345_core.c
425
426 /**
427 * irqreturn_t adxl345_event_handler() - Handle events of the ADXL345.
428 * @irq: The irq being handled.
429 * @p: The struct iio_device pointer for the device.
430 *
431 * Return: The interrupt was handled.
432 */
433 static irqreturn_t adxl345_event_handler(int irq, void *p)
> 434 { 435 struct iio_dev *indio_dev = p;
436 struct adxl345_state *st = iio_priv(indio_dev);
437 u8 int_stat;
438 int samples;
439
440 int_stat = adxl345_get_status(st);
441 if (int_stat < 0)
442 return IRQ_NONE;
443
444 if (int_stat == 0x0)
445 goto err;
446
447 if (int_stat & ADXL345_INT_OVERRUN)
448 goto err;
449
450 if (int_stat & (ADXL345_INT_DATA_READY | ADXL345_INT_WATERMARK)) {
451 samples = adxl345_get_samples(st);
452 if (samples < 0)
453 goto err;
454
455 if (adxl345_fifo_push(indio_dev, samples) < 0)
456 goto err;
457
458 }
459 return IRQ_HANDLED;
460
461 err:
462 adxl345_fifo_reset(st);
463
464 return IRQ_HANDLED;
465 }
466
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki