Debian Codegraph @

drivers/iio/imu/bmi270/bmi270_i2c.c

raw
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/pm.h>
8 #include <linux/regmap.h>
9
10 #include "bmi270.h"
11
12 static const struct regmap_config bmi270_i2c_regmap_config = {
13 .reg_bits = 8,
14 .val_bits = 8,
15 };
16
17 static int bmi270_i2c_probe(struct i2c_client *client)
18 {
19 struct regmap *regmap;
20 struct device *dev = &client->dev;
21 const struct bmi270_chip_info *chip_info;
22
23 chip_info = i2c_get_match_data(client);
24 if (!chip_info)
25 return -ENODEV;
26
27 regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
28 if (IS_ERR(regmap))
29 return dev_err_probe(dev, PTR_ERR(regmap),
30 "Failed to init i2c regmap");
31
32 return bmi270_core_probe(dev, regmap, chip_info);
33 }
34
35 static const struct i2c_device_id bmi270_i2c_id[] = {
36 { "bmi260", (kernel_ulong_t)&bmi260_chip_info },
37 { "bmi270", (kernel_ulong_t)&bmi270_chip_info },
38 { }
39 };
40 MODULE_DEVICE_TABLE(i2c, bmi270_i2c_id);
41
42 static const struct acpi_device_id bmi270_acpi_match[] = {
43 /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */
44 { "BMI0160", (kernel_ulong_t)&bmi260_chip_info },
45 /* GPD Win Max 2 2023(sincice BIOS v0.40), etc. */
46 { "BMI0260", (kernel_ulong_t)&bmi260_chip_info },
47 { }
48 };
49 MODULE_DEVICE_TABLE(acpi, bmi270_acpi_match);
50
51 static const struct of_device_id bmi270_of_match[] = {
52 { .compatible = "bosch,bmi260", .data = &bmi260_chip_info },
53 { .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
54 { }
55 };
56 MODULE_DEVICE_TABLE(of, bmi270_of_match);
57
58 static struct i2c_driver bmi270_i2c_driver = {
59 .driver = {
60 .name = "bmi270_i2c",
61 .pm = pm_ptr(&bmi270_core_pm_ops),
62 .acpi_match_table = bmi270_acpi_match,
63 .of_match_table = bmi270_of_match,
64 },
65 .probe = bmi270_i2c_probe,
66 .id_table = bmi270_i2c_id,
67 };
68 module_i2c_driver(bmi270_i2c_driver);
69
70 MODULE_AUTHOR("Alex Lanzano");
71 MODULE_DESCRIPTION("BMI270 driver");
72 MODULE_LICENSE("GPL");
73 MODULE_IMPORT_NS("IIO_BMI270");