xref: /linux/drivers/iio/imu/bmi160/bmi160_i2c.c (revision 0d5ec7919f3747193f051036b2301734a4b5e1d6)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * BMI160 - Bosch IMU, I2C bits
4  *
5  * Copyright (c) 2016, Intel Corporation.
6  *
7  * 7-bit I2C slave address is:
8  *      - 0x68 if SDO is pulled to GND
9  *      - 0x69 if SDO is pulled to VDDIO
10  */
11 #include <linux/i2c.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/module.h>
14 #include <linux/pm.h>
15 #include <linux/regmap.h>
16 
17 #include "bmi160.h"
18 
bmi160_i2c_probe(struct i2c_client * client)19 static int bmi160_i2c_probe(struct i2c_client *client)
20 {
21 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
22 	struct regmap *regmap;
23 	const char *name;
24 
25 	regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
26 	if (IS_ERR(regmap)) {
27 		dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
28 			regmap);
29 		return PTR_ERR(regmap);
30 	}
31 
32 	if (id)
33 		name = id->name;
34 	else
35 		name = dev_name(&client->dev);
36 
37 	return bmi160_core_probe(&client->dev, regmap, name, false);
38 }
39 
40 static const struct i2c_device_id bmi160_i2c_id[] = {
41 	{ "bmi120" },
42 	{ "bmi160" },
43 	{ }
44 };
45 MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id);
46 
47 static const struct acpi_device_id bmi160_acpi_match[] = {
48 	/*
49 	 * FIRMWARE BUG WORKAROUND
50 	 * Some manufacturers like GPD, Lenovo or Aya used the incorrect
51 	 * ID "10EC5280" for bmi160 in their DSDT. A fixed firmware is not
52 	 * available as of Feb 2024 after trying to work with OEMs, and
53 	 * this is not expected to change anymore since at least some of
54 	 * the affected devices are from 2021/2022.
55 	 */
56 	{"10EC5280", 0},
57 	{"BMI0120", 0},
58 	{"BMI0160", 0},
59 	{ }
60 };
61 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
62 
63 static const struct of_device_id bmi160_of_match[] = {
64 	{ .compatible = "bosch,bmi120" },
65 	{ .compatible = "bosch,bmi160" },
66 	{ }
67 };
68 MODULE_DEVICE_TABLE(of, bmi160_of_match);
69 
70 static struct i2c_driver bmi160_i2c_driver = {
71 	.driver = {
72 		.name			= "bmi160_i2c",
73 		.pm			= pm_ptr(&bmi160_core_pm_ops),
74 		.acpi_match_table	= bmi160_acpi_match,
75 		.of_match_table		= bmi160_of_match,
76 	},
77 	.probe		= bmi160_i2c_probe,
78 	.id_table	= bmi160_i2c_id,
79 };
80 module_i2c_driver(bmi160_i2c_driver);
81 
82 MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
83 MODULE_DESCRIPTION("BMI160 I2C driver");
84 MODULE_LICENSE("GPL v2");
85 MODULE_IMPORT_NS("IIO_BMI160");
86