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 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[] = { 4077c4ad2dSDaniel Baluta {"bmi160", 0}, 4177c4ad2dSDaniel Baluta {} 4277c4ad2dSDaniel Baluta }; 4377c4ad2dSDaniel Baluta MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id); 4477c4ad2dSDaniel Baluta 4577c4ad2dSDaniel Baluta static const struct acpi_device_id bmi160_acpi_match[] = { 46*ca2f16c3SJesus Gonzalez /* 47*ca2f16c3SJesus Gonzalez * FIRMWARE BUG WORKAROUND 48*ca2f16c3SJesus Gonzalez * Some manufacturers like GPD, Lenovo or Aya used the incorrect 49*ca2f16c3SJesus Gonzalez * ID "10EC5280" for bmi160 in their DSDT. A fixed firmware is not 50*ca2f16c3SJesus Gonzalez * available as of Feb 2024 after trying to work with OEMs, and 51*ca2f16c3SJesus Gonzalez * this is not expected to change anymore since at least some of 52*ca2f16c3SJesus Gonzalez * the affected devices are from 2021/2022. 53*ca2f16c3SJesus Gonzalez */ 54*ca2f16c3SJesus Gonzalez {"10EC5280", 0}, 5577c4ad2dSDaniel Baluta {"BMI0160", 0}, 5677c4ad2dSDaniel Baluta { }, 5777c4ad2dSDaniel Baluta }; 5877c4ad2dSDaniel Baluta MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 5977c4ad2dSDaniel Baluta 60968bdbf8SMarcin Niestroj static const struct of_device_id bmi160_of_match[] = { 61968bdbf8SMarcin Niestroj { .compatible = "bosch,bmi160" }, 62968bdbf8SMarcin Niestroj { }, 63968bdbf8SMarcin Niestroj }; 64968bdbf8SMarcin Niestroj MODULE_DEVICE_TABLE(of, bmi160_of_match); 65968bdbf8SMarcin Niestroj 6677c4ad2dSDaniel Baluta static struct i2c_driver bmi160_i2c_driver = { 6777c4ad2dSDaniel Baluta .driver = { 6877c4ad2dSDaniel Baluta .name = "bmi160_i2c", 695f474919SAndy Shevchenko .acpi_match_table = bmi160_acpi_match, 705f474919SAndy Shevchenko .of_match_table = bmi160_of_match, 7177c4ad2dSDaniel Baluta }, 727cf15f42SUwe Kleine-König .probe = bmi160_i2c_probe, 7377c4ad2dSDaniel Baluta .id_table = bmi160_i2c_id, 7477c4ad2dSDaniel Baluta }; 7577c4ad2dSDaniel Baluta module_i2c_driver(bmi160_i2c_driver); 7677c4ad2dSDaniel Baluta 7777c4ad2dSDaniel Baluta MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); 7877c4ad2dSDaniel Baluta MODULE_DESCRIPTION("BMI160 I2C driver"); 7977c4ad2dSDaniel Baluta MODULE_LICENSE("GPL v2"); 802a8efd8bSJonathan Cameron MODULE_IMPORT_NS(IIO_BMI160); 81