Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Dec 2018 18:39:17 +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: r342091 - head/sys/arm/allwinner
Message-ID:  <201812141839.wBEIdHwS023405@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: manu
Date: Fri Dec 14 18:39:17 2018
New Revision: 342091
URL: https://svnweb.freebsd.org/changeset/base/342091

Log:
  allwinner: aw_pwm: Read value at attach
  
  The booloaded might have configured the pwm controller so read the values.

Modified:
  head/sys/arm/allwinner/aw_pwm.c

Modified: head/sys/arm/allwinner/aw_pwm.c
==============================================================================
--- head/sys/arm/allwinner/aw_pwm.c	Fri Dec 14 18:39:06 2018	(r342090)
+++ head/sys/arm/allwinner/aw_pwm.c	Fri Dec 14 18:39:17 2018	(r342091)
@@ -136,7 +136,8 @@ static int
 aw_pwm_attach(device_t dev)
 {
 	struct aw_pwm_softc *sc;
-	/* uint32_t reg; */
+	uint64_t clk_freq;
+	uint32_t reg;
 	int error;
 
 	sc = device_get_softc(dev);
@@ -160,6 +161,26 @@ aw_pwm_attach(device_t dev)
 	if ((sc->busdev = pwmbus_attach_bus(dev)) == NULL)
 		device_printf(dev, "Cannot attach pwm bus\n");
 
+	/* Read the configuration left by U-Boot */
+	reg = AW_PWM_READ(sc, AW_PWM_CTRL);
+	if (reg & (AW_PWM_CTRL_GATE | AW_PWM_CTRL_EN))
+		sc->enabled = true;
+
+	reg = AW_PWM_READ(sc, AW_PWM_CTRL);
+	reg &= AW_PWM_CTRL_PRESCALE_MASK;
+	if (reg > nitems(aw_pwm_clk_prescaler)) {
+		device_printf(dev, "Bad prescaler %x, cannot guess current settings\n", reg);
+		goto out;
+	}
+	clk_freq = sc->clk_freq / aw_pwm_clk_prescaler[reg];
+
+	reg = AW_PWM_READ(sc, AW_PWM_PERIOD);
+	sc->period = NS_PER_SEC /
+		(clk_freq / ((reg >> AW_PWM_PERIOD_TOTAL_SHIFT) & AW_PWM_PERIOD_TOTAL_MASK));
+	sc->duty = NS_PER_SEC /
+		(clk_freq / ((reg >> AW_PWM_PERIOD_ACTIVE_SHIFT) & AW_PWM_PERIOD_ACTIVE_MASK));
+
+out:
 	return (0);
 
 fail:



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