blob: 7164aeff3ab13ca14325585b12967b51c44bafa3 [file] [log] [blame]
Denis Cioccad6251162013-01-25 23:44:00 +00001/*
2 * STMicroelectronics accelerometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/iio/iio.h>
Denis Cioccad6251162013-01-25 23:44:00 +000016
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_accel.h"
20
Linus Walleij2d7768a2014-08-07 08:16:00 +010021#ifdef CONFIG_OF
22static const struct of_device_id st_accel_of_match[] = {
23 {
24 .compatible = "st,lsm303dlh-accel",
25 .data = LSM303DLH_ACCEL_DEV_NAME,
26 },
27 {
28 .compatible = "st,lsm303dlhc-accel",
29 .data = LSM303DLHC_ACCEL_DEV_NAME,
30 },
31 {
32 .compatible = "st,lis3dh-accel",
33 .data = LIS3DH_ACCEL_DEV_NAME,
34 },
35 {
36 .compatible = "st,lsm330d-accel",
37 .data = LSM330D_ACCEL_DEV_NAME,
38 },
39 {
40 .compatible = "st,lsm330dl-accel",
41 .data = LSM330DL_ACCEL_DEV_NAME,
42 },
43 {
44 .compatible = "st,lsm330dlc-accel",
45 .data = LSM330DLC_ACCEL_DEV_NAME,
46 },
47 {
48 .compatible = "st,lis331dlh-accel",
49 .data = LIS331DLH_ACCEL_DEV_NAME,
50 },
51 {
52 .compatible = "st,lsm303dl-accel",
53 .data = LSM303DL_ACCEL_DEV_NAME,
54 },
55 {
56 .compatible = "st,lsm303dlm-accel",
57 .data = LSM303DLM_ACCEL_DEV_NAME,
58 },
59 {
60 .compatible = "st,lsm330-accel",
61 .data = LSM330_ACCEL_DEV_NAME,
62 },
63 {},
64};
65MODULE_DEVICE_TABLE(of, st_accel_of_match);
66#else
67#define st_accel_of_match NULL
68#endif
69
Denis Cioccad6251162013-01-25 23:44:00 +000070static int st_accel_i2c_probe(struct i2c_client *client,
71 const struct i2c_device_id *id)
72{
73 struct iio_dev *indio_dev;
74 struct st_sensor_data *adata;
75 int err;
76
Sachin Kamat6b7e0a92013-07-23 07:47:00 +010077 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
78 if (!indio_dev)
79 return -ENOMEM;
Denis Cioccad6251162013-01-25 23:44:00 +000080
81 adata = iio_priv(indio_dev);
82 adata->dev = &client->dev;
Linus Walleij2d7768a2014-08-07 08:16:00 +010083 st_sensors_of_i2c_probe(client, st_accel_of_match);
Denis Cioccad6251162013-01-25 23:44:00 +000084
85 st_sensors_i2c_configure(indio_dev, client, adata);
86
Denis CIOCCA23cde4d2013-06-19 09:28:00 +010087 err = st_accel_common_probe(indio_dev, client->dev.platform_data);
Denis Cioccad6251162013-01-25 23:44:00 +000088 if (err < 0)
Sachin Kamat6b7e0a92013-07-23 07:47:00 +010089 return err;
Denis Cioccad6251162013-01-25 23:44:00 +000090
91 return 0;
Denis Cioccad6251162013-01-25 23:44:00 +000092}
93
94static int st_accel_i2c_remove(struct i2c_client *client)
95{
96 st_accel_common_remove(i2c_get_clientdata(client));
97
98 return 0;
99}
100
101static const struct i2c_device_id st_accel_id_table[] = {
102 { LSM303DLH_ACCEL_DEV_NAME },
103 { LSM303DLHC_ACCEL_DEV_NAME },
104 { LIS3DH_ACCEL_DEV_NAME },
105 { LSM330D_ACCEL_DEV_NAME },
106 { LSM330DL_ACCEL_DEV_NAME },
107 { LSM330DLC_ACCEL_DEV_NAME },
108 { LIS331DLH_ACCEL_DEV_NAME },
109 { LSM303DL_ACCEL_DEV_NAME },
110 { LSM303DLM_ACCEL_DEV_NAME },
111 { LSM330_ACCEL_DEV_NAME },
112 {},
113};
114MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
115
116static struct i2c_driver st_accel_driver = {
117 .driver = {
118 .owner = THIS_MODULE,
119 .name = "st-accel-i2c",
Linus Walleij2d7768a2014-08-07 08:16:00 +0100120 .of_match_table = of_match_ptr(st_accel_of_match),
Denis Cioccad6251162013-01-25 23:44:00 +0000121 },
122 .probe = st_accel_i2c_probe,
123 .remove = st_accel_i2c_remove,
124 .id_table = st_accel_id_table,
125};
126module_i2c_driver(st_accel_driver);
127
128MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
129MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
130MODULE_LICENSE("GPL v2");