bmp280-i2c.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/module.h>
  3. #include <linux/i2c.h>
  4. #include <linux/regmap.h>
  5. #include "bmp280.h"
  6. static int bmp280_i2c_probe(struct i2c_client *client,
  7. const struct i2c_device_id *id)
  8. {
  9. struct regmap *regmap;
  10. const struct regmap_config *regmap_config;
  11. switch (id->driver_data) {
  12. case BMP180_CHIP_ID:
  13. regmap_config = &bmp180_regmap_config;
  14. break;
  15. case BMP280_CHIP_ID:
  16. case BME280_CHIP_ID:
  17. regmap_config = &bmp280_regmap_config;
  18. break;
  19. case BMP380_CHIP_ID:
  20. regmap_config = &bmp380_regmap_config;
  21. break;
  22. default:
  23. return -EINVAL;
  24. }
  25. regmap = devm_regmap_init_i2c(client, regmap_config);
  26. if (IS_ERR(regmap)) {
  27. dev_err(&client->dev, "failed to allocate register map\n");
  28. return PTR_ERR(regmap);
  29. }
  30. return bmp280_common_probe(&client->dev,
  31. regmap,
  32. id->driver_data,
  33. id->name,
  34. client->irq);
  35. }
  36. static const struct of_device_id bmp280_of_i2c_match[] = {
  37. { .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID },
  38. { .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID },
  39. { .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID },
  40. { .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID },
  41. { .compatible = "bosch,bmp380", .data = (void *)BMP380_CHIP_ID },
  42. { },
  43. };
  44. MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
  45. static const struct i2c_device_id bmp280_i2c_id[] = {
  46. {"bmp085", BMP180_CHIP_ID },
  47. {"bmp180", BMP180_CHIP_ID },
  48. {"bmp280", BMP280_CHIP_ID },
  49. {"bme280", BME280_CHIP_ID },
  50. {"bmp380", BMP380_CHIP_ID },
  51. { },
  52. };
  53. MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
  54. static struct i2c_driver bmp280_i2c_driver = {
  55. .driver = {
  56. .name = "bmp280",
  57. .of_match_table = bmp280_of_i2c_match,
  58. .pm = pm_ptr(&bmp280_dev_pm_ops),
  59. },
  60. .probe = bmp280_i2c_probe,
  61. .id_table = bmp280_i2c_id,
  62. };
  63. module_i2c_driver(bmp280_i2c_driver);
  64. MODULE_AUTHOR("Vlad Dogaru <[email protected]>");
  65. MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
  66. MODULE_LICENSE("GPL v2");
  67. MODULE_IMPORT_NS(IIO_BMP280);