1fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
23025c868SLorenzo Bianconi /*
33025c868SLorenzo Bianconi * STMicroelectronics uvis25 spi driver
43025c868SLorenzo Bianconi *
53025c868SLorenzo Bianconi * Copyright 2017 STMicroelectronics Inc.
63025c868SLorenzo Bianconi *
73025c868SLorenzo Bianconi * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
83025c868SLorenzo Bianconi */
93025c868SLorenzo Bianconi
103025c868SLorenzo Bianconi #include <linux/kernel.h>
113025c868SLorenzo Bianconi #include <linux/module.h>
12645aee51SJonathan Cameron #include <linux/mod_devicetable.h>
133025c868SLorenzo Bianconi #include <linux/spi/spi.h>
143025c868SLorenzo Bianconi #include <linux/slab.h>
153025c868SLorenzo Bianconi #include <linux/regmap.h>
163025c868SLorenzo Bianconi
173025c868SLorenzo Bianconi #include "st_uvis25.h"
183025c868SLorenzo Bianconi
193025c868SLorenzo Bianconi #define UVIS25_SENSORS_SPI_READ BIT(7)
203025c868SLorenzo Bianconi #define UVIS25_SPI_AUTO_INCREMENT BIT(6)
213025c868SLorenzo Bianconi
22debbbbefSColin Ian King static const struct regmap_config st_uvis25_spi_regmap_config = {
233025c868SLorenzo Bianconi .reg_bits = 8,
243025c868SLorenzo Bianconi .val_bits = 8,
253025c868SLorenzo Bianconi .read_flag_mask = UVIS25_SENSORS_SPI_READ | UVIS25_SPI_AUTO_INCREMENT,
263025c868SLorenzo Bianconi .write_flag_mask = UVIS25_SPI_AUTO_INCREMENT,
273025c868SLorenzo Bianconi };
283025c868SLorenzo Bianconi
st_uvis25_spi_probe(struct spi_device * spi)293025c868SLorenzo Bianconi static int st_uvis25_spi_probe(struct spi_device *spi)
303025c868SLorenzo Bianconi {
313025c868SLorenzo Bianconi struct regmap *regmap;
323025c868SLorenzo Bianconi
333025c868SLorenzo Bianconi regmap = devm_regmap_init_spi(spi, &st_uvis25_spi_regmap_config);
343025c868SLorenzo Bianconi if (IS_ERR(regmap)) {
353c50dee9SAndy Shevchenko dev_err(&spi->dev, "Failed to register spi regmap %ld\n",
363c50dee9SAndy Shevchenko PTR_ERR(regmap));
373025c868SLorenzo Bianconi return PTR_ERR(regmap);
383025c868SLorenzo Bianconi }
393025c868SLorenzo Bianconi
403025c868SLorenzo Bianconi return st_uvis25_probe(&spi->dev, spi->irq, regmap);
413025c868SLorenzo Bianconi }
423025c868SLorenzo Bianconi
433025c868SLorenzo Bianconi static const struct of_device_id st_uvis25_spi_of_match[] = {
443025c868SLorenzo Bianconi { .compatible = "st,uvis25", },
453025c868SLorenzo Bianconi {},
463025c868SLorenzo Bianconi };
473025c868SLorenzo Bianconi MODULE_DEVICE_TABLE(of, st_uvis25_spi_of_match);
483025c868SLorenzo Bianconi
493025c868SLorenzo Bianconi static const struct spi_device_id st_uvis25_spi_id_table[] = {
503025c868SLorenzo Bianconi { ST_UVIS25_DEV_NAME },
513025c868SLorenzo Bianconi {},
523025c868SLorenzo Bianconi };
533025c868SLorenzo Bianconi MODULE_DEVICE_TABLE(spi, st_uvis25_spi_id_table);
543025c868SLorenzo Bianconi
553025c868SLorenzo Bianconi static struct spi_driver st_uvis25_driver = {
563025c868SLorenzo Bianconi .driver = {
573025c868SLorenzo Bianconi .name = "st_uvis25_spi",
58*3259b99eSJonathan Cameron .pm = pm_sleep_ptr(&st_uvis25_pm_ops),
59645aee51SJonathan Cameron .of_match_table = st_uvis25_spi_of_match,
603025c868SLorenzo Bianconi },
613025c868SLorenzo Bianconi .probe = st_uvis25_spi_probe,
623025c868SLorenzo Bianconi .id_table = st_uvis25_spi_id_table,
633025c868SLorenzo Bianconi };
643025c868SLorenzo Bianconi module_spi_driver(st_uvis25_driver);
653025c868SLorenzo Bianconi
663025c868SLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
673025c868SLorenzo Bianconi MODULE_DESCRIPTION("STMicroelectronics uvis25 spi driver");
683025c868SLorenzo Bianconi MODULE_LICENSE("GPL v2");
69cfaa5482SJonathan Cameron MODULE_IMPORT_NS(IIO_UVIS25);
70