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