X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fthermal%2Fimx_thermal.c;h=09a3c52680276d134880d389bcb6c20e85c2135f;hb=3e1b4dcf1cb6d5edbb6a78824a2f30531ef8ea55;hp=116158511dba7928115a6d5f1ddda22d3cd4a122;hpb=1fc4e6f486cc1e9d2dcf0ba86e6021c3d83dce51;p=u-boot diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 116158511d..09a3c52680 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -12,19 +12,22 @@ #include #include #include +#include #include #include #include #include #include -#define TEMPERATURE_MIN -40 -#define TEMPERATURE_HOT 80 -#define TEMPERATURE_MAX 125 +/* board will busyloop until this many degrees C below CPU max temperature */ +#define TEMPERATURE_HOT_DELTA 5 /* CPU maxT - 5C */ #define FACTOR0 10000000 #define FACTOR1 15976 #define FACTOR2 4297157 #define MEASURE_FREQ 327 +#define TEMPERATURE_MIN -40 +#define TEMPERATURE_HOT 85 +#define TEMPERATURE_MAX 125 #define TEMPSENSE0_TEMP_CNT_SHIFT 8 #define TEMPSENSE0_TEMP_CNT_MASK (0xfff << TEMPSENSE0_TEMP_CNT_SHIFT) @@ -34,14 +37,22 @@ #define MISC0_REFTOP_SELBIASOFF (1 << 3) #define TEMPSENSE1_MEASURE_FREQ 0xffff +struct thermal_data { + unsigned int fuse; + int critical; + int minc; + int maxc; +}; + +#if defined(CONFIG_MX6) static int read_cpu_temperature(struct udevice *dev) { int temperature; unsigned int reg, n_meas; const struct imx_thermal_plat *pdata = dev_get_platdata(dev); struct anatop_regs *anatop = (struct anatop_regs *)pdata->regs; - unsigned int *priv = dev_get_priv(dev); - u32 fuse = *priv; + struct thermal_data *priv = dev_get_priv(dev); + u32 fuse = priv->fuse; int t1, n1; u32 c1, c2; u64 temp64; @@ -108,7 +119,7 @@ static int read_cpu_temperature(struct udevice *dev) writel(TEMPSENSE0_FINISHED, &anatop->tempsense0_clr); /* milli_Tmeas = c2 - Nmeas * c1 */ - temperature = (c2 - n_meas * c1)/1000; + temperature = (long)(c2 - n_meas * c1)/1000; /* power down anatop thermal sensor */ writel(TEMPSENSE0_POWER_DOWN, &anatop->tempsense0_set); @@ -116,21 +127,87 @@ static int read_cpu_temperature(struct udevice *dev) return temperature; } +#elif defined(CONFIG_MX7) +static int read_cpu_temperature(struct udevice *dev) +{ + unsigned int reg, tmp, start; + unsigned int raw_25c, te1; + int temperature; + unsigned int *priv = dev_get_priv(dev); + u32 fuse = *priv; + struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *) + ANATOP_BASE_ADDR; + /* + * fuse data layout: + * [31:21] sensor value @ 25C + * [20:18] hot temperature value + * [17:9] sensor value of room + * [8:0] sensor value of hot + */ + + raw_25c = fuse >> 21; + if (raw_25c == 0) + raw_25c = 25; + + te1 = (fuse >> 9) & 0x1ff; + + /* + * now we only use single measure, every time we read + * the temperature, we will power on/down anadig thermal + * module + */ + writel(TEMPMON_HW_ANADIG_TEMPSENSE1_POWER_DOWN_MASK, &ccm_anatop->tempsense1_clr); + writel(PMU_REF_REFTOP_SELFBIASOFF_MASK, &ccm_anatop->ref_set); + + /* write measure freq */ + reg = readl(&ccm_anatop->tempsense1); + reg &= ~TEMPMON_HW_ANADIG_TEMPSENSE1_MEASURE_FREQ_MASK; + reg |= TEMPMON_HW_ANADIG_TEMPSENSE1_MEASURE_FREQ(MEASURE_FREQ); + writel(reg, &ccm_anatop->tempsense1); + + writel(TEMPMON_HW_ANADIG_TEMPSENSE1_MEASURE_TEMP_MASK, &ccm_anatop->tempsense1_clr); + writel(TEMPMON_HW_ANADIG_TEMPSENSE1_FINISHED_MASK, &ccm_anatop->tempsense1_clr); + writel(TEMPMON_HW_ANADIG_TEMPSENSE1_MEASURE_TEMP_MASK, &ccm_anatop->tempsense1_set); + + start = get_timer(0); + /* Wait max 100ms */ + do { + /* + * Since we can not rely on finish bit, use 1ms delay to get + * temperature. From RM, 17us is enough to get data, but + * to gurantee to get the data, delay 100ms here. + */ + reg = readl(&ccm_anatop->tempsense1); + tmp = (reg & TEMPMON_HW_ANADIG_TEMPSENSE1_TEMP_VALUE_MASK) + >> TEMPMON_HW_ANADIG_TEMPSENSE1_TEMP_VALUE_SHIFT; + } while (get_timer(0) < (start + 100)); + + writel(TEMPMON_HW_ANADIG_TEMPSENSE1_FINISHED_MASK, &ccm_anatop->tempsense1_clr); + + /* power down anatop thermal sensor */ + writel(TEMPMON_HW_ANADIG_TEMPSENSE1_POWER_DOWN_MASK, &ccm_anatop->tempsense1_set); + writel(PMU_REF_REFTOP_SELFBIASOFF_MASK, &ccm_anatop->ref_clr); + + /* Single point */ + temperature = tmp - (te1 - raw_25c); + + return temperature; +} +#endif int imx_thermal_get_temp(struct udevice *dev, int *temp) { + struct thermal_data *priv = dev_get_priv(dev); int cpu_tmp = 0; cpu_tmp = read_cpu_temperature(dev); - while (cpu_tmp > TEMPERATURE_MIN && cpu_tmp < TEMPERATURE_MAX) { - if (cpu_tmp >= TEMPERATURE_HOT) { - printf("CPU Temperature is %d C, too hot to boot, waiting...\n", - cpu_tmp); - udelay(5000000); - cpu_tmp = read_cpu_temperature(dev); - } else { - break; - } + + while (cpu_tmp >= priv->critical) { + printf("CPU Temperature (%dC) too close to max (%dC)", + cpu_tmp, priv->maxc); + puts(" waiting...\n"); + udelay(5000000); + cpu_tmp = read_cpu_temperature(dev); } *temp = cpu_tmp; @@ -147,20 +224,31 @@ static int imx_thermal_probe(struct udevice *dev) unsigned int fuse = ~0; const struct imx_thermal_plat *pdata = dev_get_platdata(dev); - unsigned int *priv = dev_get_priv(dev); + struct thermal_data *priv = dev_get_priv(dev); /* Read Temperature calibration data fuse */ fuse_read(pdata->fuse_bank, pdata->fuse_word, &fuse); - /* Check for valid fuse */ - if (fuse == 0 || fuse == ~0) { - printf("CPU: Thermal invalid data, fuse: 0x%x\n", fuse); - return -EPERM; - } else { - printf("CPU: Thermal calibration data: 0x%x\n", fuse); + if (is_soc_type(MXC_SOC_MX6)) { + /* Check for valid fuse */ + if (fuse == 0 || fuse == ~0) { + debug("CPU: Thermal invalid data, fuse: 0x%x\n", + fuse); + return -EPERM; + } + } else if (is_soc_type(MXC_SOC_MX7)) { + /* No Calibration data in FUSE? */ + if ((fuse & 0x3ffff) == 0) + return -EPERM; + /* We do not support 105C TE2 */ + if (((fuse & 0x1c0000) >> 18) == 0x6) + return -EPERM; } - *priv = fuse; + /* set critical cooling temp */ + get_cpu_temp_grade(&priv->minc, &priv->maxc); + priv->critical = priv->maxc - TEMPERATURE_HOT_DELTA; + priv->fuse = fuse; enable_thermal_clk(); @@ -172,6 +260,6 @@ U_BOOT_DRIVER(imx_thermal) = { .id = UCLASS_THERMAL, .ops = &imx_thermal_ops, .probe = imx_thermal_probe, - .priv_auto_alloc_size = sizeof(unsigned int), + .priv_auto_alloc_size = sizeof(struct thermal_data), .flags = DM_FLAG_PRE_RELOC, };