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 /* GPD Win Max 2 2023(sincice BIOS v0.40), etc. */ 45 { "BMI0260", (kernel_ulong_t)&bmi260_chip_info }, 46 { } 47 }; 48 49 static const struct of_device_id bmi270_of_match[] = { 50 { .compatible = "bosch,bmi260", .data = &bmi260_chip_info }, 51 { .compatible = "bosch,bmi270", .data = &bmi270_chip_info }, 52 { } 53 }; 54 55 static struct i2c_driver bmi270_i2c_driver = { 56 .driver = { 57 .name = "bmi270_i2c", 58 .pm = pm_ptr(&bmi270_core_pm_ops), 59 .acpi_match_table = bmi270_acpi_match, 60 .of_match_table = bmi270_of_match, 61 }, 62 .probe = bmi270_i2c_probe, 63 .id_table = bmi270_i2c_id, 64 }; 65 module_i2c_driver(bmi270_i2c_driver); 66 67 MODULE_AUTHOR("Alex Lanzano"); 68 MODULE_DESCRIPTION("BMI270 driver"); 69 MODULE_LICENSE("GPL"); 70 MODULE_IMPORT_NS("IIO_BMI270"); 71