1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 3 #include <linux/i2c.h> 4 #include <linux/iio/iio.h> 5 #include <linux/module.h> 6 #include <linux/mod_devicetable.h> 7 #include <linux/pm.h> 8 #include <linux/regmap.h> 9 10 #include "bmi270.h" 11 12 static const struct regmap_config bmi270_i2c_regmap_config = { 13 .reg_bits = 8, 14 .val_bits = 8, 15 }; 16 17 static int bmi270_i2c_probe(struct i2c_client *client) 18 { 19 struct regmap *regmap; 20 struct device *dev = &client->dev; 21 const struct bmi270_chip_info *chip_info; 22 23 chip_info = i2c_get_match_data(client); 24 if (!chip_info) 25 return -ENODEV; 26 27 regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config); 28 if (IS_ERR(regmap)) 29 return dev_err_probe(dev, PTR_ERR(regmap), 30 "Failed to init i2c regmap"); 31 32 return bmi270_core_probe(dev, regmap, chip_info); 33 } 34 35 static const struct i2c_device_id bmi270_i2c_id[] = { 36 { "bmi260", (kernel_ulong_t)&bmi260_chip_info }, 37 { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, 38 { } 39 }; 40 41 static const struct acpi_device_id bmi270_acpi_match[] = { 42 /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */ 43 { "BMI0160", (kernel_ulong_t)&bmi260_chip_info }, 44 { } 45 }; 46 47 static const struct of_device_id bmi270_of_match[] = { 48 { .compatible = "bosch,bmi260", .data = &bmi260_chip_info }, 49 { .compatible = "bosch,bmi270", .data = &bmi270_chip_info }, 50 { } 51 }; 52 53 static struct i2c_driver bmi270_i2c_driver = { 54 .driver = { 55 .name = "bmi270_i2c", 56 .pm = pm_ptr(&bmi270_core_pm_ops), 57 .acpi_match_table = bmi270_acpi_match, 58 .of_match_table = bmi270_of_match, 59 }, 60 .probe = bmi270_i2c_probe, 61 .id_table = bmi270_i2c_id, 62 }; 63 module_i2c_driver(bmi270_i2c_driver); 64 65 MODULE_AUTHOR("Alex Lanzano"); 66 MODULE_DESCRIPTION("BMI270 driver"); 67 MODULE_LICENSE("GPL"); 68 MODULE_IMPORT_NS("IIO_BMI270"); 69