blob: ed18701c68c97efe1d5604a85e6178bd097ea123 [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>
14#include <linux/i2c.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_pressure.h"
20
Linus Walleij2d7768a2014-08-07 08:16:00 +010021#ifdef CONFIG_OF
22static const struct of_device_id st_press_of_match[] = {
23 {
24 .compatible = "st,lps001wp-press",
25 .data = LPS001WP_PRESS_DEV_NAME,
26 },
27 {
28 .compatible = "st,lps25h-press",
29 .data = LPS25H_PRESS_DEV_NAME,
30 },
31 {
32 .compatible = "st,lps331ap-press",
33 .data = LPS331AP_PRESS_DEV_NAME,
34 },
Gregor Boiriee039e2f2016-04-19 11:18:32 +020035 {
36 .compatible = "st,lps22hb-press",
37 .data = LPS22HB_PRESS_DEV_NAME,
38 },
Linus Walleij2d7768a2014-08-07 08:16:00 +010039 {},
40};
41MODULE_DEVICE_TABLE(of, st_press_of_match);
42#else
43#define st_press_of_match NULL
44#endif
45
Denis CIOCCA217494e2013-06-03 15:58:00 +010046static int st_press_i2c_probe(struct i2c_client *client,
47 const struct i2c_device_id *id)
48{
49 struct iio_dev *indio_dev;
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020050 struct st_sensor_data *press_data;
Denis CIOCCA217494e2013-06-03 15:58:00 +010051 int err;
52
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020053 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
Sachin Kamatd0fe8c8b2013-07-30 07:24:00 +010054 if (!indio_dev)
55 return -ENOMEM;
Denis CIOCCA217494e2013-06-03 15:58:00 +010056
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020057 press_data = iio_priv(indio_dev);
Linus Walleij2d7768a2014-08-07 08:16:00 +010058 st_sensors_of_i2c_probe(client, st_press_of_match);
Denis CIOCCA217494e2013-06-03 15:58:00 +010059
Denis CIOCCAa1dcf422014-10-03 17:35:40 +020060 st_sensors_i2c_configure(indio_dev, client, press_data);
Denis CIOCCA217494e2013-06-03 15:58:00 +010061
Denis CIOCCA0baa3fc2014-10-03 17:35:39 +020062 err = st_press_common_probe(indio_dev);
Denis CIOCCA217494e2013-06-03 15:58:00 +010063 if (err < 0)
Sachin Kamatd0fe8c8b2013-07-30 07:24:00 +010064 return err;
Denis CIOCCA217494e2013-06-03 15:58:00 +010065
66 return 0;
Denis CIOCCA217494e2013-06-03 15:58:00 +010067}
68
69static int st_press_i2c_remove(struct i2c_client *client)
70{
71 st_press_common_remove(i2c_get_clientdata(client));
72
73 return 0;
74}
75
76static const struct i2c_device_id st_press_id_table[] = {
Lee Jones7885a8c2013-09-16 17:02:00 +010077 { LPS001WP_PRESS_DEV_NAME },
Denis CIOCCA93187842014-02-20 17:49:00 +000078 { LPS25H_PRESS_DEV_NAME },
Denis CIOCCA217494e2013-06-03 15:58:00 +010079 { LPS331AP_PRESS_DEV_NAME },
80 {},
81};
82MODULE_DEVICE_TABLE(i2c, st_press_id_table);
83
84static struct i2c_driver st_press_driver = {
85 .driver = {
Denis CIOCCA217494e2013-06-03 15:58:00 +010086 .name = "st-press-i2c",
Linus Walleij2d7768a2014-08-07 08:16:00 +010087 .of_match_table = of_match_ptr(st_press_of_match),
Denis CIOCCA217494e2013-06-03 15:58:00 +010088 },
89 .probe = st_press_i2c_probe,
90 .remove = st_press_i2c_remove,
91 .id_table = st_press_id_table,
92};
93module_i2c_driver(st_press_driver);
94
95MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
96MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
97MODULE_LICENSE("GPL v2");