Commit | Line | Data |
---|---|---|
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> | |
14 | #include <linux/spi/spi.h> | |
15 | #include <linux/iio/iio.h> | |
16 | ||
17 | #include <linux/iio/common/st_sensors.h> | |
18 | #include <linux/iio/common/st_sensors_spi.h> | |
19 | #include "st_pressure.h" | |
20 | ||
2ff59bf3 LB |
21 | #ifdef CONFIG_OF |
22 | /* | |
23 | * For new single-chip sensors use <device_name> as compatible string. | |
24 | * For old single-chip devices keep <device_name>-press to maintain | |
25 | * compatibility | |
26 | */ | |
27 | static const struct of_device_id st_press_of_match[] = { | |
28 | { | |
29 | .compatible = "st,lps001wp-press", | |
30 | .data = LPS001WP_PRESS_DEV_NAME, | |
31 | }, | |
32 | { | |
33 | .compatible = "st,lps25h-press", | |
34 | .data = LPS25H_PRESS_DEV_NAME, | |
35 | }, | |
36 | { | |
37 | .compatible = "st,lps331ap-press", | |
38 | .data = LPS331AP_PRESS_DEV_NAME, | |
39 | }, | |
40 | { | |
41 | .compatible = "st,lps22hb-press", | |
42 | .data = LPS22HB_PRESS_DEV_NAME, | |
43 | }, | |
b954d77a LB |
44 | { |
45 | .compatible = "st,lps33hw", | |
46 | .data = LPS33HW_PRESS_DEV_NAME, | |
47 | }, | |
48 | { | |
49 | .compatible = "st,lps35hw", | |
50 | .data = LPS35HW_PRESS_DEV_NAME, | |
51 | }, | |
2ff59bf3 LB |
52 | {}, |
53 | }; | |
54 | MODULE_DEVICE_TABLE(of, st_press_of_match); | |
55 | #else | |
56 | #define st_press_of_match NULL | |
57 | #endif | |
58 | ||
217494e5 DC |
59 | static int st_press_spi_probe(struct spi_device *spi) |
60 | { | |
61 | struct iio_dev *indio_dev; | |
a1dcf429 | 62 | struct st_sensor_data *press_data; |
217494e5 DC |
63 | int err; |
64 | ||
a1dcf429 | 65 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data)); |
d0fe8c8b SK |
66 | if (indio_dev == NULL) |
67 | return -ENOMEM; | |
217494e5 | 68 | |
a1dcf429 | 69 | press_data = iio_priv(indio_dev); |
217494e5 | 70 | |
2ff59bf3 LB |
71 | st_sensors_of_name_probe(&spi->dev, st_press_of_match, |
72 | spi->modalias, sizeof(spi->modalias)); | |
a1dcf429 | 73 | st_sensors_spi_configure(indio_dev, spi, press_data); |
217494e5 | 74 | |
0baa3fc1 | 75 | err = st_press_common_probe(indio_dev); |
217494e5 | 76 | if (err < 0) |
d0fe8c8b | 77 | return err; |
217494e5 DC |
78 | |
79 | return 0; | |
217494e5 DC |
80 | } |
81 | ||
82 | static int st_press_spi_remove(struct spi_device *spi) | |
83 | { | |
84 | st_press_common_remove(spi_get_drvdata(spi)); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | static const struct spi_device_id st_press_id_table[] = { | |
d141ab77 | 90 | { LPS001WP_PRESS_DEV_NAME }, |
93187840 | 91 | { LPS25H_PRESS_DEV_NAME }, |
217494e5 | 92 | { LPS331AP_PRESS_DEV_NAME }, |
e039e2f5 | 93 | { LPS22HB_PRESS_DEV_NAME }, |
b954d77a LB |
94 | { LPS33HW_PRESS_DEV_NAME }, |
95 | { LPS35HW_PRESS_DEV_NAME }, | |
217494e5 DC |
96 | {}, |
97 | }; | |
98 | MODULE_DEVICE_TABLE(spi, st_press_id_table); | |
99 | ||
100 | static struct spi_driver st_press_driver = { | |
101 | .driver = { | |
217494e5 | 102 | .name = "st-press-spi", |
2ff59bf3 | 103 | .of_match_table = of_match_ptr(st_press_of_match), |
217494e5 DC |
104 | }, |
105 | .probe = st_press_spi_probe, | |
106 | .remove = st_press_spi_remove, | |
107 | .id_table = st_press_id_table, | |
108 | }; | |
109 | module_spi_driver(st_press_driver); | |
110 | ||
111 | MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); | |
112 | MODULE_DESCRIPTION("STMicroelectronics pressures spi driver"); | |
113 | MODULE_LICENSE("GPL v2"); |