From owner-svn-src-head@freebsd.org Fri Dec 14 18:39:21 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5FFD133F1CD; Fri, 14 Dec 2018 18:39:20 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8CBAA8B608; Fri, 14 Dec 2018 18:39:20 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6FC4F36D4; Fri, 14 Dec 2018 18:39:17 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBEIdHfT023406; Fri, 14 Dec 2018 18:39:17 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBEIdHwS023405; Fri, 14 Dec 2018 18:39:17 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201812141839.wBEIdHwS023405@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Fri, 14 Dec 2018 18:39:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342091 - head/sys/arm/allwinner X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/arm/allwinner X-SVN-Commit-Revision: 342091 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8CBAA8B608 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.71 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.86)[-0.855,0]; NEURAL_HAM_SHORT(-0.98)[-0.975,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-0.88)[-0.883,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2018 18:39:21 -0000 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: