Add i.MX6 CPU temperature sensor support
Subsystems (2)
PATCH v2 1/1 Add i.MX6 CPU temperature sensor support
i.MX6 SoC has onChip temperature sensor. Add support for this sensor.
Signed-off-by Nitin Garg <[email protected]>
---
arch/arm/cpu/armv7/mx6/soc.c | 142 +++++++- arch/arm/imx-common/cpu.c | 7 +- arch/arm/include/asm/arch-mx6/crm_regs.h | 543 +++++++++++++++++++++++++++++- arch/arm/include/asm/arch-mx6/imx-regs.h | 9 +- include/configs/mx6sabre_common.h | 1 + 5 files changed, 698 insertions(+), 4 deletions(-)
arch/arm/cpu/armv7/mx6/soc.c +141 -1
@@ -2,7 +2,7 @@* (C) Copyright 2007 * Sascha Hauer, Pengutronix * -* (C) Copyright 2009 Freescale Semiconductor, Inc. +* (C) Copyright 2009-2014 Freescale Semiconductor, Inc. * * SPDX-License-Identifier: GPL-2.0+ */
@@ -35,6 +35,20 @@ struct scu_regs {u32 fpga_rev; }; +#define TEMPERATURE_MIN -40 +#define TEMPERATURE_HOT 80 +#define TEMPERATURE_MAX 125 +#define FACTOR1 15976 +#define FACTOR2 4297157 +#define MEASURE_FREQ 327 + +#define REG_VALUE_TO_CEL (ratio, raw) \ + ((raw_n40c - raw) * 100 / ratio - 40) + +#ifdef CONFIG_IMX6_TEMP_SENSOR +static unsigned int fuse = ~0 ; +#endif +u32 get_nr_cpus (void ) {struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR ;
@@ -218,6 +232,132 @@ static void imx_set_wdog_powerdown(bool enable)writew (enable, &wdog2->wmcr); } +#ifdef CONFIG_IMX6_TEMP_SENSOR +static int read_cpu_temperature (void ) +{ +int temperature; +unsigned int ccm_ccgr2; +unsigned int reg, tmp; +unsigned int raw_25c, raw_n40c, ratio; +struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR ; +struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR ; +struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR ; +struct fuse_bank *bank = &ocotp->bank[1 ]; +struct fuse_bank1_regs *fuse_bank1 = + (struct fuse_bank1_regs *)bank->fuse_regs; + +/* need to make sure pll3 is enabled for thermal sensor */ +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); + } + + ccm_ccgr2 =readl (&mxc_ccm->CCGR2); +/* enable OCOTP_CTRL clock in CCGR2 */ +writel (ccm_ccgr2 |MXC_CCM_CCGR2_OCOTP_CTRL_MASK , &mxc_ccm->CCGR2); + fuse =readl (&fuse_bank1->ana1); + +/* restore CCGR2 */ +writel (ccm_ccgr2, &mxc_ccm->CCGR2); + +if (fuse ==0 || fuse ==0xffffffff || (fuse &0xfff00000 ) ==0 ) +return TEMPERATURE_MIN ; + +/* +* fuse data layout: +* [31:20] sensor value @ 25C +* [19:8] sensor value of hot +* [7:0] hot temperature value +*/ + raw_25c = fuse >>20 ; + +/* +* The universal equation for thermal sensor +* is slope = 0.4297157 - (0.0015976 * 25C fuse), +* here we convert them to integer to make them +* easy for counting, FACTOR1 is 15976, +* FACTOR2 is 4297157. Our ratio = -100 * slope +*/ + ratio = ((FACTOR1 * raw_25c -FACTOR2 ) +50000 ) /100000 ; + +debug ("Thermal sensor with ratio = %d\n" , ratio); + + raw_n40c = raw_25c + (13 * ratio) /20 ; + +/* +* now we only use single measure, every time we read +* the temperature, we will power on/down anadig thermal +* module +*/ +writel (BM_ANADIG_TEMPSENSE0_POWER_DOWN , &anatop->tempsense0_clr); +writel (BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF , &anatop->ana_misc0_set); + +/* write measure freq */ + reg =readl (&anatop->tempsense1); + reg &= ~BM_ANADIG_TEMPSENSE1_MEASURE_FREQ ; + reg |=MEASURE_FREQ ; +writel (reg, &anatop->tempsense1); + +writel (BM_ANADIG_TEMPSENSE0_MEASURE_TEMP , &anatop->tempsense0_clr); +writel (BM_ANADIG_TEMPSENSE0_FINISHED , &anatop->tempsense0_clr); +writel (BM_ANADIG_TEMPSENSE0_MEASURE_TEMP , &anatop->tempsense0_set); + +while ((readl (&anatop->tempsense0) & +BM_ANADIG_TEMPSENSE0_FINISHED ) ==0 ) +udelay (10000 ); + + reg =readl (&anatop->tempsense0); + tmp = (reg &BM_ANADIG_TEMPSENSE0_TEMP_VALUE ) + >>BP_ANADIG_TEMPSENSE0_TEMP_VALUE ; +writel (BM_ANADIG_TEMPSENSE0_FINISHED , &anatop->tempsense0_clr); + +if (tmp <= raw_n40c) + temperature =REG_VALUE_TO_CEL (ratio, tmp); +else + temperature =TEMPERATURE_MIN ; +/* power down anatop thermal sensor */ +writel (BM_ANADIG_TEMPSENSE0_POWER_DOWN , &anatop->tempsense0_set); +writel (BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF , &anatop->ana_misc0_clr); + +return temperature; +} + +void check_cpu_temperature (void ) +{ +int cpu_tmp =0 ; + + cpu_tmp =read_cpu_temperature (); +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 (); + }else { +break ; + } + } +if (cpu_tmp >TEMPERATURE_MIN && cpu_tmp <TEMPERATURE_MAX ) +printf ("CPU: Temperature %d C, calibration data: 0x%x\n" , + cpu_tmp, fuse); +else +printf ("CPU: Temperature: can't get valid data or fuse not programmed!\n" ); +} +#endif +static void set_ahb_rate (u32 val) {struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR ;
arch/arm/imx-common/cpu.c +6 -1
@@ -2,7 +2,7 @@* (C) Copyright 2007 * Sascha Hauer, Pengutronix * -* (C) Copyright 2009 Freescale Semiconductor, Inc. +* (C) Copyright 2009-2014 Freescale Semiconductor, Inc. * * SPDX-License-Identifier: GPL-2.0+ */
@@ -139,6 +139,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_TEMP_SENSOR ) +check_cpu_temperature (); +#endif +printf ("Reset cause: %s\n" ,get_reset_cause ());return 0 ; }
arch/arm/include/asm/arch-mx6/crm_regs.h +542 -1
551 lines not on this page · raw message
arch/arm/include/asm/arch-mx6/imx-regs.h +8 -1
@@ -1,5 +1,5 @@/* -* Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. +* Copyright (C) 2011-2014 Freescale Semiconductor, Inc. All Rights Reserved. * * SPDX-License-Identifier: GPL-2.0+ */
@@ -587,6 +587,12 @@ struct fuse_bank0_regs {u32 rsvd7[4 ]; }; +struct fuse_bank1_regs { +u32 mem[0x18 ]; +u32 ana1; +u32 ana2; +}; + #ifdef CONFIG_MX6SX struct fuse_bank4_regs { u32 sjc_resp_low;
@@ -805,5 +811,6 @@ struct pwm_regs {u32 pr;u32 cnr; }; +void check_cpu_temperature (void );#endif /* __ASSEMBLER__*/ #endif /* __ASM_ARCH_MX6_IMX_REGS_H__ */
include/configs/mx6sabre_common.h +1 -0
@@ -24,6 +24,7 @@#define CONFIG_SETUP_MEMORY_TAGS #define CONFIG_INITRD_TAG #define CONFIG_REVISION_TAG +#define CONFIG_IMX6_TEMP_SENSOR #define CONFIG_SYS_GENERIC_BOARD
Signature · 1 line
1.7.9.5
Fabio Estevam
reviewerPATCH v2 1/1 Add i.MX6 CPU temperature sensor support
Hi Nitin,
Quoted 11 lines · Nitin Garg
i.MX6 SoC has onChip temperature sensor. Add support for this sensor.
Signed-off-by Nitin Garg <[email protected]>---
arch/arm/cpu/armv7/mx6/soc.c | 142 +++++++- arch/arm/imx-common/cpu.c | 7 +- arch/arm/include/asm/arch-mx6/crm_regs.h | 543 +++++++++++++++++++++++++++++- arch/arm/include/asm/arch-mx6/imx-regs.h | 9 +- include/configs/mx6sabre_common.h | 1 +
Looks better, but I would split this patch in 2:
1/2 that adds the mx6 temperature support
2/2 that adds the mx6 temperature support to mx6sabresd board.
Quoted 8 lines
arch/arm/cpu/armv7/mx6/soc.c +8
-0+void check_cpu_temperature (void ) +{ +int cpu_tmp =0 ; + + cpu_tmp =read_cpu_temperature (); +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",
arch/arm/cpu/armv7/mx6/soc.c static void imx_set_wdog_powerdown(bool enable) · line 355
Quoted 10 lines
arch/arm/cpu/armv7/mx6/soc.c +10
-0+ cpu_tmp); +udelay (5000000 ); + cpu_tmp =read_cpu_temperature (); + }else { +break ; + } + } +if (cpu_tmp >TEMPERATURE_MIN && cpu_tmp <TEMPERATURE_MAX ) +printf ("CPU: Temperature %d C, calibration data: 0x%x\n" , + cpu_tmp, fuse);
The temperature is useful information to display, but this calibration data is just noise to have it displayed on every boot.
Could you please change this to only print the temperature?
Thanks