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