perf python: Do not force closing original perf descriptor in evlist.get_pollfd()
[linux/fpc-iii.git] / drivers / iio / chemical / bme680_i2c.c
blob06d4be539d2e32092aa21a7d51aaceafcc88e2b8
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * BME680 - I2C Driver
5 * Copyright (C) 2018 Himanshu Jha <himanshujha199640@gmail.com>
7 * 7-Bit I2C slave address is:
8 * - 0x76 if SDO is pulled to GND
9 * - 0x77 if SDO is pulled to VDDIO
11 * Note: SDO pin cannot be left floating otherwise I2C address
12 * will be undefined.
14 #include <linux/acpi.h>
15 #include <linux/i2c.h>
16 #include <linux/module.h>
17 #include <linux/regmap.h>
19 #include "bme680.h"
21 static int bme680_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id)
24 struct regmap *regmap;
25 const char *name = NULL;
26 unsigned int val;
27 int ret;
29 regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
30 if (IS_ERR(regmap)) {
31 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
32 (int)PTR_ERR(regmap));
33 return PTR_ERR(regmap);
36 ret = regmap_write(regmap, BME680_REG_SOFT_RESET_I2C,
37 BME680_CMD_SOFTRESET);
38 if (ret < 0) {
39 dev_err(&client->dev, "Failed to reset chip\n");
40 return ret;
43 ret = regmap_read(regmap, BME680_REG_CHIP_I2C_ID, &val);
44 if (ret < 0) {
45 dev_err(&client->dev, "Error reading I2C chip ID\n");
46 return ret;
49 if (val != BME680_CHIP_ID_VAL) {
50 dev_err(&client->dev, "Wrong chip ID, got %x expected %x\n",
51 val, BME680_CHIP_ID_VAL);
52 return -ENODEV;
55 if (id)
56 name = id->name;
58 return bme680_core_probe(&client->dev, regmap, name);
61 static const struct i2c_device_id bme680_i2c_id[] = {
62 {"bme680", 0},
63 {},
65 MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
67 static const struct acpi_device_id bme680_acpi_match[] = {
68 {"BME0680", 0},
69 {},
71 MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
73 static struct i2c_driver bme680_i2c_driver = {
74 .driver = {
75 .name = "bme680_i2c",
76 .acpi_match_table = ACPI_PTR(bme680_acpi_match),
78 .probe = bme680_i2c_probe,
79 .id_table = bme680_i2c_id,
81 module_i2c_driver(bme680_i2c_driver);
83 MODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>");
84 MODULE_DESCRIPTION("BME680 I2C driver");
85 MODULE_LICENSE("GPL v2");