Linux 4.19.133
[linux/fpc-iii.git] / drivers / iio / imu / bmi160 / bmi160_i2c.c
blob155a31f72445832d2d8d5f5d92bc71bba5323418
1 /*
2 * BMI160 - Bosch IMU, I2C bits
4 * Copyright (c) 2016, Intel Corporation.
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
10 * 7-bit I2C slave address is:
11 * - 0x68 if SDO is pulled to GND
12 * - 0x69 if SDO is pulled to VDDIO
14 #include <linux/acpi.h>
15 #include <linux/i2c.h>
16 #include <linux/module.h>
17 #include <linux/of.h>
18 #include <linux/regmap.h>
20 #include "bmi160.h"
22 static int bmi160_i2c_probe(struct i2c_client *client,
23 const struct i2c_device_id *id)
25 struct regmap *regmap;
26 const char *name = NULL;
28 regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
29 if (IS_ERR(regmap)) {
30 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
31 (int)PTR_ERR(regmap));
32 return PTR_ERR(regmap);
35 if (id)
36 name = id->name;
38 return bmi160_core_probe(&client->dev, regmap, name, false);
41 static int bmi160_i2c_remove(struct i2c_client *client)
43 bmi160_core_remove(&client->dev);
45 return 0;
48 static const struct i2c_device_id bmi160_i2c_id[] = {
49 {"bmi160", 0},
52 MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id);
54 static const struct acpi_device_id bmi160_acpi_match[] = {
55 {"BMI0160", 0},
56 { },
58 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
60 #ifdef CONFIG_OF
61 static const struct of_device_id bmi160_of_match[] = {
62 { .compatible = "bosch,bmi160" },
63 { },
65 MODULE_DEVICE_TABLE(of, bmi160_of_match);
66 #endif
68 static struct i2c_driver bmi160_i2c_driver = {
69 .driver = {
70 .name = "bmi160_i2c",
71 .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
72 .of_match_table = of_match_ptr(bmi160_of_match),
74 .probe = bmi160_i2c_probe,
75 .remove = bmi160_i2c_remove,
76 .id_table = bmi160_i2c_id,
78 module_i2c_driver(bmi160_i2c_driver);
80 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
81 MODULE_DESCRIPTION("BMI160 I2C driver");
82 MODULE_LICENSE("GPL v2");