Lines Matching +full:power +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
3 * System Control and Management Interface(SCMI) based hwmon sensor driver
5 * Copyright (C) 2018-2021 ARM Ltd.
32 while (x--) in __pow10()
38 static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value) in scmi_hwmon_scale() argument
40 int scale = sensor->scale; in scmi_hwmon_scale()
43 switch (sensor->type) { in scmi_hwmon_scale()
49 case POWER: in scmi_hwmon_scale()
61 return -E2BIG; in scmi_hwmon_scale()
73 const struct scmi_sensor_info *sensor, in scmi_hwmon_read_scaled_value() argument
79 ret = sensor_ops->reading_get(ph, sensor->id, &value); in scmi_hwmon_read_scaled_value()
83 ret = scmi_hwmon_scale(sensor, &value); in scmi_hwmon_read_scaled_value()
93 const struct scmi_sensor_info *sensor; in scmi_hwmon_read() local
96 sensor = *(scmi_sensors->info[type] + channel); in scmi_hwmon_read()
98 return scmi_hwmon_read_scaled_value(scmi_sensors->ph, sensor, val); in scmi_hwmon_read()
105 const struct scmi_sensor_info *sensor; in scmi_hwmon_read_string() local
108 sensor = *(scmi_sensors->info[type] + channel); in scmi_hwmon_read_string()
109 *str = sensor->name; in scmi_hwmon_read_string()
118 const struct scmi_sensor_info *sensor; in scmi_hwmon_is_visible() local
121 sensor = *(scmi_sensors->info[type] + channel); in scmi_hwmon_is_visible()
122 if (sensor) in scmi_hwmon_is_visible()
146 ret = scmi_hwmon_read_scaled_value(th_sensor->ph, th_sensor->info, in scmi_hwmon_thermal_get_temp()
166 return -ENOMEM; in scmi_hwmon_add_chan_info()
168 scmi_hwmon_chan->type = type; in scmi_hwmon_add_chan_info()
169 scmi_hwmon_chan->config = cfg; in scmi_hwmon_add_chan_info()
180 [POWER] = hwmon_power,
194 const struct scmi_sensor_info *sensor) in scmi_thermal_sensor_register() argument
201 return -ENOMEM; in scmi_thermal_sensor_register()
203 th_sensor->ph = ph; in scmi_thermal_sensor_register()
204 th_sensor->info = sensor; in scmi_thermal_sensor_register()
207 * Try to register a temperature sensor with the Thermal Framework: in scmi_thermal_sensor_register()
208 * skip sensors not defined as part of any thermal zone (-ENODEV) but in scmi_thermal_sensor_register()
211 tzd = devm_thermal_of_zone_register(dev, th_sensor->info->id, th_sensor, in scmi_thermal_sensor_register()
216 if (PTR_ERR(tzd) != -ENODEV) in scmi_thermal_sensor_register()
219 dev_dbg(dev, "Sensor '%s' not attached to any thermal zone.\n", in scmi_thermal_sensor_register()
220 sensor->name); in scmi_thermal_sensor_register()
222 dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n", in scmi_thermal_sensor_register()
223 sensor->name, thermal_zone_device_id(tzd)); in scmi_thermal_sensor_register()
235 const struct scmi_sensor_info *sensor; in scmi_hwmon_probe() local
238 struct device *hwdev, *dev = &sdev->dev; in scmi_hwmon_probe()
241 const struct scmi_handle *handle = sdev->handle; in scmi_hwmon_probe()
245 return -ENODEV; in scmi_hwmon_probe()
247 sensor_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_SENSOR, &ph); in scmi_hwmon_probe()
251 nr_sensors = sensor_ops->count_get(ph); in scmi_hwmon_probe()
253 return -EIO; in scmi_hwmon_probe()
257 return -ENOMEM; in scmi_hwmon_probe()
259 scmi_sensors->ph = ph; in scmi_hwmon_probe()
262 sensor = sensor_ops->info_get(ph, i); in scmi_hwmon_probe()
263 if (!sensor) in scmi_hwmon_probe()
264 return -EINVAL; in scmi_hwmon_probe()
266 switch (sensor->type) { in scmi_hwmon_probe()
270 case POWER: in scmi_hwmon_probe()
272 type = scmi_types[sensor->type]; in scmi_hwmon_probe()
286 return -ENOMEM; in scmi_hwmon_probe()
291 return -ENOMEM; in scmi_hwmon_probe()
304 scmi_sensors->info[type] = in scmi_hwmon_probe()
306 sizeof(*scmi_sensors->info), GFP_KERNEL); in scmi_hwmon_probe()
307 if (!scmi_sensors->info[type]) in scmi_hwmon_probe()
308 return -ENOMEM; in scmi_hwmon_probe()
311 for (i = nr_sensors - 1; i >= 0 ; i--) { in scmi_hwmon_probe()
312 sensor = sensor_ops->info_get(ph, i); in scmi_hwmon_probe()
313 if (!sensor) in scmi_hwmon_probe()
316 switch (sensor->type) { in scmi_hwmon_probe()
320 case POWER: in scmi_hwmon_probe()
322 type = scmi_types[sensor->type]; in scmi_hwmon_probe()
323 idx = --nr_count[type]; in scmi_hwmon_probe()
324 *(scmi_sensors->info[type] + idx) = sensor; in scmi_hwmon_probe()
338 sensor = *(scmi_sensors->info[hwmon_temp] + i); in scmi_hwmon_probe()
339 if (!sensor) in scmi_hwmon_probe()
346 ret = scmi_thermal_sensor_register(dev, ph, sensor); in scmi_hwmon_probe()
348 if (ret == -ENOMEM) in scmi_hwmon_probe()
352 sensor->name, ret); in scmi_hwmon_probe()
366 .name = "scmi-hwmon",