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