hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/hwmon/scmi-hwmon.c
....@@ -2,7 +2,7 @@
22 /*
33 * System Control and Management Interface(SCMI) based hwmon sensor driver
44 *
5
- * Copyright (C) 2018 ARM Ltd.
5
+ * Copyright (C) 2018-2020 ARM Ltd.
66 * Sudeep Holla <sudeep.holla@arm.com>
77 */
88
....@@ -13,8 +13,10 @@
1313 #include <linux/sysfs.h>
1414 #include <linux/thermal.h>
1515
16
+static const struct scmi_sensor_proto_ops *sensor_ops;
17
+
1618 struct scmi_sensors {
17
- const struct scmi_handle *handle;
19
+ const struct scmi_protocol_handle *ph;
1820 const struct scmi_sensor_info **info[hwmon_max];
1921 };
2022
....@@ -30,7 +32,7 @@
3032
3133 static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
3234 {
33
- s8 scale = sensor->scale;
35
+ int scale = sensor->scale;
3436 u64 f;
3537
3638 switch (sensor->type) {
....@@ -69,10 +71,9 @@
6971 u64 value;
7072 const struct scmi_sensor_info *sensor;
7173 struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
72
- const struct scmi_handle *h = scmi_sensors->handle;
7374
7475 sensor = *(scmi_sensors->info[type] + channel);
75
- ret = h->sensor_ops->reading_get(h, sensor->id, &value);
76
+ ret = sensor_ops->reading_get(scmi_sensors->ph, sensor->id, &value);
7677 if (ret)
7778 return ret;
7879
....@@ -104,8 +105,8 @@
104105 const struct scmi_sensors *scmi_sensors = drvdata;
105106
106107 sensor = *(scmi_sensors->info[type] + channel);
107
- if (sensor && sensor->name)
108
- return S_IRUGO;
108
+ if (sensor)
109
+ return 0444;
109110
110111 return 0;
111112 }
....@@ -169,11 +170,16 @@
169170 struct hwmon_channel_info *scmi_hwmon_chan;
170171 const struct hwmon_channel_info **ptr_scmi_ci;
171172 const struct scmi_handle *handle = sdev->handle;
173
+ struct scmi_protocol_handle *ph;
172174
173
- if (!handle || !handle->sensor_ops)
175
+ if (!handle)
174176 return -ENODEV;
175177
176
- nr_sensors = handle->sensor_ops->count_get(handle);
178
+ sensor_ops = handle->devm_get_protocol(sdev, SCMI_PROTOCOL_SENSOR, &ph);
179
+ if (IS_ERR(sensor_ops))
180
+ return PTR_ERR(sensor_ops);
181
+
182
+ nr_sensors = sensor_ops->count_get(ph);
177183 if (!nr_sensors)
178184 return -EIO;
179185
....@@ -181,10 +187,10 @@
181187 if (!scmi_sensors)
182188 return -ENOMEM;
183189
184
- scmi_sensors->handle = handle;
190
+ scmi_sensors->ph = ph;
185191
186192 for (i = 0; i < nr_sensors; i++) {
187
- sensor = handle->sensor_ops->info_get(handle, i);
193
+ sensor = sensor_ops->info_get(ph, i);
188194 if (!sensor)
189195 return -EINVAL;
190196
....@@ -202,8 +208,10 @@
202208 }
203209 }
204210
205
- if (nr_count[hwmon_temp])
206
- nr_count[hwmon_chip]++, nr_types++;
211
+ if (nr_count[hwmon_temp]) {
212
+ nr_count[hwmon_chip]++;
213
+ nr_types++;
214
+ }
207215
208216 scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan),
209217 GFP_KERNEL);
....@@ -234,7 +242,7 @@
234242 }
235243
236244 for (i = nr_sensors - 1; i >= 0 ; i--) {
237
- sensor = handle->sensor_ops->info_get(handle, i);
245
+ sensor = sensor_ops->info_get(ph, i);
238246 if (!sensor)
239247 continue;
240248
....@@ -259,7 +267,7 @@
259267 }
260268
261269 static const struct scmi_device_id scmi_id_table[] = {
262
- { SCMI_PROTOCOL_SENSOR },
270
+ { SCMI_PROTOCOL_SENSOR, "hwmon" },
263271 { },
264272 };
265273 MODULE_DEVICE_TABLE(scmi, scmi_id_table);