bme680_i2c.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * BME680 - I2C Driver
  4. *
  5. * Copyright (C) 2018 Himanshu Jha <himanshujha199640@gmail.com>
  6. *
  7. * 7-Bit I2C slave address is:
  8. * - 0x76 if SDO is pulled to GND
  9. * - 0x77 if SDO is pulled to VDDIO
  10. *
  11. * Note: SDO pin cannot be left floating otherwise I2C address
  12. * will be undefined.
  13. */
  14. #include <linux/acpi.h>
  15. #include <linux/i2c.h>
  16. #include <linux/module.h>
  17. #include <linux/regmap.h>
  18. #include "bme680.h"
  19. static int bme680_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, &bme680_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 bme680_core_probe(&client->dev, regmap, name);
  33. }
  34. static const struct i2c_device_id bme680_i2c_id[] = {
  35. {"bme680", 0},
  36. {},
  37. };
  38. MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
  39. static const struct acpi_device_id bme680_acpi_match[] = {
  40. {"BME0680", 0},
  41. {},
  42. };
  43. MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
  44. static const struct of_device_id bme680_of_i2c_match[] = {
  45. { .compatible = "bosch,bme680", },
  46. {},
  47. };
  48. MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
  49. static struct i2c_driver bme680_i2c_driver = {
  50. .driver = {
  51. .name = "bme680_i2c",
  52. .acpi_match_table = ACPI_PTR(bme680_acpi_match),
  53. .of_match_table = bme680_of_i2c_match,
  54. },
  55. .probe = bme680_i2c_probe,
  56. .id_table = bme680_i2c_id,
  57. };
  58. module_i2c_driver(bme680_i2c_driver);
  59. MODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>");
  60. MODULE_DESCRIPTION("BME680 I2C driver");
  61. MODULE_LICENSE("GPL v2");