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