Commit 987bae41 authored by Cristian Marussi's avatar Cristian Marussi Committed by Sudeep Holla
Browse files

hwmon: (scmi) port driver to the new scmi_sensor_proto_ops interface

Port the scmi hwmon driver to the new SCMI sensor interface based on
protocol handles and common devm_get_ops().

Link: https://lore.kernel.org/r/20210316124903.35011-25-cristian.marussi@arm.com


Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Jean Delvare <jdelvare@suse.com>
Tested-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Acked-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
parent 9694a7f6
Loading
Loading
Loading
Loading
+15 −9
Original line number Original line Diff line number Diff line
@@ -2,7 +2,7 @@
/*
/*
 * System Control and Management Interface(SCMI) based hwmon sensor driver
 * System Control and Management Interface(SCMI) based hwmon sensor driver
 *
 *
 * Copyright (C) 2018 ARM Ltd.
 * Copyright (C) 2018-2021 ARM Ltd.
 * Sudeep Holla <sudeep.holla@arm.com>
 * Sudeep Holla <sudeep.holla@arm.com>
 */
 */


@@ -13,8 +13,10 @@
#include <linux/sysfs.h>
#include <linux/sysfs.h>
#include <linux/thermal.h>
#include <linux/thermal.h>


static const struct scmi_sensor_proto_ops *sensor_ops;

struct scmi_sensors {
struct scmi_sensors {
	const struct scmi_handle *handle;
	const struct scmi_protocol_handle *ph;
	const struct scmi_sensor_info **info[hwmon_max];
	const struct scmi_sensor_info **info[hwmon_max];
};
};


@@ -69,10 +71,9 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
	u64 value;
	u64 value;
	const struct scmi_sensor_info *sensor;
	const struct scmi_sensor_info *sensor;
	struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
	struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
	const struct scmi_handle *h = scmi_sensors->handle;


	sensor = *(scmi_sensors->info[type] + channel);
	sensor = *(scmi_sensors->info[type] + channel);
	ret = h->sensor_ops->reading_get(h, sensor->id, &value);
	ret = sensor_ops->reading_get(scmi_sensors->ph, sensor->id, &value);
	if (ret)
	if (ret)
		return ret;
		return ret;


@@ -169,11 +170,16 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
	struct hwmon_channel_info *scmi_hwmon_chan;
	struct hwmon_channel_info *scmi_hwmon_chan;
	const struct hwmon_channel_info **ptr_scmi_ci;
	const struct hwmon_channel_info **ptr_scmi_ci;
	const struct scmi_handle *handle = sdev->handle;
	const struct scmi_handle *handle = sdev->handle;
	struct scmi_protocol_handle *ph;


	if (!handle || !handle->sensor_ops)
	if (!handle)
		return -ENODEV;
		return -ENODEV;


	nr_sensors = handle->sensor_ops->count_get(handle);
	sensor_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_SENSOR, &ph);
	if (IS_ERR(sensor_ops))
		return PTR_ERR(sensor_ops);

	nr_sensors = sensor_ops->count_get(ph);
	if (!nr_sensors)
	if (!nr_sensors)
		return -EIO;
		return -EIO;


@@ -181,10 +187,10 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
	if (!scmi_sensors)
	if (!scmi_sensors)
		return -ENOMEM;
		return -ENOMEM;


	scmi_sensors->handle = handle;
	scmi_sensors->ph = ph;


	for (i = 0; i < nr_sensors; i++) {
	for (i = 0; i < nr_sensors; i++) {
		sensor = handle->sensor_ops->info_get(handle, i);
		sensor = sensor_ops->info_get(ph, i);
		if (!sensor)
		if (!sensor)
			return -EINVAL;
			return -EINVAL;


@@ -236,7 +242,7 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
	}
	}


	for (i = nr_sensors - 1; i >= 0 ; i--) {
	for (i = nr_sensors - 1; i >= 0 ; i--) {
		sensor = handle->sensor_ops->info_get(handle, i);
		sensor = sensor_ops->info_get(ph, i);
		if (!sensor)
		if (!sensor)
			continue;
			continue;