GNU Linux-libre 4.19.286-gnu1
[releases.git] / drivers / iio / light / st_uvis25_spi.c
1 /*
2  * STMicroelectronics uvis25 spi driver
3  *
4  * Copyright 2017 STMicroelectronics Inc.
5  *
6  * Lorenzo Bianconi <lorenzo.bianconi83@gmail.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>
15 #include <linux/regmap.h>
16
17 #include "st_uvis25.h"
18
19 #define UVIS25_SENSORS_SPI_READ         BIT(7)
20 #define UVIS25_SPI_AUTO_INCREMENT       BIT(6)
21
22 static const struct regmap_config st_uvis25_spi_regmap_config = {
23         .reg_bits = 8,
24         .val_bits = 8,
25         .read_flag_mask = UVIS25_SENSORS_SPI_READ | UVIS25_SPI_AUTO_INCREMENT,
26         .write_flag_mask = UVIS25_SPI_AUTO_INCREMENT,
27 };
28
29 static int st_uvis25_spi_probe(struct spi_device *spi)
30 {
31         struct regmap *regmap;
32
33         regmap = devm_regmap_init_spi(spi, &st_uvis25_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
40         return st_uvis25_probe(&spi->dev, spi->irq, regmap);
41 }
42
43 static const struct of_device_id st_uvis25_spi_of_match[] = {
44         { .compatible = "st,uvis25", },
45         {},
46 };
47 MODULE_DEVICE_TABLE(of, st_uvis25_spi_of_match);
48
49 static const struct spi_device_id st_uvis25_spi_id_table[] = {
50         { ST_UVIS25_DEV_NAME },
51         {},
52 };
53 MODULE_DEVICE_TABLE(spi, st_uvis25_spi_id_table);
54
55 static struct spi_driver st_uvis25_driver = {
56         .driver = {
57                 .name = "st_uvis25_spi",
58                 .pm = &st_uvis25_pm_ops,
59                 .of_match_table = of_match_ptr(st_uvis25_spi_of_match),
60         },
61         .probe = st_uvis25_spi_probe,
62         .id_table = st_uvis25_spi_id_table,
63 };
64 module_spi_driver(st_uvis25_driver);
65
66 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
67 MODULE_DESCRIPTION("STMicroelectronics uvis25 spi driver");
68 MODULE_LICENSE("GPL v2");