bmi160_i2c.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * BMI160 - Bosch IMU, I2C bits
  3. *
  4. * Copyright (c) 2016, Intel Corporation.
  5. *
  6. * This file is subject to the terms and conditions of version 2 of
  7. * the GNU General Public License. See the file COPYING in the main
  8. * directory of this archive for more details.
  9. *
  10. * 7-bit I2C slave address is:
  11. * - 0x68 if SDO is pulled to GND
  12. * - 0x69 if SDO is pulled to VDDIO
  13. */
  14. #include <linux/module.h>
  15. #include <linux/i2c.h>
  16. #include <linux/regmap.h>
  17. #include <linux/acpi.h>
  18. #include "bmi160.h"
  19. static int bmi160_i2c_probe(struct i2c_client *client,
  20. const struct i2c_device_id *id)
  21. {
  22. struct regmap *regmap;
  23. const char *name = NULL;
  24. regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
  25. if (IS_ERR(regmap)) {
  26. dev_err(&client->dev, "Failed to register i2c regmap %d\n",
  27. (int)PTR_ERR(regmap));
  28. return PTR_ERR(regmap);
  29. }
  30. if (id)
  31. name = id->name;
  32. return bmi160_core_probe(&client->dev, regmap, name, false);
  33. }
  34. static int bmi160_i2c_remove(struct i2c_client *client)
  35. {
  36. bmi160_core_remove(&client->dev);
  37. return 0;
  38. }
  39. static const struct i2c_device_id bmi160_i2c_id[] = {
  40. {"bmi160", 0},
  41. {}
  42. };
  43. MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id);
  44. static const struct acpi_device_id bmi160_acpi_match[] = {
  45. {"BMI0160", 0},
  46. { },
  47. };
  48. MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
  49. static struct i2c_driver bmi160_i2c_driver = {
  50. .driver = {
  51. .name = "bmi160_i2c",
  52. .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
  53. },
  54. .probe = bmi160_i2c_probe,
  55. .remove = bmi160_i2c_remove,
  56. .id_table = bmi160_i2c_id,
  57. };
  58. module_i2c_driver(bmi160_i2c_driver);
  59. MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
  60. MODULE_DESCRIPTION("BMI160 I2C driver");
  61. MODULE_LICENSE("GPL v2");