blob: 8b03ea15c0d08c3602f97db80616bd228ba1a97c [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Walleij14e80152016-06-30 03:48:49 +02002#include <linux/module.h>
3#include <linux/i2c.h>
Linus Walleij14e80152016-06-30 03:48:49 +02004#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,
Linus Walleijaae95392016-06-30 03:48:52 +020035 id->name,
36 client->irq);
Linus Walleij14e80152016-06-30 03:48:49 +020037}
38
Linus Walleij14e80152016-06-30 03:48:49 +020039static 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);
Linus Walleij14e80152016-06-30 03:48:49 +020047
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",
Andy Shevchenkoae968592019-12-09 20:28:05 +020060 .of_match_table = bmp280_of_i2c_match,
Linus Walleij3d838112016-06-30 03:48:53 +020061 .pm = &bmp280_dev_pm_ops,
Linus Walleij14e80152016-06-30 03:48:49 +020062 },
63 .probe = bmp280_i2c_probe,
Linus Walleij14e80152016-06-30 03:48:49 +020064 .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");