114e8015fSLinus Walleij #include <linux/module.h>
214e8015fSLinus Walleij #include <linux/i2c.h>
314e8015fSLinus Walleij #include <linux/acpi.h>
414e8015fSLinus Walleij #include <linux/of.h>
514e8015fSLinus Walleij #include <linux/regmap.h>
614e8015fSLinus Walleij 
714e8015fSLinus Walleij #include "bmp280.h"
814e8015fSLinus Walleij 
914e8015fSLinus Walleij static int bmp280_i2c_probe(struct i2c_client *client,
1014e8015fSLinus Walleij 			    const struct i2c_device_id *id)
1114e8015fSLinus Walleij {
1214e8015fSLinus Walleij 	struct regmap *regmap;
1314e8015fSLinus Walleij 	const struct regmap_config *regmap_config;
1414e8015fSLinus Walleij 
1514e8015fSLinus Walleij 	switch (id->driver_data) {
1614e8015fSLinus Walleij 	case BMP180_CHIP_ID:
1714e8015fSLinus Walleij 		regmap_config = &bmp180_regmap_config;
1814e8015fSLinus Walleij 		break;
1914e8015fSLinus Walleij 	case BMP280_CHIP_ID:
2014e8015fSLinus Walleij 	case BME280_CHIP_ID:
2114e8015fSLinus Walleij 		regmap_config = &bmp280_regmap_config;
2214e8015fSLinus Walleij 		break;
2314e8015fSLinus Walleij 	default:
2414e8015fSLinus Walleij 		return -EINVAL;
2514e8015fSLinus Walleij 	}
2614e8015fSLinus Walleij 
2714e8015fSLinus Walleij 	regmap = devm_regmap_init_i2c(client, regmap_config);
2814e8015fSLinus Walleij 	if (IS_ERR(regmap)) {
2914e8015fSLinus Walleij 		dev_err(&client->dev, "failed to allocate register map\n");
3014e8015fSLinus Walleij 		return PTR_ERR(regmap);
3114e8015fSLinus Walleij 	}
3214e8015fSLinus Walleij 
3314e8015fSLinus Walleij 	return bmp280_common_probe(&client->dev,
3414e8015fSLinus Walleij 				   regmap,
3514e8015fSLinus Walleij 				   id->driver_data,
36aae95394SLinus Walleij 				   id->name,
37aae95394SLinus Walleij 				   client->irq);
3814e8015fSLinus Walleij }
3914e8015fSLinus Walleij 
4014e8015fSLinus Walleij static int bmp280_i2c_remove(struct i2c_client *client)
4114e8015fSLinus Walleij {
4214e8015fSLinus Walleij 	return bmp280_common_remove(&client->dev);
4314e8015fSLinus Walleij }
4414e8015fSLinus Walleij 
4514e8015fSLinus Walleij static const struct acpi_device_id bmp280_acpi_i2c_match[] = {
4614e8015fSLinus Walleij 	{"BMP0280", BMP280_CHIP_ID },
4714e8015fSLinus Walleij 	{"BMP0180", BMP180_CHIP_ID },
4814e8015fSLinus Walleij 	{"BMP0085", BMP180_CHIP_ID },
4914e8015fSLinus Walleij 	{"BME0280", BME280_CHIP_ID },
5014e8015fSLinus Walleij 	{ },
5114e8015fSLinus Walleij };
5214e8015fSLinus Walleij MODULE_DEVICE_TABLE(acpi, bmp280_acpi_i2c_match);
5314e8015fSLinus Walleij 
5414e8015fSLinus Walleij #ifdef CONFIG_OF
5514e8015fSLinus Walleij static const struct of_device_id bmp280_of_i2c_match[] = {
5614e8015fSLinus Walleij 	{ .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID },
5714e8015fSLinus Walleij 	{ .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID },
5814e8015fSLinus Walleij 	{ .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID },
5914e8015fSLinus Walleij 	{ .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID },
6014e8015fSLinus Walleij 	{ },
6114e8015fSLinus Walleij };
6214e8015fSLinus Walleij MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
6314e8015fSLinus Walleij #else
6414e8015fSLinus Walleij #define bmp280_of_i2c_match NULL
6514e8015fSLinus Walleij #endif
6614e8015fSLinus Walleij 
6714e8015fSLinus Walleij static const struct i2c_device_id bmp280_i2c_id[] = {
6814e8015fSLinus Walleij 	{"bmp280", BMP280_CHIP_ID },
6914e8015fSLinus Walleij 	{"bmp180", BMP180_CHIP_ID },
7014e8015fSLinus Walleij 	{"bmp085", BMP180_CHIP_ID },
7114e8015fSLinus Walleij 	{"bme280", BME280_CHIP_ID },
7214e8015fSLinus Walleij 	{ },
7314e8015fSLinus Walleij };
7414e8015fSLinus Walleij MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
7514e8015fSLinus Walleij 
7614e8015fSLinus Walleij static struct i2c_driver bmp280_i2c_driver = {
7714e8015fSLinus Walleij 	.driver = {
7814e8015fSLinus Walleij 		.name	= "bmp280",
7914e8015fSLinus Walleij 		.acpi_match_table = ACPI_PTR(bmp280_acpi_i2c_match),
8014e8015fSLinus Walleij 		.of_match_table = of_match_ptr(bmp280_of_i2c_match),
813d838118SLinus Walleij 		.pm = &bmp280_dev_pm_ops,
8214e8015fSLinus Walleij 	},
8314e8015fSLinus Walleij 	.probe		= bmp280_i2c_probe,
8414e8015fSLinus Walleij 	.remove		= bmp280_i2c_remove,
8514e8015fSLinus Walleij 	.id_table	= bmp280_i2c_id,
8614e8015fSLinus Walleij };
8714e8015fSLinus Walleij module_i2c_driver(bmp280_i2c_driver);
8814e8015fSLinus Walleij 
8914e8015fSLinus Walleij MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
9014e8015fSLinus Walleij MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
9114e8015fSLinus Walleij MODULE_LICENSE("GPL v2");
92