18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * STMicroelectronics hts221 spi driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2016 STMicroelectronics Inc. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Lorenzo Bianconi <lorenzo.bianconi@st.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <linux/spi/spi.h> 138c2ecf20Sopenharmony_ci#include <linux/slab.h> 148c2ecf20Sopenharmony_ci#include <linux/regmap.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include "hts221.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define HTS221_SPI_READ BIT(7) 198c2ecf20Sopenharmony_ci#define HTS221_SPI_AUTO_INCREMENT BIT(6) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic const struct regmap_config hts221_spi_regmap_config = { 228c2ecf20Sopenharmony_ci .reg_bits = 8, 238c2ecf20Sopenharmony_ci .val_bits = 8, 248c2ecf20Sopenharmony_ci .write_flag_mask = HTS221_SPI_AUTO_INCREMENT, 258c2ecf20Sopenharmony_ci .read_flag_mask = HTS221_SPI_READ | HTS221_SPI_AUTO_INCREMENT, 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic int hts221_spi_probe(struct spi_device *spi) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci struct regmap *regmap; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config); 338c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 348c2ecf20Sopenharmony_ci dev_err(&spi->dev, "Failed to register spi regmap %ld\n", 358c2ecf20Sopenharmony_ci PTR_ERR(regmap)); 368c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci return hts221_probe(&spi->dev, spi->irq, 408c2ecf20Sopenharmony_ci spi->modalias, regmap); 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic const struct of_device_id hts221_spi_of_match[] = { 448c2ecf20Sopenharmony_ci { .compatible = "st,hts221", }, 458c2ecf20Sopenharmony_ci {}, 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, hts221_spi_of_match); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic const struct spi_device_id hts221_spi_id_table[] = { 508c2ecf20Sopenharmony_ci { HTS221_DEV_NAME }, 518c2ecf20Sopenharmony_ci {}, 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(spi, hts221_spi_id_table); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic struct spi_driver hts221_driver = { 568c2ecf20Sopenharmony_ci .driver = { 578c2ecf20Sopenharmony_ci .name = "hts221_spi", 588c2ecf20Sopenharmony_ci .pm = &hts221_pm_ops, 598c2ecf20Sopenharmony_ci .of_match_table = hts221_spi_of_match, 608c2ecf20Sopenharmony_ci }, 618c2ecf20Sopenharmony_ci .probe = hts221_spi_probe, 628c2ecf20Sopenharmony_ci .id_table = hts221_spi_id_table, 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_cimodule_spi_driver(hts221_driver); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciMODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 678c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("STMicroelectronics hts221 spi driver"); 688c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 69