Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Feb 2019 13:18:15 +0000 (UTC)
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r344580 - head/sys/arm64/rockchip
Message-ID:  <201902261318.x1QDIFvK017946@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: manu
Date: Tue Feb 26 13:18:14 2019
New Revision: 344580
URL: https://svnweb.freebsd.org/changeset/base/344580

Log:
   arm64: rockchip: rk805: Map the regulator
  
  No map function was provided before so every regulator lookup resolved
  the regulator with id 1, as it uses the default mapper, which is wrong.
  Correctly map the regulators.
  While here remove some debug printfs and make them disable by default.
  
  MFC after:	1 week

Modified:
  head/sys/arm64/rockchip/rk805.c
  head/sys/arm64/rockchip/rk805reg.h

Modified: head/sys/arm64/rockchip/rk805.c
==============================================================================
--- head/sys/arm64/rockchip/rk805.c	Tue Feb 26 13:17:09 2019	(r344579)
+++ head/sys/arm64/rockchip/rk805.c	Tue Feb 26 13:18:14 2019	(r344580)
@@ -51,6 +51,9 @@ __FBSDID("$FreeBSD$");
 
 MALLOC_DEFINE(M_RK805_REG, "RK805 regulator", "RK805 power regulator");
 
+/* #define	dprintf(sc, format, arg...)	device_printf(sc->base_dev, "%s: " format, __func__, arg) */
+#define	dprintf(sc, format, arg...)
+
 enum rk_pmic_type {
 	RK805 = 1,
 	RK808,
@@ -258,6 +261,9 @@ rk805_regnode_enable(struct regnode *regnode, bool ena
 
 	sc = regnode_get_softc(regnode);
 
+	dprintf(sc, "%sabling regulator %s\n",
+	    enable ? "En" : "Dis",
+	    sc->def->name);
 	rk805_read(sc->base_dev, sc->def->enable_reg, &val, 1);
 	if (enable)
 		val |= sc->def->enable_mask;
@@ -308,25 +314,32 @@ rk805_regnode_set_voltage(struct regnode *regnode, int
 {
 	struct rk805_reg_sc *sc;
 	uint8_t val;
+	int uvolt;
 
 	sc = regnode_get_softc(regnode);
 
 	if (!sc->def->voltage_step)
 		return (ENXIO);
 
+	dprintf(sc, "Setting %s to %d<->%d uvolts\n",
+	    sc->def->name,
+	    min_uvolt,
+	    max_uvolt);
 	rk805_read(sc->base_dev, sc->def->voltage_reg, &val, 1);
-	printf("rk805_set_voltage: Current value for %x: %x\n", sc->def->voltage_reg, val);
 	if (rk805_regnode_voltage_to_reg(sc, min_uvolt, max_uvolt, &val) != 0)
 		return (ERANGE);
 
-	printf("rk805_set_voltage: Setting %x to %x\n", sc->def->voltage_reg, val);
 	rk805_write(sc->base_dev, sc->def->voltage_reg, val);
 
 	rk805_read(sc->base_dev, sc->def->voltage_reg, &val, 1);
-	printf("rk805_set_voltage: Set value for %x: %x\n", sc->def->voltage_reg, val);
 
 	*udelay = 0;
 
+	rk805_regnode_reg_to_voltage(sc, val, &uvolt);
+	dprintf(sc, "Regulator %s set to %d uvolt\n",
+	  sc->def->name,
+	  uvolt);
+
 	return (0);
 }
 
@@ -344,6 +357,10 @@ rk805_regnode_get_voltage(struct regnode *regnode, int
 	rk805_read(sc->base_dev, sc->def->voltage_reg, &val, 1);
 	rk805_regnode_reg_to_voltage(sc, val & sc->def->voltage_mask, uvolt);
 
+	dprintf(sc, "Regulator %s is at %d uvolt\n",
+	  sc->def->name,
+	  *uvolt);
+
 	return (0);
 }
 
@@ -377,6 +394,7 @@ rk805_reg_attach(device_t dev, phandle_t node,
 		initdef.std_param.max_uvolt = def->voltage_max;
 	initdef.id = def->id;
 	initdef.ofw_node = node;
+
 	regnode = regnode_create(dev, &rk805_regnode_class, &initdef);
 	if (regnode == NULL) {
 		device_printf(dev, "cannot create regulator\n");
@@ -504,11 +522,32 @@ rk805_detach(device_t dev)
 	return (EBUSY);
 }
 
+static int
+rk805_map(device_t dev, phandle_t xref, int ncells,
+    pcell_t *cells, intptr_t *id)
+{
+	struct rk805_softc *sc;
+	int i;
+
+	sc = device_get_softc(dev);
+
+	for (i = 0; i < sc->nregs; i++) {
+		if (sc->regs[i]->xref == xref) {
+			*id = sc->regs[i]->def->id;
+			return (0);
+		}
+	}
+
+	return (ERANGE);
+}
+
 static device_method_t rk805_methods[] = {
 	DEVMETHOD(device_probe,		rk805_probe),
 	DEVMETHOD(device_attach,	rk805_attach),
 	DEVMETHOD(device_detach,	rk805_detach),
 
+	/* regdev interface */
+	DEVMETHOD(regdev_map,		rk805_map),
 	DEVMETHOD_END
 };
 

Modified: head/sys/arm64/rockchip/rk805reg.h
==============================================================================
--- head/sys/arm64/rockchip/rk805reg.h	Tue Feb 26 13:17:09 2019	(r344579)
+++ head/sys/arm64/rockchip/rk805reg.h	Tue Feb 26 13:18:14 2019	(r344580)
@@ -61,7 +61,7 @@
 #define	RK805_LDO3_SLEEP_VSEL	0x40
 
 enum rk805_regulator {
-	RK805_DCDC1,
+	RK805_DCDC1 = 0,
 	RK805_DCDC2,
 	RK805_DCDC3,
 	RK805_DCDC4,
@@ -71,7 +71,7 @@ enum rk805_regulator {
 };
 
 enum rk808_regulator {
-	RK808_DCDC1,
+	RK808_DCDC1 = 0,
 	RK808_DCDC2,
 	RK808_DCDC3,
 	RK808_DCDC4,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902261318.x1QDIFvK017946>