]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
f543701960984738d5fa149276eb4781aac94296
[linux.git] / drivers / iio / imu / st_lsm6dsx / st_lsm6dsx_i2c.c
1 /*
2  * STMicroelectronics st_lsm6dsx i2c driver
3  *
4  * Copyright 2016 STMicroelectronics Inc.
5  *
6  * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7  * Denis Ciocca <denis.ciocca@st.com>
8  *
9  * Licensed under the GPL-2.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/i2c.h>
15 #include <linux/slab.h>
16 #include <linux/of.h>
17 #include <linux/regmap.h>
18
19 #include "st_lsm6dsx.h"
20
21 static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
22         .reg_bits = 8,
23         .val_bits = 8,
24 };
25
26 static int st_lsm6dsx_i2c_probe(struct i2c_client *client,
27                                 const struct i2c_device_id *id)
28 {
29         int hw_id = id->driver_data;
30         struct regmap *regmap;
31
32         regmap = devm_regmap_init_i2c(client, &st_lsm6dsx_i2c_regmap_config);
33         if (IS_ERR(regmap)) {
34                 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
35                         (int)PTR_ERR(regmap));
36                 return PTR_ERR(regmap);
37         }
38
39         return st_lsm6dsx_probe(&client->dev, client->irq,
40                                 hw_id, id->name, regmap);
41 }
42
43 static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
44         {
45                 .compatible = "st,lsm6ds3",
46                 .data = (void *)ST_LSM6DS3_ID,
47         },
48         {
49                 .compatible = "st,lsm6ds3h",
50                 .data = (void *)ST_LSM6DS3H_ID,
51         },
52         {
53                 .compatible = "st,lsm6dsl",
54                 .data = (void *)ST_LSM6DSL_ID,
55         },
56         {
57                 .compatible = "st,lsm6dsm",
58                 .data = (void *)ST_LSM6DSM_ID,
59         },
60         {
61                 .compatible = "st,ism330dlc",
62                 .data = (void *)ST_ISM330DLC_ID,
63         },
64         {
65                 .compatible = "st,lsm6dso",
66                 .data = (void *)ST_LSM6DSO_ID,
67         },
68         {
69                 .compatible = "st,asm330lhh",
70                 .data = (void *)ST_ASM330LHH_ID,
71         },
72         {
73                 .compatible = "st,lsm6dsox",
74                 .data = (void *)ST_LSM6DSOX_ID,
75         },
76         {
77                 .compatible = "st,lsm6dsr",
78                 .data = (void *)ST_LSM6DSR_ID,
79         },
80         {},
81 };
82 MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
83
84 static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
85         { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
86         { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
87         { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
88         { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
89         { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
90         { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
91         { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
92         { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
93         { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
94         {},
95 };
96 MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
97
98 static struct i2c_driver st_lsm6dsx_driver = {
99         .driver = {
100                 .name = "st_lsm6dsx_i2c",
101                 .pm = &st_lsm6dsx_pm_ops,
102                 .of_match_table = of_match_ptr(st_lsm6dsx_i2c_of_match),
103         },
104         .probe = st_lsm6dsx_i2c_probe,
105         .id_table = st_lsm6dsx_i2c_id_table,
106 };
107 module_i2c_driver(st_lsm6dsx_driver);
108
109 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
110 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
111 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver");
112 MODULE_LICENSE("GPL v2");