18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * BME680 - I2C Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2018 Himanshu Jha <himanshujha199640@gmail.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * 7-Bit I2C slave address is:
88c2ecf20Sopenharmony_ci *	- 0x76 if SDO is pulled to GND
98c2ecf20Sopenharmony_ci *	- 0x77 if SDO is pulled to VDDIO
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Note: SDO pin cannot be left floating otherwise I2C address
128c2ecf20Sopenharmony_ci *	 will be undefined.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci#include <linux/acpi.h>
158c2ecf20Sopenharmony_ci#include <linux/i2c.h>
168c2ecf20Sopenharmony_ci#include <linux/module.h>
178c2ecf20Sopenharmony_ci#include <linux/regmap.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "bme680.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic int bme680_i2c_probe(struct i2c_client *client,
228c2ecf20Sopenharmony_ci			    const struct i2c_device_id *id)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	struct regmap *regmap;
258c2ecf20Sopenharmony_ci	const char *name = NULL;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
288c2ecf20Sopenharmony_ci	if (IS_ERR(regmap)) {
298c2ecf20Sopenharmony_ci		dev_err(&client->dev, "Failed to register i2c regmap %d\n",
308c2ecf20Sopenharmony_ci				(int)PTR_ERR(regmap));
318c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
328c2ecf20Sopenharmony_ci	}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	if (id)
358c2ecf20Sopenharmony_ci		name = id->name;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	return bme680_core_probe(&client->dev, regmap, name);
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic const struct i2c_device_id bme680_i2c_id[] = {
418c2ecf20Sopenharmony_ci	{"bme680", 0},
428c2ecf20Sopenharmony_ci	{},
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic const struct acpi_device_id bme680_acpi_match[] = {
478c2ecf20Sopenharmony_ci	{"BME0680", 0},
488c2ecf20Sopenharmony_ci	{},
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic const struct of_device_id bme680_of_i2c_match[] = {
538c2ecf20Sopenharmony_ci	{ .compatible = "bosch,bme680", },
548c2ecf20Sopenharmony_ci	{},
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct i2c_driver bme680_i2c_driver = {
598c2ecf20Sopenharmony_ci	.driver = {
608c2ecf20Sopenharmony_ci		.name			= "bme680_i2c",
618c2ecf20Sopenharmony_ci		.acpi_match_table       = ACPI_PTR(bme680_acpi_match),
628c2ecf20Sopenharmony_ci		.of_match_table		= bme680_of_i2c_match,
638c2ecf20Sopenharmony_ci	},
648c2ecf20Sopenharmony_ci	.probe = bme680_i2c_probe,
658c2ecf20Sopenharmony_ci	.id_table = bme680_i2c_id,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_cimodule_i2c_driver(bme680_i2c_driver);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciMODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>");
708c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("BME680 I2C driver");
718c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
72