Re: [PATCH v2 16/18] hwmon: add support for sensors exported via ARM SCMI

2017-08-14 Thread Guenter Roeck
On Mon, Aug 14, 2017 at 04:09:18PM +0100, Sudeep Holla wrote:
> Hi Guenter,
> 
> On 07/08/17 13:25, Sudeep Holla wrote:
> > 
> > 
> > On 04/08/17 20:32, Guenter Roeck wrote:
> >> On Fri, Aug 04, 2017 at 03:31:42PM +0100, Sudeep Holla wrote:
> > 
> > [...]
> > 
> >>> + platform_set_drvdata(pdev, scmi_sensors);
> >>> +
> >>> + hwdev = devm_hwmon_device_register_with_groups(dev, "scmi_sensors",
> >>> +scmi_sensors,
> >>> +scmi_sensors->groups);
> >>
> >> Can you rework this to use devm_hwmon_device_register_with_info(),
> >> and if possible let it handle the thermal registration ? 
> >>
> > 
> > Thanks for the pointers. I will check on the possibility and use it if
> > possible.
> > 
> 
> I had a look at devm_hwmon_device_register_with_info. It mostly deals
> with constant structures where all the attributes are known at the boot
> time. In case of SCMI, the firmware presents all the sensors and all the
> information(type, scale, name/label, ...etc). Unless I create those
> structures dynamically and typecast as const during probe, I can't get
> it working. Are you OK with that ? If so, I can try making those changes.
> 

Yes, please.

What operations exactly fail, though ? The idea was that the structures
are not modified by the infrastructure code, not that they must be constant
in the driver. Maybe some of the structure definitions are simply wrong. 

Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 16/18] hwmon: add support for sensors exported via ARM SCMI

2017-08-14 Thread Sudeep Holla
Hi Guenter,

On 07/08/17 13:25, Sudeep Holla wrote:
> 
> 
> On 04/08/17 20:32, Guenter Roeck wrote:
>> On Fri, Aug 04, 2017 at 03:31:42PM +0100, Sudeep Holla wrote:
> 
> [...]
> 
>>> +   platform_set_drvdata(pdev, scmi_sensors);
>>> +
>>> +   hwdev = devm_hwmon_device_register_with_groups(dev, "scmi_sensors",
>>> +  scmi_sensors,
>>> +  scmi_sensors->groups);
>>
>> Can you rework this to use devm_hwmon_device_register_with_info(),
>> and if possible let it handle the thermal registration ? 
>>
> 
> Thanks for the pointers. I will check on the possibility and use it if
> possible.
> 

I had a look at devm_hwmon_device_register_with_info. It mostly deals
with constant structures where all the attributes are known at the boot
time. In case of SCMI, the firmware presents all the sensors and all the
information(type, scale, name/label, ...etc). Unless I create those
structures dynamically and typecast as const during probe, I can't get
it working. Are you OK with that ? If so, I can try making those changes.

-- 
Regards,
Sudeep
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 16/18] hwmon: add support for sensors exported via ARM SCMI

2017-08-07 Thread Sudeep Holla


On 04/08/17 20:32, Guenter Roeck wrote:
> On Fri, Aug 04, 2017 at 03:31:42PM +0100, Sudeep Holla wrote:

[...]

>> +platform_set_drvdata(pdev, scmi_sensors);
>> +
>> +hwdev = devm_hwmon_device_register_with_groups(dev, "scmi_sensors",
>> +   scmi_sensors,
>> +   scmi_sensors->groups);
> 
> Can you rework this to use devm_hwmon_device_register_with_info(),
> and if possible let it handle the thermal registration ? 
> 

Thanks for the pointers. I will check on the possibility and use it if
possible.

-- 
Regards,
Sudeep
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 16/18] hwmon: add support for sensors exported via ARM SCMI

2017-08-04 Thread Guenter Roeck
On Fri, Aug 04, 2017 at 03:31:42PM +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 
> Cc: linux-hwmon@vger.kernel.org
> Signed-off-by: Sudeep Holla 
> ---
>  drivers/hwmon/Kconfig  |  12 +++
>  drivers/hwmon/Makefile |   1 +
>  drivers/hwmon/scmi-hwmon.c | 261 
> +
>  3 files changed, 274 insertions(+)
>  create mode 100644 drivers/hwmon/scmi-hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 5ef2814345ef..2bb63af8d674 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 d4641a9f16c1..02c3783c319f 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 ..f38c9708d99c
> --- /dev/null
> +++ b/drivers/hwmon/scmi-hwmon.c
> @@ -0,0 +1,261 @@
> +/*
> + * System Control and Management Interface(SCMI) based hwmon sensor driver
> + *
> + * Copyright (C) 2017 ARM Ltd.
> + * Punit Agrawal 
> + *
> + * 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +struct sensor_data {
> + const struct scmi_sensor_info *info;
> + struct device_attribute dev_attr_input;
> + struct device_attribute dev_attr_label;
> + char input[20];
> + char label[20];
> +};
> +
> +struct scmi_thermal_zone {
> + int sensor_id;
> + struct scmi_sensors *scmi_sensors;
> +};
> +
> +struct scmi_sensors {
> + const struct scmi_handle *handle;
> + struct sensor_data *data;
> + struct list_head thermal_zones;
> + struct attribute **attrs;
> + struct attribute_group group;
> + const struct attribute_group *groups[2];
> +};
> +
> +static int scmi_read_temp(void *dev, int *temp)
> +{
> + struct scmi_thermal_zone *zone = dev;
> + struct scmi_sensors *scmi_sensors = zone->scmi_sensors;
> + const struct scmi_handle *handle = scmi_sensors->handle;
> + struct sensor_data *sensor = _sensors->data[zone->sensor_id];
> + u64 value;
> + int ret;
> +
> + ret = handle->sensor_ops->reading_get(handle, sensor->info->id,
> +   false, );
> + if (ret)
> + return ret;
> +
> + *temp = value;
> + return 0;
> +}
> +
> +/* hwmon callback functions */
> +static ssize_t
> +scmi_show_sensor(struct device *dev, struct device_attribute *attr, char 
> *buf)
> +{
> + struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
> + const struct scmi_handle *handle = scmi_sensors->handle;
> + struct sensor_data *sensor;
> + u64 value;
> + int ret;
> +
> + sensor = container_of(attr, struct sensor_data, dev_attr_input);
> +
> + ret = handle->sensor_ops->reading_get(handle, sensor->info->id,
> +   false, );
> + 

[PATCH v2 16/18] hwmon: add support for sensors exported via ARM SCMI

2017-08-04 Thread Sudeep Holla
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 
Cc: linux-hwmon@vger.kernel.org
Signed-off-by: Sudeep Holla 
---
 drivers/hwmon/Kconfig  |  12 +++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/scmi-hwmon.c | 261 +
 3 files changed, 274 insertions(+)
 create mode 100644 drivers/hwmon/scmi-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5ef2814345ef..2bb63af8d674 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 d4641a9f16c1..02c3783c319f 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 ..f38c9708d99c
--- /dev/null
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -0,0 +1,261 @@
+/*
+ * System Control and Management Interface(SCMI) based hwmon sensor driver
+ *
+ * Copyright (C) 2017 ARM Ltd.
+ * Punit Agrawal 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct sensor_data {
+   const struct scmi_sensor_info *info;
+   struct device_attribute dev_attr_input;
+   struct device_attribute dev_attr_label;
+   char input[20];
+   char label[20];
+};
+
+struct scmi_thermal_zone {
+   int sensor_id;
+   struct scmi_sensors *scmi_sensors;
+};
+
+struct scmi_sensors {
+   const struct scmi_handle *handle;
+   struct sensor_data *data;
+   struct list_head thermal_zones;
+   struct attribute **attrs;
+   struct attribute_group group;
+   const struct attribute_group *groups[2];
+};
+
+static int scmi_read_temp(void *dev, int *temp)
+{
+   struct scmi_thermal_zone *zone = dev;
+   struct scmi_sensors *scmi_sensors = zone->scmi_sensors;
+   const struct scmi_handle *handle = scmi_sensors->handle;
+   struct sensor_data *sensor = _sensors->data[zone->sensor_id];
+   u64 value;
+   int ret;
+
+   ret = handle->sensor_ops->reading_get(handle, sensor->info->id,
+ false, );
+   if (ret)
+   return ret;
+
+   *temp = value;
+   return 0;
+}
+
+/* hwmon callback functions */
+static ssize_t
+scmi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
+   const struct scmi_handle *handle = scmi_sensors->handle;
+   struct sensor_data *sensor;
+   u64 value;
+   int ret;
+
+   sensor = container_of(attr, struct sensor_data, dev_attr_input);
+
+   ret = handle->sensor_ops->reading_get(handle, sensor->info->id,
+ false, );
+   if (ret)
+   return ret;
+
+   return sprintf(buf, "%llu\n", value);
+}
+
+static ssize_t
+scmi_show_label(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   struct sensor_data *sensor;
+
+   sensor = container_of(attr, struct sensor_data,