Shutoff iMX8 when passing critical temperature

* The busy loop that polls beyond alert doesn't reduce the power
consumption at all.
* Adds using SNVS register writes to explicitly disable the PMIC when
the temperature exceeds critical.
* Drops power from ~5W to 300 mW (for entire board).
* Note: a full power cycle is needed to recover.

Change-Id: Ic9292555fe15c4288822704bca617a89f7ec0f05
diff --git a/drivers/thermal/nxp_tmu.c b/drivers/thermal/nxp_tmu.c
index c170c98..96a4842 100644
--- a/drivers/thermal/nxp_tmu.c
+++ b/drivers/thermal/nxp_tmu.c
@@ -134,6 +134,19 @@
 	}
 }
 
+#define SNVS_LPCR 0x38
+static void mx8_snvs_poweroff(void)
+{
+	u32 value;
+	void __iomem *mx8_snvs_base = (void __iomem *)SNVS_HP_BASE_ADDR;
+
+	value = readl(mx8_snvs_base + SNVS_LPCR);
+	/* Set TOP and DP_EN bit to put the PMIC into dumb mode and
+	 * explicity disable.*/
+	writel(value | 0x60, mx8_snvs_base + SNVS_LPCR);
+	/* The PMIC will pull power and execution won't continue */
+}
+
 int nxp_tmu_get_temp(struct udevice *dev, int *temp)
 {
 	struct nxp_tmu_plat *pdata = dev_get_platdata(dev);
@@ -146,8 +159,15 @@
 		return ret;
 	}
 
+
 	while (cpu_tmp >= pdata->alert) {
-		printf("CPU Temperature (%dC) has beyond alert (%dC), close to critical (%dC)",
+		if (cpu_tmp >= pdata->critical) {
+			printf("Critical temperature hit. Shutting down,
+					a power cycle will be necessary\n");
+			mx8_snvs_poweroff();
+		}
+
+		printf("CPU Temperature (%dC) has exceeded alert (%dC), close to critical (%dC)",
 		       cpu_tmp, pdata->alert, pdata->critical);
 		puts(" waiting...\n");
 		mdelay(pdata->polling_delay);