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