Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * BME680 - I2C Driver
0004  *
0005  * Copyright (C) 2018 Himanshu Jha <himanshujha199640@gmail.com>
0006  *
0007  * 7-Bit I2C slave address is:
0008  *  - 0x76 if SDO is pulled to GND
0009  *  - 0x77 if SDO is pulled to VDDIO
0010  *
0011  * Note: SDO pin cannot be left floating otherwise I2C address
0012  *   will be undefined.
0013  */
0014 #include <linux/i2c.h>
0015 #include <linux/module.h>
0016 #include <linux/regmap.h>
0017 
0018 #include "bme680.h"
0019 
0020 static int bme680_i2c_probe(struct i2c_client *client,
0021                 const struct i2c_device_id *id)
0022 {
0023     struct regmap *regmap;
0024     const char *name = NULL;
0025 
0026     regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
0027     if (IS_ERR(regmap)) {
0028         dev_err(&client->dev, "Failed to register i2c regmap %ld\n", PTR_ERR(regmap));
0029         return PTR_ERR(regmap);
0030     }
0031 
0032     if (id)
0033         name = id->name;
0034 
0035     return bme680_core_probe(&client->dev, regmap, name);
0036 }
0037 
0038 static const struct i2c_device_id bme680_i2c_id[] = {
0039     {"bme680", 0},
0040     {},
0041 };
0042 MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
0043 
0044 static const struct of_device_id bme680_of_i2c_match[] = {
0045     { .compatible = "bosch,bme680", },
0046     {},
0047 };
0048 MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
0049 
0050 static struct i2c_driver bme680_i2c_driver = {
0051     .driver = {
0052         .name           = "bme680_i2c",
0053         .of_match_table     = bme680_of_i2c_match,
0054     },
0055     .probe = bme680_i2c_probe,
0056     .id_table = bme680_i2c_id,
0057 };
0058 module_i2c_driver(bme680_i2c_driver);
0059 
0060 MODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>");
0061 MODULE_DESCRIPTION("BME680 I2C driver");
0062 MODULE_LICENSE("GPL v2");
0063 MODULE_IMPORT_NS(IIO_BME680);