162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci#include <linux/module.h>
362306a36Sopenharmony_ci#include <linux/i2c.h>
462306a36Sopenharmony_ci#include <linux/regmap.h>
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include "bmp280.h"
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistatic int bmp280_i2c_probe(struct i2c_client *client)
962306a36Sopenharmony_ci{
1062306a36Sopenharmony_ci	struct regmap *regmap;
1162306a36Sopenharmony_ci	const struct bmp280_chip_info *chip_info;
1262306a36Sopenharmony_ci	const struct i2c_device_id *id = i2c_client_get_device_id(client);
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci	chip_info = device_get_match_data(&client->dev);
1562306a36Sopenharmony_ci	if (!chip_info)
1662306a36Sopenharmony_ci		chip_info = (const struct bmp280_chip_info *) id->driver_data;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci	regmap = devm_regmap_init_i2c(client, chip_info->regmap_config);
1962306a36Sopenharmony_ci	if (IS_ERR(regmap)) {
2062306a36Sopenharmony_ci		dev_err(&client->dev, "failed to allocate register map\n");
2162306a36Sopenharmony_ci		return PTR_ERR(regmap);
2262306a36Sopenharmony_ci	}
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci	return bmp280_common_probe(&client->dev,
2562306a36Sopenharmony_ci				   regmap,
2662306a36Sopenharmony_ci				   chip_info,
2762306a36Sopenharmony_ci				   id->name,
2862306a36Sopenharmony_ci				   client->irq);
2962306a36Sopenharmony_ci}
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic const struct of_device_id bmp280_of_i2c_match[] = {
3262306a36Sopenharmony_ci	{ .compatible = "bosch,bmp085", .data = &bmp180_chip_info },
3362306a36Sopenharmony_ci	{ .compatible = "bosch,bmp180", .data = &bmp180_chip_info },
3462306a36Sopenharmony_ci	{ .compatible = "bosch,bmp280", .data = &bmp280_chip_info },
3562306a36Sopenharmony_ci	{ .compatible = "bosch,bme280", .data = &bme280_chip_info },
3662306a36Sopenharmony_ci	{ .compatible = "bosch,bmp380", .data = &bmp380_chip_info },
3762306a36Sopenharmony_ci	{ .compatible = "bosch,bmp580", .data = &bmp580_chip_info },
3862306a36Sopenharmony_ci	{ },
3962306a36Sopenharmony_ci};
4062306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, bmp280_of_i2c_match);
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistatic const struct i2c_device_id bmp280_i2c_id[] = {
4362306a36Sopenharmony_ci	{"bmp085", (kernel_ulong_t)&bmp180_chip_info },
4462306a36Sopenharmony_ci	{"bmp180", (kernel_ulong_t)&bmp180_chip_info },
4562306a36Sopenharmony_ci	{"bmp280", (kernel_ulong_t)&bmp280_chip_info },
4662306a36Sopenharmony_ci	{"bme280", (kernel_ulong_t)&bme280_chip_info },
4762306a36Sopenharmony_ci	{"bmp380", (kernel_ulong_t)&bmp380_chip_info },
4862306a36Sopenharmony_ci	{"bmp580", (kernel_ulong_t)&bmp580_chip_info },
4962306a36Sopenharmony_ci	{ },
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bmp280_i2c_id);
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cistatic struct i2c_driver bmp280_i2c_driver = {
5462306a36Sopenharmony_ci	.driver = {
5562306a36Sopenharmony_ci		.name	= "bmp280",
5662306a36Sopenharmony_ci		.of_match_table = bmp280_of_i2c_match,
5762306a36Sopenharmony_ci		.pm = pm_ptr(&bmp280_dev_pm_ops),
5862306a36Sopenharmony_ci	},
5962306a36Sopenharmony_ci	.probe		= bmp280_i2c_probe,
6062306a36Sopenharmony_ci	.id_table	= bmp280_i2c_id,
6162306a36Sopenharmony_ci};
6262306a36Sopenharmony_cimodule_i2c_driver(bmp280_i2c_driver);
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ciMODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
6562306a36Sopenharmony_ciMODULE_DESCRIPTION("Driver for Bosch Sensortec BMP180/BMP280 pressure and temperature sensor");
6662306a36Sopenharmony_ciMODULE_LICENSE("GPL v2");
6762306a36Sopenharmony_ciMODULE_IMPORT_NS(IIO_BMP280);
68