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