109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
214e8015fSLinus Walleij #include <linux/module.h>
314e8015fSLinus Walleij #include <linux/i2c.h>
414e8015fSLinus Walleij #include <linux/regmap.h>
514e8015fSLinus Walleij 
614e8015fSLinus Walleij #include "bmp280.h"
714e8015fSLinus Walleij 
814e8015fSLinus Walleij static int bmp280_i2c_probe(struct i2c_client *client,
914e8015fSLinus Walleij 			    const struct i2c_device_id *id)
1014e8015fSLinus Walleij {
1114e8015fSLinus Walleij 	struct regmap *regmap;
1214e8015fSLinus Walleij 	const struct regmap_config *regmap_config;
1314e8015fSLinus Walleij 
1414e8015fSLinus Walleij 	switch (id->driver_data) {
1514e8015fSLinus Walleij 	case BMP180_CHIP_ID:
1614e8015fSLinus Walleij 		regmap_config = &bmp180_regmap_config;
1714e8015fSLinus Walleij 		break;
1814e8015fSLinus Walleij 	case BMP280_CHIP_ID:
1914e8015fSLinus Walleij 	case BME280_CHIP_ID:
2014e8015fSLinus Walleij 		regmap_config = &bmp280_regmap_config;
2114e8015fSLinus Walleij 		break;
2214e8015fSLinus Walleij 	default:
2314e8015fSLinus Walleij 		return -EINVAL;
2414e8015fSLinus Walleij 	}
2514e8015fSLinus Walleij 
2614e8015fSLinus Walleij 	regmap = devm_regmap_init_i2c(client, regmap_config);
2714e8015fSLinus Walleij 	if (IS_ERR(regmap)) {
2814e8015fSLinus Walleij 		dev_err(&client->dev, "failed to allocate register map\n");
2914e8015fSLinus Walleij 		return PTR_ERR(regmap);
3014e8015fSLinus Walleij 	}
3114e8015fSLinus Walleij 
3214e8015fSLinus Walleij 	return bmp280_common_probe(&client->dev,
3314e8015fSLinus Walleij 				   regmap,
3414e8015fSLinus Walleij 				   id->driver_data,
35aae95394SLinus Walleij 				   id->name,
36aae95394SLinus Walleij 				   client->irq);
3714e8015fSLinus Walleij }
3814e8015fSLinus Walleij 
3914e8015fSLinus Walleij static const struct of_device_id bmp280_of_i2c_match[] = {
4014e8015fSLinus Walleij 	{ .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID },
41*18d1bb37SAngel Iglesias 	{ .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID },
42*18d1bb37SAngel Iglesias 	{ .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID },
43*18d1bb37SAngel Iglesias 	{ .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID },
4414e8015fSLinus Walleij 	{ },
4514e8015fSLinus Walleij };
4614e8015fSLinus Walleij MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
4714e8015fSLinus Walleij 
4814e8015fSLinus Walleij static const struct i2c_device_id bmp280_i2c_id[] = {
4914e8015fSLinus Walleij 	{"bmp085", BMP180_CHIP_ID },
50*18d1bb37SAngel Iglesias 	{"bmp180", BMP180_CHIP_ID },
51*18d1bb37SAngel Iglesias 	{"bmp280", BMP280_CHIP_ID },
5214e8015fSLinus Walleij 	{"bme280", BME280_CHIP_ID },
5314e8015fSLinus Walleij 	{ },
5414e8015fSLinus Walleij };
5514e8015fSLinus Walleij MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
5614e8015fSLinus Walleij 
5714e8015fSLinus Walleij static struct i2c_driver bmp280_i2c_driver = {
5814e8015fSLinus Walleij 	.driver = {
5914e8015fSLinus Walleij 		.name	= "bmp280",
60ae968599SAndy Shevchenko 		.of_match_table = bmp280_of_i2c_match,
615865918fSPaul Cercueil 		.pm = pm_ptr(&bmp280_dev_pm_ops),
6214e8015fSLinus Walleij 	},
6314e8015fSLinus Walleij 	.probe		= bmp280_i2c_probe,
6414e8015fSLinus Walleij 	.id_table	= bmp280_i2c_id,
6514e8015fSLinus Walleij };
6614e8015fSLinus Walleij module_i2c_driver(bmp280_i2c_driver);
6714e8015fSLinus Walleij 
6814e8015fSLinus Walleij MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
6914e8015fSLinus Walleij MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
7014e8015fSLinus Walleij MODULE_LICENSE("GPL v2");
710f26b9dbSJonathan Cameron MODULE_IMPORT_NS(IIO_BMP280);
72