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 
8*12491d35SAngel Iglesias static int bmp280_i2c_probe(struct i2c_client *client)
914e8015fSLinus Walleij {
1014e8015fSLinus Walleij 	struct regmap *regmap;
1114e8015fSLinus Walleij 	const struct regmap_config *regmap_config;
12*12491d35SAngel Iglesias 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
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;
228d329309SAngel Iglesias 	case BMP380_CHIP_ID:
238d329309SAngel Iglesias 		regmap_config = &bmp380_regmap_config;
248d329309SAngel Iglesias 		break;
2514e8015fSLinus Walleij 	default:
2614e8015fSLinus Walleij 		return -EINVAL;
2714e8015fSLinus Walleij 	}
2814e8015fSLinus Walleij 
2914e8015fSLinus Walleij 	regmap = devm_regmap_init_i2c(client, regmap_config);
3014e8015fSLinus Walleij 	if (IS_ERR(regmap)) {
3114e8015fSLinus Walleij 		dev_err(&client->dev, "failed to allocate register map\n");
3214e8015fSLinus Walleij 		return PTR_ERR(regmap);
3314e8015fSLinus Walleij 	}
3414e8015fSLinus Walleij 
3514e8015fSLinus Walleij 	return bmp280_common_probe(&client->dev,
3614e8015fSLinus Walleij 				   regmap,
3714e8015fSLinus Walleij 				   id->driver_data,
38aae95394SLinus Walleij 				   id->name,
39aae95394SLinus Walleij 				   client->irq);
4014e8015fSLinus Walleij }
4114e8015fSLinus Walleij 
4214e8015fSLinus Walleij static const struct of_device_id bmp280_of_i2c_match[] = {
4314e8015fSLinus Walleij 	{ .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID },
4418d1bb37SAngel Iglesias 	{ .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID },
4518d1bb37SAngel Iglesias 	{ .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID },
4618d1bb37SAngel Iglesias 	{ .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID },
478d329309SAngel Iglesias 	{ .compatible = "bosch,bmp380", .data = (void *)BMP380_CHIP_ID },
4814e8015fSLinus Walleij 	{ },
4914e8015fSLinus Walleij };
5014e8015fSLinus Walleij MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
5114e8015fSLinus Walleij 
5214e8015fSLinus Walleij static const struct i2c_device_id bmp280_i2c_id[] = {
5314e8015fSLinus Walleij 	{"bmp085", BMP180_CHIP_ID },
5418d1bb37SAngel Iglesias 	{"bmp180", BMP180_CHIP_ID },
5518d1bb37SAngel Iglesias 	{"bmp280", BMP280_CHIP_ID },
5614e8015fSLinus Walleij 	{"bme280", BME280_CHIP_ID },
578d329309SAngel Iglesias 	{"bmp380", BMP380_CHIP_ID },
5814e8015fSLinus Walleij 	{ },
5914e8015fSLinus Walleij };
6014e8015fSLinus Walleij MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
6114e8015fSLinus Walleij 
6214e8015fSLinus Walleij static struct i2c_driver bmp280_i2c_driver = {
6314e8015fSLinus Walleij 	.driver = {
6414e8015fSLinus Walleij 		.name	= "bmp280",
65ae968599SAndy Shevchenko 		.of_match_table = bmp280_of_i2c_match,
665865918fSPaul Cercueil 		.pm = pm_ptr(&bmp280_dev_pm_ops),
6714e8015fSLinus Walleij 	},
68*12491d35SAngel Iglesias 	.probe_new	= bmp280_i2c_probe,
6914e8015fSLinus Walleij 	.id_table	= bmp280_i2c_id,
7014e8015fSLinus Walleij };
7114e8015fSLinus Walleij module_i2c_driver(bmp280_i2c_driver);
7214e8015fSLinus Walleij 
7314e8015fSLinus Walleij MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
7414e8015fSLinus Walleij MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
7514e8015fSLinus Walleij MODULE_LICENSE("GPL v2");
760f26b9dbSJonathan Cameron MODULE_IMPORT_NS(IIO_BMP280);
77