thermal: Add multiple instance support
Subsystems (5)
cover thermal: Add multiple instance support
This series adds support for multiple sensor tempeatures read & also a cmd option to read out temperatures from u-boot prompt.
Keerthy (3):
thermal: Add multiple instance support
cmd: thermal: Add command line interface to read out temperatures
configs: dra7xx_evm_defconfig: Enable TI_DRA7_THERMAL & CMD_THERMAL
arch/arm/mach-imx/cpu.c | 2 +- cmd/Kconfig | 5 +++ cmd/Makefile | 1 + cmd/thermal.c | 59 ++++++++++++++++++++++++++++++++ configs/dra7xx_evm_defconfig | 3 ++ drivers/mmc/omap_hsmmc.c | 2 +- drivers/thermal/imx_thermal.c | 2 +- drivers/thermal/thermal-uclass.c | 4 +-- drivers/thermal/ti-bandgap.c | 13 +++++-- include/thermal.h | 6 ++-- 10 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 cmd/thermal.c
Signature · 1 line
2.17.1
PATCH 1/3 thermal: Add multiple instance support
Currently single instance temperature read out is supported. Enhance the same to support multiple instances.
--- arch/arm/mach-imx/cpu.c | 2 +- drivers/mmc/omap_hsmmc.c | 2 +- drivers/thermal/imx_thermal.c | 2 +- drivers/thermal/thermal-uclass.c | 4 ++-- drivers/thermal/ti-bandgap.c | 13 ++++++++++--- include/thermal.h | 6 ++++-- 6 files changed, 19 insertions(+), 10 deletions(-)
arch/arm/mach-imx/cpu.c +1 -1
@@ -231,7 +231,7 @@ int print_cpuinfo(void)printf ("(%dC to %dC)" , minc, maxc); ret =uclass_get_device (UCLASS_THERMAL ,0 , &thermal_dev);if (!ret) { - ret =thermal_get_temp (thermal_dev, &cpu_tmp); + ret =thermal_get_temp (thermal_dev,0 , &cpu_tmp);if (!ret)printf (" at %dC\n" , cpu_tmp);
drivers/mmc/omap_hsmmc.c +1 -1
@@ -642,7 +642,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)printf ("Couldn't get thermal device for tuning\n" );return ret; } - ret =thermal_get_temp (thermal_dev, &temperature); + ret =thermal_get_temp (thermal_dev,0 , &temperature);if (ret) {printf ("Couldn't get temperature for tuning\n" );return ret;
drivers/thermal/imx_thermal.c +1 -1
@@ -207,7 +207,7 @@ static int read_cpu_temperature(struct udevice *dev) }#endif -int imx_thermal_get_temp (struct udevice *dev,int *temp) +int imx_thermal_get_temp (struct udevice *dev,int instance,int *temp) {struct thermal_data *priv =dev_get_priv (dev);int cpu_tmp =0 ;
drivers/thermal/thermal-uclass.c +2 -2
@@ -13,14 +13,14 @@#include <linux/list.h> -int thermal_get_temp (struct udevice *dev,int *temp) +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp) {const struct dm_thermal_ops *ops =device_get_ops (dev);if (!ops->get_temp)return -ENOSYS ; -return ops->get_temp (dev, temp); +return ops->get_temp (dev, instance, temp); }UCLASS_DRIVER (thermal) = {
drivers/thermal/ti-bandgap.c +10 -3
@@ -27,6 +27,7 @@struct ti_bandgap {ulong base;int temperature;/* in mili degree celsius */ +int sens_cnt; };/*
@@ -158,11 +159,16 @@ static int dra752_adc_to_temp[] = { 123800, 124200, 124600, 124900, 125000, 125000, }; -static int ti_bandgap_get_temp (struct udevice *dev,int *temp) +static int ti_bandgap_get_temp (struct udevice *dev,u8 instance,int *temp) {struct ti_bandgap *bgp =dev_get_priv (dev); - bgp->temperature =0x3ff &readl (bgp->base +CTRL_CORE_TEMP_SENSOR_MPU ); +if (instance >= bgp->sens_cnt) { +printf ("Only %d insatnces are supported\n" , bgp->sens_cnt); +return -EINVAL ; + } + + bgp->temperature =0x3ff &readl (bgp->base + instance *4 ); *temp = dra752_adc_to_temp[bgp->temperature -DRA752_ADC_START_VALUE ];return 0 ;
@@ -177,13 +183,14 @@ static int ti_bandgap_probe(struct udevice *dev)struct ti_bandgap *bgp =dev_get_priv (dev); bgp->base =devfdt_get_addr_index (dev,1 ); + bgp->sens_cnt =dev_get_driver_data (dev);return 0 ; }static const struct udevice_id of_ti_bandgap_match[] = { { - .compatible ="ti,dra752-bandgap" , + .compatible ="ti,dra752-bandgap" , .data =3 , }, {}, };
include/thermal.h +4 -2
@@ -9,7 +9,7 @@#include <dm.h> -int thermal_get_temp (struct udevice *dev,int *temp); +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp);/** * struct dm_thermal_ops - Driver model Thermal operations
@@ -25,9 +25,11 @@ struct dm_thermal_ops {* It will enable and initialize any Thermal hardware as necessary. * * @dev: The Thermal device +* @instance: The instance of sensor in case multiple sensors are +* present if single sensor then this should be 0 * @temp: pointer that returns the measured temperature */ - int (*get_temp)(struct udevice *dev, int *temp); + int (*get_temp)(struct udevice *dev, u8 instance, int *temp); };#endif /* _THERMAL_H_ */
Signature · 1 line
2.17.1
PATCH 1/3 thermal: Add multiple instance support
Hi Keerthy,
Quoted 5 lines · Keerthy
Currently single instance temperature read out is supported. Enhance the same to support multiple instances.
Signed-off-by Keerthy <[email protected]>
Quoted 8 lines
--- arch/arm/mach-imx/cpu.c | 2 +- drivers/mmc/omap_hsmmc.c | 2 +- drivers/thermal/imx_thermal.c | 2 +- drivers/thermal/thermal-uclass.c | 4 ++-- drivers/thermal/ti-bandgap.c | 13 ++++++++++--- include/thermal.h | 6 ++++-- 6 files changed, 19 insertions(+), 10 deletions(-)
Please can you add a simple test for the thermal uclass in test/dm?
Quoted 113 lines
arch/arm/mach-imx/cpu.c +1
-1@@ -231,7 +231,7 @@ int print_cpuinfo(void)printf ("(%dC to %dC)" , minc, maxc); ret =uclass_get_device (UCLASS_THERMAL ,0 , &thermal_dev);if (!ret) { - ret =thermal_get_temp (thermal_dev, &cpu_tmp); + ret =thermal_get_temp (thermal_dev,0 , &cpu_tmp);if (!ret)printf (" at %dC\n" , cpu_tmp);drivers/mmc/omap_hsmmc.c +1
-1@@ -642,7 +642,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)printf ("Couldn't get thermal device for tuning\n" );return ret; } - ret =thermal_get_temp (thermal_dev, &temperature); + ret =thermal_get_temp (thermal_dev,0 , &temperature);if (ret) {printf ("Couldn't get temperature for tuning\n" );return ret;drivers/thermal/imx_thermal.c +1
-1@@ -207,7 +207,7 @@ static int read_cpu_temperature(struct udevice *dev) }#endif -int imx_thermal_get_temp (struct udevice *dev,int *temp) +int imx_thermal_get_temp (struct udevice *dev,int instance,int *temp) {struct thermal_data *priv =dev_get_priv (dev);int cpu_tmp =0 ;drivers/thermal/thermal-uclass.c +2
-2@@ -13,14 +13,14 @@#include <linux/list.h> -int thermal_get_temp (struct udevice *dev,int *temp) +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp) {const struct dm_thermal_ops *ops =device_get_ops (dev);if (!ops->get_temp)return -ENOSYS ; -return ops->get_temp (dev, temp); +return ops->get_temp (dev, instance, temp); }UCLASS_DRIVER (thermal) = {drivers/thermal/ti-bandgap.c +10
-3@@ -27,6 +27,7 @@struct ti_bandgap {ulong base;int temperature;/* in mili degree celsius */ +int sens_cnt; };/* @@ -158,11 +159,16 @@ static int dra752_adc_to_temp[] = { 123800, 124200, 124600, 124900, 125000, 125000, }; -static int ti_bandgap_get_temp (struct udevice *dev,int *temp) +static int ti_bandgap_get_temp (struct udevice *dev,u8 instance,int *temp) {struct ti_bandgap *bgp =dev_get_priv (dev); - bgp->temperature =0x3ff &readl (bgp->base +CTRL_CORE_TEMP_SENSOR_MPU ); +if (instance >= bgp->sens_cnt) { +printf ("Only %d insatnces are supported\n" , bgp->sens_cnt); +return -EINVAL ; + } + + bgp->temperature =0x3ff &readl (bgp->base + instance *4 ); *temp = dra752_adc_to_temp[bgp->temperature -DRA752_ADC_START_VALUE ];return 0 ;@@ -177,13 +183,14 @@ static int ti_bandgap_probe(struct udevice *dev)struct ti_bandgap *bgp =dev_get_priv (dev); bgp->base =devfdt_get_addr_index (dev,1 ); + bgp->sens_cnt =dev_get_driver_data (dev);return 0 ; }static const struct udevice_id of_ti_bandgap_match[] = { { - .compatible ="ti,dra752-bandgap" , + .compatible ="ti,dra752-bandgap" , .data =3 , }, {}, };include/thermal.h +0
-0
include/thermal.h line 12
Quoted 5 lines
include/thermal.h +1
-1@@ -9,7 +9,7 @@#include <dm.h> -int thermal_get_temp (struct udevice *dev,int *temp); +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp);
Please add function comment.
include/thermal.h struct dm_thermal_ops { · line 32
Quoted 13 lines
include/thermal.h +3
-1/** * struct dm_thermal_ops - Driver model Thermal operations @@ -25,9 +25,11 @@ struct dm_thermal_ops {* It will enable and initialize any Thermal hardware as necessary. * * @dev: The Thermal device +* @instance: The instance of sensor in case multiple sensors are +* present if single sensor then this should be 0 * @temp: pointer that returns the measured temperature */ -int (*get_temp)(struct udevice *dev,int *temp); +int (*get_temp)(struct udevice *dev,u8 instance,int *temp);
I don't like the name 'instance' very much. With pwm we use 'channel'. Would that be OK?
Quoted 6 lines
include/thermal.h +0
-1};#endif /* _THERMAL_H_ */ --2.17.1
Regards,
Simon
PATCH 1/3 thermal: Add multiple instance support
Quoted 17 lines · Simon Glass
Hi Keerthy,
Quoted 5 lines · Keerthy
Currently single instance temperature read out is supported. Enhance the same to support multiple instances.
Signed-off-by Keerthy <[email protected]>Quoted 8 lines
--- arch/arm/mach-imx/cpu.c | 2 +- drivers/mmc/omap_hsmmc.c | 2 +- drivers/thermal/imx_thermal.c | 2 +- drivers/thermal/thermal-uclass.c | 4 ++-- drivers/thermal/ti-bandgap.c | 13 ++++++++++--- include/thermal.h | 6 ++++-- 6 files changed, 19 insertions(+), 10 deletions(-)
Quoted 1 line
Please can you add a simple test for the thermal uclass in test/dm?
Okay. I will try to add that.
Quoted 115 lines
Quoted 115 lines
arch/arm/mach-imx/cpu.c +1
-1@@ -231,7 +231,7 @@ int print_cpuinfo(void)printf ("(%dC to %dC)" , minc, maxc); ret =uclass_get_device (UCLASS_THERMAL ,0 , &thermal_dev);if (!ret) { - ret =thermal_get_temp (thermal_dev, &cpu_tmp); + ret =thermal_get_temp (thermal_dev,0 , &cpu_tmp);if (!ret)printf (" at %dC\n" , cpu_tmp);drivers/mmc/omap_hsmmc.c +1
-1@@ -642,7 +642,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)printf ("Couldn't get thermal device for tuning\n" );return ret; } - ret =thermal_get_temp (thermal_dev, &temperature); + ret =thermal_get_temp (thermal_dev,0 , &temperature);if (ret) {printf ("Couldn't get temperature for tuning\n" );return ret;drivers/thermal/imx_thermal.c +1
-1@@ -207,7 +207,7 @@ static int read_cpu_temperature(struct udevice *dev) }#endif -int imx_thermal_get_temp (struct udevice *dev,int *temp) +int imx_thermal_get_temp (struct udevice *dev,int instance,int *temp) {struct thermal_data *priv =dev_get_priv (dev);int cpu_tmp =0 ;drivers/thermal/thermal-uclass.c +2
-2@@ -13,14 +13,14 @@#include <linux/list.h> -int thermal_get_temp (struct udevice *dev,int *temp) +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp) {const struct dm_thermal_ops *ops =device_get_ops (dev);if (!ops->get_temp)return -ENOSYS ; -return ops->get_temp (dev, temp); +return ops->get_temp (dev, instance, temp); }UCLASS_DRIVER (thermal) = {drivers/thermal/ti-bandgap.c +10
-3@@ -27,6 +27,7 @@struct ti_bandgap {ulong base;int temperature;/* in mili degree celsius */ +int sens_cnt; };/* @@ -158,11 +159,16 @@ static int dra752_adc_to_temp[] = { 123800, 124200, 124600, 124900, 125000, 125000, }; -static int ti_bandgap_get_temp (struct udevice *dev,int *temp) +static int ti_bandgap_get_temp (struct udevice *dev,u8 instance,int *temp) {struct ti_bandgap *bgp =dev_get_priv (dev); - bgp->temperature =0x3ff &readl (bgp->base +CTRL_CORE_TEMP_SENSOR_MPU ); +if (instance >= bgp->sens_cnt) { +printf ("Only %d insatnces are supported\n" , bgp->sens_cnt); +return -EINVAL ; + } + + bgp->temperature =0x3ff &readl (bgp->base + instance *4 ); *temp = dra752_adc_to_temp[bgp->temperature -DRA752_ADC_START_VALUE ];return 0 ;@@ -177,13 +183,14 @@ static int ti_bandgap_probe(struct udevice *dev)struct ti_bandgap *bgp =dev_get_priv (dev); bgp->base =devfdt_get_addr_index (dev,1 ); + bgp->sens_cnt =dev_get_driver_data (dev);return 0 ; }static const struct udevice_id of_ti_bandgap_match[] = { { - .compatible ="ti,dra752-bandgap" , + .compatible ="ti,dra752-bandgap" , .data =3 , }, {}, };include/thermal.h +0
-0@@ -9,7 +9,7 @@
Quoted 6 lines
include/thermal.h line 12
Quoted 4 lines
include/thermal.h +1
-1#include <dm.h> -int thermal_get_temp (struct udevice *dev,int *temp); +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp);Please add function comment.
Okay.
Quoted 17 lines
Quoted 5 lines
include/thermal.h +0
-0/** * struct dm_thermal_ops - Driver model Thermal operations include/thermal.h struct dm_thermal_ops { · line 32
Quoted 9 lines
include/thermal.h +3
-1@@ -25,9 +25,11 @@ struct dm_thermal_ops {* It will enable and initialize any Thermal hardware as necessary. * * @dev: The Thermal device +* @instance: The instance of sensor in case multiple sensors are +* present if single sensor then this should be 0 * @temp: pointer that returns the measured temperature */ -int (*get_temp)(struct udevice *dev,int *temp); +int (*get_temp)(struct udevice *dev,u8 instance,int *temp);I don't like the name 'instance' very much. With pwm we use 'channel'. Would that be OK?
How about 'sensors'? Basically multiple sensors give out temperatures of different thermal zones.
Quoted 11 lines
Quoted 7 lines
include/thermal.h +0
-1};#endif /* _THERMAL_H_ */ --2.17.1
Regards,
Simon
PATCH 1/3 thermal: Add multiple instance support
Hi Keerthy,
Quoted 167 lines · keerthy
Quoted 17 lines · Simon Glass
Hi Keerthy,
Quoted 5 lines · Keerthy
Currently single instance temperature read out is supported. Enhance the same to support multiple instances.
Signed-off-by Keerthy <[email protected]>Quoted 8 lines
--- arch/arm/mach-imx/cpu.c | 2 +- drivers/mmc/omap_hsmmc.c | 2 +- drivers/thermal/imx_thermal.c | 2 +- drivers/thermal/thermal-uclass.c | 4 ++-- drivers/thermal/ti-bandgap.c | 13 ++++++++++--- include/thermal.h | 6 ++++-- 6 files changed, 19 insertions(+), 10 deletions(-)Quoted 1 line
Please can you add a simple test for the thermal uclass in test/dm?
Okay. I will try to add that.
Quoted 115 lines
Quoted 115 lines
arch/arm/mach-imx/cpu.c +1
-1@@ -231,7 +231,7 @@ int print_cpuinfo(void)printf ("(%dC to %dC)" , minc, maxc); ret =uclass_get_device (UCLASS_THERMAL ,0 , &thermal_dev);if (!ret) { - ret =thermal_get_temp (thermal_dev, &cpu_tmp); + ret =thermal_get_temp (thermal_dev,0 , &cpu_tmp);if (!ret)printf (" at %dC\n" , cpu_tmp);drivers/mmc/omap_hsmmc.c +1
-1@@ -642,7 +642,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)printf ("Couldn't get thermal device for tuning\n" );return ret; } - ret =thermal_get_temp (thermal_dev, &temperature); + ret =thermal_get_temp (thermal_dev,0 , &temperature);if (ret) {printf ("Couldn't get temperature for tuning\n" );return ret;drivers/thermal/imx_thermal.c +1
-1@@ -207,7 +207,7 @@ static int read_cpu_temperature(struct udevice *dev) }#endif -int imx_thermal_get_temp (struct udevice *dev,int *temp) +int imx_thermal_get_temp (struct udevice *dev,int instance,int *temp) {struct thermal_data *priv =dev_get_priv (dev);int cpu_tmp =0 ;drivers/thermal/thermal-uclass.c +2
-2@@ -13,14 +13,14 @@#include <linux/list.h> -int thermal_get_temp (struct udevice *dev,int *temp) +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp) {const struct dm_thermal_ops *ops =device_get_ops (dev);if (!ops->get_temp)return -ENOSYS ; -return ops->get_temp (dev, temp); +return ops->get_temp (dev, instance, temp); }UCLASS_DRIVER (thermal) = {drivers/thermal/ti-bandgap.c +10
-3@@ -27,6 +27,7 @@struct ti_bandgap {ulong base;int temperature;/* in mili degree celsius */ +int sens_cnt; };/* @@ -158,11 +159,16 @@ static int dra752_adc_to_temp[] = { 123800, 124200, 124600, 124900, 125000, 125000, }; -static int ti_bandgap_get_temp (struct udevice *dev,int *temp) +static int ti_bandgap_get_temp (struct udevice *dev,u8 instance,int *temp) {struct ti_bandgap *bgp =dev_get_priv (dev); - bgp->temperature =0x3ff &readl (bgp->base +CTRL_CORE_TEMP_SENSOR_MPU ); +if (instance >= bgp->sens_cnt) { +printf ("Only %d insatnces are supported\n" , bgp->sens_cnt); +return -EINVAL ; + } + + bgp->temperature =0x3ff &readl (bgp->base + instance *4 ); *temp = dra752_adc_to_temp[bgp->temperature -DRA752_ADC_START_VALUE ];return 0 ;@@ -177,13 +183,14 @@ static int ti_bandgap_probe(struct udevice *dev)struct ti_bandgap *bgp =dev_get_priv (dev); bgp->base =devfdt_get_addr_index (dev,1 ); + bgp->sens_cnt =dev_get_driver_data (dev);return 0 ; }static const struct udevice_id of_ti_bandgap_match[] = { { - .compatible ="ti,dra752-bandgap" , + .compatible ="ti,dra752-bandgap" , .data =3 , }, {}, };include/thermal.h +0
-0@@ -9,7 +9,7 @@Quoted 6 lines
include/thermal.h line 12
Quoted 4 lines
include/thermal.h +1
-1#include <dm.h> -int thermal_get_temp (struct udevice *dev,int *temp); +int thermal_get_temp (struct udevice *dev,u8 instance,int *temp);Please add function comment.
Okay.
Quoted 17 lines
Quoted 5 lines
include/thermal.h +0
-0/** * struct dm_thermal_ops - Driver model Thermal operations include/thermal.h struct dm_thermal_ops { · line 32
Quoted 9 lines
include/thermal.h +3
-1@@ -25,9 +25,11 @@ struct dm_thermal_ops {* It will enable and initialize any Thermal hardware as necessary. * * @dev: The Thermal device +* @instance: The instance of sensor in case multiple sensors are +* present if single sensor then this should be 0 * @temp: pointer that returns the measured temperature */ -int (*get_temp)(struct udevice *dev,int *temp); +int (*get_temp)(struct udevice *dev,u8 instance,int *temp);I don't like the name 'instance' very much. With pwm we use 'channel'. Would that be OK?
Quoted 2 lines
How about 'sensors'? Basically multiple sensors give out temperatures of different thermal zones.
Hmm I still prefer channel to fit in with PWM. But if you really want to use 'sensor' (singular, not plural) then OK.
Regards,
Simon
PATCH 2/3 cmd: thermal: Add command line interface to read out temperatures
In reply to KeerthyAdd command line interface to read out temperatures from SoC. Takes two arguments. One is 'temperature' and the other is instance number. In case instance number is not provided by default 0th instance temperature is read out.
--- cmd/Kconfig | 5 +++++ cmd/Makefile | 1 + cmd/thermal.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 cmd/thermal.c
cmd/Kconfig +5 -0
@@ -1044,6 +1044,11 @@ config CMD_SPI help SPI utility command. +config CMD_THERMAL + bool "thermal" + help + THERMAL support. + config CMD_TSI148 bool "tsi148 - Command to access tsi148 device" help
cmd/Makefile +1 -0
@@ -128,6 +128,7 @@ obj-$(CONFIG_CMD_SPI) += spi.o obj-$(CONFIG_CMD_STRINGS) += strings.o obj-$(CONFIG_CMD_SMC) += smccc.o obj-$(CONFIG_CMD_TERMINAL) += terminal.o +obj-$(CONFIG_CMD_THERMAL) += thermal.o obj-$(CONFIG_CMD_TIME) += time.o obj-$(CONFIG_CMD_TRACE) += trace.o obj-$(CONFIG_HUSH_PARSER) += test.o
cmd/thermal.c new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/3 cmd: thermal: Add command line interface to read out temperatures
Hi Keerthy,
Quoted 19 lines · Keerthy
Add command line interface to read out temperatures from SoC. Takes two arguments. One is 'temperature' and the other is instance number. In case instance number is not provided by default 0th instance temperature is read out.
Signed-off-by Keerthy <[email protected]>--- cmd/Kconfig | 5 +++++ cmd/Makefile | 1 + cmd/thermal.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 cmd/thermal.ccmd/Kconfig +0
-0
cmd/Kconfig config CMD_SPI · line 1050
Quoted 7 lines
cmd/Kconfig +4
-0@@ -1044,6 +1044,11 @@ config CMD_SPI help SPI utility command. +config CMD_THERMAL + bool "thermal" + help + THERMAL support.
Thermal support
Quoted 22 lines
cmd/Kconfig +1
-0+ config CMD_TSI148 bool "tsi148 - Command to access tsi148 device" helpcmd/Makefile +1
-0@@ -128,6 +128,7 @@ obj-$(CONFIG_CMD_SPI) += spi.o obj-$(CONFIG_CMD_STRINGS) += strings.o obj-$(CONFIG_CMD_SMC) += smccc.o obj-$(CONFIG_CMD_TERMINAL) += terminal.o +obj-$(CONFIG_CMD_THERMAL) += thermal.o obj-$(CONFIG_CMD_TIME) += time.o obj-$(CONFIG_CMD_TRACE) += trace.o obj-$(CONFIG_HUSH_PARSER) += test.ocmd/thermal.c new file +0
-0
cmd/thermal.c line 10
Quoted 10 lines
cmd/thermal.c new file +10
-0@@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Thermal CMD +* +* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ +*/ +#include <common.h> +#include <errno.h> +#include <dm.h> +#include <dm/uclass-internal.h>
Should go at the end
cmd/thermal.c line 13
Quoted 3 lines
cmd/thermal.c new file +3
-0+#include <thermal.h> + +#define MAX_TEMP 150
Is this in celsius?
cmd/thermal.c line 20
Quoted 7 lines
cmd/thermal.c new file +7
-0+ +static int do_read_temp (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +struct udevice *tdev; +int cpu_temp, ret =0 ; +u8 instance;
uint
Please use channel instead
cmd/thermal.c line 25
Quoted 5 lines
cmd/thermal.c new file +5
-0+const char *units; + +if (argc >2 ) { +printf ("Max Number of arguments is 2\n" ); +return -EINVAL ;
return CMD_RET_USAGE
If you return -ve values it can do strange things like cause the calling shell to exit.
cmd/thermal.c line 28
Quoted 3 lines
cmd/thermal.c new file +3
-0+ } + +/* In case instance is not given default 0th instnace is reported */
instance
cmd/thermal.c line 30
Quoted 2 lines
cmd/thermal.c new file +2
-0+if (argc ==2 ) + instance = (u8 )simple_strtoul (argv[1 ],NULL ,10 );
Drop u8 cast
cmd/thermal.c line 34
Quoted 4 lines
cmd/thermal.c new file +4
-0+else + instance =0 ; + + ret =uclass_get_device (UCLASS_THERMAL ,0 , &tdev);
uclass_first_device_err()?
That is more robust than requiring it be seq #0.
cmd/thermal.c line 41
Quoted 7 lines
cmd/thermal.c new file +7
-0+if (!ret) { + ret =thermal_get_temp (tdev, instance, &cpu_temp); +if (!ret) { +if (abs (cpu_temp) <MAX_TEMP ) + units ="C" ; +else + units ="mC" ;
The interface should be in mC, then. We can't have the range of the value determine the units.
cmd/thermal.c line 46
Quoted 5 lines
cmd/thermal.c new file +5
-0+ +printf ("Instance %d Temperature at %d%s\n" , instance, + cpu_temp, units); + }else { +debug (" - invalid sensor data\n" );
Maybe -ENOENT means invalid channel-ENODATA means the channel exists but temperature could not be read?
cmd/thermal.c line 51
Quoted 5 lines
cmd/thermal.c new file +5
-0+ } + }else { +printf (" - invalid sensor device\n" ); + } +
if (ret)
return CMD_RET_FAILURE;
return 0
cmd/thermal.c line 52
Quoted 1 line
cmd/thermal.c new file +1
-0+return ret;
Don't return -ve values from commands.
Quoted 10 lines
cmd/thermal.c new file +7
-1+} + +U_BOOT_CMD ( + temperature,2 ,0 , do_read_temp, +"Reads temperature of a given sensor" , +" [sensor number] - number of the temperature sensor" +); --2.17.1
Could we have a pytest for this command for sandbox?
Regards,
Simon
PATCH 3/3 configs: dra7xx_evm_defconfig: Enable TI_DRA7_THERMAL & CMD_THERMAL
In reply to KeerthyEnable TI_DRA7_THERMAL & CMD_THERMAL config options to read out temperatures of different instances in u-boot.
--- configs/dra7xx_evm_defconfig | 3 +++ 1 file changed, 3 insertions(+)
configs/dra7xx_evm_defconfig +3 -0
@@ -101,3 +101,6 @@ CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0451 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022 +CONFIG_DM_THERMAL=y +CONFIG_TI_DRA7_THERMAL=y +CONFIG_CMD_THERMAL=y
Signature · 1 line
2.17.1