Merge tag 'afs-next-20190628' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowel...
[linux-2.6-microblaze.git] / drivers / iio / imu / st_lsm6dsx / st_lsm6dsx_spi.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * STMicroelectronics st_lsm6dsx spi driver
4  *
5  * Copyright 2016 STMicroelectronics Inc.
6  *
7  * Lorenzo Bianconi <lorenzo.bianconi@st.com>
8  * Denis Ciocca <denis.ciocca@st.com>
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/of.h>
16 #include <linux/regmap.h>
17
18 #include "st_lsm6dsx.h"
19
20 static const struct regmap_config st_lsm6dsx_spi_regmap_config = {
21         .reg_bits = 8,
22         .val_bits = 8,
23 };
24
25 static int st_lsm6dsx_spi_probe(struct spi_device *spi)
26 {
27         const struct spi_device_id *id = spi_get_device_id(spi);
28         int hw_id = id->driver_data;
29         struct regmap *regmap;
30
31         regmap = devm_regmap_init_spi(spi, &st_lsm6dsx_spi_regmap_config);
32         if (IS_ERR(regmap)) {
33                 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
34                         (int)PTR_ERR(regmap));
35                 return PTR_ERR(regmap);
36         }
37
38         return st_lsm6dsx_probe(&spi->dev, spi->irq,
39                                 hw_id, id->name, regmap);
40 }
41
42 static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
43         {
44                 .compatible = "st,lsm6ds3",
45                 .data = (void *)ST_LSM6DS3_ID,
46         },
47         {
48                 .compatible = "st,lsm6ds3h",
49                 .data = (void *)ST_LSM6DS3H_ID,
50         },
51         {
52                 .compatible = "st,lsm6dsl",
53                 .data = (void *)ST_LSM6DSL_ID,
54         },
55         {
56                 .compatible = "st,lsm6dsm",
57                 .data = (void *)ST_LSM6DSM_ID,
58         },
59         {
60                 .compatible = "st,ism330dlc",
61                 .data = (void *)ST_ISM330DLC_ID,
62         },
63         {
64                 .compatible = "st,lsm6dso",
65                 .data = (void *)ST_LSM6DSO_ID,
66         },
67         {
68                 .compatible = "st,asm330lhh",
69                 .data = (void *)ST_ASM330LHH_ID,
70         },
71         {
72                 .compatible = "st,lsm6dsox",
73                 .data = (void *)ST_LSM6DSOX_ID,
74         },
75         {
76                 .compatible = "st,lsm6dsr",
77                 .data = (void *)ST_LSM6DSR_ID,
78         },
79         {},
80 };
81 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
82
83 static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
84         { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
85         { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
86         { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
87         { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
88         { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
89         { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
90         { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
91         { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
92         { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
93         {},
94 };
95 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
96
97 static struct spi_driver st_lsm6dsx_driver = {
98         .driver = {
99                 .name = "st_lsm6dsx_spi",
100                 .pm = &st_lsm6dsx_pm_ops,
101                 .of_match_table = of_match_ptr(st_lsm6dsx_spi_of_match),
102         },
103         .probe = st_lsm6dsx_spi_probe,
104         .id_table = st_lsm6dsx_spi_id_table,
105 };
106 module_spi_driver(st_lsm6dsx_driver);
107
108 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
109 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
110 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
111 MODULE_LICENSE("GPL v2");