1 #include <linux/i2c.h> 2 #include <linux/regmap.h> 3 #include <linux/iio/iio.h> 4 #include <linux/module.h> 5 #include <linux/acpi.h> 6 7 #include "bmg160.h" 8 9 static const struct regmap_config bmg160_regmap_i2c_conf = { 10 .reg_bits = 8, 11 .val_bits = 8, 12 .max_register = 0x3f 13 }; 14 15 static int bmg160_i2c_probe(struct i2c_client *client, 16 const struct i2c_device_id *id) 17 { 18 struct regmap *regmap; 19 const char *name = NULL; 20 21 regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf); 22 if (IS_ERR(regmap)) { 23 dev_err(&client->dev, "Failed to register i2c regmap %d\n", 24 (int)PTR_ERR(regmap)); 25 return PTR_ERR(regmap); 26 } 27 28 if (id) 29 name = id->name; 30 31 return bmg160_core_probe(&client->dev, regmap, client->irq, name); 32 } 33 34 static int bmg160_i2c_remove(struct i2c_client *client) 35 { 36 bmg160_core_remove(&client->dev); 37 38 return 0; 39 } 40 41 static const struct acpi_device_id bmg160_acpi_match[] = { 42 {"BMG0160", 0}, 43 {"BMI055B", 0}, 44 {}, 45 }; 46 47 MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match); 48 49 static const struct i2c_device_id bmg160_i2c_id[] = { 50 {"bmg160", 0}, 51 {"bmi055_gyro", 0}, 52 {} 53 }; 54 55 MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id); 56 57 static const struct of_device_id bmg160_of_match[] = { 58 { .compatible = "bosch,bmg160" }, 59 { .compatible = "bosch,bmi055_gyro" }, 60 { } 61 }; 62 63 MODULE_DEVICE_TABLE(of, bmg160_of_match); 64 65 static struct i2c_driver bmg160_i2c_driver = { 66 .driver = { 67 .name = "bmg160_i2c", 68 .acpi_match_table = ACPI_PTR(bmg160_acpi_match), 69 .of_match_table = bmg160_of_match, 70 .pm = &bmg160_pm_ops, 71 }, 72 .probe = bmg160_i2c_probe, 73 .remove = bmg160_i2c_remove, 74 .id_table = bmg160_i2c_id, 75 }; 76 module_i2c_driver(bmg160_i2c_driver); 77 78 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 79 MODULE_LICENSE("GPL v2"); 80 MODULE_DESCRIPTION("BMG160 I2C Gyro driver"); 81