| .. | .. |
|---|
| 2 | 2 | /* |
|---|
| 3 | 3 | * System Control and Management Interface(SCMI) based hwmon sensor driver |
|---|
| 4 | 4 | * |
|---|
| 5 | | - * Copyright (C) 2018 ARM Ltd. |
|---|
| 5 | + * Copyright (C) 2018-2020 ARM Ltd. |
|---|
| 6 | 6 | * Sudeep Holla <sudeep.holla@arm.com> |
|---|
| 7 | 7 | */ |
|---|
| 8 | 8 | |
|---|
| .. | .. |
|---|
| 13 | 13 | #include <linux/sysfs.h> |
|---|
| 14 | 14 | #include <linux/thermal.h> |
|---|
| 15 | 15 | |
|---|
| 16 | +static const struct scmi_sensor_proto_ops *sensor_ops; |
|---|
| 17 | + |
|---|
| 16 | 18 | struct scmi_sensors { |
|---|
| 17 | | - const struct scmi_handle *handle; |
|---|
| 19 | + const struct scmi_protocol_handle *ph; |
|---|
| 18 | 20 | const struct scmi_sensor_info **info[hwmon_max]; |
|---|
| 19 | 21 | }; |
|---|
| 20 | 22 | |
|---|
| .. | .. |
|---|
| 30 | 32 | |
|---|
| 31 | 33 | static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value) |
|---|
| 32 | 34 | { |
|---|
| 33 | | - s8 scale = sensor->scale; |
|---|
| 35 | + int scale = sensor->scale; |
|---|
| 34 | 36 | u64 f; |
|---|
| 35 | 37 | |
|---|
| 36 | 38 | switch (sensor->type) { |
|---|
| .. | .. |
|---|
| 69 | 71 | u64 value; |
|---|
| 70 | 72 | const struct scmi_sensor_info *sensor; |
|---|
| 71 | 73 | struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev); |
|---|
| 72 | | - const struct scmi_handle *h = scmi_sensors->handle; |
|---|
| 73 | 74 | |
|---|
| 74 | 75 | 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); |
|---|
| 76 | 77 | if (ret) |
|---|
| 77 | 78 | return ret; |
|---|
| 78 | 79 | |
|---|
| .. | .. |
|---|
| 104 | 105 | const struct scmi_sensors *scmi_sensors = drvdata; |
|---|
| 105 | 106 | |
|---|
| 106 | 107 | sensor = *(scmi_sensors->info[type] + channel); |
|---|
| 107 | | - if (sensor && sensor->name) |
|---|
| 108 | | - return S_IRUGO; |
|---|
| 108 | + if (sensor) |
|---|
| 109 | + return 0444; |
|---|
| 109 | 110 | |
|---|
| 110 | 111 | return 0; |
|---|
| 111 | 112 | } |
|---|
| .. | .. |
|---|
| 169 | 170 | struct hwmon_channel_info *scmi_hwmon_chan; |
|---|
| 170 | 171 | const struct hwmon_channel_info **ptr_scmi_ci; |
|---|
| 171 | 172 | const struct scmi_handle *handle = sdev->handle; |
|---|
| 173 | + struct scmi_protocol_handle *ph; |
|---|
| 172 | 174 | |
|---|
| 173 | | - if (!handle || !handle->sensor_ops) |
|---|
| 175 | + if (!handle) |
|---|
| 174 | 176 | return -ENODEV; |
|---|
| 175 | 177 | |
|---|
| 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); |
|---|
| 177 | 183 | if (!nr_sensors) |
|---|
| 178 | 184 | return -EIO; |
|---|
| 179 | 185 | |
|---|
| .. | .. |
|---|
| 181 | 187 | if (!scmi_sensors) |
|---|
| 182 | 188 | return -ENOMEM; |
|---|
| 183 | 189 | |
|---|
| 184 | | - scmi_sensors->handle = handle; |
|---|
| 190 | + scmi_sensors->ph = ph; |
|---|
| 185 | 191 | |
|---|
| 186 | 192 | for (i = 0; i < nr_sensors; i++) { |
|---|
| 187 | | - sensor = handle->sensor_ops->info_get(handle, i); |
|---|
| 193 | + sensor = sensor_ops->info_get(ph, i); |
|---|
| 188 | 194 | if (!sensor) |
|---|
| 189 | 195 | return -EINVAL; |
|---|
| 190 | 196 | |
|---|
| .. | .. |
|---|
| 202 | 208 | } |
|---|
| 203 | 209 | } |
|---|
| 204 | 210 | |
|---|
| 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 | + } |
|---|
| 207 | 215 | |
|---|
| 208 | 216 | scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan), |
|---|
| 209 | 217 | GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 234 | 242 | } |
|---|
| 235 | 243 | |
|---|
| 236 | 244 | 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); |
|---|
| 238 | 246 | if (!sensor) |
|---|
| 239 | 247 | continue; |
|---|
| 240 | 248 | |
|---|
| .. | .. |
|---|
| 259 | 267 | } |
|---|
| 260 | 268 | |
|---|
| 261 | 269 | static const struct scmi_device_id scmi_id_table[] = { |
|---|
| 262 | | - { SCMI_PROTOCOL_SENSOR }, |
|---|
| 270 | + { SCMI_PROTOCOL_SENSOR, "hwmon" }, |
|---|
| 263 | 271 | { }, |
|---|
| 264 | 272 | }; |
|---|
| 265 | 273 | MODULE_DEVICE_TABLE(scmi, scmi_id_table); |
|---|