bmi160_i2c.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/acpi.h>
  15. #include <linux/i2c.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/regmap.h>
  19. #include "bmi160.h"
  20. static int bmi160_i2c_probe(struct i2c_client *client,
  21. const struct i2c_device_id *id)
  22. {
  23. struct regmap *regmap;
  24. const char *name = NULL;
  25. regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
  26. if (IS_ERR(regmap)) {
  27. dev_err(&client->dev, "Failed to register i2c regmap %d\n",
  28. (int)PTR_ERR(regmap));
  29. return PTR_ERR(regmap);
  30. }
  31. if (id)
  32. name = id->name;
  33. return bmi160_core_probe(&client->dev, regmap, name, false);
  34. }
  35. static int bmi160_i2c_remove(struct i2c_client *client)
  36. {
  37. bmi160_core_remove(&client->dev);
  38. return 0;
  39. }
  40. static const struct i2c_device_id bmi160_i2c_id[] = {
  41. {"bmi160", 0},
  42. {}
  43. };
  44. MODULE_DEVICE_TABLE(i2c, bmi160_i2c_id);
  45. static const struct acpi_device_id bmi160_acpi_match[] = {
  46. {"BMI0160", 0},
  47. { },
  48. };
  49. MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
  50. #ifdef CONFIG_OF
  51. static const struct of_device_id bmi160_of_match[] = {
  52. { .compatible = "bosch,bmi160" },
  53. { },
  54. };
  55. MODULE_DEVICE_TABLE(of, bmi160_of_match);
  56. #endif
  57. static struct i2c_driver bmi160_i2c_driver = {
  58. .driver = {
  59. .name = "bmi160_i2c",
  60. .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
  61. .of_match_table = of_match_ptr(bmi160_of_match),
  62. },
  63. .probe = bmi160_i2c_probe,
  64. .remove = bmi160_i2c_remove,
  65. .id_table = bmi160_i2c_id,
  66. };
  67. module_i2c_driver(bmi160_i2c_driver);
  68. MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
  69. MODULE_DESCRIPTION("BMI160 I2C driver");
  70. MODULE_LICENSE("GPL v2");