1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics hts221 spi driver
5 * Copyright 2016 STMicroelectronics Inc.
7 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/spi/spi.h>
13 #include <linux/slab.h>
14 #include <linux/regmap.h>
18 #define HTS221_SPI_READ BIT(7)
19 #define HTS221_SPI_AUTO_INCREMENT BIT(6)
21 static const struct regmap_config hts221_spi_regmap_config
= {
24 .write_flag_mask
= HTS221_SPI_AUTO_INCREMENT
,
25 .read_flag_mask
= HTS221_SPI_READ
| HTS221_SPI_AUTO_INCREMENT
,
28 static int hts221_spi_probe(struct spi_device
*spi
)
30 struct regmap
*regmap
;
32 regmap
= devm_regmap_init_spi(spi
, &hts221_spi_regmap_config
);
34 dev_err(&spi
->dev
, "Failed to register spi regmap %ld\n",
36 return PTR_ERR(regmap
);
39 return hts221_probe(&spi
->dev
, spi
->irq
,
40 spi
->modalias
, regmap
);
43 static const struct of_device_id hts221_spi_of_match
[] = {
44 { .compatible
= "st,hts221", },
47 MODULE_DEVICE_TABLE(of
, hts221_spi_of_match
);
49 static const struct spi_device_id hts221_spi_id_table
[] = {
53 MODULE_DEVICE_TABLE(spi
, hts221_spi_id_table
);
55 static struct spi_driver hts221_driver
= {
58 .pm
= pm_sleep_ptr(&hts221_pm_ops
),
59 .of_match_table
= hts221_spi_of_match
,
61 .probe
= hts221_spi_probe
,
62 .id_table
= hts221_spi_id_table
,
64 module_spi_driver(hts221_driver
);
66 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
67 MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver");
68 MODULE_LICENSE("GPL v2");
69 MODULE_IMPORT_NS("IIO_HTS221");