forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/pressure/st_pressure_i2c.c
....@@ -1,17 +1,15 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * STMicroelectronics pressures driver
34 *
45 * Copyright 2013 STMicroelectronics Inc.
56 *
67 * Denis Ciocca <denis.ciocca@st.com>
7
- *
8
- * Licensed under the GPL-2.
98 */
109
1110 #include <linux/kernel.h>
1211 #include <linux/module.h>
1312 #include <linux/slab.h>
14
-#include <linux/acpi.h>
1513 #include <linux/i2c.h>
1614 #include <linux/iio/iio.h>
1715
....@@ -19,7 +17,6 @@
1917 #include <linux/iio/common/st_sensors_i2c.h>
2018 #include "st_pressure.h"
2119
22
-#ifdef CONFIG_OF
2320 static const struct of_device_id st_press_of_match[] = {
2421 {
2522 .compatible = "st,lps001wp-press",
....@@ -45,12 +42,13 @@
4542 .compatible = "st,lps35hw",
4643 .data = LPS35HW_PRESS_DEV_NAME,
4744 },
45
+ {
46
+ .compatible = "st,lps22hh",
47
+ .data = LPS22HH_PRESS_DEV_NAME,
48
+ },
4849 {},
4950 };
5051 MODULE_DEVICE_TABLE(of, st_press_of_match);
51
-#else
52
-#define st_press_of_match NULL
53
-#endif
5452
5553 #ifdef CONFIG_ACPI
5654 static const struct acpi_device_id st_press_acpi_match[] = {
....@@ -58,8 +56,6 @@
5856 { },
5957 };
6058 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
61
-#else
62
-#define st_press_acpi_match NULL
6359 #endif
6460
6561 static const struct i2c_device_id st_press_id_table[] = {
....@@ -69,48 +65,62 @@
6965 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
7066 { LPS33HW_PRESS_DEV_NAME, LPS33HW },
7167 { LPS35HW_PRESS_DEV_NAME, LPS35HW },
68
+ { LPS22HH_PRESS_DEV_NAME, LPS22HH },
7269 {},
7370 };
7471 MODULE_DEVICE_TABLE(i2c, st_press_id_table);
7572
7673 static int st_press_i2c_probe(struct i2c_client *client,
77
- const struct i2c_device_id *id)
74
+ const struct i2c_device_id *id)
7875 {
79
- struct iio_dev *indio_dev;
76
+ const struct st_sensor_settings *settings;
8077 struct st_sensor_data *press_data;
78
+ struct iio_dev *indio_dev;
8179 int ret;
80
+
81
+ st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
82
+
83
+ settings = st_press_get_settings(client->name);
84
+ if (!settings) {
85
+ dev_err(&client->dev, "device name %s not recognized.\n",
86
+ client->name);
87
+ return -ENODEV;
88
+ }
8289
8390 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
8491 if (!indio_dev)
8592 return -ENOMEM;
8693
8794 press_data = iio_priv(indio_dev);
95
+ press_data->sensor_settings = (struct st_sensor_settings *)settings;
8896
89
- if (client->dev.of_node) {
90
- st_sensors_of_name_probe(&client->dev, st_press_of_match,
91
- client->name, sizeof(client->name));
92
- } else if (ACPI_HANDLE(&client->dev)) {
93
- ret = st_sensors_match_acpi_device(&client->dev);
94
- if ((ret < 0) || (ret >= ST_PRESS_MAX))
95
- return -ENODEV;
96
-
97
- strlcpy(client->name, st_press_id_table[ret].name,
98
- sizeof(client->name));
99
- } else if (!id)
100
- return -ENODEV;
101
-
102
- st_sensors_i2c_configure(indio_dev, client, press_data);
103
-
104
- ret = st_press_common_probe(indio_dev);
97
+ ret = st_sensors_i2c_configure(indio_dev, client);
10598 if (ret < 0)
10699 return ret;
107100
101
+ ret = st_sensors_power_enable(indio_dev);
102
+ if (ret)
103
+ return ret;
104
+
105
+ ret = st_press_common_probe(indio_dev);
106
+ if (ret < 0)
107
+ goto st_press_power_off;
108
+
108109 return 0;
110
+
111
+st_press_power_off:
112
+ st_sensors_power_disable(indio_dev);
113
+
114
+ return ret;
109115 }
110116
111117 static int st_press_i2c_remove(struct i2c_client *client)
112118 {
113
- st_press_common_remove(i2c_get_clientdata(client));
119
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
120
+
121
+ st_press_common_remove(indio_dev);
122
+
123
+ st_sensors_power_disable(indio_dev);
114124
115125 return 0;
116126 }
....@@ -118,7 +128,7 @@
118128 static struct i2c_driver st_press_driver = {
119129 .driver = {
120130 .name = "st-press-i2c",
121
- .of_match_table = of_match_ptr(st_press_of_match),
131
+ .of_match_table = st_press_of_match,
122132 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
123133 },
124134 .probe = st_press_i2c_probe,