public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver
@ 2014-11-14 20:13 nitin.garg at freescale.com
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 1/4] mx6: clock: Add api to enable pll3 nitin.garg at freescale.com
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: nitin.garg at freescale.com @ 2014-11-14 20:13 UTC (permalink / raw)
  To: u-boot

From: Nitin Garg <nitin.garg@freescale.com>

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

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 1/4] mx6: clock: Add api to enable pll3
  2014-11-14 20:13 [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver nitin.garg at freescale.com
@ 2014-11-14 20:13 ` nitin.garg at freescale.com
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support nitin.garg at freescale.com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: nitin.garg at freescale.com @ 2014-11-14 20:13 UTC (permalink / raw)
  To: u-boot

From: Nitin Garg <nitin.garg@freescale.com>

Add api to check and enable pll3 as required
for thermal sensor driver.

Signed-off-by: Nitin Garg <nitin.garg@freescale.com>
---
 arch/arm/cpu/armv7/mx6/clock.c        |   25 +++++++++++++++++++++++++
 arch/arm/include/asm/arch-mx6/clock.h |    1 +
 2 files changed, 26 insertions(+)

diff --git a/arch/arm/cpu/armv7/mx6/clock.c b/arch/arm/cpu/armv7/mx6/clock.c
index 6c9c78c..e174b91 100644
--- a/arch/arm/cpu/armv7/mx6/clock.c
+++ b/arch/arm/cpu/armv7/mx6/clock.c
@@ -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) {
diff --git a/arch/arm/include/asm/arch-mx6/clock.h b/arch/arm/include/asm/arch-mx6/clock.h
index 3c58a0a..b42d942 100644
--- a/arch/arm/include/asm/arch-mx6/clock.h
+++ b/arch/arm/include/asm/arch-mx6/clock.h
@@ -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 */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support
  2014-11-14 20:13 [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver nitin.garg at freescale.com
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 1/4] mx6: clock: Add api to enable pll3 nitin.garg at freescale.com
@ 2014-11-14 20:13 ` nitin.garg at freescale.com
  2014-11-17 12:49   ` Stefano Babic
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 3/4] mx6: thermal: Check cpu temperature via thermal sensor nitin.garg at freescale.com
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: nitin.garg at freescale.com @ 2014-11-14 20:13 UTC (permalink / raw)
  To: u-boot

From: Nitin Garg <nitin.garg@freescale.com>

i.MX6 SoC has onchip temperature sensor. Add driver
for this sensor.

Signed-off-by: Nitin Garg <nitin.garg@freescale.com>
---
 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

diff --git a/drivers/Makefile b/drivers/Makefile
index 33227c8..7683c61 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -21,3 +21,4 @@ obj-y += pwm/
 obj-y += input/
 # SOC specific infrastructure drivers.
 obj-y += soc/
+obj-y += thermal/
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
new file mode 100644
index 0000000..04ae395
--- /dev/null
+++ b/drivers/thermal/Makefile
@@ -0,0 +1,8 @@
+#
+# (C) Copyright 2014 Freescale Semiconductor, Inc.
+# Author: Nitin Garg <nitin.garg@freescale.com>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_IMX6_THERMAL) += imx_thermal.o
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
new file mode 100644
index 0000000..fe9dd85
--- /dev/null
+++ b/drivers/thermal/imx_thermal.c
@@ -0,0 +1,144 @@
+/*
+ * (C) Copyright 2014 Freescale Semiconductor, Inc.
+ * Author: Nitin Garg <nitin.garg@freescale.com>
+ *
+ * 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);
+	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;
+		}
+	}
+
+	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");
+}
diff --git a/include/imx_thermal.h b/include/imx_thermal.h
new file mode 100644
index 0000000..979664a
--- /dev/null
+++ b/include/imx_thermal.h
@@ -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__ */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 3/4] mx6: thermal: Check cpu temperature via thermal sensor
  2014-11-14 20:13 [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver nitin.garg at freescale.com
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 1/4] mx6: clock: Add api to enable pll3 nitin.garg at freescale.com
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support nitin.garg at freescale.com
@ 2014-11-14 20:13 ` nitin.garg at freescale.com
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 4/4] mx6: thermal: Enable thermal sensor for mx6 sabre boards nitin.garg at freescale.com
  2014-11-15 12:34 ` [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver Albert ARIBAUD
  4 siblings, 0 replies; 11+ messages in thread
From: nitin.garg at freescale.com @ 2014-11-14 20:13 UTC (permalink / raw)
  To: u-boot

From: Nitin Garg <nitin.garg@freescale.com>

read cpu temperature using the onchip thermal
sensor.

Signed-off-by: Nitin Garg <nitin.garg@freescale.com>
---
 arch/arm/imx-common/cpu.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/imx-common/cpu.c b/arch/arm/imx-common/cpu.c
index 09fc227..441c484 100644
--- a/arch/arm/imx-common/cpu.c
+++ b/arch/arm/imx-common/cpu.c
@@ -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;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 4/4] mx6: thermal: Enable thermal sensor for mx6 sabre boards.
  2014-11-14 20:13 [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver nitin.garg at freescale.com
                   ` (2 preceding siblings ...)
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 3/4] mx6: thermal: Check cpu temperature via thermal sensor nitin.garg at freescale.com
@ 2014-11-14 20:13 ` nitin.garg at freescale.com
  2014-11-15 12:34 ` [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver Albert ARIBAUD
  4 siblings, 0 replies; 11+ messages in thread
From: nitin.garg at freescale.com @ 2014-11-14 20:13 UTC (permalink / raw)
  To: u-boot

From: Nitin Garg <nitin.garg@freescale.com>

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.

Signed-off-by: Nitin Garg <nitin.garg@freescale.com>
---
 include/configs/mx6sabre_common.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/configs/mx6sabre_common.h b/include/configs/mx6sabre_common.h
index c81e9e9..7db06fe 100644
--- a/include/configs/mx6sabre_common.h
+++ b/include/configs/mx6sabre_common.h
@@ -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
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver
  2014-11-14 20:13 [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver nitin.garg at freescale.com
                   ` (3 preceding siblings ...)
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 4/4] mx6: thermal: Enable thermal sensor for mx6 sabre boards nitin.garg at freescale.com
@ 2014-11-15 12:34 ` Albert ARIBAUD
  2014-11-15 22:34   ` Nitin Garg
  4 siblings, 1 reply; 11+ messages in thread
From: Albert ARIBAUD @ 2014-11-15 12:34 UTC (permalink / raw)
  To: u-boot

Hello nitin.garg at freescale.com,

On Fri, 14 Nov 2014 14:13:02 -0600, nitin.garg at freescale.com
<nitin.garg@freescale.com> wrote:
> From: Nitin Garg <nitin.garg@freescale.com>
> 
> 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.

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,
-- 
Albert.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver
  2014-11-15 12:34 ` [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver Albert ARIBAUD
@ 2014-11-15 22:34   ` Nitin Garg
  0 siblings, 0 replies; 11+ messages in thread
From: Nitin Garg @ 2014-11-15 22:34 UTC (permalink / raw)
  To: u-boot

On 11/15/2014 06:34 AM, Albert ARIBAUD wrote:
> Hello nitin.garg at freescale.com,
> 
> On Fri, 14 Nov 2014 14:13:02 -0600, nitin.garg at freescale.com
> <nitin.garg@freescale.com> wrote:
>> From: Nitin Garg <nitin.garg@freescale.com>
>>
>> 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.
> 
> 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,
> 

Just the cover subject is wrong (0/5 should be 0/4). Thanks,

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support
  2014-11-14 20:13 ` [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support nitin.garg at freescale.com
@ 2014-11-17 12:49   ` Stefano Babic
  2014-11-18 14:16     ` Fabio Estevam
  0 siblings, 1 reply; 11+ messages in thread
From: Stefano Babic @ 2014-11-17 12:49 UTC (permalink / raw)
  To: u-boot

Hi Nitin,


On 14/11/2014 21:13, nitin.garg at freescale.com wrote:
> From: Nitin Garg <nitin.garg@freescale.com>
> 
> i.MX6 SoC has onchip temperature sensor. Add driver
> for this sensor.
> 
> Signed-off-by: Nitin Garg <nitin.garg@freescale.com>
> ---
>  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).

> diff --git a/drivers/Makefile b/drivers/Makefile
> index 33227c8..7683c61 100644
> --- a/drivers/Makefile
> +++ b/drivers/Makefile
> @@ -21,3 +21,4 @@ obj-y += pwm/
>  obj-y += input/
>  # SOC specific infrastructure drivers.
>  obj-y += soc/
> +obj-y += thermal/
> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> new file mode 100644
> index 0000000..04ae395
> --- /dev/null
> +++ b/drivers/thermal/Makefile
> @@ -0,0 +1,8 @@
> +#
> +# (C) Copyright 2014 Freescale Semiconductor, Inc.
> +# Author: Nitin Garg <nitin.garg@freescale.com>
> +#
> +# SPDX-License-Identifier:	GPL-2.0+
> +#
> +
> +obj-$(CONFIG_IMX6_THERMAL) += imx_thermal.o
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> new file mode 100644
> index 0000000..fe9dd85
> --- /dev/null
> +++ b/drivers/thermal/imx_thermal.c
> @@ -0,0 +1,144 @@
> +/*
> + * (C) Copyright 2014 Freescale Semiconductor, Inc.
> + * Author: Nitin Garg <nitin.garg@freescale.com>
> + *
> + * 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);
> +	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).


> +
> +	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");
> +}
> diff --git a/include/imx_thermal.h b/include/imx_thermal.h
> new file mode 100644
> index 0000000..979664a
> --- /dev/null
> +++ b/include/imx_thermal.h
> @@ -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__ */
> 

Best regards,
Stefano Babic

-- 
=====================================================================
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
=====================================================================

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support
  2014-11-17 12:49   ` Stefano Babic
@ 2014-11-18 14:16     ` Fabio Estevam
  2014-11-19  9:08       ` Stefano Babic
  0 siblings, 1 reply; 11+ messages in thread
From: Fabio Estevam @ 2014-11-18 14:16 UTC (permalink / raw)
  To: u-boot

Hi Stefano,

On Mon, Nov 17, 2014 at 10:49 AM, Stefano Babic <sbabic@denx.de> wrote:

> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support
  2014-11-18 14:16     ` Fabio Estevam
@ 2014-11-19  9:08       ` Stefano Babic
  2014-11-19 13:55         ` Otavio Salvador
  0 siblings, 1 reply; 11+ messages in thread
From: Stefano Babic @ 2014-11-19  9:08 UTC (permalink / raw)
  To: u-boot

Hi Fabio,

On 18/11/2014 15:16, Fabio Estevam wrote:
> Hi Stefano,
> 
> On Mon, Nov 17, 2014 at 10:49 AM, Stefano Babic <sbabic@denx.de> wrote:
> 
>> 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?

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


-- 
=====================================================================
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
=====================================================================

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support
  2014-11-19  9:08       ` Stefano Babic
@ 2014-11-19 13:55         ` Otavio Salvador
  0 siblings, 0 replies; 11+ messages in thread
From: Otavio Salvador @ 2014-11-19 13:55 UTC (permalink / raw)
  To: u-boot

On Wed, Nov 19, 2014 at 7:08 AM, Stefano Babic <sbabic@denx.de> wrote:
> On 18/11/2014 15:16, Fabio Estevam wrote:
>> On Mon, Nov 17, 2014 at 10:49 AM, Stefano Babic <sbabic@denx.de> wrote:
>>
>>> 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?
>
> 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).

-- 
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-11-19 13:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-14 20:13 [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver nitin.garg at freescale.com
2014-11-14 20:13 ` [U-Boot] [PATCH v6 1/4] mx6: clock: Add api to enable pll3 nitin.garg at freescale.com
2014-11-14 20:13 ` [U-Boot] [PATCH v6 2/4] mx6: thermal: Add i.MX6 CPU thermal sensor support nitin.garg at freescale.com
2014-11-17 12:49   ` Stefano Babic
2014-11-18 14:16     ` Fabio Estevam
2014-11-19  9:08       ` Stefano Babic
2014-11-19 13:55         ` Otavio Salvador
2014-11-14 20:13 ` [U-Boot] [PATCH v6 3/4] mx6: thermal: Check cpu temperature via thermal sensor nitin.garg at freescale.com
2014-11-14 20:13 ` [U-Boot] [PATCH v6 4/4] mx6: thermal: Enable thermal sensor for mx6 sabre boards nitin.garg at freescale.com
2014-11-15 12:34 ` [U-Boot] [PATCH v6 0/5] add i.MX6 thermal sensor driver Albert ARIBAUD
2014-11-15 22:34   ` Nitin Garg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox