Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * STMicroelectronics pressures driver
0004  *
0005  * Copyright 2013 STMicroelectronics Inc.
0006  *
0007  * Denis Ciocca <denis.ciocca@st.com>
0008  */
0009 
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include <linux/mod_devicetable.h>
0013 #include <linux/spi/spi.h>
0014 #include <linux/iio/iio.h>
0015 
0016 #include <linux/iio/common/st_sensors.h>
0017 #include <linux/iio/common/st_sensors_spi.h>
0018 #include "st_pressure.h"
0019 
0020 /*
0021  * For new single-chip sensors use <device_name> as compatible string.
0022  * For old single-chip devices keep <device_name>-press to maintain
0023  * compatibility
0024  */
0025 static const struct of_device_id st_press_of_match[] = {
0026     {
0027         .compatible = "st,lps001wp-press",
0028         .data = LPS001WP_PRESS_DEV_NAME,
0029     },
0030     {
0031         .compatible = "st,lps25h-press",
0032         .data = LPS25H_PRESS_DEV_NAME,
0033     },
0034     {
0035         .compatible = "st,lps331ap-press",
0036         .data = LPS331AP_PRESS_DEV_NAME,
0037     },
0038     {
0039         .compatible = "st,lps22hb-press",
0040         .data = LPS22HB_PRESS_DEV_NAME,
0041     },
0042     {
0043         .compatible = "st,lps33hw",
0044         .data = LPS33HW_PRESS_DEV_NAME,
0045     },
0046     {
0047         .compatible = "st,lps35hw",
0048         .data = LPS35HW_PRESS_DEV_NAME,
0049     },
0050     {
0051         .compatible = "st,lps22hh",
0052         .data = LPS22HH_PRESS_DEV_NAME,
0053     },
0054     {},
0055 };
0056 MODULE_DEVICE_TABLE(of, st_press_of_match);
0057 
0058 static int st_press_spi_probe(struct spi_device *spi)
0059 {
0060     const struct st_sensor_settings *settings;
0061     struct st_sensor_data *press_data;
0062     struct iio_dev *indio_dev;
0063     int err;
0064 
0065     st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
0066 
0067     settings = st_press_get_settings(spi->modalias);
0068     if (!settings) {
0069         dev_err(&spi->dev, "device name %s not recognized.\n",
0070             spi->modalias);
0071         return -ENODEV;
0072     }
0073 
0074     indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
0075     if (!indio_dev)
0076         return -ENOMEM;
0077 
0078     press_data = iio_priv(indio_dev);
0079     press_data->sensor_settings = (struct st_sensor_settings *)settings;
0080 
0081     err = st_sensors_spi_configure(indio_dev, spi);
0082     if (err < 0)
0083         return err;
0084 
0085     err = st_sensors_power_enable(indio_dev);
0086     if (err)
0087         return err;
0088 
0089     return st_press_common_probe(indio_dev);
0090 }
0091 
0092 static const struct spi_device_id st_press_id_table[] = {
0093     { LPS001WP_PRESS_DEV_NAME },
0094     { LPS25H_PRESS_DEV_NAME },
0095     { LPS331AP_PRESS_DEV_NAME },
0096     { LPS22HB_PRESS_DEV_NAME },
0097     { LPS33HW_PRESS_DEV_NAME },
0098     { LPS35HW_PRESS_DEV_NAME },
0099     { LPS22HH_PRESS_DEV_NAME },
0100     { "lps001wp-press" },
0101     { "lps25h-press", },
0102     { "lps331ap-press" },
0103     { "lps22hb-press" },
0104     {},
0105 };
0106 MODULE_DEVICE_TABLE(spi, st_press_id_table);
0107 
0108 static struct spi_driver st_press_driver = {
0109     .driver = {
0110         .name = "st-press-spi",
0111         .of_match_table = st_press_of_match,
0112     },
0113     .probe = st_press_spi_probe,
0114     .id_table = st_press_id_table,
0115 };
0116 module_spi_driver(st_press_driver);
0117 
0118 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
0119 MODULE_DESCRIPTION("STMicroelectronics pressures spi driver");
0120 MODULE_LICENSE("GPL v2");
0121 MODULE_IMPORT_NS(IIO_ST_SENSORS);