blob: 7f15e927fa2bce3acf5e190a16c7b4878fb123d2 [file] [log] [blame]
Denis CIOCCA217494e2013-06-03 15:58:00 +01001/*
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>
Shrirang Bagul9d317722016-11-24 13:33:45 +080014#include <linux/acpi.h>
Denis CIOCCA217494e2013-06-03 15:58:00 +010015#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
Linus Walleij2d7768a2014-08-07 08:16:00 +010022#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 },
Gregor Boiriee039e2f2016-04-19 11:18:32 +020036 {
37 .compatible = "st,lps22hb-press",
38 .data = LPS22HB_PRESS_DEV_NAME,
39 },
Linus Walleij2d7768a2014-08-07 08:16:00 +010040 {},
41};
42MODULE_DEVICE_TABLE(of, st_press_of_match);
43#else
44#define st_press_of_match NULL
45#endif
46
Shrirang Bagul9d317722016-11-24 13:33:45 +080047#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
Denis CIOCCA217494e2013-06-03 15:58:00 +010066static int st_press_i2c_probe(struct i2c_client *client,
67 const struct i2c_device_id *id)
68{
69 struct iio_dev *indio_dev;
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020070 struct st_sensor_data *press_data;
Shrirang Bagul9d317722016-11-24 13:33:45 +080071 int ret;
Denis CIOCCA217494e2013-06-03 15:58:00 +010072
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020073 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
Sachin Kamatd0fe8c8b2013-07-30 07:24:00 +010074 if (!indio_dev)
75 return -ENOMEM;
Denis CIOCCA217494e2013-06-03 15:58:00 +010076
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020077 press_data = iio_priv(indio_dev);
Shrirang Bagul9d317722016-11-24 13:33:45 +080078
79 if (client->dev.of_node) {
Lorenzo Bianconi250bbbd2017-06-20 21:52:08 +020080 st_sensors_of_name_probe(&client->dev, st_press_of_match,
81 client->name, sizeof(client->name));
Shrirang Bagul9d317722016-11-24 13:33:45 +080082 } else if (ACPI_HANDLE(&client->dev)) {
83 ret = st_sensors_match_acpi_device(&client->dev);
84 if ((ret < 0) || (ret >= ST_PRESS_MAX))
85 return -ENODEV;
86
87 strncpy(client->name, st_press_id_table[ret].name,
88 sizeof(client->name));
89 client->name[sizeof(client->name) - 1] = '\0';
90 } else if (!id)
91 return -ENODEV;
Denis CIOCCA217494e2013-06-03 15:58:00 +010092
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020093 st_sensors_i2c_configure(indio_dev, client, press_data);
Denis CIOCCA217494e2013-06-03 15:58:00 +010094
Shrirang Bagul9d317722016-11-24 13:33:45 +080095 ret = st_press_common_probe(indio_dev);
96 if (ret < 0)
97 return ret;
Denis CIOCCA217494e2013-06-03 15:58:00 +010098
99 return 0;
Denis CIOCCA217494e2013-06-03 15:58:00 +0100100}
101
102static int st_press_i2c_remove(struct i2c_client *client)
103{
104 st_press_common_remove(i2c_get_clientdata(client));
105
106 return 0;
107}
108
Denis CIOCCA217494e2013-06-03 15:58:00 +0100109static struct i2c_driver st_press_driver = {
110 .driver = {
Denis CIOCCA217494e2013-06-03 15:58:00 +0100111 .name = "st-press-i2c",
Linus Walleij2d7768a2014-08-07 08:16:00 +0100112 .of_match_table = of_match_ptr(st_press_of_match),
Shrirang Bagul9d317722016-11-24 13:33:45 +0800113 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
Denis CIOCCA217494e2013-06-03 15:58:00 +0100114 },
115 .probe = st_press_i2c_probe,
116 .remove = st_press_i2c_remove,
117 .id_table = st_press_id_table,
118};
119module_i2c_driver(st_press_driver);
120
121MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
122MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
123MODULE_LICENSE("GPL v2");