xref: /openbmc/linux/drivers/iio/gyro/bmg160_i2c.c (revision 99a15348)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/i2c.h>
3 #include <linux/regmap.h>
4 #include <linux/iio/iio.h>
5 #include <linux/module.h>
6 #include <linux/acpi.h>
7 
8 #include "bmg160.h"
9 
10 static const struct regmap_config bmg160_regmap_i2c_conf = {
11 	.reg_bits = 8,
12 	.val_bits = 8,
13 	.max_register = 0x3f
14 };
15 
16 static int bmg160_i2c_probe(struct i2c_client *client,
17 			    const struct i2c_device_id *id)
18 {
19 	struct regmap *regmap;
20 	const char *name = NULL;
21 
22 	regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
23 	if (IS_ERR(regmap)) {
24 		dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
25 			regmap);
26 		return PTR_ERR(regmap);
27 	}
28 
29 	if (id)
30 		name = id->name;
31 
32 	return bmg160_core_probe(&client->dev, regmap, client->irq, name);
33 }
34 
35 static int bmg160_i2c_remove(struct i2c_client *client)
36 {
37 	bmg160_core_remove(&client->dev);
38 
39 	return 0;
40 }
41 
42 static const struct acpi_device_id bmg160_acpi_match[] = {
43 	{"BMG0160", 0},
44 	{"BMI055B", 0},
45 	{"BMI088B", 0},
46 	{},
47 };
48 
49 MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
50 
51 static const struct i2c_device_id bmg160_i2c_id[] = {
52 	{"bmg160", 0},
53 	{"bmi055_gyro", 0},
54 	{"bmi088_gyro", 0},
55 	{}
56 };
57 
58 MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
59 
60 static const struct of_device_id bmg160_of_match[] = {
61 	{ .compatible = "bosch,bmg160" },
62 	{ .compatible = "bosch,bmi055_gyro" },
63 	{ }
64 };
65 
66 MODULE_DEVICE_TABLE(of, bmg160_of_match);
67 
68 static struct i2c_driver bmg160_i2c_driver = {
69 	.driver = {
70 		.name	= "bmg160_i2c",
71 		.acpi_match_table = ACPI_PTR(bmg160_acpi_match),
72 		.of_match_table = bmg160_of_match,
73 		.pm	= &bmg160_pm_ops,
74 	},
75 	.probe		= bmg160_i2c_probe,
76 	.remove		= bmg160_i2c_remove,
77 	.id_table	= bmg160_i2c_id,
78 };
79 module_i2c_driver(bmg160_i2c_driver);
80 
81 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
82 MODULE_LICENSE("GPL v2");
83 MODULE_DESCRIPTION("BMG160 I2C Gyro driver");
84