xref: /linux/drivers/iio/chemical/ens160_i2c.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * ScioSense ENS160 multi-gas sensor I2C driver
4  *
5  * Copyright (c) 2024 Gustavo Silva <gustavograzs@gmail.com>
6  *
7  * 7-Bit I2C slave address is:
8  *	- 0x52 if ADDR pin LOW
9  *	- 0x53 if ADDR pin HIGH
10  */
11 
12 #include <linux/i2c.h>
13 #include <linux/module.h>
14 #include <linux/regmap.h>
15 
16 #include "ens160.h"
17 
18 static const struct regmap_config ens160_regmap_i2c_conf = {
19 	.reg_bits = 8,
20 	.val_bits = 8,
21 };
22 
ens160_i2c_probe(struct i2c_client * client)23 static int ens160_i2c_probe(struct i2c_client *client)
24 {
25 	struct regmap *regmap;
26 
27 	regmap = devm_regmap_init_i2c(client, &ens160_regmap_i2c_conf);
28 	if (IS_ERR(regmap))
29 		return dev_err_probe(&client->dev, PTR_ERR(regmap),
30 				     "Failed to register i2c regmap\n");
31 
32 	return devm_ens160_core_probe(&client->dev, regmap, client->irq,
33 				      "ens160");
34 }
35 
36 static const struct i2c_device_id ens160_i2c_id[] = {
37 	{ "ens160" },
38 	{ }
39 };
40 MODULE_DEVICE_TABLE(i2c, ens160_i2c_id);
41 
42 static const struct of_device_id ens160_of_i2c_match[] = {
43 	{ .compatible = "sciosense,ens160" },
44 	{ }
45 };
46 MODULE_DEVICE_TABLE(of, ens160_of_i2c_match);
47 
48 static struct i2c_driver ens160_i2c_driver = {
49 	.driver = {
50 		.name		= "ens160",
51 		.of_match_table	= ens160_of_i2c_match,
52 		.pm		= pm_sleep_ptr(&ens160_pm_ops),
53 	},
54 	.probe = ens160_i2c_probe,
55 	.id_table = ens160_i2c_id,
56 };
57 module_i2c_driver(ens160_i2c_driver);
58 
59 MODULE_AUTHOR("Gustavo Silva <gustavograzs@gmail.com>");
60 MODULE_DESCRIPTION("ScioSense ENS160 I2C driver");
61 MODULE_LICENSE("GPL v2");
62 MODULE_IMPORT_NS(IIO_ENS160);
63