1*37402329SMartin 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 */ 1177c4ad2dSDaniel Baluta #include <linux/acpi.h> 12968bdbf8SMarcin Niestroj #include <linux/i2c.h> 13968bdbf8SMarcin Niestroj #include <linux/module.h> 14968bdbf8SMarcin Niestroj #include <linux/of.h> 15968bdbf8SMarcin Niestroj #include <linux/regmap.h> 1677c4ad2dSDaniel Baluta 1777c4ad2dSDaniel Baluta #include "bmi160.h" 1877c4ad2dSDaniel Baluta 1977c4ad2dSDaniel Baluta static int bmi160_i2c_probe(struct i2c_client *client, 2077c4ad2dSDaniel Baluta const struct i2c_device_id *id) 2177c4ad2dSDaniel Baluta { 2277c4ad2dSDaniel Baluta struct regmap *regmap; 2377c4ad2dSDaniel Baluta const char *name = NULL; 2477c4ad2dSDaniel Baluta 2577c4ad2dSDaniel Baluta regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config); 2677c4ad2dSDaniel Baluta if (IS_ERR(regmap)) { 2777c4ad2dSDaniel Baluta dev_err(&client->dev, "Failed to register i2c regmap %d\n", 2877c4ad2dSDaniel Baluta (int)PTR_ERR(regmap)); 2977c4ad2dSDaniel Baluta return PTR_ERR(regmap); 3077c4ad2dSDaniel Baluta } 3177c4ad2dSDaniel Baluta 3277c4ad2dSDaniel Baluta if (id) 3377c4ad2dSDaniel Baluta name = id->name; 3477c4ad2dSDaniel Baluta 3577c4ad2dSDaniel Baluta return bmi160_core_probe(&client->dev, regmap, name, false); 3677c4ad2dSDaniel Baluta } 3777c4ad2dSDaniel Baluta 3877c4ad2dSDaniel Baluta static const struct i2c_device_id bmi160_i2c_id[] = { 3977c4ad2dSDaniel Baluta {"bmi160", 0}, 4077c4ad2dSDaniel Baluta {} 4177c4ad2dSDaniel Baluta }; 4277c4ad2dSDaniel Baluta MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id); 4377c4ad2dSDaniel Baluta 4477c4ad2dSDaniel Baluta static const struct acpi_device_id bmi160_acpi_match[] = { 4577c4ad2dSDaniel Baluta {"BMI0160", 0}, 4677c4ad2dSDaniel Baluta { }, 4777c4ad2dSDaniel Baluta }; 4877c4ad2dSDaniel Baluta MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 4977c4ad2dSDaniel Baluta 50968bdbf8SMarcin Niestroj #ifdef CONFIG_OF 51968bdbf8SMarcin Niestroj static const struct of_device_id bmi160_of_match[] = { 52968bdbf8SMarcin Niestroj { .compatible = "bosch,bmi160" }, 53968bdbf8SMarcin Niestroj { }, 54968bdbf8SMarcin Niestroj }; 55968bdbf8SMarcin Niestroj MODULE_DEVICE_TABLE(of, bmi160_of_match); 56968bdbf8SMarcin Niestroj #endif 57968bdbf8SMarcin Niestroj 5877c4ad2dSDaniel Baluta static struct i2c_driver bmi160_i2c_driver = { 5977c4ad2dSDaniel Baluta .driver = { 6077c4ad2dSDaniel Baluta .name = "bmi160_i2c", 6177c4ad2dSDaniel Baluta .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 62968bdbf8SMarcin Niestroj .of_match_table = of_match_ptr(bmi160_of_match), 6377c4ad2dSDaniel Baluta }, 6477c4ad2dSDaniel Baluta .probe = bmi160_i2c_probe, 6577c4ad2dSDaniel Baluta .id_table = bmi160_i2c_id, 6677c4ad2dSDaniel Baluta }; 6777c4ad2dSDaniel Baluta module_i2c_driver(bmi160_i2c_driver); 6877c4ad2dSDaniel Baluta 6977c4ad2dSDaniel Baluta MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>"); 7077c4ad2dSDaniel Baluta MODULE_DESCRIPTION("BMI160 I2C driver"); 7177c4ad2dSDaniel Baluta MODULE_LICENSE("GPL v2"); 72