18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci#include <linux/module.h> 38c2ecf20Sopenharmony_ci#include <linux/i2c.h> 48c2ecf20Sopenharmony_ci#include <linux/regmap.h> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include "bmp280.h" 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_cistatic int bmp280_i2c_probe(struct i2c_client *client, 98c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 108c2ecf20Sopenharmony_ci{ 118c2ecf20Sopenharmony_ci struct regmap *regmap; 128c2ecf20Sopenharmony_ci const struct regmap_config *regmap_config; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci switch (id->driver_data) { 158c2ecf20Sopenharmony_ci case BMP180_CHIP_ID: 168c2ecf20Sopenharmony_ci regmap_config = &bmp180_regmap_config; 178c2ecf20Sopenharmony_ci break; 188c2ecf20Sopenharmony_ci case BMP280_CHIP_ID: 198c2ecf20Sopenharmony_ci case BME280_CHIP_ID: 208c2ecf20Sopenharmony_ci regmap_config = &bmp280_regmap_config; 218c2ecf20Sopenharmony_ci break; 228c2ecf20Sopenharmony_ci default: 238c2ecf20Sopenharmony_ci return -EINVAL; 248c2ecf20Sopenharmony_ci } 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, regmap_config); 278c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 288c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to allocate register map\n"); 298c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 308c2ecf20Sopenharmony_ci } 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci return bmp280_common_probe(&client->dev, 338c2ecf20Sopenharmony_ci regmap, 348c2ecf20Sopenharmony_ci id->driver_data, 358c2ecf20Sopenharmony_ci id->name, 368c2ecf20Sopenharmony_ci client->irq); 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic const struct of_device_id bmp280_of_i2c_match[] = { 408c2ecf20Sopenharmony_ci { .compatible = "bosch,bme280", .data = (void *)BME280_CHIP_ID }, 418c2ecf20Sopenharmony_ci { .compatible = "bosch,bmp280", .data = (void *)BMP280_CHIP_ID }, 428c2ecf20Sopenharmony_ci { .compatible = "bosch,bmp180", .data = (void *)BMP180_CHIP_ID }, 438c2ecf20Sopenharmony_ci { .compatible = "bosch,bmp085", .data = (void *)BMP180_CHIP_ID }, 448c2ecf20Sopenharmony_ci { }, 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistatic const struct i2c_device_id bmp280_i2c_id[] = { 498c2ecf20Sopenharmony_ci {"bmp280", BMP280_CHIP_ID }, 508c2ecf20Sopenharmony_ci {"bmp180", BMP180_CHIP_ID }, 518c2ecf20Sopenharmony_ci {"bmp085", BMP180_CHIP_ID }, 528c2ecf20Sopenharmony_ci {"bme280", BME280_CHIP_ID }, 538c2ecf20Sopenharmony_ci { }, 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bmp280_i2c_id); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic struct i2c_driver bmp280_i2c_driver = { 588c2ecf20Sopenharmony_ci .driver = { 598c2ecf20Sopenharmony_ci .name = "bmp280", 608c2ecf20Sopenharmony_ci .of_match_table = bmp280_of_i2c_match, 618c2ecf20Sopenharmony_ci .pm = &bmp280_dev_pm_ops, 628c2ecf20Sopenharmony_ci }, 638c2ecf20Sopenharmony_ci .probe = bmp280_i2c_probe, 648c2ecf20Sopenharmony_ci .id_table = bmp280_i2c_id, 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_cimodule_i2c_driver(bmp280_i2c_driver); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciMODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 698c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor"); 708c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 71