1e4a70e3eSLorenzo Bianconi /* 2e4a70e3eSLorenzo Bianconi * STMicroelectronics hts221 spi driver 3e4a70e3eSLorenzo Bianconi * 4e4a70e3eSLorenzo Bianconi * Copyright 2016 STMicroelectronics Inc. 5e4a70e3eSLorenzo Bianconi * 6e4a70e3eSLorenzo Bianconi * Lorenzo Bianconi <lorenzo.bianconi@st.com> 7e4a70e3eSLorenzo Bianconi * 8e4a70e3eSLorenzo Bianconi * Licensed under the GPL-2. 9e4a70e3eSLorenzo Bianconi */ 10e4a70e3eSLorenzo Bianconi 11e4a70e3eSLorenzo Bianconi #include <linux/kernel.h> 12e4a70e3eSLorenzo Bianconi #include <linux/module.h> 13e4a70e3eSLorenzo Bianconi #include <linux/spi/spi.h> 14e4a70e3eSLorenzo Bianconi #include <linux/slab.h> 15*62177922SLorenzo Bianconi #include <linux/regmap.h> 16*62177922SLorenzo Bianconi 17e4a70e3eSLorenzo Bianconi #include "hts221.h" 18e4a70e3eSLorenzo Bianconi 19*62177922SLorenzo Bianconi #define HTS221_SPI_READ BIT(7) 20*62177922SLorenzo Bianconi #define HTS221_SPI_AUTO_INCREMENT BIT(6) 21e4a70e3eSLorenzo Bianconi 22*62177922SLorenzo Bianconi static const struct regmap_config hts221_spi_regmap_config = { 23*62177922SLorenzo Bianconi .reg_bits = 8, 24*62177922SLorenzo Bianconi .val_bits = 8, 25*62177922SLorenzo Bianconi .write_flag_mask = HTS221_SPI_AUTO_INCREMENT, 26*62177922SLorenzo Bianconi .read_flag_mask = HTS221_SPI_READ | HTS221_SPI_AUTO_INCREMENT, 27e4a70e3eSLorenzo Bianconi }; 28e4a70e3eSLorenzo Bianconi 29e4a70e3eSLorenzo Bianconi static int hts221_spi_probe(struct spi_device *spi) 30e4a70e3eSLorenzo Bianconi { 31*62177922SLorenzo Bianconi struct regmap *regmap; 32*62177922SLorenzo Bianconi 33*62177922SLorenzo Bianconi regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config); 34*62177922SLorenzo Bianconi if (IS_ERR(regmap)) { 35*62177922SLorenzo Bianconi dev_err(&spi->dev, "Failed to register spi regmap %d\n", 36*62177922SLorenzo Bianconi (int)PTR_ERR(regmap)); 37*62177922SLorenzo Bianconi return PTR_ERR(regmap); 38*62177922SLorenzo Bianconi } 39*62177922SLorenzo Bianconi 40e1ca1141SLorenzo Bianconi return hts221_probe(&spi->dev, spi->irq, 41*62177922SLorenzo Bianconi spi->modalias, regmap); 42e4a70e3eSLorenzo Bianconi } 43e4a70e3eSLorenzo Bianconi 44e4a70e3eSLorenzo Bianconi static const struct of_device_id hts221_spi_of_match[] = { 45e4a70e3eSLorenzo Bianconi { .compatible = "st,hts221", }, 46e4a70e3eSLorenzo Bianconi {}, 47e4a70e3eSLorenzo Bianconi }; 48e4a70e3eSLorenzo Bianconi MODULE_DEVICE_TABLE(of, hts221_spi_of_match); 49e4a70e3eSLorenzo Bianconi 50e4a70e3eSLorenzo Bianconi static const struct spi_device_id hts221_spi_id_table[] = { 51e4a70e3eSLorenzo Bianconi { HTS221_DEV_NAME }, 52e4a70e3eSLorenzo Bianconi {}, 53e4a70e3eSLorenzo Bianconi }; 54e4a70e3eSLorenzo Bianconi MODULE_DEVICE_TABLE(spi, hts221_spi_id_table); 55e4a70e3eSLorenzo Bianconi 56e4a70e3eSLorenzo Bianconi static struct spi_driver hts221_driver = { 57e4a70e3eSLorenzo Bianconi .driver = { 58e4a70e3eSLorenzo Bianconi .name = "hts221_spi", 59b7079eeaSLorenzo Bianconi .pm = &hts221_pm_ops, 60e4a70e3eSLorenzo Bianconi .of_match_table = of_match_ptr(hts221_spi_of_match), 61e4a70e3eSLorenzo Bianconi }, 62e4a70e3eSLorenzo Bianconi .probe = hts221_spi_probe, 63e4a70e3eSLorenzo Bianconi .id_table = hts221_spi_id_table, 64e4a70e3eSLorenzo Bianconi }; 65e4a70e3eSLorenzo Bianconi module_spi_driver(hts221_driver); 66e4a70e3eSLorenzo Bianconi 67e4a70e3eSLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 68e4a70e3eSLorenzo Bianconi MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver"); 69e4a70e3eSLorenzo Bianconi MODULE_LICENSE("GPL v2"); 70