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