^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * BME680 - I2C Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2018 Himanshu Jha <himanshujha199640@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * 7-Bit I2C slave address is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * - 0x76 if SDO is pulled to GND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * - 0x77 if SDO is pulled to VDDIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Note: SDO pin cannot be left floating otherwise I2C address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * will be undefined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "bme680.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int bme680_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) const char *name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) dev_err(&client->dev, "Failed to register i2c regmap %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) (int)PTR_ERR(regmap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) name = id->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return bme680_core_probe(&client->dev, regmap, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static const struct i2c_device_id bme680_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {"bme680", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static const struct acpi_device_id bme680_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {"BME0680", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static const struct of_device_id bme680_of_i2c_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) { .compatible = "bosch,bme680", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static struct i2c_driver bme680_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .name = "bme680_i2c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .acpi_match_table = ACPI_PTR(bme680_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .of_match_table = bme680_of_i2c_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .probe = bme680_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .id_table = bme680_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) module_i2c_driver(bme680_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) MODULE_AUTHOR("Himanshu Jha <himanshujha199640@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) MODULE_DESCRIPTION("BME680 I2C driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) MODULE_LICENSE("GPL v2");