1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
3 #include <linux/iio/iio.h>
4 #include <linux/mod_devicetable.h>
5 #include <linux/module.h>
6 #include <linux/regmap.h>
7 #include <linux/spi/spi.h>
12 * The following two functions are taken from the BMI323 spi driver code.
13 * In section 6.4 of the BMI270 data it specifies that after a read
14 * operation the first data byte from the device is a dummy byte
16 static int bmi270_regmap_spi_read(void *spi
, const void *reg_buf
,
17 size_t reg_size
, void *val_buf
,
20 return spi_write_then_read(spi
, reg_buf
, reg_size
, val_buf
, val_size
);
23 static int bmi270_regmap_spi_write(void *spi
, const void *data
,
26 u8
*data_buff
= (u8
*)data
;
29 * Remove the extra pad byte since its only needed for the read
32 data_buff
[1] = data_buff
[0];
33 return spi_write_then_read(spi
, data_buff
+ 1, count
- 1, NULL
, 0);
36 static const struct regmap_bus bmi270_regmap_bus
= {
37 .read
= bmi270_regmap_spi_read
,
38 .write
= bmi270_regmap_spi_write
,
41 static const struct regmap_config bmi270_spi_regmap_config
= {
45 .read_flag_mask
= BIT(7),
48 static int bmi270_spi_probe(struct spi_device
*spi
)
50 struct regmap
*regmap
;
51 struct device
*dev
= &spi
->dev
;
52 const struct bmi270_chip_info
*chip_info
;
54 chip_info
= spi_get_device_match_data(spi
);
58 regmap
= devm_regmap_init(dev
, &bmi270_regmap_bus
, dev
,
59 &bmi270_spi_regmap_config
);
61 return dev_err_probe(dev
, PTR_ERR(regmap
),
62 "Failed to init i2c regmap");
64 return bmi270_core_probe(dev
, regmap
, chip_info
);
67 static const struct spi_device_id bmi270_spi_id
[] = {
68 { "bmi260", (kernel_ulong_t
)&bmi260_chip_info
},
69 { "bmi270", (kernel_ulong_t
)&bmi270_chip_info
},
73 static const struct of_device_id bmi270_of_match
[] = {
74 { .compatible
= "bosch,bmi260", .data
= &bmi260_chip_info
},
75 { .compatible
= "bosch,bmi270", .data
= &bmi270_chip_info
},
79 static struct spi_driver bmi270_spi_driver
= {
82 .of_match_table
= bmi270_of_match
,
84 .probe
= bmi270_spi_probe
,
85 .id_table
= bmi270_spi_id
,
87 module_spi_driver(bmi270_spi_driver
);
89 MODULE_AUTHOR("Alex Lanzano");
90 MODULE_DESCRIPTION("BMI270 driver");
91 MODULE_LICENSE("GPL");
92 MODULE_IMPORT_NS("IIO_BMI270");