svn commit: r331989 - head/sys/dev/extres/regulator

Emmanuel Vadot manu at FreeBSD.org
Wed Apr 4 06:44:26 UTC 2018


Author: manu
Date: Wed Apr  4 06:44:24 2018
New Revision: 331989
URL: https://svnweb.freebsd.org/changeset/base/331989

Log:
  regulator: Disable unused regulator
  
  bootloaders such as u-boot might enable regulators, or simply regulators could
  be enabled by default by the PMIC, even if we don't have a driver for
  the device or subsystem.
  Disable unused regulators just before going to userland.
  A tunable hw.regulator.disable_unused is added to not disable them in case
  this causes problems on some board but the default behavior is to disable
  everything unused.
  I prefer to break thinks now and fix them rather than never switch to the
  case were we disable regulators.
  
  Tested on : Pine64-LTS (an idle board goes from ~0.33A to ~0.27A)
  Tested on : BananaPi M2
  Differential Revision:	https://reviews.freebsd.org/D14781

Modified:
  head/sys/dev/extres/regulator/regulator.c

Modified: head/sys/dev/extres/regulator/regulator.c
==============================================================================
--- head/sys/dev/extres/regulator/regulator.c	Wed Apr  4 06:11:05 2018	(r331988)
+++ head/sys/dev/extres/regulator/regulator.c	Wed Apr  4 06:44:24 2018	(r331989)
@@ -71,6 +71,7 @@ static int regnode_method_status(struct regnode *regno
 static int regnode_method_set_voltage(struct regnode *regnode, int min_uvolt,
     int max_uvolt, int *udelay);
 static int regnode_method_get_voltage(struct regnode *regnode, int *uvolt);
+static void regulator_shutdown(void *dummy);
 
 /*
  * Regulator controller methods.
@@ -150,6 +151,36 @@ SX_SYSINIT(regulator_topology, &regnode_topo_lock, "Re
 #define REGNODE_SLOCK(_sc)	sx_slock(&((_sc)->lock))
 #define REGNODE_XLOCK(_sc)	sx_xlock(&((_sc)->lock))
 #define REGNODE_UNLOCK(_sc)	sx_unlock(&((_sc)->lock))
+
+SYSINIT(regulator_shutdown, SI_SUB_LAST, SI_ORDER_ANY, regulator_shutdown,
+    NULL);
+
+/*
+ * Disable unused regulator
+ * We run this function at SI_SUB_LAST which mean that every driver that needs
+ * regulator should have already enable them.
+ * All the remaining regulators should be those left enabled by the bootloader
+ * or enable by default by the PMIC.
+ */
+static void
+regulator_shutdown(void *dummy)
+{
+	struct regnode *entry;
+	int disable = 1;
+
+	REG_TOPO_SLOCK();
+	TUNABLE_INT_FETCH("hw.regulator.disable_unused", &disable);
+	TAILQ_FOREACH(entry, &regnode_list, reglist_link) {
+		if (entry->enable_cnt == 0 &&
+		    entry->std_param.always_on == 0 && disable) {
+			if (bootverbose)
+				printf("regulator: shuting down %s\n",
+				    entry->name);
+			regnode_stop(entry, 0);
+		}
+	}
+	REG_TOPO_UNLOCK();
+}
 
 /*
  * sysctl handler


More information about the svn-src-all mailing list