blob: 9c005f0370266d83dd4c6f81c4862f05043d62f8 [file] [log] [blame]
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +02001/*
2 * STMicroelectronics hts221 spi driver
3 *
4 * Copyright 2016 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/spi/spi.h>
14#include <linux/slab.h>
Lorenzo Bianconi62177922018-01-08 23:12:30 +010015#include <linux/regmap.h>
16
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020017#include "hts221.h"
18
Lorenzo Bianconi62177922018-01-08 23:12:30 +010019#define HTS221_SPI_READ BIT(7)
20#define HTS221_SPI_AUTO_INCREMENT BIT(6)
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020021
Lorenzo Bianconi62177922018-01-08 23:12:30 +010022static const struct regmap_config hts221_spi_regmap_config = {
23 .reg_bits = 8,
24 .val_bits = 8,
25 .write_flag_mask = HTS221_SPI_AUTO_INCREMENT,
26 .read_flag_mask = HTS221_SPI_READ | HTS221_SPI_AUTO_INCREMENT,
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020027};
28
29static int hts221_spi_probe(struct spi_device *spi)
30{
Lorenzo Bianconi62177922018-01-08 23:12:30 +010031 struct regmap *regmap;
32
33 regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config);
34 if (IS_ERR(regmap)) {
35 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
36 (int)PTR_ERR(regmap));
37 return PTR_ERR(regmap);
38 }
39
Lorenzo Bianconie1ca1142017-12-30 00:33:04 +010040 return hts221_probe(&spi->dev, spi->irq,
Lorenzo Bianconi62177922018-01-08 23:12:30 +010041 spi->modalias, regmap);
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020042}
43
44static const struct of_device_id hts221_spi_of_match[] = {
45 { .compatible = "st,hts221", },
46 {},
47};
48MODULE_DEVICE_TABLE(of, hts221_spi_of_match);
49
50static const struct spi_device_id hts221_spi_id_table[] = {
51 { HTS221_DEV_NAME },
52 {},
53};
54MODULE_DEVICE_TABLE(spi, hts221_spi_id_table);
55
56static struct spi_driver hts221_driver = {
57 .driver = {
58 .name = "hts221_spi",
Lorenzo Bianconib7079ee2017-05-14 17:45:44 +020059 .pm = &hts221_pm_ops,
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020060 .of_match_table = of_match_ptr(hts221_spi_of_match),
61 },
62 .probe = hts221_spi_probe,
63 .id_table = hts221_spi_id_table,
64};
65module_spi_driver(hts221_driver);
66
67MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
68MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver");
69MODULE_LICENSE("GPL v2");