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/acpi.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/mod_devicetable.h>
0014 #include <linux/i2c.h>
0015 #include <linux/iio/iio.h>
0016 
0017 #include <linux/iio/common/st_sensors.h>
0018 #include <linux/iio/common/st_sensors_i2c.h>
0019 #include "st_pressure.h"
0020 
0021 static const struct of_device_id st_press_of_match[] = {
0022     {
0023         .compatible = "st,lps001wp-press",
0024         .data = LPS001WP_PRESS_DEV_NAME,
0025     },
0026     {
0027         .compatible = "st,lps25h-press",
0028         .data = LPS25H_PRESS_DEV_NAME,
0029     },
0030     {
0031         .compatible = "st,lps331ap-press",
0032         .data = LPS331AP_PRESS_DEV_NAME,
0033     },
0034     {
0035         .compatible = "st,lps22hb-press",
0036         .data = LPS22HB_PRESS_DEV_NAME,
0037     },
0038     {
0039         .compatible = "st,lps33hw",
0040         .data = LPS33HW_PRESS_DEV_NAME,
0041     },
0042     {
0043         .compatible = "st,lps35hw",
0044         .data = LPS35HW_PRESS_DEV_NAME,
0045     },
0046     {
0047         .compatible = "st,lps22hh",
0048         .data = LPS22HH_PRESS_DEV_NAME,
0049     },
0050     {},
0051 };
0052 MODULE_DEVICE_TABLE(of, st_press_of_match);
0053 
0054 #ifdef CONFIG_ACPI
0055 static const struct acpi_device_id st_press_acpi_match[] = {
0056     {"SNO9210", LPS22HB},
0057     { },
0058 };
0059 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
0060 #endif
0061 
0062 static const struct i2c_device_id st_press_id_table[] = {
0063     { LPS001WP_PRESS_DEV_NAME, LPS001WP },
0064     { LPS25H_PRESS_DEV_NAME,  LPS25H },
0065     { LPS331AP_PRESS_DEV_NAME, LPS331AP },
0066     { LPS22HB_PRESS_DEV_NAME, LPS22HB },
0067     { LPS33HW_PRESS_DEV_NAME, LPS33HW },
0068     { LPS35HW_PRESS_DEV_NAME, LPS35HW },
0069     { LPS22HH_PRESS_DEV_NAME, LPS22HH },
0070     {},
0071 };
0072 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
0073 
0074 static int st_press_i2c_probe(struct i2c_client *client,
0075                   const struct i2c_device_id *id)
0076 {
0077     const struct st_sensor_settings *settings;
0078     struct st_sensor_data *press_data;
0079     struct iio_dev *indio_dev;
0080     int ret;
0081 
0082     st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
0083 
0084     settings = st_press_get_settings(client->name);
0085     if (!settings) {
0086         dev_err(&client->dev, "device name %s not recognized.\n",
0087             client->name);
0088         return -ENODEV;
0089     }
0090 
0091     indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
0092     if (!indio_dev)
0093         return -ENOMEM;
0094 
0095     press_data = iio_priv(indio_dev);
0096     press_data->sensor_settings = (struct st_sensor_settings *)settings;
0097 
0098     ret = st_sensors_i2c_configure(indio_dev, client);
0099     if (ret < 0)
0100         return ret;
0101 
0102     ret = st_sensors_power_enable(indio_dev);
0103     if (ret)
0104         return ret;
0105 
0106     return st_press_common_probe(indio_dev);
0107 }
0108 
0109 static struct i2c_driver st_press_driver = {
0110     .driver = {
0111         .name = "st-press-i2c",
0112         .of_match_table = st_press_of_match,
0113         .acpi_match_table = ACPI_PTR(st_press_acpi_match),
0114     },
0115     .probe = st_press_i2c_probe,
0116     .id_table = st_press_id_table,
0117 };
0118 module_i2c_driver(st_press_driver);
0119 
0120 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
0121 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
0122 MODULE_LICENSE("GPL v2");
0123 MODULE_IMPORT_NS(IIO_ST_SENSORS);