Skip to content

Commit af38b0f

Browse files
Rubuschjic23
authored andcommitted
iio: accel: adxl345: initialize FIFO delay value for SPI
Add 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. Signed-off-by: Lothar Rubusch <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent e2e6d24 commit af38b0f

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

drivers/iio/accel/adxl345.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct adxl345_chip_info {
6262
};
6363

6464
int adxl345_core_probe(struct device *dev, struct regmap *regmap,
65+
bool fifo_delay_default,
6566
int (*setup)(struct device*, struct regmap*));
6667

6768
#endif /* _ADXL345_H_ */

drivers/iio/accel/adxl345_core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
struct adxl345_state {
2626
const struct adxl345_chip_info *info;
2727
struct regmap *regmap;
28+
bool fifo_delay; /* delay: delay is needed for SPI */
2829
int irq;
2930
u8 intio;
3031
};
@@ -196,12 +197,21 @@ static const struct iio_info adxl345_info = {
196197
* adxl345_core_probe() - Probe and setup for the accelerometer.
197198
* @dev: Driver model representation of the device
198199
* @regmap: Regmap instance for the device
200+
* @fifo_delay_default: Using FIFO with SPI needs delay
199201
* @setup: Setup routine to be executed right before the standard device
200202
* setup
201203
*
204+
* For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS
205+
* pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient.
206+
* The total delay necessary for 5 MHz operation is at most 3.4 us. This is not
207+
* a concern when using I2C mode because the communication rate is low enough
208+
* to ensure a sufficient delay between FIFO reads.
209+
* Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G
210+
*
202211
* Return: 0 on success, negative errno on error
203212
*/
204213
int adxl345_core_probe(struct device *dev, struct regmap *regmap,
214+
bool fifo_delay_default,
205215
int (*setup)(struct device*, struct regmap*))
206216
{
207217
struct adxl345_state *st;
@@ -222,6 +232,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
222232
st->info = device_get_match_data(dev);
223233
if (!st->info)
224234
return -ENODEV;
235+
st->fifo_delay = fifo_delay_default;
225236

226237
indio_dev->name = st->info->name;
227238
indio_dev->info = &adxl345_info;

drivers/iio/accel/adxl345_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client)
2727
if (IS_ERR(regmap))
2828
return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
2929

30-
return adxl345_core_probe(&client->dev, regmap, NULL);
30+
return adxl345_core_probe(&client->dev, regmap, false, NULL);
3131
}
3232

3333
static const struct adxl345_chip_info adxl345_i2c_info = {

drivers/iio/accel/adxl345_spi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "adxl345.h"
1313

1414
#define ADXL345_MAX_SPI_FREQ_HZ 5000000
15+
#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000
1516

1617
static const struct regmap_config adxl345_spi_regmap_config = {
1718
.reg_bits = 8,
@@ -28,6 +29,7 @@ static int adxl345_spi_setup(struct device *dev, struct regmap *regmap)
2829
static int adxl345_spi_probe(struct spi_device *spi)
2930
{
3031
struct regmap *regmap;
32+
bool needs_delay;
3133

3234
/* Bail out if max_speed_hz exceeds 5 MHz */
3335
if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ)
@@ -38,10 +40,11 @@ static int adxl345_spi_probe(struct spi_device *spi)
3840
if (IS_ERR(regmap))
3941
return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n");
4042

43+
needs_delay = spi->max_speed_hz > ADXL345_MAX_FREQ_NO_FIFO_DELAY;
4144
if (spi->mode & SPI_3WIRE)
42-
return adxl345_core_probe(&spi->dev, regmap, adxl345_spi_setup);
45+
return adxl345_core_probe(&spi->dev, regmap, needs_delay, adxl345_spi_setup);
4346
else
44-
return adxl345_core_probe(&spi->dev, regmap, NULL);
47+
return adxl345_core_probe(&spi->dev, regmap, needs_delay, NULL);
4548
}
4649

4750
static const struct adxl345_chip_info adxl345_spi_info = {

0 commit comments

Comments
 (0)