xref: /linux/drivers/iio/imu/bmi160/bmi160_i2c.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
137402329SMartin Kelly // SPDX-License-Identifier: GPL-2.0
277c4ad2dSDaniel Baluta /*
377c4ad2dSDaniel Baluta  * BMI160 - Bosch IMU, I2C bits
477c4ad2dSDaniel Baluta  *
577c4ad2dSDaniel Baluta  * Copyright (c) 2016, Intel Corporation.
677c4ad2dSDaniel Baluta  *
777c4ad2dSDaniel Baluta  * 7-bit I2C slave address is:
877c4ad2dSDaniel Baluta  *      - 0x68 if SDO is pulled to GND
977c4ad2dSDaniel Baluta  *      - 0x69 if SDO is pulled to VDDIO
1077c4ad2dSDaniel Baluta  */
11968bdbf8SMarcin Niestroj #include <linux/i2c.h>
125f474919SAndy Shevchenko #include <linux/mod_devicetable.h>
13968bdbf8SMarcin Niestroj #include <linux/module.h>
14968bdbf8SMarcin Niestroj #include <linux/regmap.h>
1577c4ad2dSDaniel Baluta 
1677c4ad2dSDaniel Baluta #include "bmi160.h"
1777c4ad2dSDaniel Baluta 
bmi160_i2c_probe(struct i2c_client * client)1897202c55SUwe Kleine-König static int bmi160_i2c_probe(struct i2c_client *client)
1977c4ad2dSDaniel Baluta {
2097202c55SUwe Kleine-König 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
2177c4ad2dSDaniel Baluta 	struct regmap *regmap;
225f474919SAndy Shevchenko 	const char *name;
2377c4ad2dSDaniel Baluta 
2477c4ad2dSDaniel Baluta 	regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
2577c4ad2dSDaniel Baluta 	if (IS_ERR(regmap)) {
266e924c52SNishant Malpani 		dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
276e924c52SNishant Malpani 			regmap);
2877c4ad2dSDaniel Baluta 		return PTR_ERR(regmap);
2977c4ad2dSDaniel Baluta 	}
3077c4ad2dSDaniel Baluta 
3177c4ad2dSDaniel Baluta 	if (id)
3277c4ad2dSDaniel Baluta 		name = id->name;
335f474919SAndy Shevchenko 	else
345f474919SAndy Shevchenko 		name = dev_name(&client->dev);
3577c4ad2dSDaniel Baluta 
3677c4ad2dSDaniel Baluta 	return bmi160_core_probe(&client->dev, regmap, name, false);
3777c4ad2dSDaniel Baluta }
3877c4ad2dSDaniel Baluta 
3977c4ad2dSDaniel Baluta static const struct i2c_device_id bmi160_i2c_id[] = {
40*4391affaSUwe Kleine-König 	{ "bmi120" },
41*4391affaSUwe Kleine-König 	{ "bmi160" },
4277c4ad2dSDaniel Baluta 	{}
4377c4ad2dSDaniel Baluta };
4477c4ad2dSDaniel Baluta MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id);
4577c4ad2dSDaniel Baluta 
4677c4ad2dSDaniel Baluta static const struct acpi_device_id bmi160_acpi_match[] = {
47ca2f16c3SJesus Gonzalez 	/*
48ca2f16c3SJesus Gonzalez 	 * FIRMWARE BUG WORKAROUND
49ca2f16c3SJesus Gonzalez 	 * Some manufacturers like GPD, Lenovo or Aya used the incorrect
50ca2f16c3SJesus Gonzalez 	 * ID "10EC5280" for bmi160 in their DSDT. A fixed firmware is not
51ca2f16c3SJesus Gonzalez 	 * available as of Feb 2024 after trying to work with OEMs, and
52ca2f16c3SJesus Gonzalez 	 * this is not expected to change anymore since at least some of
53ca2f16c3SJesus Gonzalez 	 * the affected devices are from 2021/2022.
54ca2f16c3SJesus Gonzalez 	 */
55ca2f16c3SJesus Gonzalez 	{"10EC5280", 0},
56cedb9bd8SDanila Tikhonov 	{"BMI0120", 0},
5777c4ad2dSDaniel Baluta 	{"BMI0160", 0},
5877c4ad2dSDaniel Baluta 	{ },
5977c4ad2dSDaniel Baluta };
6077c4ad2dSDaniel Baluta MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
6177c4ad2dSDaniel Baluta 
62968bdbf8SMarcin Niestroj static const struct of_device_id bmi160_of_match[] = {
63cedb9bd8SDanila Tikhonov 	{ .compatible = "bosch,bmi120" },
64968bdbf8SMarcin Niestroj 	{ .compatible = "bosch,bmi160" },
65968bdbf8SMarcin Niestroj 	{ },
66968bdbf8SMarcin Niestroj };
67968bdbf8SMarcin Niestroj MODULE_DEVICE_TABLE(of, bmi160_of_match);
68968bdbf8SMarcin Niestroj 
6977c4ad2dSDaniel Baluta static struct i2c_driver bmi160_i2c_driver = {
7077c4ad2dSDaniel Baluta 	.driver = {
7177c4ad2dSDaniel Baluta 		.name			= "bmi160_i2c",
725f474919SAndy Shevchenko 		.acpi_match_table	= bmi160_acpi_match,
735f474919SAndy Shevchenko 		.of_match_table		= bmi160_of_match,
7477c4ad2dSDaniel Baluta 	},
757cf15f42SUwe Kleine-König 	.probe		= bmi160_i2c_probe,
7677c4ad2dSDaniel Baluta 	.id_table	= bmi160_i2c_id,
7777c4ad2dSDaniel Baluta };
7877c4ad2dSDaniel Baluta module_i2c_driver(bmi160_i2c_driver);
7977c4ad2dSDaniel Baluta 
8077c4ad2dSDaniel Baluta MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
8177c4ad2dSDaniel Baluta MODULE_DESCRIPTION("BMI160 I2C driver");
8277c4ad2dSDaniel Baluta MODULE_LICENSE("GPL v2");
832a8efd8bSJonathan Cameron MODULE_IMPORT_NS(IIO_BMI160);
84