add i.MX6 thermal sensor driver
Subsystems (3)
v6 cover add i.MX6 thermal sensor driver
From: Nitin Garg <[email protected]>
This patch set adds i.MX6 thermal sensor driver
and enables it for mx6sabre boards. Also adds
various anadig bit definitions as required for
upcoming drivers.
Changes in v6:
-Aligned imx thermal driver macro defines with kernel
Changes in v5:
-Don't modify the copyright of cpu.c and crm_regs.h file
Changes in v4:
-Added imx6 thermal sensor as a driver
-Renamed the config define to be more meaningful
-Move the clock code to clock.c
-Reusing ocotp driver for reading fuse
-Fix check for calibration fuse not programmed
-Aligned the slope computation with kernel
-Added Anadig register defines as seperate commit
Changes in v3:
-adds the mx6 thermal driver support
-adds the mx6 thermal support to mx6sabresd board.
Changes in v2:
-run checkpatch and fix reported issues
Nitin Garg (4):
mx6: clock: Add api to enable pll3
mx6: thermal: Add i.MX6 CPU thermal sensor support
mx6: thermal: Check cpu temperature via thermal sensor
mx6: thermal: Enable thermal sensor for mx6 sabre boards.
arch/arm/cpu/armv7/mx6/clock.c | 25 ++++++ arch/arm/imx-common/cpu.c | 6 ++ arch/arm/include/asm/arch-mx6/clock.h | 1 + drivers/Makefile | 1 + drivers/thermal/Makefile | 8 ++ drivers/thermal/imx_thermal.c | 144 +++++++++++++++++++++++++++++++++ include/configs/mx6sabre_common.h | 3 +- include/imx_thermal.h | 15 ++++ 8 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/Makefile create mode 100644 drivers/thermal/imx_thermal.c create mode 100644 include/imx_thermal.h
Signature · 1 line
1.7.9.5
PATCH v6 1/4 mx6: clock: Add api to enable pll3
From: Nitin Garg <[email protected]>
Add api to check and enable pll3 as required
for thermal sensor driver.
--- arch/arm/cpu/armv7/mx6/clock.c | 25 +++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/clock.h | 1 + 2 files changed, 26 insertions(+)
arch/arm/cpu/armv7/mx6/clock.c +25 -0
@@ -673,6 +673,31 @@ void hab_caam_clock_enable(unsigned char enable) }#endif +void enable_pll3 (void ) +{ +struct anatop_regs __iomem *anatop = + (struct anatop_regs __iomem *)ANATOP_BASE_ADDR ; + +/* make sure pll3 is enabled */ +if ((readl (&anatop->usb1_pll_480_ctrl) & +BM_ANADIG_USB1_PLL_480_CTRL_LOCK ) ==0 ) { +/* enable pll's power */ +writel (BM_ANADIG_USB1_PLL_480_CTRL_POWER , + &anatop->usb1_pll_480_ctrl_set); +writel (0x80 , &anatop->ana_misc2_clr); +/* wait for pll lock */ +while ((readl (&anatop->usb1_pll_480_ctrl) & +BM_ANADIG_USB1_PLL_480_CTRL_LOCK ) ==0 ) + ; +/* disable bypass */ +writel (BM_ANADIG_USB1_PLL_480_CTRL_BYPASS , + &anatop->usb1_pll_480_ctrl_clr); +/* enable pll output */ +writel (BM_ANADIG_USB1_PLL_480_CTRL_ENABLE , + &anatop->usb1_pll_480_ctrl_set); + } +} +unsigned int mxc_get_clock (enum mxc_clock clk) {switch (clk) {
arch/arm/include/asm/arch-mx6/clock.h +1 -0
@@ -66,4 +66,5 @@ int enable_spi_clk(unsigned char enable, unsigned spi_num);void enable_ipu_clock (void );int enable_fec_anatop_clock (enum enet_freq freq);void enable_enet_clk (unsigned char enable); +void enable_pll3 (void );#endif /* __ASM_ARCH_CLOCK_H */
Signature · 1 line
1.7.9.5
PATCH v6 2/4 mx6: thermal: Add i.MX6 CPU thermal sensor support
In reply to nitin.garg at freescale.comFrom: Nitin Garg <[email protected]>
i.MX6 SoC has onchip temperature sensor. Add driver for this sensor.
--- drivers/Makefile | 1 + drivers/thermal/Makefile | 8 +++ drivers/thermal/imx_thermal.c | 144 +++++++++++++++++++++++++++++++++++++++++ include/imx_thermal.h | 15 +++++ 4 files changed, 168 insertions(+) create mode 100644 drivers/thermal/Makefile create mode 100644 drivers/thermal/imx_thermal.c create mode 100644 include/imx_thermal.h
drivers/Makefile +1 -0
@@ -21,3 +21,4 @@ obj-y += pwm/ obj-y += input/ # SOC specific infrastructure drivers. obj-y += soc/ +obj-y += thermal/
drivers/thermal/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# (C) Copyright 2014 Freescale Semiconductor, Inc. +# Author: Nitin Garg <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_IMX6_THERMAL) += imx_thermal.o
drivers/thermal/imx_thermal.c new file +144 -0
144 lines not on this page · raw message
include/imx_thermal.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* IMX Thermal Defines +*------------------------------------------------------------------- +* +* Copyright 2014 Freescale Semiconductor, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __IMX6_THERMAL_H__ +#define __IMX6_THERMAL_H__ + +void check_cpu_temperature (void ); + +#endif /* __IMX6_THERMAL_H__ */
Signature · 1 line
1.7.9.5
PATCH v6 2/4 mx6: thermal: Add i.MX6 CPU thermal sensor support
Hi Nitin,
Quoted 6 lines · nitin.garg at freescale.com
From: Nitin Garg <[email protected]>
i.MX6 SoC has onchip temperature sensor. Add driver for this sensor.
Signed-off-by Nitin Garg <[email protected]>
Quoted 10 lines
--- drivers/Makefile | 1 + drivers/thermal/Makefile | 8 +++ drivers/thermal/imx_thermal.c | 144 +++++++++++++++++++++++++++++++++++++++++ include/imx_thermal.h | 15 +++++ 4 files changed, 168 insertions(+) create mode 100644 drivers/thermal/Makefile create mode 100644 drivers/thermal/imx_thermal.c create mode 100644 include/imx_thermal.h
I have some conceptional question here. This introduces a new set or, better, "class" of drivers, as we are used to see in kernel as "thermal". As we discussed in last u-boot mini summit, the preferred way to introduce new drivers into current u-boot is to use DM (Driver Model), because this is the way u-boot will follow in the future. It will take some time porting the current drivers, but it is easier for drivers introducing new features.
This is exactly this case: there is at the moment no "thermal" drivers, and it would be nice to introduce it using DM, else we will have the problem in the near future to port this drivers, too, and maybe some further drivers adding thermal monitoring.
This means you have to add a "thermal" class (you can take a look at the spi driver, it was already ported to dm) and define the functions your class exports. I think at the moment you define only a "monitor", but feel free to add further functions, preferably in the same way as the linux kernel does (see include/linux/thermal.h in kernel tree).
Quoted 157 lines
drivers/Makefile +1
-0@@ -21,3 +21,4 @@ obj-y += pwm/ obj-y += input/ # SOC specific infrastructure drivers. obj-y += soc/ +obj-y += thermal/drivers/thermal/Makefile new file +8
-0@@ -0,0 +1,8 @@ +# +# (C) Copyright 2014 Freescale Semiconductor, Inc. +# Author: Nitin Garg <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_IMX6_THERMAL) += imx_thermal.odrivers/thermal/imx_thermal.c new file +128
-0@@ -0,0 +1,144 @@ +/* +* (C) Copyright 2014 Freescale Semiconductor, Inc. +* Author: Nitin Garg <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <config.h> +#include <common.h> +#include <div64.h> +#include <fuse.h> +#include <asm/io.h> +#include <asm/arch/clock.h> + +#define TEMPERATURE_MIN -40 +#define TEMPERATURE_HOT 80 +#define TEMPERATURE_MAX 125 +#define FACTOR0 10000000 +#define FACTOR1 15976 +#define FACTOR2 4297157 +#define MEASURE_FREQ 327 + +#define TEMPSENSE0_TEMP_CNT_SHIFT 8 +#define TEMPSENSE0_TEMP_CNT_MASK (0xfff << TEMPSENSE0_TEMP_CNT_SHIFT) +#define TEMPSENSE0_FINISHED (1 << 2) +#define TEMPSENSE0_MEASURE_TEMP (1 << 1) +#define TEMPSENSE0_POWER_DOWN (1 << 0) +#define MISC0_REFTOP_SELBIASOFF (1 << 3) +#define TEMPSENSE1_MEASURE_FREQ 0xffff + +static int read_cpu_temperature (u32 fuse) +{ +int temperature; +unsigned int reg, n_meas; +struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR ; +int t1, n1; +u32 c1, c2; +u64 temp64; + +/* make sure pll3 is enabled for thermal sensor */ +enable_pll3 (); + +/* +* Sensor data layout: +* [31:20] - sensor value @ 25C +* We use universal formula now and only need sensor value @ 25C +* slope = 0.4297157 - (0.0015976 * 25C fuse) +*/ + n1 = fuse >>20 ; + t1 =25 ;/* t1 always 25C */ + +/* +* Derived from linear interpolation: +* slope = 0.4297157 - (0.0015976 * 25C fuse) +* slope = (FACTOR2 - FACTOR1 * n1) / FACTOR0 +* (Nmeas - n1) / (Tmeas - t1) = slope +* We want to reduce this down to the minimum computation necessary +* for each temperature read. Also, we want Tmeas in millicelsius +* and we don't want to lose precision from integer division. So... +* Tmeas = (Nmeas - n1) / slope + t1 +* milli_Tmeas = 1000 * (Nmeas - n1) / slope + 1000 * t1 +* milli_Tmeas = -1000 * (n1 - Nmeas) / slope + 1000 * t1 +* Let constant c1 = (-1000 / slope) +* milli_Tmeas = (n1 - Nmeas) * c1 + 1000 * t1 +* Let constant c2 = n1 *c1 + 1000 * t1 +* milli_Tmeas = c2 - Nmeas * c1 +*/ + temp64 =FACTOR0 ; + temp64 *=1000 ; +do_div (temp64,FACTOR1 * n1 -FACTOR2 ); + c1 = temp64; + c2 = n1 * c1 +1000 * t1; + +/* +* now we only use single measure, every time we read +* the temperature, we will power on/down anadig thermal +* module +*/ +writel (TEMPSENSE0_POWER_DOWN , &anatop->tempsense0_clr); +writel (MISC0_REFTOP_SELBIASOFF , &anatop->ana_misc0_set); + +/* setup measure freq */ + reg =readl (&anatop->tempsense1); + reg &= ~TEMPSENSE1_MEASURE_FREQ ; + reg |=MEASURE_FREQ ; +writel (reg, &anatop->tempsense1); + +/* start the measurement process */ +writel (TEMPSENSE0_MEASURE_TEMP , &anatop->tempsense0_clr); +writel (TEMPSENSE0_FINISHED , &anatop->tempsense0_clr); +writel (TEMPSENSE0_MEASURE_TEMP , &anatop->tempsense0_set); + +/* make sure that the latest temp is valid */ +while ((readl (&anatop->tempsense0) & +TEMPSENSE0_FINISHED ) ==0 ) +udelay (10000 ); + +/* read temperature count */ + reg =readl (&anatop->tempsense0); + n_meas = (reg &TEMPSENSE0_TEMP_CNT_MASK ) + >>TEMPSENSE0_TEMP_CNT_SHIFT ; +writel (TEMPSENSE0_FINISHED , &anatop->tempsense0_clr); + +/* milli_Tmeas = c2 - Nmeas * c1 */ + temperature = (c2 - n_meas * c1)/1000 ; + +/* power down anatop thermal sensor */ +writel (TEMPSENSE0_POWER_DOWN , &anatop->tempsense0_set); +writel (MISC0_REFTOP_SELBIASOFF , &anatop->ana_misc0_clr); + +return temperature; +} + +void check_cpu_temperature (void ) +{ +int cpu_tmp =0 ; +u32 fuse = ~0 ; + +/* Read Temperature calibration data fuse */ +fuse_read (1 ,6 , &fuse); + +/* Check for valid fuse */ +if (fuse ==0 || fuse == ~0 ) { +printf ("CPU: Temperature: invalid data, fuse: 0x%x\n" , fuse); +return ; + } + + cpu_tmp =read_cpu_temperature (fuse);
drivers/thermal/imx_thermal.c line 138
Quoted 10 lines
drivers/thermal/imx_thermal.c new file +10
-0+while (cpu_tmp >TEMPERATURE_MIN && cpu_tmp <TEMPERATURE_MAX ) { +if (cpu_tmp >=TEMPERATURE_HOT ) { +printf ("CPU is %d C, too hot to boot, waiting...\n" , + cpu_tmp); +udelay (5000000 ); + cpu_tmp =read_cpu_temperature (fuse); + }else { +break ; + } + }
I would split here the interface. We have a driver, and this should return back its result - but without taking an action. This decision should be done by the user of the driver (the cpu code).
Quoted 18 lines
drivers/thermal/imx_thermal.c new file +6
-0+ +if (cpu_tmp >TEMPERATURE_MIN && cpu_tmp <TEMPERATURE_MAX ) +printf ("CPU: Temperature %d C\n" , cpu_tmp); +else +printf ("CPU: Temperature: invalid sensor data\n" ); +}include/imx_thermal.h new file +5
-0@@ -0,0 +1,15 @@ +/* +* IMX Thermal Defines +*------------------------------------------------------------------- +* +* Copyright 2014 Freescale Semiconductor, Inc
include/imx_thermal.h line 15
Quoted 10 lines
include/imx_thermal.h new file +10
-0+* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __IMX6_THERMAL_H__ +#define __IMX6_THERMAL_H__ + +void check_cpu_temperature (void ); + +#endif /* __IMX6_THERMAL_H__ */
Best regards,
Stefano Babic
Signature · 5 lines
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
Fabio Estevam
reviewerPATCH v6 2/4 mx6: thermal: Add i.MX6 CPU thermal sensor support
Hi Stefano,
Quoted 7 lines · Stefano Babic
I have some conceptional question here. This introduces a new set or, better, "class" of drivers, as we are used to see in kernel as "thermal". As we discussed in last u-boot mini summit, the preferred way to introduce new drivers into current u-boot is to use DM (Driver Model), because this is the way u-boot will follow in the future. It will take some time porting the current drivers, but it is easier for drivers introducing new features.
It is a good idea to convert this to the driver model, but Nitin is already at v6 and only now this request is made. First version of this patch series was sent back in August:
http://lists.denx.de/pipermail/u-boot/2014-August/187685.html
Could the conversion to DM be handled later by a separate patch?
Regards,
Fabio Estevam
PATCH v6 2/4 mx6: thermal: Add i.MX6 CPU thermal sensor support
Hi Fabio,
Quoted 12 lines · Fabio Estevam
Hi Stefano,
Quoted 7 lines · Stefano Babic
I have some conceptional question here. This introduces a new set or, better, "class" of drivers, as we are used to see in kernel as "thermal". As we discussed in last u-boot mini summit, the preferred way to introduce new drivers into current u-boot is to use DM (Driver Model), because this is the way u-boot will follow in the future. It will take some time porting the current drivers, but it is easier for drivers introducing new features.
Quoted 7 lines
It is a good idea to convert this to the driver model, but Nitin is already at v6 and only now this request is made.
First version of this
patch series was sent back in August:
http://lists.denx.de/pipermail/u-boot/2014-August/187685.htmlCould the conversion to DM be handled later by a separate patch?
It is fine with me, but we agreed on the last mini summit last month to accept new drivers if they are developped under DM rules. Tom, can the driver be accepted and later converted to DM, or this driver (it is the first driver regarding thermal) must be converted first ?
Best regards,
Stefano Babic
Signature · 5 lines
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH v6 2/4 mx6: thermal: Add i.MX6 CPU thermal sensor support
Quoted 17 lines · Stefano Babic
Quoted 16 lines · Fabio Estevam
Quoted 7 lines · Stefano Babic
I have some conceptional question here. This introduces a new set or, better, "class" of drivers, as we are used to see in kernel as "thermal". As we discussed in last u-boot mini summit, the preferred way to introduce new drivers into current u-boot is to use DM (Driver Model), because this is the way u-boot will follow in the future. It will take some time porting the current drivers, but it is easier for drivers introducing new features.
It is a good idea to convert this to the driver model, but Nitin is already at v6 and only now this request is made.
First version of this
patch series was sent back in August:
http://lists.denx.de/pipermail/u-boot/2014-August/187685.html
Quoted 6 lines
Quoted 1 line
Could the conversion to DM be handled later by a separate patch?
It is fine with me, but we agreed on the last mini summit last month to accept new drivers if they are developped under DM rules. Tom, can the driver be accepted and later converted to DM, or this driver (it is the first driver regarding thermal) must be converted first ?
I agree with the general idea but as Fabio I believe it is wrong to demand this change now. This patch has been send long time ago and been in review process for quite some time. Every new submission for drivers should be requested to move to DM framework however this is not new (it was sent in August).
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://code.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
PATCH v6 3/4 mx6: thermal: Check cpu temperature via thermal sensor
In reply to nitin.garg at freescale.comFrom: Nitin Garg <[email protected]>
read cpu temperature using the onchip thermal
sensor.
--- arch/arm/imx-common/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/imx-common/cpu.c +6 -0
@@ -17,6 +17,7 @@#include <asm/arch/sys_proto.h> #include <asm/arch/crm_regs.h> #include <ipu_pixfmt.h> +#include <imx_thermal.h> #ifdef CONFIG_FSL_ESDHC #include <fsl_esdhc.h>
@@ -141,6 +142,11 @@ int print_cpuinfo(void) (cpurev &0x000F0 ) >>4 , (cpurev &0x0000F ) >>0 , mxc_get_clock(MXC_ARM_CLK) / 1000000); + +#if defined(CONFIG_MX6 ) && defined(CONFIG_IMX6_THERMAL ) +check_cpu_temperature (); +#endif +printf ("Reset cause: %s\n" ,get_reset_cause ());return 0 ; }
Signature · 1 line
1.7.9.5
PATCH v6 4/4 mx6: thermal: Enable thermal sensor for mx6 sabre boards.
In reply to nitin.garg at freescale.comFrom: Nitin Garg <[email protected]>
Add CONFIG_IMX6_THERMAL to mx6sabre_common.h file. Since thermal driver depends on ocotp, make sure to enable CONFIG_MXC_OCOTP when CONFIG_IMX6_THERMAL is slected.
--- include/configs/mx6sabre_common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/configs/mx6sabre_common.h +2 -1
@@ -24,6 +24,7 @@#define CONFIG_SETUP_MEMORY_TAGS #define CONFIG_INITRD_TAG #define CONFIG_REVISION_TAG +#define CONFIG_IMX6_THERMAL #define CONFIG_SYS_GENERIC_BOARD
@@ -37,7 +38,7 @@#define CONFIG_MXC_UART #define CONFIG_CMD_FUSE -#ifdef CONFIG_CMD_FUSE +#if defined(CONFIG_CMD_FUSE ) || defined(CONFIG_IMX6_THERMAL )#define CONFIG_MXC_OCOTP #endif
Signature · 1 line
1.7.9.5
v6 cover add i.MX6 thermal sensor driver
In reply to nitin.garg at freescale.comHello nitin.garg at freescale.com,
Quoted 26 lines · nitin.garg at freescale.com
From: Nitin Garg <[email protected]>
This patch set adds i.MX6 thermal sensor driver
and enables it for mx6sabre boards. Also adds
various anadig bit definitions as required for
upcoming drivers.Changes in v6:
-Aligned imx thermal driver macro defines with kernelChanges in v5:
-Don't modify the copyright ofcpu.candcrm_regs.hfileChanges in v4:
(quoted diff) +0
-7-Added imx6 thermal sensor as a driver -Renamed the config define to be more meaningful -Move the clock code to clock.c -Reusing ocotp driver for reading fuse -Fix check for calibration fuse not programmed -Aligned the slope computation with kernel -Added Anadig register defines as seperate commitChanges in v3:
(quoted diff) +0
-2-adds the mx6 thermal driver support -adds the mx6 thermal support to mx6sabresd board.
Quoted 8 lines
Changes in v2:
-run checkpatch and fix reported issuesNitin Garg (4):
mx6: clock: Add api to enable pll3
mx6: thermal: Add i.MX6 CPU thermal sensor support
mx6: thermal: Check cpu temperature via thermal sensor
mx6: thermal: Enable thermal sensor for mx6 sabre boards.
So, is it 5 as the cover letter says, or 4 as the patches say? If actually 4 and only the cover letter is wrong, then there's no need to repost. If actually 5, then please repost them all, renumbered accordingly.
Amicalement,
Signature · 1 line
Albert.
v6 cover add i.MX6 thermal sensor driver
Quoted 44 lines · Albert ARIBAUD
Hello nitin.garg at freescale.com,
Quoted 26 lines · nitin.garg at freescale.com
From: Nitin Garg <[email protected]>
This patch set adds i.MX6 thermal sensor driver
and enables it for mx6sabre boards. Also adds
various anadig bit definitions as required for
upcoming drivers.Changes in v6:
-Aligned imx thermal driver macro defines with kernelChanges in v5:
-Don't modify the copyright ofcpu.candcrm_regs.hfileChanges in v4:
(quoted diff) +0
-7-Added imx6 thermal sensor as a driver -Renamed the config define to be more meaningful -Move the clock code to clock.c -Reusing ocotp driver for reading fuse -Fix check for calibration fuse not programmed -Aligned the slope computation with kernel -Added Anadig register defines as seperate commitChanges in v3:
(quoted diff) +0
-2-adds the mx6 thermal driver support -adds the mx6 thermal support to mx6sabresd board.Quoted 8 lines
Changes in v2:
-run checkpatch and fix reported issuesNitin Garg (4):
mx6: clock: Add api to enable pll3
mx6: thermal: Add i.MX6 CPU thermal sensor support
mx6: thermal: Check cpu temperature via thermal sensor
mx6: thermal: Enable thermal sensor for mx6 sabre boards.So, is it 5 as the cover letter says, or 4 as the patches say? If actually 4 and only the cover letter is wrong, then there's no need to repost. If actually 5, then please repost them all, renumbered accordingly.
Quoted 2 lines
Amicalement,
Just the cover subject is wrong (0/5 should be 0/4). Thanks,