1
2
3
4
5
6
7
8
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/spi/spi.h>
14#include <linux/iio/iio.h>
15
16#include <linux/iio/common/st_sensors.h>
17#include <linux/iio/common/st_sensors_spi.h>
18#include "st_pressure.h"
19
20#ifdef CONFIG_OF
21
22
23
24
25
26static const struct of_device_id st_press_of_match[] = {
27 {
28 .compatible = "st,lps001wp-press",
29 .data = LPS001WP_PRESS_DEV_NAME,
30 },
31 {
32 .compatible = "st,lps25h-press",
33 .data = LPS25H_PRESS_DEV_NAME,
34 },
35 {
36 .compatible = "st,lps331ap-press",
37 .data = LPS331AP_PRESS_DEV_NAME,
38 },
39 {
40 .compatible = "st,lps22hb-press",
41 .data = LPS22HB_PRESS_DEV_NAME,
42 },
43 {
44 .compatible = "st,lps33hw",
45 .data = LPS33HW_PRESS_DEV_NAME,
46 },
47 {
48 .compatible = "st,lps35hw",
49 .data = LPS35HW_PRESS_DEV_NAME,
50 },
51 {
52 .compatible = "st,lps22hh",
53 .data = LPS22HH_PRESS_DEV_NAME,
54 },
55 {},
56};
57MODULE_DEVICE_TABLE(of, st_press_of_match);
58#else
59#define st_press_of_match NULL
60#endif
61
62static int st_press_spi_probe(struct spi_device *spi)
63{
64 struct iio_dev *indio_dev;
65 struct st_sensor_data *press_data;
66 int err;
67
68 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
69 if (indio_dev == NULL)
70 return -ENOMEM;
71
72 press_data = iio_priv(indio_dev);
73
74 st_sensors_of_name_probe(&spi->dev, st_press_of_match,
75 spi->modalias, sizeof(spi->modalias));
76 st_sensors_spi_configure(indio_dev, spi, press_data);
77
78 err = st_press_common_probe(indio_dev);
79 if (err < 0)
80 return err;
81
82 return 0;
83}
84
85static int st_press_spi_remove(struct spi_device *spi)
86{
87 st_press_common_remove(spi_get_drvdata(spi));
88
89 return 0;
90}
91
92static const struct spi_device_id st_press_id_table[] = {
93 { LPS001WP_PRESS_DEV_NAME },
94 { LPS25H_PRESS_DEV_NAME },
95 { LPS331AP_PRESS_DEV_NAME },
96 { LPS22HB_PRESS_DEV_NAME },
97 { LPS33HW_PRESS_DEV_NAME },
98 { LPS35HW_PRESS_DEV_NAME },
99 { LPS22HH_PRESS_DEV_NAME },
100 {},
101};
102MODULE_DEVICE_TABLE(spi, st_press_id_table);
103
104static struct spi_driver st_press_driver = {
105 .driver = {
106 .name = "st-press-spi",
107 .of_match_table = of_match_ptr(st_press_of_match),
108 },
109 .probe = st_press_spi_probe,
110 .remove = st_press_spi_remove,
111 .id_table = st_press_id_table,
112};
113module_spi_driver(st_press_driver);
114
115MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
116MODULE_DESCRIPTION("STMicroelectronics pressures spi driver");
117MODULE_LICENSE("GPL v2");
118