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 const struct i2c_device_id *id) 10 { 11 struct regmap *regmap; 12 const struct regmap_config *regmap_config; 13 14 switch (id->driver_data) { 15 case BMP180_CHIP_ID: 16 regmap_config = &bmp180_regmap_config; 17 break; 18 case BMP280_CHIP_ID: 19 case BME280_CHIP_ID: 20 regmap_config = &bmp280_regmap_config; 21 break; 22 case BMP380_CHIP_ID: 23 regmap_config = &bmp380_regmap_config; 24 break; 25 default: 26 return -EINVAL; 27 } 28 29 regmap = devm_regmap_init_i2c(client, regmap_config); 30 if (IS_ERR(regmap)) { 31 dev_err(&client->dev, "failed to allocate register map\n"); 32 return PTR_ERR(regmap); 33 } 34 35 return bmp280_common_probe(&client->dev, 36 regmap, 37 id->driver_data, 38 id->name, 39 client->irq); 40 } 41 42 static const struct of_device_id bmp280_of_i2c_match[] = { 43 { .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID }, 44 { .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID }, 45 { .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID }, 46 { .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID }, 47 { .compatible = "bosch,bmp380", .data = (void *)BMP380_CHIP_ID }, 48 { }, 49 }; 50 MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); 51 52 static const struct i2c_device_id bmp280_i2c_id[] = { 53 {"bmp085", BMP180_CHIP_ID }, 54 {"bmp180", BMP180_CHIP_ID }, 55 {"bmp280", BMP280_CHIP_ID }, 56 {"bme280", BME280_CHIP_ID }, 57 {"bmp380", BMP380_CHIP_ID }, 58 { }, 59 }; 60 MODULE_DEVICE_TABLE(i2c, bmp280_i2c_id); 61 62 static struct i2c_driver bmp280_i2c_driver = { 63 .driver = { 64 .name = "bmp280", 65 .of_match_table = bmp280_of_i2c_match, 66 .pm = pm_ptr(&bmp280_dev_pm_ops), 67 }, 68 .probe = bmp280_i2c_probe, 69 .id_table = bmp280_i2c_id, 70 }; 71 module_i2c_driver(bmp280_i2c_driver); 72 73 MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 74 MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor"); 75 MODULE_LICENSE("GPL v2"); 76 MODULE_IMPORT_NS(IIO_BMP280); 77