xref: /linux/drivers/iio/gyro/bmg160_i2c.c (revision b58b13f156c00c2457035b7071eaaac105fe6836)
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/mod_devicetable.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 {
18 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
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 void bmg160_i2c_remove(struct i2c_client *client)
36 {
37 	bmg160_core_remove(&client->dev);
38 }
39 
40 static const struct acpi_device_id bmg160_acpi_match[] = {
41 	{"BMG0160", 0},
42 	{"BMI055B", 0},
43 	{"BMI088B", 0},
44 	{},
45 };
46 
47 MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
48 
49 static const struct i2c_device_id bmg160_i2c_id[] = {
50 	{"bmg160", 0},
51 	{"bmi055_gyro", 0},
52 	{"bmi088_gyro", 0},
53 	{}
54 };
55 
56 MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
57 
58 static const struct of_device_id bmg160_of_match[] = {
59 	{ .compatible = "bosch,bmg160" },
60 	{ .compatible = "bosch,bmi055_gyro" },
61 	{ }
62 };
63 
64 MODULE_DEVICE_TABLE(of, bmg160_of_match);
65 
66 static struct i2c_driver bmg160_i2c_driver = {
67 	.driver = {
68 		.name	= "bmg160_i2c",
69 		.acpi_match_table = bmg160_acpi_match,
70 		.of_match_table = bmg160_of_match,
71 		.pm	= &bmg160_pm_ops,
72 	},
73 	.probe		= bmg160_i2c_probe,
74 	.remove		= bmg160_i2c_remove,
75 	.id_table	= bmg160_i2c_id,
76 };
77 module_i2c_driver(bmg160_i2c_driver);
78 
79 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
80 MODULE_LICENSE("GPL v2");
81 MODULE_DESCRIPTION("BMG160 I2C Gyro driver");
82