bme680_i2c.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * BME680 - I2C Driver
  4. *
  5. * Copyright (C) 2018 Himanshu Jha <[email protected]>
  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/i2c.h>
  15. #include <linux/module.h>
  16. #include <linux/regmap.h>
  17. #include "bme680.h"
  18. static int bme680_i2c_probe(struct i2c_client *client,
  19. const struct i2c_device_id *id)
  20. {
  21. struct regmap *regmap;
  22. const char *name = NULL;
  23. regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
  24. if (IS_ERR(regmap)) {
  25. dev_err(&client->dev, "Failed to register i2c regmap %ld\n", PTR_ERR(regmap));
  26. return PTR_ERR(regmap);
  27. }
  28. if (id)
  29. name = id->name;
  30. return bme680_core_probe(&client->dev, regmap, name);
  31. }
  32. static const struct i2c_device_id bme680_i2c_id[] = {
  33. {"bme680", 0},
  34. {},
  35. };
  36. MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
  37. static const struct of_device_id bme680_of_i2c_match[] = {
  38. { .compatible = "bosch,bme680", },
  39. {},
  40. };
  41. MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
  42. static struct i2c_driver bme680_i2c_driver = {
  43. .driver = {
  44. .name = "bme680_i2c",
  45. .of_match_table = bme680_of_i2c_match,
  46. },
  47. .probe = bme680_i2c_probe,
  48. .id_table = bme680_i2c_id,
  49. };
  50. module_i2c_driver(bme680_i2c_driver);
  51. MODULE_AUTHOR("Himanshu Jha <[email protected]>");
  52. MODULE_DESCRIPTION("BME680 I2C driver");
  53. MODULE_LICENSE("GPL v2");
  54. MODULE_IMPORT_NS(IIO_BME680);