Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 1 | /* |
| 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 Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 15 | #include <linux/regmap.h> |
| 16 | |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 17 | #include "hts221.h" |
| 18 | |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 19 | #define HTS221_SPI_READ BIT(7) |
| 20 | #define HTS221_SPI_AUTO_INCREMENT BIT(6) |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 21 | |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 22 | static 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 Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static int hts221_spi_probe(struct spi_device *spi) |
| 30 | { |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 31 | 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 Bianconi | e1ca114 | 2017-12-30 00:33:04 +0100 | [diff] [blame] | 40 | return hts221_probe(&spi->dev, spi->irq, |
Lorenzo Bianconi | 6217792 | 2018-01-08 23:12:30 +0100 | [diff] [blame] | 41 | spi->modalias, regmap); |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static const struct of_device_id hts221_spi_of_match[] = { |
| 45 | { .compatible = "st,hts221", }, |
| 46 | {}, |
| 47 | }; |
| 48 | MODULE_DEVICE_TABLE(of, hts221_spi_of_match); |
| 49 | |
| 50 | static const struct spi_device_id hts221_spi_id_table[] = { |
| 51 | { HTS221_DEV_NAME }, |
| 52 | {}, |
| 53 | }; |
| 54 | MODULE_DEVICE_TABLE(spi, hts221_spi_id_table); |
| 55 | |
| 56 | static struct spi_driver hts221_driver = { |
| 57 | .driver = { |
| 58 | .name = "hts221_spi", |
Lorenzo Bianconi | b7079ee | 2017-05-14 17:45:44 +0200 | [diff] [blame] | 59 | .pm = &hts221_pm_ops, |
Lorenzo Bianconi | e4a70e3 | 2016-10-13 22:06:04 +0200 | [diff] [blame] | 60 | .of_match_table = of_match_ptr(hts221_spi_of_match), |
| 61 | }, |
| 62 | .probe = hts221_spi_probe, |
| 63 | .id_table = hts221_spi_id_table, |
| 64 | }; |
| 65 | module_spi_driver(hts221_driver); |
| 66 | |
| 67 | MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); |
| 68 | MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver"); |
| 69 | MODULE_LICENSE("GPL v2"); |