drm/panel-edp: Add BOE NV140FHM-NZ panel entry
[drm/drm-misc.git] / drivers / iio / imu / bmi270 / bmi270_spi.c
blob88a77aba5e4f7d6f36d508a6490ff79ffcf2d5df
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>
9 #include "bmi270.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,
18 size_t val_size)
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,
24 size_t count)
26 u8 *data_buff = (u8 *)data;
29 * Remove the extra pad byte since its only needed for the read
30 * operation
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 = {
42 .reg_bits = 8,
43 .val_bits = 8,
44 .pad_bits = 8,
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);
55 if (!chip_info)
56 return -ENODEV;
58 regmap = devm_regmap_init(dev, &bmi270_regmap_bus, dev,
59 &bmi270_spi_regmap_config);
60 if (IS_ERR(regmap))
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 },
70 { }
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 },
76 { }
79 static struct spi_driver bmi270_spi_driver = {
80 .driver = {
81 .name = "bmi270",
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");