dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / iio / accel / st_accel_i2c.c
blobde8ae4327094b26454181d511c44c3199718eabf
1 /*
2 * STMicroelectronics accelerometers driver
4 * Copyright 2012-2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
8 * Licensed under the GPL-2.
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/acpi.h>
15 #include <linux/i2c.h>
16 #include <linux/iio/iio.h>
17 #include <linux/property.h>
19 #include <linux/iio/common/st_sensors_i2c.h>
20 #include "st_accel.h"
22 #ifdef CONFIG_OF
23 static const struct of_device_id st_accel_of_match[] = {
25 /* An older compatible */
26 .compatible = "st,lis3lv02d",
27 .data = LIS3LV02DL_ACCEL_DEV_NAME,
30 .compatible = "st,lis3lv02dl-accel",
31 .data = LIS3LV02DL_ACCEL_DEV_NAME,
34 .compatible = "st,lsm303dlh-accel",
35 .data = LSM303DLH_ACCEL_DEV_NAME,
38 .compatible = "st,lsm303dlhc-accel",
39 .data = LSM303DLHC_ACCEL_DEV_NAME,
42 .compatible = "st,lis3dh-accel",
43 .data = LIS3DH_ACCEL_DEV_NAME,
46 .compatible = "st,lsm330d-accel",
47 .data = LSM330D_ACCEL_DEV_NAME,
50 .compatible = "st,lsm330dl-accel",
51 .data = LSM330DL_ACCEL_DEV_NAME,
54 .compatible = "st,lsm330dlc-accel",
55 .data = LSM330DLC_ACCEL_DEV_NAME,
58 .compatible = "st,lis331dl-accel",
59 .data = LIS331DL_ACCEL_DEV_NAME,
62 .compatible = "st,lis331dlh-accel",
63 .data = LIS331DLH_ACCEL_DEV_NAME,
66 .compatible = "st,lsm303dl-accel",
67 .data = LSM303DL_ACCEL_DEV_NAME,
70 .compatible = "st,lsm303dlm-accel",
71 .data = LSM303DLM_ACCEL_DEV_NAME,
74 .compatible = "st,lsm330-accel",
75 .data = LSM330_ACCEL_DEV_NAME,
78 .compatible = "st,lsm303agr-accel",
79 .data = LSM303AGR_ACCEL_DEV_NAME,
82 .compatible = "st,lis2dh12-accel",
83 .data = LIS2DH12_ACCEL_DEV_NAME,
86 .compatible = "st,h3lis331dl-accel",
87 .data = H3LIS331DL_ACCEL_DEV_NAME,
90 .compatible = "st,lis3l02dq",
91 .data = LIS3L02DQ_ACCEL_DEV_NAME,
94 .compatible = "st,lng2dm-accel",
95 .data = LNG2DM_ACCEL_DEV_NAME,
98 .compatible = "st,lis2dw12",
99 .data = LIS2DW12_ACCEL_DEV_NAME,
102 .compatible = "st,lis3de",
103 .data = LIS3DE_ACCEL_DEV_NAME,
107 MODULE_DEVICE_TABLE(of, st_accel_of_match);
108 #else
109 #define st_accel_of_match NULL
110 #endif
112 #ifdef CONFIG_ACPI
113 static const struct acpi_device_id st_accel_acpi_match[] = {
114 {"SMO8840", (kernel_ulong_t)LNG2DM_ACCEL_DEV_NAME},
115 {"SMO8A90", (kernel_ulong_t)LNG2DM_ACCEL_DEV_NAME},
116 { },
118 MODULE_DEVICE_TABLE(acpi, st_accel_acpi_match);
119 #else
120 #define st_accel_acpi_match NULL
121 #endif
123 static const struct i2c_device_id st_accel_id_table[] = {
124 { LSM303DLH_ACCEL_DEV_NAME },
125 { LSM303DLHC_ACCEL_DEV_NAME },
126 { LIS3DH_ACCEL_DEV_NAME },
127 { LSM330D_ACCEL_DEV_NAME },
128 { LSM330DL_ACCEL_DEV_NAME },
129 { LSM330DLC_ACCEL_DEV_NAME },
130 { LIS331DLH_ACCEL_DEV_NAME },
131 { LSM303DL_ACCEL_DEV_NAME },
132 { LSM303DLM_ACCEL_DEV_NAME },
133 { LSM330_ACCEL_DEV_NAME },
134 { LSM303AGR_ACCEL_DEV_NAME },
135 { LIS2DH12_ACCEL_DEV_NAME },
136 { LIS3L02DQ_ACCEL_DEV_NAME },
137 { LNG2DM_ACCEL_DEV_NAME },
138 { H3LIS331DL_ACCEL_DEV_NAME },
139 { LIS331DL_ACCEL_DEV_NAME },
140 { LIS3LV02DL_ACCEL_DEV_NAME },
141 { LIS2DW12_ACCEL_DEV_NAME },
142 { LIS3DE_ACCEL_DEV_NAME },
145 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
147 static int st_accel_i2c_probe(struct i2c_client *client)
149 struct iio_dev *indio_dev;
150 struct st_sensor_data *adata;
151 const char *match;
152 int ret;
154 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
155 if (!indio_dev)
156 return -ENOMEM;
158 adata = iio_priv(indio_dev);
160 match = device_get_match_data(&client->dev);
161 if (match)
162 strlcpy(client->name, match, sizeof(client->name));
164 st_sensors_i2c_configure(indio_dev, client, adata);
166 ret = st_accel_common_probe(indio_dev);
167 if (ret < 0)
168 return ret;
170 return 0;
173 static int st_accel_i2c_remove(struct i2c_client *client)
175 st_accel_common_remove(i2c_get_clientdata(client));
177 return 0;
180 static struct i2c_driver st_accel_driver = {
181 .driver = {
182 .name = "st-accel-i2c",
183 .of_match_table = of_match_ptr(st_accel_of_match),
184 .acpi_match_table = ACPI_PTR(st_accel_acpi_match),
186 .probe_new = st_accel_i2c_probe,
187 .remove = st_accel_i2c_remove,
188 .id_table = st_accel_id_table,
190 module_i2c_driver(st_accel_driver);
192 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
193 MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
194 MODULE_LICENSE("GPL v2");