Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / iio / pressure / st_pressure_spi.c
blob1a4bd1a0f78745505cca1c12bf242d80c9770afa
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics pressures driver
5 * Copyright 2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
8 */
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/spi/spi.h>
14 #include <linux/iio/iio.h>
16 #include <linux/iio/common/st_sensors.h>
17 #include <linux/iio/common/st_sensors_spi.h>
18 #include "st_pressure.h"
21 * For new single-chip sensors use <device_name> as compatible string.
22 * For old single-chip devices keep <device_name>-press to maintain
23 * compatibility
25 static const struct of_device_id st_press_of_match[] = {
27 .compatible = "st,lps001wp-press",
28 .data = LPS001WP_PRESS_DEV_NAME,
31 .compatible = "st,lps25h-press",
32 .data = LPS25H_PRESS_DEV_NAME,
35 .compatible = "st,lps331ap-press",
36 .data = LPS331AP_PRESS_DEV_NAME,
39 .compatible = "st,lps22hb-press",
40 .data = LPS22HB_PRESS_DEV_NAME,
43 .compatible = "st,lps33hw",
44 .data = LPS33HW_PRESS_DEV_NAME,
47 .compatible = "st,lps35hw",
48 .data = LPS35HW_PRESS_DEV_NAME,
51 .compatible = "st,lps22hh",
52 .data = LPS22HH_PRESS_DEV_NAME,
55 .compatible = "st,lps22df",
56 .data = LPS22DF_PRESS_DEV_NAME,
58 {},
60 MODULE_DEVICE_TABLE(of, st_press_of_match);
62 static int st_press_spi_probe(struct spi_device *spi)
64 const struct st_sensor_settings *settings;
65 struct st_sensor_data *press_data;
66 struct iio_dev *indio_dev;
67 int err;
69 st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
71 settings = st_press_get_settings(spi->modalias);
72 if (!settings) {
73 dev_err(&spi->dev, "device name %s not recognized.\n",
74 spi->modalias);
75 return -ENODEV;
78 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
79 if (!indio_dev)
80 return -ENOMEM;
82 press_data = iio_priv(indio_dev);
83 press_data->sensor_settings = (struct st_sensor_settings *)settings;
85 err = st_sensors_spi_configure(indio_dev, spi);
86 if (err < 0)
87 return err;
89 err = st_sensors_power_enable(indio_dev);
90 if (err)
91 return err;
93 return st_press_common_probe(indio_dev);
96 static const struct spi_device_id st_press_id_table[] = {
97 { LPS001WP_PRESS_DEV_NAME },
98 { LPS25H_PRESS_DEV_NAME },
99 { LPS331AP_PRESS_DEV_NAME },
100 { LPS22HB_PRESS_DEV_NAME },
101 { LPS33HW_PRESS_DEV_NAME },
102 { LPS35HW_PRESS_DEV_NAME },
103 { LPS22HH_PRESS_DEV_NAME },
104 { LPS22DF_PRESS_DEV_NAME },
105 { "lps001wp-press" },
106 { "lps25h-press", },
107 { "lps331ap-press" },
108 { "lps22hb-press" },
111 MODULE_DEVICE_TABLE(spi, st_press_id_table);
113 static struct spi_driver st_press_driver = {
114 .driver = {
115 .name = "st-press-spi",
116 .of_match_table = st_press_of_match,
118 .probe = st_press_spi_probe,
119 .id_table = st_press_id_table,
121 module_spi_driver(st_press_driver);
123 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
124 MODULE_DESCRIPTION("STMicroelectronics pressures spi driver");
125 MODULE_LICENSE("GPL v2");
126 MODULE_IMPORT_NS("IIO_ST_SENSORS");