11b3bd859SHimanshu Jha // SPDX-License-Identifier: GPL-2.0
21b3bd859SHimanshu Jha /*
31b3bd859SHimanshu Jha  * BME680 - I2C Driver
41b3bd859SHimanshu Jha  *
51b3bd859SHimanshu Jha  * Copyright (C) 2018 Himanshu Jha <himanshujha199640@gmail.com>
61b3bd859SHimanshu Jha  *
71b3bd859SHimanshu Jha  * 7-Bit I2C slave address is:
81b3bd859SHimanshu Jha  *	- 0x76 if SDO is pulled to GND
91b3bd859SHimanshu Jha  *	- 0x77 if SDO is pulled to VDDIO
101b3bd859SHimanshu Jha  *
111b3bd859SHimanshu Jha  * Note: SDO pin cannot be left floating otherwise I2C address
121b3bd859SHimanshu Jha  *	 will be undefined.
131b3bd859SHimanshu Jha  */
141b3bd859SHimanshu Jha #include <linux/i2c.h>
151b3bd859SHimanshu Jha #include <linux/module.h>
161b3bd859SHimanshu Jha #include <linux/regmap.h>
171b3bd859SHimanshu Jha 
181b3bd859SHimanshu Jha #include "bme680.h"
191b3bd859SHimanshu Jha 
bme680_i2c_probe(struct i2c_client * client)205aa37765SUwe Kleine-König static int bme680_i2c_probe(struct i2c_client *client)
211b3bd859SHimanshu Jha {
225aa37765SUwe Kleine-König 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
231b3bd859SHimanshu Jha 	struct regmap *regmap;
241b3bd859SHimanshu Jha 	const char *name = NULL;
251b3bd859SHimanshu Jha 
261b3bd859SHimanshu Jha 	regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
271b3bd859SHimanshu Jha 	if (IS_ERR(regmap)) {
28d612eb13SAndy Shevchenko 		dev_err(&client->dev, "Failed to register i2c regmap %ld\n", PTR_ERR(regmap));
291b3bd859SHimanshu Jha 		return PTR_ERR(regmap);
301b3bd859SHimanshu Jha 	}
311b3bd859SHimanshu Jha 
321b3bd859SHimanshu Jha 	if (id)
331b3bd859SHimanshu Jha 		name = id->name;
341b3bd859SHimanshu Jha 
351b3bd859SHimanshu Jha 	return bme680_core_probe(&client->dev, regmap, name);
361b3bd859SHimanshu Jha }
371b3bd859SHimanshu Jha 
381b3bd859SHimanshu Jha static const struct i2c_device_id bme680_i2c_id[] = {
391b3bd859SHimanshu Jha 	{"bme680", 0},
401b3bd859SHimanshu Jha 	{},
411b3bd859SHimanshu Jha };
421b3bd859SHimanshu Jha MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
431b3bd859SHimanshu Jha 
44f7da8845SSebastien Bourdelin static const struct of_device_id bme680_of_i2c_match[] = {
45f7da8845SSebastien Bourdelin 	{ .compatible = "bosch,bme680", },
46f7da8845SSebastien Bourdelin 	{},
47f7da8845SSebastien Bourdelin };
48f7da8845SSebastien Bourdelin MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
49f7da8845SSebastien Bourdelin 
501b3bd859SHimanshu Jha static struct i2c_driver bme680_i2c_driver = {
511b3bd859SHimanshu Jha 	.driver = {
521b3bd859SHimanshu Jha 		.name			= "bme680_i2c",
53f7da8845SSebastien Bourdelin 		.of_match_table		= bme680_of_i2c_match,
541b3bd859SHimanshu Jha 	},
55*7cf15f42SUwe Kleine-König 	.probe = bme680_i2c_probe,
561b3bd859SHimanshu Jha 	.id_table = bme680_i2c_id,
571b3bd859SHimanshu Jha };
581b3bd859SHimanshu Jha module_i2c_driver(bme680_i2c_driver);
591b3bd859SHimanshu Jha 
601b3bd859SHimanshu Jha MODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>");
611b3bd859SHimanshu Jha MODULE_DESCRIPTION("BME680 I2C driver");
621b3bd859SHimanshu Jha MODULE_LICENSE("GPL v2");
63146b43d9SJonathan Cameron MODULE_IMPORT_NS(IIO_BME680);
64