Module Name:    src
Committed By:   jakllsch
Date:           Sat Apr 29 20:43:48 UTC 2017

Modified Files:
        src/sys/arch/arm/nvidia: tegra124_cpu.c
        src/sys/dev/i2c: as3722.c

Log Message:
 - Recognize the AS3722 sd0_v_minus_200mV bit, which is 1 on my Jetson TK1.
 - Reduce intended core voltage for Tegra K1 124 by 200mV to 1.2V.

The actual value programmed into the SD0 regulator remains the same (0x50),
a value corresponding to 1.20V.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/nvidia/tegra124_cpu.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/i2c/as3722.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/nvidia/tegra124_cpu.c
diff -u src/sys/arch/arm/nvidia/tegra124_cpu.c:1.1 src/sys/arch/arm/nvidia/tegra124_cpu.c:1.2
--- src/sys/arch/arm/nvidia/tegra124_cpu.c:1.1	Sun Apr 23 12:31:38 2017
+++ src/sys/arch/arm/nvidia/tegra124_cpu.c	Sat Apr 29 20:43:48 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra124_cpu.c,v 1.1 2017/04/23 12:31:38 jmcneill Exp $ */
+/* $NetBSD: tegra124_cpu.c,v 1.2 2017/04/29 20:43:48 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -30,7 +30,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra124_cpu.c,v 1.1 2017/04/23 12:31:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra124_cpu.c,v 1.2 2017/04/29 20:43:48 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -88,15 +88,15 @@ static struct tegra124_cpufreq_rate {
 	u_int divp;
 	u_int uvol;
 } tegra124_cpufreq_rates[] = {
-	{ 2316, 1, 193, 0, 1400000 },
-	{ 2100, 1, 175, 0, 1400000 },
-	{ 1896, 1, 158, 0, 1400000 },
-	{ 1692, 1, 141, 0, 1400000 },
-	{ 1500, 1, 125, 0, 1400000 },
-	{ 1296, 1, 108, 0, 1400000 },
-	{ 1092, 1, 91,  0, 1400000 },
-	{ 900,  1, 75,  0, 1400000 },
-	{ 696,  1, 58,  0, 1400000 }
+	{ 2316, 1, 193, 0, 1200000 },
+	{ 2100, 1, 175, 0, 1200000 },
+	{ 1896, 1, 158, 0, 1200000 },
+	{ 1692, 1, 141, 0, 1200000 },
+	{ 1500, 1, 125, 0, 1200000 },
+	{ 1296, 1, 108, 0, 1200000 },
+	{ 1092, 1, 91,  0, 1200000 },
+	{ 900,  1, 75,  0, 1200000 },
+	{ 696,  1, 58,  0, 1200000 }
 };
 
 static const u_int tegra124_cpufreq_max[] = {

Index: src/sys/dev/i2c/as3722.c
diff -u src/sys/dev/i2c/as3722.c:1.10 src/sys/dev/i2c/as3722.c:1.11
--- src/sys/dev/i2c/as3722.c:1.10	Sat Apr 29 19:56:59 2017
+++ src/sys/dev/i2c/as3722.c	Sat Apr 29 20:43:48 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: as3722.c,v 1.10 2017/04/29 19:56:59 jakllsch Exp $ */
+/* $NetBSD: as3722.c,v 1.11 2017/04/29 20:43:48 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -29,7 +29,7 @@
 #include "opt_fdt.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.10 2017/04/29 19:56:59 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.11 2017/04/29 20:43:48 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -101,11 +101,16 @@ __KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1
 #define AS3722_ASIC_ID1_REG		0x90
 #define AS3722_ASIC_ID2_REG		0x91
 
+#define AS3722_FUSE7_REG		0xa7
+#define AS3722_FUSE7_SD0_V_MINUS_200MV	__BIT(4)
+
 struct as3722_softc {
 	device_t	sc_dev;
 	i2c_tag_t	sc_i2c;
 	i2c_addr_t	sc_addr;
 	int		sc_phandle;
+	int		sc_flags;
+#define AS3722_FLAG_SD0_V_MINUS_200MV 0x01
 
 	struct sysmon_wdog sc_smw;
 	struct todr_chip_handle sc_todr;
@@ -468,6 +473,20 @@ as3722_regulator_attach(struct as3722_so
 {
 	struct as3722reg_attach_args raa;
 	int phandle, child;
+	int error;
+	const int flags = (cold ? I2C_F_POLL : 0);
+	uint8_t tmp;
+
+	iic_acquire_bus(sc->sc_i2c, flags);
+	error = as3722_read(sc, AS3722_FUSE7_REG, &tmp, flags);
+	iic_release_bus(sc->sc_i2c, flags);
+	if (error != 0) {
+		aprint_error_dev(sc->sc_dev, "failed to read Fuse7: %d\n", error);
+		return;
+	}
+
+	if (tmp & AS3722_FUSE7_SD0_V_MINUS_200MV)
+		sc->sc_flags |= AS3722_FLAG_SD0_V_MINUS_200MV;
 
 	phandle = of_find_firstchild_byname(sc->sc_phandle, "regulators");
 	if (phandle <= 0)
@@ -634,11 +653,21 @@ as3722reg_set_voltage_sd0(device_t dev, 
 	u_int uvol;
 	int error;
 
-	for (uint8_t v = 0x01; v <= 0x5a; v++) {
-		uvol = 600000 + (v * 10000);
-		if (uvol >= min_uvol && uvol <= max_uvol) {
-			set_v = v;
-			goto done;
+	if (asc->sc_flags & AS3722_FLAG_SD0_V_MINUS_200MV) {
+		for (uint8_t v = 0x01; v <= 0x6e; v++) {
+			uvol = 400000 + (v * 10000);
+			if (uvol >= min_uvol && uvol <= max_uvol) {
+				set_v = v;
+				goto done;
+			}
+		}
+	} else {
+		for (uint8_t v = 0x01; v <= 0x5a; v++) {
+			uvol = 600000 + (v * 10000);
+			if (uvol >= min_uvol && uvol <= max_uvol) {
+				set_v = v;
+				goto done;
+			}
 		}
 	}
 	if (set_v == 0)
@@ -671,14 +700,23 @@ as3722reg_get_voltage_sd0(device_t dev, 
 
 	v &= regdef->vsel_mask;
 
-	if (v == 0)
+	if (v == 0) {
 		*puvol = 0;	/* DC/DC powered down */
-	else if (v >= 0x01 && v <= 0x5a)
-		*puvol = 600000 + (v * 10000);
-	else
-		return EINVAL;
+		return 0;
+	}
+	if (asc->sc_flags & AS3722_FLAG_SD0_V_MINUS_200MV) {
+		if (v >= 0x01 && v <= 0x6e) {
+			*puvol = 400000 + (v * 10000);
+			return 0;
+		}
+	} else {
+		if (v >= 0x01 && v <= 0x5a) {
+			*puvol = 600000 + (v * 10000);
+			return 0;
+		}
+	}
 
-	return 0;
+	return EINVAL;
 }
 
 static int

Reply via email to