Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
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 */
27static 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 },
44 {
45 .compatible = "st,lps33hw",
46 .data = LPS33HW_PRESS_DEV_NAME,
47 },
48 {
49 .compatible = "st,lps35hw",
50 .data = LPS35HW_PRESS_DEV_NAME,
51 },
52 {
53 .compatible = "st,lps22hh",
54 .data = LPS22HH_PRESS_DEV_NAME,
55 },
56 {},
57};
58MODULE_DEVICE_TABLE(of, st_press_of_match);
59#else
60#define st_press_of_match NULL
61#endif
62
63static int st_press_spi_probe(struct spi_device *spi)
64{
65 struct iio_dev *indio_dev;
66 struct st_sensor_data *press_data;
67 int err;
68
69 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
70 if (indio_dev == NULL)
71 return -ENOMEM;
72
73 press_data = iio_priv(indio_dev);
74
75 st_sensors_of_name_probe(&spi->dev, st_press_of_match,
76 spi->modalias, sizeof(spi->modalias));
77 st_sensors_spi_configure(indio_dev, spi, press_data);
78
79 err = st_press_common_probe(indio_dev);
80 if (err < 0)
81 return err;
82
83 return 0;
84}
85
86static int st_press_spi_remove(struct spi_device *spi)
87{
88 st_press_common_remove(spi_get_drvdata(spi));
89
90 return 0;
91}
92
93static const struct spi_device_id st_press_id_table[] = {
94 { LPS001WP_PRESS_DEV_NAME },
95 { LPS25H_PRESS_DEV_NAME },
96 { LPS331AP_PRESS_DEV_NAME },
97 { LPS22HB_PRESS_DEV_NAME },
98 { LPS33HW_PRESS_DEV_NAME },
99 { LPS35HW_PRESS_DEV_NAME },
100 { LPS22HH_PRESS_DEV_NAME },
101 {},
102};
103MODULE_DEVICE_TABLE(spi, st_press_id_table);
104
105static struct spi_driver st_press_driver = {
106 .driver = {
107 .name = "st-press-spi",
108 .of_match_table = of_match_ptr(st_press_of_match),
109 },
110 .probe = st_press_spi_probe,
111 .remove = st_press_spi_remove,
112 .id_table = st_press_id_table,
113};
114module_spi_driver(st_press_driver);
115
116MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
117MODULE_DESCRIPTION("STMicroelectronics pressures spi driver");
118MODULE_LICENSE("GPL v2");