1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * ScioSense ENS160 multi-gas sensor SPI driver
4  *
5  * Copyright (c) 2024 Gustavo Silva <gustavograzs@gmail.com>
6  */
7 
8 #include <linux/module.h>
9 #include <linux/regmap.h>
10 #include <linux/spi/spi.h>
11 
12 #include "ens160.h"
13 
14 #define ENS160_SPI_READ BIT(0)
15 
16 static const struct regmap_config ens160_regmap_spi_conf = {
17 	.reg_bits = 8,
18 	.val_bits = 8,
19 	.reg_shift = -1,
20 	.read_flag_mask = ENS160_SPI_READ,
21 };
22 
ens160_spi_probe(struct spi_device * spi)23 static int ens160_spi_probe(struct spi_device *spi)
24 {
25 	struct regmap *regmap;
26 
27 	regmap = devm_regmap_init_spi(spi, &ens160_regmap_spi_conf);
28 	if (IS_ERR(regmap))
29 		return dev_err_probe(&spi->dev, PTR_ERR(regmap),
30 				     "Failed to register spi regmap\n");
31 
32 	return devm_ens160_core_probe(&spi->dev, regmap, spi->irq, "ens160");
33 }
34 
35 static const struct of_device_id ens160_spi_of_match[] = {
36 	{ .compatible = "sciosense,ens160" },
37 	{ }
38 };
39 MODULE_DEVICE_TABLE(of, ens160_spi_of_match);
40 
41 static const struct spi_device_id ens160_spi_id[] = {
42 	{ "ens160" },
43 	{ }
44 };
45 MODULE_DEVICE_TABLE(spi, ens160_spi_id);
46 
47 static struct spi_driver ens160_spi_driver = {
48 	.driver = {
49 		.name	= "ens160",
50 		.of_match_table = ens160_spi_of_match,
51 		.pm = pm_sleep_ptr(&ens160_pm_ops),
52 	},
53 	.probe		= ens160_spi_probe,
54 	.id_table	= ens160_spi_id,
55 };
56 module_spi_driver(ens160_spi_driver);
57 
58 MODULE_AUTHOR("Gustavo Silva <gustavograzs@gmail.com>");
59 MODULE_DESCRIPTION("ScioSense ENS160 SPI driver");
60 MODULE_LICENSE("GPL v2");
61 MODULE_IMPORT_NS(IIO_ENS160);
62