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