All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Sudeep Holla <Sudeep.Holla@arm.com>
Cc: ALKML <linux-arm-kernel@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	DTML <devicetree@vger.kernel.org>,
	Roy Franz <roy.franz@cavium.com>,
	Harb Abdulhamid <harba@codeaurora.org>,
	Nishanth Menon <nm@ti.com>, Arnd Bergmann <arnd@arndb.de>,
	Loc Ho <lho@apm.com>, Alexey Klimov <alexey.klimov@arm.com>,
	Ryan Harkin <Ryan.Harkin@arm.com>,
	Jassi Brar <jassisinghbrar@gmail.com>,
	linux-hwmon@vger.kernel.org
Subject: Re: [v3,20/22] hwmon: add support for sensors exported via ARM SCMI
Date: Sun, 1 Oct 2017 07:26:05 -0700	[thread overview]
Message-ID: <20171001142605.GA340@roeck-us.net> (raw)
In-Reply-To: <1506604306-20739-21-git-send-email-sudeep.holla@arm.com>

On Thu, Sep 28, 2017 at 02:11:44PM +0100, Sudeep Holla wrote:
> Create a driver to add support for SoC sensors exported by the System
> Control Processor (SCP) via the System Control and Management Interface
> (SCMI). The supported sensor types is one of voltage, temperature,
> current, and power.
> 
> The sensor labels and values provided by the SCP are exported via the
> hwmon sysfs interface.
> 
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: linux-hwmon@vger.kernel.org
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

Couple of minor comments. With those addressed,

Acked-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/hwmon/Kconfig      |  12 +++
>  drivers/hwmon/Makefile     |   1 +
>  drivers/hwmon/scmi-hwmon.c | 235 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 248 insertions(+)
>  create mode 100644 drivers/hwmon/scmi-hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index d65431417b17..0b75e9a89463 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -321,6 +321,18 @@ config SENSORS_APPLESMC
>  	  Say Y here if you have an applicable laptop and want to experience
>  	  the awesome power of applesmc.
>  
> +config SENSORS_ARM_SCMI
> +	tristate "ARM SCMI Sensors"
> +	depends on ARM_SCMI_PROTOCOL
> +	depends on THERMAL || !THERMAL_OF
> +	help
> +	  This driver provides support for temperature, voltage, current
> +	  and power sensors available on SCMI based platforms. The actual
> +	  number and type of sensors exported depend on the platform.
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called scmi-hwmon.
> +
>  config SENSORS_ARM_SCPI
>  	tristate "ARM SCPI Sensors"
>  	depends on ARM_SCPI_PROTOCOL
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index c84d9784be98..a51c2dcef11c 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -44,6 +44,7 @@ obj-$(CONFIG_SENSORS_ADT7462)	+= adt7462.o
>  obj-$(CONFIG_SENSORS_ADT7470)	+= adt7470.o
>  obj-$(CONFIG_SENSORS_ADT7475)	+= adt7475.o
>  obj-$(CONFIG_SENSORS_APPLESMC)	+= applesmc.o
> +obj-$(CONFIG_SENSORS_ARM_SCMI)	+= scmi-hwmon.o
>  obj-$(CONFIG_SENSORS_ARM_SCPI)	+= scpi-hwmon.o
>  obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
>  obj-$(CONFIG_SENSORS_ASPEED)	+= aspeed-pwm-tacho.o
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> new file mode 100644
> index 000000000000..0a8c0e8dc5d1
> --- /dev/null
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -0,0 +1,235 @@
> +/*
> + * System Control and Management Interface(SCMI) based hwmon sensor driver
> + *
> + * Copyright (C) 2017 ARM Ltd.
> + * Sudeep Holla <sudeep.holla@arm.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/hwmon.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/scmi_protocol.h>
> +#include <linux/slab.h>
> +#include <linux/sysfs.h>
> +#include <linux/thermal.h>
> +
> +struct scmi_sensors {
> +	const struct scmi_handle *handle;
> +	const struct scmi_sensor_info **info[hwmon_max];
> +};
> +
> +static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
> +			   u32 attr, int channel, long *val)
> +{
> +	int ret;
> +	u64 value;
> +	const struct scmi_sensor_info *sensor;
> +	struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
> +	const struct scmi_handle *h = scmi_sensors->handle;
> +
> +	sensor = *(scmi_sensors->info[type] + channel);
> +	ret = h->sensor_ops->reading_get(h, sensor->id, false, &value);
> +	if (!ret)
> +		*val = value;
> +
> +	return ret;
> +}
> +
> +static int
> +scmi_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type,
> +		       u32 attr, int channel, const char **str)
> +{
> +	const struct scmi_sensor_info *sensor;
> +	struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
> +
> +	sensor = *(scmi_sensors->info[type] + channel);
> +	*str = sensor->name;
> +
> +	return 0;
> +}
> +
> +static umode_t
> +scmi_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
> +		      u32 attr, int channel)
> +{
> +	const struct scmi_sensor_info *sensor;
> +	const struct scmi_sensors *scmi_sensors = drvdata;
> +
> +	sensor = *(scmi_sensors->info[type] + channel);
> +	if (sensor && sensor->name)
> +		return S_IRUGO;
> +
> +	return 0;
> +}
> +
> +static const struct hwmon_ops scmi_hwmon_ops = {
> +	.is_visible = scmi_hwmon_is_visible,
> +	.read = scmi_hwmon_read,
> +	.read_string = scmi_hwmon_read_string,
> +};
> +
> +static struct hwmon_chip_info scmi_chip_info = {
> +	.ops = &scmi_hwmon_ops,
> +	.info = NULL,
> +};
> +
> +static int scmi_hwmon_add_chan_info(struct hwmon_channel_info *scmi_hwmon_chan,
> +				    struct device *dev, int num,
> +				    enum hwmon_sensor_types type, u32 config)
> +{
> +	int i;
> +	u32 *cfg = devm_kcalloc(dev, num + 1, sizeof(*cfg), GFP_KERNEL);
> +
> +	if (!cfg)
> +		return -ENOMEM;
> +
> +	scmi_hwmon_chan->type = type;
> +	scmi_hwmon_chan->config = cfg;
> +	for (i = 0; i < num; i++, cfg++)
> +		*cfg = config;
> +
> +	return 0;
> +}
> +
> +static enum hwmon_sensor_types scmi_types[] = {
> +	[TEMPERATURE_C] = hwmon_temp,
> +	[VOLTAGE] = hwmon_in,
> +	[CURRENT] = hwmon_curr,
> +	[POWER] = hwmon_power,
> +	[ENERGY] = hwmon_energy,
> +};
> +
> +static u32 hwmon_attributes[] = {
> +	[hwmon_chip] = HWMON_C_REGISTER_TZ,
> +	[hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL,
> +	[hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL,
> +	[hwmon_curr] = HWMON_C_INPUT | HWMON_C_LABEL,
> +	[hwmon_power] = HWMON_P_INPUT | HWMON_P_LABEL,
> +	[hwmon_energy] = HWMON_E_INPUT | HWMON_E_LABEL,
> +};
> +
> +static int scmi_hwmon_probe(struct platform_device *pdev)
> +{
> +	int i, idx;
> +	u16 nr_sensors;
> +	enum hwmon_sensor_types type;
> +	struct scmi_sensors *scmi_sensors;
> +	const struct scmi_sensor_info *sensor;
> +	int nr_count[hwmon_max] = {0}, nr_types = 0;
> +	const struct hwmon_chip_info *chip_info;
> +	struct device *hwdev, *dev = &pdev->dev;
> +	struct hwmon_channel_info *scmi_hwmon_chan;
> +	const struct hwmon_channel_info **ptr_scmi_ci;
> +	const struct scmi_handle *handle = devm_scmi_handle_get(dev);
> +
> +	if (IS_ERR_OR_NULL(handle) || !handle->sensor_ops)
> +		return -EPROBE_DEFER;
> +
> +	nr_sensors = handle->sensor_ops->count_get(handle);
> +	if (!nr_sensors)
> +		return -EIO;
> +
> +	scmi_sensors = devm_kzalloc(dev, sizeof(*scmi_sensors), GFP_KERNEL);
> +	if (!scmi_sensors)
> +		return -ENOMEM;
> +
> +	scmi_sensors->handle = handle;
> +
> +	for (i = 0; i < nr_sensors; i++) {
> +		sensor = handle->sensor_ops->info_get(handle, i);
> +		if (!sensor)
> +			return PTR_ERR(sensor);
> +
> +		switch (sensor->type) {
> +		case TEMPERATURE_C:
> +		case VOLTAGE:
> +		case CURRENT:
> +		case POWER:
> +		case ENERGY:
> +			type = scmi_types[sensor->type];
> +			if (!nr_count[type])
> +				nr_types++;
> +			nr_count[type]++;
> +			break;
> +		}
> +	}
> +
> +	if (nr_count[hwmon_temp])
> +		nr_count[hwmon_chip]++, nr_types++;
> +
> +	scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan),
> +				       GFP_KERNEL);
> +	if (!scmi_hwmon_chan)
> +		return -ENOMEM;
> +
> +	ptr_scmi_ci = devm_kcalloc(dev, nr_types + 1, sizeof(*ptr_scmi_ci),
> +				   GFP_KERNEL);
> +	if (!ptr_scmi_ci)
> +		return -ENOMEM;
> +
> +	scmi_chip_info.info = ptr_scmi_ci;
> +	chip_info = &scmi_chip_info;
> +
> +	for (type = 0; type < hwmon_max && nr_count[type]; type++) {
> +		scmi_hwmon_add_chan_info(scmi_hwmon_chan, dev, nr_count[type],
> +					 type, hwmon_attributes[type]);
> +		*ptr_scmi_ci++ = scmi_hwmon_chan++;
> +
> +		scmi_sensors->info[type] =
> +			devm_kcalloc(dev, nr_count[type],
> +				     sizeof(*scmi_sensors->info), GFP_KERNEL);
> +		if (!scmi_sensors->info[type])
> +			return -ENOMEM;
> +	}
> +
> +	*ptr_scmi_ci = NULL;

Unnecessary; devm_kcalloc() clears out the allocated memory.

> +	platform_set_drvdata(pdev, scmi_sensors);
> +
> +	for (i = nr_sensors - 1; i >= 0 ; i--) {
> +		sensor = handle->sensor_ops->info_get(handle, i);
> +		if (!sensor)
> +			continue;
> +
> +		switch (sensor->type) {
> +		case TEMPERATURE_C:
> +		case VOLTAGE:
> +		case CURRENT:
> +		case POWER:
> +		case ENERGY:
> +			type = scmi_types[sensor->type];
> +			idx = --nr_count[type];
> +			*(scmi_sensors->info[type] + idx) = sensor;
> +			break;
> +		}
> +	}
> +
> +	hwdev = devm_hwmon_device_register_with_info(dev, "scmi_sensors",
> +						     scmi_sensors, chip_info,
> +						     NULL);
> +
> +	if (IS_ERR(hwdev))
> +		return PTR_ERR(hwdev);
> +
> +	return 0;

	return PTR_ERR_OR_ZERO(hwdev);

> +}
> +
> +static struct platform_driver scmi_hwmon_platdrv = {
> +	.driver = {
> +		.name	= "scmi-hwmon",
> +	},
> +	.probe		= scmi_hwmon_probe,
> +};
> +module_platform_driver(scmi_hwmon_platdrv);
> +
> +MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
> +MODULE_DESCRIPTION("ARM SCMI HWMON interface driver");
> +MODULE_LICENSE("GPL v2");

WARNING: multiple messages have this Message-ID (diff)
From: linux@roeck-us.net (Guenter Roeck)
To: linux-arm-kernel@lists.infradead.org
Subject: [v3,20/22] hwmon: add support for sensors exported via ARM SCMI
Date: Sun, 1 Oct 2017 07:26:05 -0700	[thread overview]
Message-ID: <20171001142605.GA340@roeck-us.net> (raw)
In-Reply-To: <1506604306-20739-21-git-send-email-sudeep.holla@arm.com>

On Thu, Sep 28, 2017 at 02:11:44PM +0100, Sudeep Holla wrote:
> Create a driver to add support for SoC sensors exported by the System
> Control Processor (SCP) via the System Control and Management Interface
> (SCMI). The supported sensor types is one of voltage, temperature,
> current, and power.
> 
> The sensor labels and values provided by the SCP are exported via the
> hwmon sysfs interface.
> 
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: linux-hwmon at vger.kernel.org
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

Couple of minor comments. With those addressed,

Acked-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/hwmon/Kconfig      |  12 +++
>  drivers/hwmon/Makefile     |   1 +
>  drivers/hwmon/scmi-hwmon.c | 235 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 248 insertions(+)
>  create mode 100644 drivers/hwmon/scmi-hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index d65431417b17..0b75e9a89463 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -321,6 +321,18 @@ config SENSORS_APPLESMC
>  	  Say Y here if you have an applicable laptop and want to experience
>  	  the awesome power of applesmc.
>  
> +config SENSORS_ARM_SCMI
> +	tristate "ARM SCMI Sensors"
> +	depends on ARM_SCMI_PROTOCOL
> +	depends on THERMAL || !THERMAL_OF
> +	help
> +	  This driver provides support for temperature, voltage, current
> +	  and power sensors available on SCMI based platforms. The actual
> +	  number and type of sensors exported depend on the platform.
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called scmi-hwmon.
> +
>  config SENSORS_ARM_SCPI
>  	tristate "ARM SCPI Sensors"
>  	depends on ARM_SCPI_PROTOCOL
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index c84d9784be98..a51c2dcef11c 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -44,6 +44,7 @@ obj-$(CONFIG_SENSORS_ADT7462)	+= adt7462.o
>  obj-$(CONFIG_SENSORS_ADT7470)	+= adt7470.o
>  obj-$(CONFIG_SENSORS_ADT7475)	+= adt7475.o
>  obj-$(CONFIG_SENSORS_APPLESMC)	+= applesmc.o
> +obj-$(CONFIG_SENSORS_ARM_SCMI)	+= scmi-hwmon.o
>  obj-$(CONFIG_SENSORS_ARM_SCPI)	+= scpi-hwmon.o
>  obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
>  obj-$(CONFIG_SENSORS_ASPEED)	+= aspeed-pwm-tacho.o
> diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
> new file mode 100644
> index 000000000000..0a8c0e8dc5d1
> --- /dev/null
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -0,0 +1,235 @@
> +/*
> + * System Control and Management Interface(SCMI) based hwmon sensor driver
> + *
> + * Copyright (C) 2017 ARM Ltd.
> + * Sudeep Holla <sudeep.holla@arm.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/hwmon.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/scmi_protocol.h>
> +#include <linux/slab.h>
> +#include <linux/sysfs.h>
> +#include <linux/thermal.h>
> +
> +struct scmi_sensors {
> +	const struct scmi_handle *handle;
> +	const struct scmi_sensor_info **info[hwmon_max];
> +};
> +
> +static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
> +			   u32 attr, int channel, long *val)
> +{
> +	int ret;
> +	u64 value;
> +	const struct scmi_sensor_info *sensor;
> +	struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
> +	const struct scmi_handle *h = scmi_sensors->handle;
> +
> +	sensor = *(scmi_sensors->info[type] + channel);
> +	ret = h->sensor_ops->reading_get(h, sensor->id, false, &value);
> +	if (!ret)
> +		*val = value;
> +
> +	return ret;
> +}
> +
> +static int
> +scmi_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type,
> +		       u32 attr, int channel, const char **str)
> +{
> +	const struct scmi_sensor_info *sensor;
> +	struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
> +
> +	sensor = *(scmi_sensors->info[type] + channel);
> +	*str = sensor->name;
> +
> +	return 0;
> +}
> +
> +static umode_t
> +scmi_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
> +		      u32 attr, int channel)
> +{
> +	const struct scmi_sensor_info *sensor;
> +	const struct scmi_sensors *scmi_sensors = drvdata;
> +
> +	sensor = *(scmi_sensors->info[type] + channel);
> +	if (sensor && sensor->name)
> +		return S_IRUGO;
> +
> +	return 0;
> +}
> +
> +static const struct hwmon_ops scmi_hwmon_ops = {
> +	.is_visible = scmi_hwmon_is_visible,
> +	.read = scmi_hwmon_read,
> +	.read_string = scmi_hwmon_read_string,
> +};
> +
> +static struct hwmon_chip_info scmi_chip_info = {
> +	.ops = &scmi_hwmon_ops,
> +	.info = NULL,
> +};
> +
> +static int scmi_hwmon_add_chan_info(struct hwmon_channel_info *scmi_hwmon_chan,
> +				    struct device *dev, int num,
> +				    enum hwmon_sensor_types type, u32 config)
> +{
> +	int i;
> +	u32 *cfg = devm_kcalloc(dev, num + 1, sizeof(*cfg), GFP_KERNEL);
> +
> +	if (!cfg)
> +		return -ENOMEM;
> +
> +	scmi_hwmon_chan->type = type;
> +	scmi_hwmon_chan->config = cfg;
> +	for (i = 0; i < num; i++, cfg++)
> +		*cfg = config;
> +
> +	return 0;
> +}
> +
> +static enum hwmon_sensor_types scmi_types[] = {
> +	[TEMPERATURE_C] = hwmon_temp,
> +	[VOLTAGE] = hwmon_in,
> +	[CURRENT] = hwmon_curr,
> +	[POWER] = hwmon_power,
> +	[ENERGY] = hwmon_energy,
> +};
> +
> +static u32 hwmon_attributes[] = {
> +	[hwmon_chip] = HWMON_C_REGISTER_TZ,
> +	[hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL,
> +	[hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL,
> +	[hwmon_curr] = HWMON_C_INPUT | HWMON_C_LABEL,
> +	[hwmon_power] = HWMON_P_INPUT | HWMON_P_LABEL,
> +	[hwmon_energy] = HWMON_E_INPUT | HWMON_E_LABEL,
> +};
> +
> +static int scmi_hwmon_probe(struct platform_device *pdev)
> +{
> +	int i, idx;
> +	u16 nr_sensors;
> +	enum hwmon_sensor_types type;
> +	struct scmi_sensors *scmi_sensors;
> +	const struct scmi_sensor_info *sensor;
> +	int nr_count[hwmon_max] = {0}, nr_types = 0;
> +	const struct hwmon_chip_info *chip_info;
> +	struct device *hwdev, *dev = &pdev->dev;
> +	struct hwmon_channel_info *scmi_hwmon_chan;
> +	const struct hwmon_channel_info **ptr_scmi_ci;
> +	const struct scmi_handle *handle = devm_scmi_handle_get(dev);
> +
> +	if (IS_ERR_OR_NULL(handle) || !handle->sensor_ops)
> +		return -EPROBE_DEFER;
> +
> +	nr_sensors = handle->sensor_ops->count_get(handle);
> +	if (!nr_sensors)
> +		return -EIO;
> +
> +	scmi_sensors = devm_kzalloc(dev, sizeof(*scmi_sensors), GFP_KERNEL);
> +	if (!scmi_sensors)
> +		return -ENOMEM;
> +
> +	scmi_sensors->handle = handle;
> +
> +	for (i = 0; i < nr_sensors; i++) {
> +		sensor = handle->sensor_ops->info_get(handle, i);
> +		if (!sensor)
> +			return PTR_ERR(sensor);
> +
> +		switch (sensor->type) {
> +		case TEMPERATURE_C:
> +		case VOLTAGE:
> +		case CURRENT:
> +		case POWER:
> +		case ENERGY:
> +			type = scmi_types[sensor->type];
> +			if (!nr_count[type])
> +				nr_types++;
> +			nr_count[type]++;
> +			break;
> +		}
> +	}
> +
> +	if (nr_count[hwmon_temp])
> +		nr_count[hwmon_chip]++, nr_types++;
> +
> +	scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan),
> +				       GFP_KERNEL);
> +	if (!scmi_hwmon_chan)
> +		return -ENOMEM;
> +
> +	ptr_scmi_ci = devm_kcalloc(dev, nr_types + 1, sizeof(*ptr_scmi_ci),
> +				   GFP_KERNEL);
> +	if (!ptr_scmi_ci)
> +		return -ENOMEM;
> +
> +	scmi_chip_info.info = ptr_scmi_ci;
> +	chip_info = &scmi_chip_info;
> +
> +	for (type = 0; type < hwmon_max && nr_count[type]; type++) {
> +		scmi_hwmon_add_chan_info(scmi_hwmon_chan, dev, nr_count[type],
> +					 type, hwmon_attributes[type]);
> +		*ptr_scmi_ci++ = scmi_hwmon_chan++;
> +
> +		scmi_sensors->info[type] =
> +			devm_kcalloc(dev, nr_count[type],
> +				     sizeof(*scmi_sensors->info), GFP_KERNEL);
> +		if (!scmi_sensors->info[type])
> +			return -ENOMEM;
> +	}
> +
> +	*ptr_scmi_ci = NULL;

Unnecessary; devm_kcalloc() clears out the allocated memory.

> +	platform_set_drvdata(pdev, scmi_sensors);
> +
> +	for (i = nr_sensors - 1; i >= 0 ; i--) {
> +		sensor = handle->sensor_ops->info_get(handle, i);
> +		if (!sensor)
> +			continue;
> +
> +		switch (sensor->type) {
> +		case TEMPERATURE_C:
> +		case VOLTAGE:
> +		case CURRENT:
> +		case POWER:
> +		case ENERGY:
> +			type = scmi_types[sensor->type];
> +			idx = --nr_count[type];
> +			*(scmi_sensors->info[type] + idx) = sensor;
> +			break;
> +		}
> +	}
> +
> +	hwdev = devm_hwmon_device_register_with_info(dev, "scmi_sensors",
> +						     scmi_sensors, chip_info,
> +						     NULL);
> +
> +	if (IS_ERR(hwdev))
> +		return PTR_ERR(hwdev);
> +
> +	return 0;

	return PTR_ERR_OR_ZERO(hwdev);

> +}
> +
> +static struct platform_driver scmi_hwmon_platdrv = {
> +	.driver = {
> +		.name	= "scmi-hwmon",
> +	},
> +	.probe		= scmi_hwmon_probe,
> +};
> +module_platform_driver(scmi_hwmon_platdrv);
> +
> +MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
> +MODULE_DESCRIPTION("ARM SCMI HWMON interface driver");
> +MODULE_LICENSE("GPL v2");

  reply	other threads:[~2017-10-01 14:26 UTC|newest]

Thread overview: 208+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-28 13:11 [PATCH v3 00/22] firmware: ARM System Control and Management Interface(SCMI) support Sudeep Holla
2017-09-28 13:11 ` Sudeep Holla
2017-09-28 13:11 ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 01/22] dt-bindings: mailbox: add support for mailbox client shared memory Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 02/22] dt-bindings: arm: add support for ARM System Control and Management Interface(SCMI) protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-04 10:50   ` Arnd Bergmann
2017-10-04 10:50     ` Arnd Bergmann
2017-10-04 10:50     ` Arnd Bergmann
2017-10-04 11:07     ` Sudeep Holla
2017-10-04 11:07       ` Sudeep Holla
2017-10-04 11:07       ` Sudeep Holla
2017-10-04 12:35       ` Arnd Bergmann
2017-10-04 12:35         ` Arnd Bergmann
2017-10-04 12:35         ` Arnd Bergmann
2017-10-04 13:53         ` Sudeep Holla
2017-10-04 13:53           ` Sudeep Holla
2017-10-04 13:53           ` Sudeep Holla
2017-10-04 14:17           ` Arnd Bergmann
2017-10-04 14:17             ` Arnd Bergmann
2017-10-04 14:17             ` Arnd Bergmann
2017-10-04 14:47             ` Sudeep Holla
2017-10-04 14:47               ` Sudeep Holla
2017-10-04 14:47               ` Sudeep Holla
2017-10-05 11:56               ` Arnd Bergmann
2017-10-05 11:56                 ` Arnd Bergmann
2017-10-05 11:56                 ` Arnd Bergmann
2017-10-05 12:56                 ` Sudeep Holla
2017-10-05 12:56                   ` Sudeep Holla
2017-10-05 13:20         ` Jassi Brar
2017-10-05 13:20           ` Jassi Brar
2017-10-05 14:10           ` Sudeep Holla
2017-10-05 14:10             ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 03/22] dt-bindings: arm: scmi: add ARM MHU specific mailbox client bindings Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-05 23:20   ` Rob Herring
2017-10-05 23:20     ` Rob Herring
2017-10-05 23:20     ` Rob Herring
2017-10-06  9:42     ` Sudeep Holla
2017-10-06  9:42       ` Sudeep Holla
2017-10-06 11:01     ` Jassi Brar
2017-10-06 11:01       ` Jassi Brar
2017-10-06 11:01       ` Jassi Brar
2017-10-06 15:54       ` Rob Herring
2017-10-06 15:54         ` Rob Herring
2017-10-07  2:26         ` Jassi Brar
2017-10-07  2:26           ` Jassi Brar
2017-10-09 13:52           ` Rob Herring
2017-10-09 13:52             ` Rob Herring
2017-10-09 14:37             ` Sudeep Holla
2017-10-09 14:37               ` Sudeep Holla
2017-10-09 14:37               ` Sudeep Holla
2017-10-09 14:46             ` Jassi Brar
2017-10-09 14:46               ` Jassi Brar
2017-10-09 14:46               ` Jassi Brar
2017-10-09 22:57               ` Rob Herring
2017-10-09 22:57                 ` Rob Herring
2017-10-09 22:57                 ` Rob Herring
2017-10-10  1:52                 ` Jassi Brar
2017-10-10  1:52                   ` Jassi Brar
2017-10-10 11:04                 ` Sudeep Holla
2017-10-10 11:04                   ` Sudeep Holla
2017-10-10 11:04                   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 04/22] firmware: arm_scmi: add basic driver infrastructure for SCMI Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-04 10:59   ` Arnd Bergmann
2017-10-04 10:59     ` Arnd Bergmann
2017-10-04 10:59     ` Arnd Bergmann
2017-10-04 17:37     ` Sudeep Holla
2017-10-04 17:37       ` Sudeep Holla
2017-10-04 17:37       ` Sudeep Holla
2017-10-04 11:19   ` Arnd Bergmann
2017-10-04 11:19     ` Arnd Bergmann
2017-10-04 11:19     ` Arnd Bergmann
2017-09-28 13:11 ` [PATCH v3 05/22] firmware: arm_scmi: add common infrastructure and support for base protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 06/22] firmware: arm_scmi: add initial support for performance protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 07/22] firmware: arm_scmi: add initial support for clock protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 08/22] firmware: arm_scmi: add initial support for power protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 09/22] firmware: arm_scmi: add initial support for sensor protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 10/22] firmware: arm_scmi: probe and initialise all the supported protocols Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-04 11:06   ` Arnd Bergmann
2017-10-04 11:06     ` Arnd Bergmann
2017-10-04 11:06     ` Arnd Bergmann
2017-09-28 13:11 ` [PATCH v3 11/22] firmware: arm_scmi: add support for polling based SCMI transfers Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-04 11:13   ` Arnd Bergmann
2017-10-04 11:13     ` Arnd Bergmann
2017-10-04 11:13     ` Arnd Bergmann
2017-10-04 11:18     ` Sudeep Holla
2017-10-04 11:18       ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 12/22] firmware: arm_scmi: add option for polling based performance domain operations Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 13/22] firmware: arm_scmi: refactor in preparation to support per-protocol channels Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 14/22] firmware: arm_scmi: add per-protocol channels support using idr objects Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 15/22] firmware: arm_scmi: abstract mailbox interface Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-04 11:24   ` Arnd Bergmann
2017-10-04 11:24     ` Arnd Bergmann
2017-10-04 11:24     ` Arnd Bergmann
2017-10-04 11:32     ` Sudeep Holla
2017-10-04 11:32       ` Sudeep Holla
2017-10-04 11:32       ` Sudeep Holla
2017-10-06 11:34       ` Jassi Brar
2017-10-06 11:34         ` Jassi Brar
2017-10-06 11:34         ` Jassi Brar
2017-10-06 13:27         ` Sudeep Holla
2017-10-06 13:27           ` Sudeep Holla
2017-10-06 13:27           ` Sudeep Holla
2017-10-06 13:34           ` Jassi Brar
2017-10-06 13:34             ` Jassi Brar
2017-10-06 13:41             ` Sudeep Holla
2017-10-06 13:41               ` Sudeep Holla
2017-10-12 21:20       ` Bjorn Andersson
2017-10-12 21:20         ` Bjorn Andersson
2017-09-28 13:11 ` [PATCH v3 16/22] firmware: arm_scmi: add arm_mhu specific " Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-04 11:36   ` Arnd Bergmann
2017-10-04 11:36     ` Arnd Bergmann
2017-10-04 11:48     ` Sudeep Holla
2017-10-04 11:48       ` Sudeep Holla
2017-10-04 11:48       ` Sudeep Holla
2017-10-06 11:26     ` Jassi Brar
2017-10-06 11:26       ` Jassi Brar
2017-10-06 11:26       ` Jassi Brar
2017-10-06 13:32       ` Sudeep Holla
2017-10-06 13:32         ` Sudeep Holla
2017-10-06 13:47         ` Jassi Brar
2017-10-06 13:47           ` Jassi Brar
2017-10-06 13:47           ` Jassi Brar
2017-10-06 13:51           ` Sudeep Holla
2017-10-06 13:51             ` Sudeep Holla
2017-10-06 13:51             ` Sudeep Holla
2017-10-12 21:03             ` Bjorn Andersson
2017-10-12 21:03               ` Bjorn Andersson
2017-10-13 13:42               ` Sudeep Holla
2017-10-13 13:42                 ` Sudeep Holla
2017-10-13 13:42                 ` Sudeep Holla
2017-10-13 14:12                 ` Jassi Brar
2017-10-13 14:12                   ` Jassi Brar
2017-10-13 14:12                   ` Jassi Brar
2017-10-13 14:47                   ` Sudeep Holla
2017-10-13 14:47                     ` Sudeep Holla
2017-10-13 15:19                     ` Jassi Brar
2017-10-13 15:19                       ` Jassi Brar
2017-10-13 15:19                       ` Jassi Brar
2017-09-28 13:11 ` [PATCH v3 17/22] firmware: arm_scmi: add device power domain support using genpd Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-09-28 21:18   ` Ulf Hansson
2017-09-28 21:18     ` Ulf Hansson
2017-09-29 13:40     ` Sudeep Holla
2017-09-29 13:40       ` Sudeep Holla
2017-09-29 13:40       ` Sudeep Holla
2017-09-29 13:42   ` [PATCH v3 17/22][UPDATE] firmware: arm_scmi: add device power domain support genpd Sudeep Holla
2017-09-29 13:42     ` Sudeep Holla
2017-09-29 13:42     ` Sudeep Holla
2017-10-10 11:05     ` Ulf Hansson
2017-10-10 11:05       ` Ulf Hansson
2017-10-10 13:02       ` Sudeep Holla
2017-10-10 13:02         ` Sudeep Holla
2017-10-10 13:02         ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 18/22] clk: add support for clocks provided by SCMI Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-11-02  7:23   ` Stephen Boyd
2017-11-02  7:23     ` Stephen Boyd
2017-11-02  7:23     ` Stephen Boyd
2017-11-02 10:04     ` Sudeep Holla
2017-11-02 10:04       ` Sudeep Holla
2017-11-02 10:04       ` Sudeep Holla
2017-11-03 15:12       ` Stephen Boyd
2017-11-03 15:12         ` Stephen Boyd
2017-11-03 15:12         ` Stephen Boyd
2017-09-28 13:11 ` [PATCH v3 19/22] hwmon: (core) Add hwmon_max to hwmon_sensor_types enumeration Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-01 14:21   ` [v3, " Guenter Roeck
2017-10-01 14:21     ` Guenter Roeck
2017-09-28 13:11 ` [PATCH v3 20/22] hwmon: add support for sensors exported via ARM SCMI Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
2017-10-01 14:26   ` Guenter Roeck [this message]
2017-10-01 14:26     ` [v3,20/22] " Guenter Roeck
2017-10-02  9:25     ` Sudeep Holla
2017-10-02  9:25       ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 21/22] cpufreq: add support for CPU DVFS based on SCMI message protocol Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla
     [not found]   ` <1506604306-20739-22-git-send-email-sudeep.holla-5wv7dgnIgG8@public.gmane.org>
2017-10-04 11:30     ` Arnd Bergmann
2017-10-04 11:30       ` Arnd Bergmann
2017-10-04 11:30       ` Arnd Bergmann
2017-10-04 15:01       ` Sudeep Holla
2017-10-04 15:01         ` Sudeep Holla
     [not found]         ` <5efbd0a7-8b62-5b30-98e6-dfaff64e2628-5wv7dgnIgG8@public.gmane.org>
2017-10-05 11:20           ` Arnd Bergmann
2017-10-05 11:20             ` Arnd Bergmann
2017-10-05 11:20             ` Arnd Bergmann
     [not found]             ` <CAK8P3a18i-=6PE2WAZ5LkYHty5CrVjMhTF_qJjtGGE3aCxLOuw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-05 11:26               ` Sudeep Holla
2017-10-05 11:26                 ` Sudeep Holla
2017-10-05 11:26                 ` Sudeep Holla
2017-09-28 13:11 ` [PATCH v3 22/22] cpufreq: scmi: add support for fast frequency switching Sudeep Holla
2017-09-28 13:11   ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171001142605.GA340@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Ryan.Harkin@arm.com \
    --cc=Sudeep.Holla@arm.com \
    --cc=alexey.klimov@arm.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=harba@codeaurora.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=lho@apm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=roy.franz@cavium.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.