summaryrefslogtreecommitdiff
path: root/drivers/iio/light/st_uvis25_spi.c
blob: af9d94d1278724b0fea7bed40e99f0632c2b7998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: GPL-2.0-only
/*
 * STMicroelectronics uvis25 spi driver
 *
 * Copyright 2017 STMicroelectronics Inc.
 *
 * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
#include <linux/regmap.h>

#include "st_uvis25.h"

#define UVIS25_SENSORS_SPI_READ		BIT(7)
#define UVIS25_SPI_AUTO_INCREMENT	BIT(6)

static const struct regmap_config st_uvis25_spi_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.read_flag_mask = UVIS25_SENSORS_SPI_READ | UVIS25_SPI_AUTO_INCREMENT,
	.write_flag_mask = UVIS25_SPI_AUTO_INCREMENT,
};

static int st_uvis25_spi_probe(struct spi_device *spi)
{
	struct regmap *regmap;

	regmap = devm_regmap_init_spi(spi, &st_uvis25_spi_regmap_config);
	if (IS_ERR(regmap)) {
		dev_err(&spi->dev, "Failed to register spi regmap %ld\n",
			PTR_ERR(regmap));
		return PTR_ERR(regmap);
	}

	return st_uvis25_probe(&spi->dev, spi->irq, regmap);
}

static const struct of_device_id st_uvis25_spi_of_match[] = {
	{ .compatible = "st,uvis25", },
	{},
};
MODULE_DEVICE_TABLE(of, st_uvis25_spi_of_match);

static const struct spi_device_id st_uvis25_spi_id_table[] = {
	{ ST_UVIS25_DEV_NAME },
	{},
};
MODULE_DEVICE_TABLE(spi, st_uvis25_spi_id_table);

static struct spi_driver st_uvis25_driver = {
	.driver = {
		.name = "st_uvis25_spi",
		.pm = &st_uvis25_pm_ops,
		.of_match_table = st_uvis25_spi_of_match,
	},
	.probe = st_uvis25_spi_probe,
	.id_table = st_uvis25_spi_id_table,
};
module_spi_driver(st_uvis25_driver);

MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
MODULE_DESCRIPTION("STMicroelectronics uvis25 spi driver");
MODULE_LICENSE("GPL v2");