bmp280-i2c.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <linux/module.h>
  2. #include <linux/i2c.h>
  3. #include <linux/acpi.h>
  4. #include <linux/of.h>
  5. #include <linux/regmap.h>
  6. #include "bmp280.h"
  7. static int bmp280_i2c_probe(struct i2c_client *client,
  8. const struct i2c_device_id *id)
  9. {
  10. struct regmap *regmap;
  11. const struct regmap_config *regmap_config;
  12. switch (id->driver_data) {
  13. case BMP180_CHIP_ID:
  14. regmap_config = &bmp180_regmap_config;
  15. break;
  16. case BMP280_CHIP_ID:
  17. case BME280_CHIP_ID:
  18. regmap_config = &bmp280_regmap_config;
  19. break;
  20. default:
  21. return -EINVAL;
  22. }
  23. regmap = devm_regmap_init_i2c(client, regmap_config);
  24. if (IS_ERR(regmap)) {
  25. dev_err(&client->dev, "failed to allocate register map\n");
  26. return PTR_ERR(regmap);
  27. }
  28. return bmp280_common_probe(&client->dev,
  29. regmap,
  30. id->driver_data,
  31. id->name,
  32. client->irq);
  33. }
  34. static int bmp280_i2c_remove(struct i2c_client *client)
  35. {
  36. return bmp280_common_remove(&client->dev);
  37. }
  38. static const struct acpi_device_id bmp280_acpi_i2c_match[] = {
  39. {"BMP0280", BMP280_CHIP_ID },
  40. {"BMP0180", BMP180_CHIP_ID },
  41. {"BMP0085", BMP180_CHIP_ID },
  42. {"BME0280", BME280_CHIP_ID },
  43. { },
  44. };
  45. MODULE_DEVICE_TABLE(acpi, bmp280_acpi_i2c_match);
  46. #ifdef CONFIG_OF
  47. static const struct of_device_id bmp280_of_i2c_match[] = {
  48. { .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID },
  49. { .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID },
  50. { .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID },
  51. { .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID },
  52. { },
  53. };
  54. MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
  55. #else
  56. #define bmp280_of_i2c_match NULL
  57. #endif
  58. static const struct i2c_device_id bmp280_i2c_id[] = {
  59. {"bmp280", BMP280_CHIP_ID },
  60. {"bmp180", BMP180_CHIP_ID },
  61. {"bmp085", BMP180_CHIP_ID },
  62. {"bme280", BME280_CHIP_ID },
  63. { },
  64. };
  65. MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
  66. static struct i2c_driver bmp280_i2c_driver = {
  67. .driver = {
  68. .name = "bmp280",
  69. .acpi_match_table = ACPI_PTR(bmp280_acpi_i2c_match),
  70. .of_match_table = of_match_ptr(bmp280_of_i2c_match),
  71. .pm = &bmp280_dev_pm_ops,
  72. },
  73. .probe = bmp280_i2c_probe,
  74. .remove = bmp280_i2c_remove,
  75. .id_table = bmp280_i2c_id,
  76. };
  77. module_i2c_driver(bmp280_i2c_driver);
  78. MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
  79. MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
  80. MODULE_LICENSE("GPL v2");