Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / iio / humidity / hts221_spi.c
blob729e86e433b1fd20311c92695f99e6dfbfe581d5
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics hts221 spi driver
5 * Copyright 2016 STMicroelectronics Inc.
7 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
8 */
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>
16 #include "hts221.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 = {
22 .reg_bits = 8,
23 .val_bits = 8,
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);
33 if (IS_ERR(regmap)) {
34 dev_err(&spi->dev, "Failed to register spi regmap %ld\n",
35 PTR_ERR(regmap));
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", },
45 {},
47 MODULE_DEVICE_TABLE(of, hts221_spi_of_match);
49 static const struct spi_device_id hts221_spi_id_table[] = {
50 { HTS221_DEV_NAME },
51 {},
53 MODULE_DEVICE_TABLE(spi, hts221_spi_id_table);
55 static struct spi_driver hts221_driver = {
56 .driver = {
57 .name = "hts221_spi",
58 .pm = &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");