Merge tag 'trace-v4.11-rc5-4' of git://git.kernel.org/pub/scm/linux/kernel/git/rosted...
[linux-2.6-block.git] / drivers / iio / pressure / st_pressure_i2c.c
CommitLineData
217494e5
DC
1/*
2 * STMicroelectronics pressures driver
3 *
4 * Copyright 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>
9d317724 14#include <linux/acpi.h>
217494e5
DC
15#include <linux/i2c.h>
16#include <linux/iio/iio.h>
17
18#include <linux/iio/common/st_sensors.h>
19#include <linux/iio/common/st_sensors_i2c.h>
20#include "st_pressure.h"
21
2d7768a8
LW
22#ifdef CONFIG_OF
23static const struct of_device_id st_press_of_match[] = {
24 {
25 .compatible = "st,lps001wp-press",
26 .data = LPS001WP_PRESS_DEV_NAME,
27 },
28 {
29 .compatible = "st,lps25h-press",
30 .data = LPS25H_PRESS_DEV_NAME,
31 },
32 {
33 .compatible = "st,lps331ap-press",
34 .data = LPS331AP_PRESS_DEV_NAME,
35 },
e039e2f5
GB
36 {
37 .compatible = "st,lps22hb-press",
38 .data = LPS22HB_PRESS_DEV_NAME,
39 },
2d7768a8
LW
40 {},
41};
42MODULE_DEVICE_TABLE(of, st_press_of_match);
43#else
44#define st_press_of_match NULL
45#endif
46
9d317724
SB
47#ifdef CONFIG_ACPI
48static const struct acpi_device_id st_press_acpi_match[] = {
49 {"SNO9210", LPS22HB},
50 { },
51};
52MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
53#else
54#define st_press_acpi_match NULL
55#endif
56
57static const struct i2c_device_id st_press_id_table[] = {
58 { LPS001WP_PRESS_DEV_NAME, LPS001WP },
59 { LPS25H_PRESS_DEV_NAME, LPS25H },
60 { LPS331AP_PRESS_DEV_NAME, LPS331AP },
61 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
62 {},
63};
64MODULE_DEVICE_TABLE(i2c, st_press_id_table);
65
217494e5
DC
66static int st_press_i2c_probe(struct i2c_client *client,
67 const struct i2c_device_id *id)
68{
69 struct iio_dev *indio_dev;
a1dcf429 70 struct st_sensor_data *press_data;
9d317724 71 int ret;
217494e5 72
a1dcf429 73 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
d0fe8c8b
SK
74 if (!indio_dev)
75 return -ENOMEM;
217494e5 76
a1dcf429 77 press_data = iio_priv(indio_dev);
9d317724
SB
78
79 if (client->dev.of_node) {
80 st_sensors_of_i2c_probe(client, st_press_of_match);
81 } else if (ACPI_HANDLE(&client->dev)) {
82 ret = st_sensors_match_acpi_device(&client->dev);
83 if ((ret < 0) || (ret >= ST_PRESS_MAX))
84 return -ENODEV;
85
86 strncpy(client->name, st_press_id_table[ret].name,
87 sizeof(client->name));
88 client->name[sizeof(client->name) - 1] = '\0';
89 } else if (!id)
90 return -ENODEV;
217494e5 91
a1dcf429 92 st_sensors_i2c_configure(indio_dev, client, press_data);
217494e5 93
9d317724
SB
94 ret = st_press_common_probe(indio_dev);
95 if (ret < 0)
96 return ret;
217494e5
DC
97
98 return 0;
217494e5
DC
99}
100
101static int st_press_i2c_remove(struct i2c_client *client)
102{
103 st_press_common_remove(i2c_get_clientdata(client));
104
105 return 0;
106}
107
217494e5
DC
108static struct i2c_driver st_press_driver = {
109 .driver = {
217494e5 110 .name = "st-press-i2c",
2d7768a8 111 .of_match_table = of_match_ptr(st_press_of_match),
9d317724 112 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
217494e5
DC
113 },
114 .probe = st_press_i2c_probe,
115 .remove = st_press_i2c_remove,
116 .id_table = st_press_id_table,
117};
118module_i2c_driver(st_press_driver);
119
120MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
121MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
122MODULE_LICENSE("GPL v2");