xref: /linux/drivers/iio/imu/bmi270/bmi270_i2c.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 
3 #include <linux/i2c.h>
4 #include <linux/iio/iio.h>
5 #include <linux/module.h>
6 #include <linux/mod_devicetable.h>
7 #include <linux/regmap.h>
8 
9 #include "bmi270.h"
10 
11 static const struct regmap_config bmi270_i2c_regmap_config = {
12 	.reg_bits = 8,
13 	.val_bits = 8,
14 };
15 
16 static int bmi270_i2c_probe(struct i2c_client *client)
17 {
18 	struct regmap *regmap;
19 	struct device *dev = &client->dev;
20 	const struct bmi270_chip_info *chip_info;
21 
22 	chip_info = i2c_get_match_data(client);
23 	if (!chip_info)
24 		return -ENODEV;
25 
26 	regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
27 	if (IS_ERR(regmap))
28 		return dev_err_probe(dev, PTR_ERR(regmap),
29 				     "Failed to init i2c regmap");
30 
31 	return bmi270_core_probe(dev, regmap, chip_info);
32 }
33 
34 static const struct i2c_device_id bmi270_i2c_id[] = {
35 	{ "bmi260", (kernel_ulong_t)&bmi260_chip_info },
36 	{ "bmi270", (kernel_ulong_t)&bmi270_chip_info },
37 	{ }
38 };
39 
40 static const struct acpi_device_id bmi270_acpi_match[] = {
41 	/* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */
42 	{ "BMI0160",  (kernel_ulong_t)&bmi260_chip_info },
43 	{ }
44 };
45 
46 static const struct of_device_id bmi270_of_match[] = {
47 	{ .compatible = "bosch,bmi260", .data = &bmi260_chip_info },
48 	{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
49 	{ }
50 };
51 
52 static struct i2c_driver bmi270_i2c_driver = {
53 	.driver = {
54 		.name = "bmi270_i2c",
55 		.acpi_match_table = bmi270_acpi_match,
56 		.of_match_table = bmi270_of_match,
57 	},
58 	.probe = bmi270_i2c_probe,
59 	.id_table = bmi270_i2c_id,
60 };
61 module_i2c_driver(bmi270_i2c_driver);
62 
63 MODULE_AUTHOR("Alex Lanzano");
64 MODULE_DESCRIPTION("BMI270 driver");
65 MODULE_LICENSE("GPL");
66 MODULE_IMPORT_NS(IIO_BMI270);
67