bmg160_i2c.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "bmg160.h"
  7. static const struct regmap_config bmg160_regmap_i2c_conf = {
  8. .reg_bits = 8,
  9. .val_bits = 8,
  10. .max_register = 0x3f
  11. };
  12. static int bmg160_i2c_probe(struct i2c_client *client,
  13. const struct i2c_device_id *id)
  14. {
  15. struct regmap *regmap;
  16. const char *name = NULL;
  17. regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
  18. if (IS_ERR(regmap)) {
  19. dev_err(&client->dev, "Failed to register i2c regmap %d\n",
  20. (int)PTR_ERR(regmap));
  21. return PTR_ERR(regmap);
  22. }
  23. if (id)
  24. name = id->name;
  25. return bmg160_core_probe(&client->dev, regmap, client->irq, name);
  26. }
  27. static int bmg160_i2c_remove(struct i2c_client *client)
  28. {
  29. bmg160_core_remove(&client->dev);
  30. return 0;
  31. }
  32. static const struct acpi_device_id bmg160_acpi_match[] = {
  33. {"BMG0160", 0},
  34. {"BMI055B", 0},
  35. {},
  36. };
  37. MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
  38. static const struct i2c_device_id bmg160_i2c_id[] = {
  39. {"bmg160", 0},
  40. {"bmi055_gyro", 0},
  41. {}
  42. };
  43. MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
  44. static struct i2c_driver bmg160_i2c_driver = {
  45. .driver = {
  46. .name = "bmg160_i2c",
  47. .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
  48. .pm = &bmg160_pm_ops,
  49. },
  50. .probe = bmg160_i2c_probe,
  51. .remove = bmg160_i2c_remove,
  52. .id_table = bmg160_i2c_id,
  53. };
  54. module_i2c_driver(bmg160_i2c_driver);
  55. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  56. MODULE_LICENSE("GPL v2");
  57. MODULE_DESCRIPTION("BMG160 I2C Gyro driver");