Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jun 2019 15:34:35 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r349415 - in stable/12: share/man/man9 sys/arm/allwinner sys/arm64/conf sys/conf sys/dev/pwm sys/dts/arm64/overlays sys/modules/dtb/allwinner sys/sys usr.sbin usr.sbin/pwm
Message-ID:  <201906261534.x5QFYZco019422@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Wed Jun 26 15:34:35 2019
New Revision: 349415
URL: https://svnweb.freebsd.org/changeset/base/349415

Log:
  MFC r341268, r342003-r342007, r342087-r342088, r342091
  
  r341268 by manu:
  arm64: allwinner: Add a dtbo to have cpu operating points
  
  This enables cpufreq on A64 boards.
  
  r342003 by manu:
  Add a pwm subsystem so we can configure pwm controller from kernel and userland.
  
  The pwm subsystem consist of API for PWM controllers, pwmbus to register them
  and a pwm(8) utility to talk to them from userland.
  
  Reviewed by:	oshgobo (capsicum), bcr (manpage), 0mp (manpage)
  Differential Revision:	https://reviews.freebsd.org/D17938
  
  r342004 by manu:
  arm64: allwinner: Add pwm driver
  
  Add a pwm driver for Allwinner PWM
  Add pwm and aw_pwm to the GENERIC kernel
  
  r342005 by manu:
  arm64: allwinner: Add DTSO for pwm and r_pwm
  
  Those are both dtso (overlays) for the two pwm controllers found on the A64.
  
  r342006 by manu:
  arm64: allwinner: Fix pwm dtso
  
  Double patched files ended up in the tree
  
  Reported by:	kevans
  
  r342007 by manu:
  pwm: Fix some arches by using %ju and casting to uintmax_t
  
  Reported by:	ci.freebsd.org
  
  r342087 by manu:
  pwm: Convert period and duty to unsigned int
  
  We don't need a 64 bits value to store nanoseconds
  
  Discused with:	ian, jhibbits
  
  r342088 by manu:
  pwm(8): Add percentage value support for duty cycle
  
  r342091 by manu:
  allwinner: aw_pwm: Read value at attach
  
  The booloaded might have configured the pwm controller so read the values.

Added:
  stable/12/share/man/man9/pwm.9
     - copied unchanged from r342007, head/share/man/man9/pwm.9
  stable/12/share/man/man9/pwmbus.9
     - copied unchanged from r342007, head/share/man/man9/pwmbus.9
  stable/12/sys/arm/allwinner/aw_pwm.c
     - copied, changed from r342007, head/sys/arm/allwinner/aw_pwm.c
  stable/12/sys/dev/pwm/
     - copied from r342007, head/sys/dev/pwm/
  stable/12/sys/dts/arm64/overlays/sun50i-a64-opp.dtso
     - copied unchanged from r341268, head/sys/dts/arm64/overlays/sun50i-a64-opp.dtso
  stable/12/sys/dts/arm64/overlays/sun50i-a64-pwm.dtso
     - copied unchanged from r342007, head/sys/dts/arm64/overlays/sun50i-a64-pwm.dtso
  stable/12/sys/dts/arm64/overlays/sun50i-a64-rpwm.dtso
     - copied unchanged from r342007, head/sys/dts/arm64/overlays/sun50i-a64-rpwm.dtso
  stable/12/sys/sys/pwm.h
     - copied, changed from r342007, head/sys/sys/pwm.h
  stable/12/usr.sbin/pwm/
     - copied from r342007, head/usr.sbin/pwm/
Modified:
  stable/12/share/man/man9/Makefile
  stable/12/sys/arm64/conf/GENERIC
  stable/12/sys/conf/files
  stable/12/sys/conf/files.arm64
  stable/12/sys/dev/pwm/pwm_if.m
  stable/12/sys/dev/pwm/pwmbus.c
  stable/12/sys/dev/pwm/pwmbus_if.m
  stable/12/sys/modules/dtb/allwinner/Makefile
  stable/12/usr.sbin/Makefile
  stable/12/usr.sbin/pwm/pwm.8
  stable/12/usr.sbin/pwm/pwm.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/share/man/man9/Makefile
==============================================================================
--- stable/12/share/man/man9/Makefile	Wed Jun 26 15:28:21 2019	(r349414)
+++ stable/12/share/man/man9/Makefile	Wed Jun 26 15:34:35 2019	(r349415)
@@ -269,6 +269,8 @@ MAN=	accept_filter.9 \
 	proc_rwmem.9 \
 	pseudofs.9 \
 	psignal.9 \
+	pwm.9 \
+	pwmbus.9 \
 	random.9 \
 	random_harvest.9 \
 	ratecheck.9 \

Copied: stable/12/share/man/man9/pwm.9 (from r342007, head/share/man/man9/pwm.9)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/share/man/man9/pwm.9	Wed Jun 26 15:34:35 2019	(r349415, copy of r342007, head/share/man/man9/pwm.9)
@@ -0,0 +1,93 @@
+.\" Copyright (c) 2018 Emmanuel Vadot <manu@freebsd.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd November 12, 2018
+.Dt PWM 9
+.Os
+.Sh NAME
+.Nm pwm ,
+.Nm PWM_GET_BUS ,
+.Nm PWM_CHANNEL_CONFIG ,
+.Nm PWM_CHANNEL_GET_CONFIG ,
+.Nm PWM_CHANNEL_SET_FLAGS ,
+.Nm PWM_CHANNEL_GET_FLAGS ,
+.Nm PWM_CHANNEL_ENABLE ,
+.Nm PWM_CHANNEL_IS_ENABLED ,
+.Nm PWM_CHANNEL_MAX
+.Nd PWM methods
+.Sh SYNOPSIS
+.Cd "device pwm"
+.In "pwm_if.h"
+.Ft device_t
+.Fn PWM_GET_BUS "device_t dev"
+.Ft int
+.Fn PWM_CHANNEL_CONFIG "device_t dev" "int channel" "uint64_t period" "uint64_t duty"
+.Ft int
+.Fn PWM_CHANNEL_GET_CONFIG "device_t dev" "int channel" "uint64_t *period" "uint64_t *duty"
+.Ft int
+.Fn PWM_CHANNEL_SET_FLAGS "device_t dev" "int channel" "uint32_t flags"
+.Ft int
+.Fn PWM_CHANNEL_GET_FLAGS "device_t dev" "int channel" "uint32_t *flags"
+.Ft int
+.Fn PWM_CHANNEL_ENABLE "device_t dev" "int channel" "bool enable"
+.Ft int
+.Fn PWM_CHANNEL_IS_ENABLED "device_t dev" "int channel" "bool *enabled"
+.Ft int
+.Fn PWM_CHANNEL_MAX "device_t dev" "int channel" "int *nchannel"
+.Sh DESCRIPTION
+The PWM (Pulse-Width Modulation) interface allows the device driver to register to a global
+bus so other devices in the kernel can use them in a generic way.
+.Sh INTERFACE
+.Bl -tag -width indent
+.It Fn PWM_GET_BUS "device_t dev"
+Return the bus device.
+.It Fn PWM_CHANNEL_CONFIG "device_t dev" "int channel" "uint64_t period" "uint64_t duty"
+Configure the period and duty (in nanoseconds) in the PWM controller for the specified channel.
+Returns 0 on success or
+.Er EINVAL
+if the values are not supported by the controller or
+.Er EBUSY
+is the PWM controller is in use and does not support changing the value on the fly.
+.It Fn PWM_CHANNEL_GET_CONFIG "device_t dev" "int channel" "uint64_t *period" "uint64_t *duty"
+Get the current configuration of the period and duty for the specified channel.
+.It Fn PWM_CHANNEL_SET_FLAGS "device_t dev" "int channel" "uint32_t flags"
+Set the flags of the channel (like inverted polarity).
+.It Fn PWM_CHANNEL_GET_FLAGS "device_t dev" "int channel" "uint32_t *flags"
+Get the current flags for the channel.
+.It Fn PWM_CHANNEL_ENABLE "device_t dev" "int channel" "bool enable"
+Enable the PWM channel.
+.It Fn PWM_CHANNEL_ISENABLED "device_t dev" "int channel" "bool *enable"
+Test if the PWM channel is enabled.
+.It PWM_CHANNEL_MAX "device_t dev" "int channel" "int *nchannel"
+Get the maximum number of channels supported by the controller.
+.El
+.Sh HISTORY
+The
+.Nm pwm
+interface first appeared in
+.Fx 13.0 .
+The
+.Nm pwm
+interface and manual page was written by
+.An Emmanuel Vadot Aq Mt manu@FreeBSD.org .

Copied: stable/12/share/man/man9/pwmbus.9 (from r342007, head/share/man/man9/pwmbus.9)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/share/man/man9/pwmbus.9	Wed Jun 26 15:34:35 2019	(r349415, copy of r342007, head/share/man/man9/pwmbus.9)
@@ -0,0 +1,98 @@
+.\" Copyright (c) 2018 Emmanuel Vadot <manu@freebsd.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd November 12, 2018
+.Dt PWMBUS 9
+.Os
+.Sh NAME
+.Nm pwmbus ,
+.Nm pwmbus_attach_bus ,
+.Nm PWMBUS_GET_BUS ,
+.Nm PWMBUS_CHANNEL_CONFIG ,
+.Nm PWMBUS_CHANNEL_GET_CONFIG ,
+.Nm PWMBUS_CHANNEL_SET_FLAGS ,
+.Nm PWMBUS_CHANNEL_GET_FLAGS ,
+.Nm PWMBUS_CHANNEL_ENABLE ,
+.Nm PWMBUS_CHANNEL_IS_ENABLED ,
+.Nm PWMBUS_CHANNEL_MAX
+.Nd PWMBUS methods
+.Sh SYNOPSIS
+.Cd "device pwm"
+.In "pwmbus_if.h"
+.Ft device_t
+.Fn pwmbus_attach_bus "device_t dev"
+.Ft int
+.Fn PWMBUS_CHANNEL_CONFIG "device_t bus" "int channel" "uint64_t period" "uint64_t duty"
+.Ft int
+.Fn PWMBUS_CHANNEL_GET_CONFIG "device_t bus" "int channel" "uint64_t *period" "uint64_t *duty"
+.Ft int
+.Fn PWMBUS_CHANNEL_SET_FLAGS "device_t bus" "int channel" "uint32_t flags"
+.Ft int
+.Fn PWMBUS_CHANNEL_GET_FLAGS "device_t bus" "int channel" "uint32_t *flags"
+.Ft int
+.Fn PWMBUS_CHANNEL_ENABLE "device_t bus" "int channel" "bool enable"
+.Ft int
+.Fn PWMBUS_CHANNEL_IS_ENABLED "device_t bus" "int channel" "bool *enabled"
+.Ft int
+.Fn PWMBUS_CHANNEL_MAX "device_t bus" "int channel" "int *nchannel"
+.Sh DESCRIPTION
+The PWMBUS (Pulse-Width Modulation) interface allows the device driver to register to a global
+bus so other devices in the kernel can use them in a generic way
+.Sh INTERFACE
+.Bl -tag -width indent
+.It Fn pwmbus_attach_bus "device_t dev"
+Attach the
+.Nm pwmbus
+to the device driver
+.It Fn PWMBUS_CHANNEL_CONFIG "device_t bus" "int channel" "uint64_t period" "uint64_t duty"
+Configure the period and duty (in nanoseconds) in the PWM controller on the bus for the specified channel.
+Returns 0 on success or
+.Er EINVAL
+is the values are not supported by the controller or
+.Er EBUSY
+is the PWMBUS controller is in use and doesn't support changing the value on the fly.
+.It Fn PWMBUS_CHANNEL_GET_CONFIG "device_t bus" "int channel" "uint64_t *period" "uint64_t *duty"
+Get the current configuration of the period and duty for the specified channel.
+.It Fn PWMBUS_CHANNEL_SET_FLAGS "device_t bus" "int channel" "uint32_t flags"
+Set the flags of the channel (like inverted polarity), if the driver or controller
+doesn't support this a default method is used.
+.It Fn PWMBUS_CHANNEL_GET_FLAGS "device_t bus" "int channel" "uint32_t *flags"
+Get the current flags for the channel, if the driver or controller
+doesn't support this, a default method is used.
+.It Fn PWMBUS_CHANNEL_ENABLE "device_t bus" "int channel" "bool enable"
+Enable the PWM channel.
+.It Fn PWMBUS_CHANNEL_ISENABLED "device_t bus" "int channel" "bool *enable"
+Test if the PWM channel is enabled.
+.It PWMBUS_CHANNEL_MAX "device_t bus" "int channel" "int *nchannel"
+Get the maximum number of channel supported by the controller.
+.El
+.Sh HISTORY
+The
+.Nm pwmbus
+interface first appear in
+.Fx 13.0 .
+The
+.Nm pwmbus
+interface and manual page was written by
+.An Emmanuel Vadot Aq Mt manu@FreeBSD.org .

Copied and modified: stable/12/sys/arm/allwinner/aw_pwm.c (from r342007, head/sys/arm/allwinner/aw_pwm.c)
==============================================================================
--- head/sys/arm/allwinner/aw_pwm.c	Wed Dec 12 21:25:52 2018	(r342007, copy source)
+++ stable/12/sys/arm/allwinner/aw_pwm.c	Wed Jun 26 15:34:35 2019	(r349415)
@@ -87,8 +87,8 @@ struct aw_pwm_softc {
 	struct resource	*res;
 
 	uint64_t	clk_freq;
-	uint64_t	period;
-	uint64_t	duty;
+	unsigned int	period;
+	unsigned int	duty;
 	uint32_t	flags;
 	bool		enabled;
 };
@@ -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:
@@ -191,7 +212,7 @@ aw_pwm_channel_max(device_t dev, int *nchannel)
 }
 
 static int
-aw_pwm_channel_config(device_t dev, int channel, uint64_t period, uint64_t duty)
+aw_pwm_channel_config(device_t dev, int channel, unsigned int period, unsigned int duty)
 {
 	struct aw_pwm_softc *sc;
 	uint64_t period_freq, duty_freq;
@@ -254,7 +275,7 @@ aw_pwm_channel_config(device_t dev, int channel, uint6
 }
 
 static int
-aw_pwm_channel_get_config(device_t dev, int channel, uint64_t *period, uint64_t *duty)
+aw_pwm_channel_get_config(device_t dev, int channel, unsigned int *period, unsigned int *duty)
 {
 	struct aw_pwm_softc *sc;
 

Modified: stable/12/sys/arm64/conf/GENERIC
==============================================================================
--- stable/12/sys/arm64/conf/GENERIC	Wed Jun 26 15:28:21 2019	(r349414)
+++ stable/12/sys/arm64/conf/GENERIC	Wed Jun 26 15:34:35 2019	(r349415)
@@ -231,6 +231,10 @@ device		aw_thermal	# Allwinner Thermal Sensor Controll
 device		spibus
 device		bcm2835_spi	# Broadcom BCM283x SPI bus
 
+# PWM
+device		pwm
+device		aw_pwm
+
 # Console
 device		vt
 device		kbdmux

Modified: stable/12/sys/conf/files
==============================================================================
--- stable/12/sys/conf/files	Wed Jun 26 15:28:21 2019	(r349414)
+++ stable/12/sys/conf/files	Wed Jun 26 15:34:35 2019	(r349415)
@@ -2775,6 +2775,11 @@ dev/puc/puc.c			optional puc
 dev/puc/puc_cfg.c		optional puc
 dev/puc/puc_pccard.c		optional puc pccard
 dev/puc/puc_pci.c		optional puc pci
+dev/pwm/pwmc.c			optional pwm
+dev/pwm/pwmbus.c		optional pwm
+dev/pwm/pwm_if.m		optional pwm
+dev/pwm/pwmbus_if.m		optional pwm
+dev/pwm/ofw_pwm.c		optional pwm fdt
 dev/quicc/quicc_core.c		optional quicc
 dev/ral/rt2560.c		optional ral
 dev/ral/rt2661.c		optional ral

Modified: stable/12/sys/conf/files.arm64
==============================================================================
--- stable/12/sys/conf/files.arm64	Wed Jun 26 15:28:21 2019	(r349414)
+++ stable/12/sys/conf/files.arm64	Wed Jun 26 15:34:35 2019	(r349415)
@@ -31,6 +31,7 @@ arm/allwinner/aw_gpio.c		optional	gpio aw_gpio fdt
 arm/allwinner/aw_mmc.c		optional	mmc aw_mmc fdt | mmccam aw_mmc fdt
 arm/allwinner/aw_nmi.c		optional	aw_nmi fdt \
 	compile-with "${NORMAL_C} -I$S/gnu/dts/include"
+arm/allwinner/aw_pwm.c		optional	aw_pwm fdt
 arm/allwinner/aw_rsb.c		optional	aw_rsb fdt
 arm/allwinner/aw_rtc.c		optional	aw_rtc fdt
 arm/allwinner/aw_sid.c		optional	aw_sid nvmem fdt

Modified: stable/12/sys/dev/pwm/pwm_if.m
==============================================================================
--- head/sys/dev/pwm/pwm_if.m	Wed Dec 12 21:25:52 2018	(r342007)
+++ stable/12/sys/dev/pwm/pwm_if.m	Wed Jun 26 15:34:35 2019	(r349415)
@@ -46,8 +46,8 @@ METHOD device_t get_bus {
 METHOD int channel_config {
 	device_t dev;
 	int channel;
-	uint64_t period;
-	uint64_t duty;
+	unsigned int period;
+	unsigned duty;
 };
 
 #
@@ -57,8 +57,8 @@ METHOD int channel_config {
 METHOD int channel_get_config {
 	device_t dev;
 	int channel;
-	uint64_t *period;
-	uint64_t *duty;
+	unsigned int *period;
+	unsigned int *duty;
 };
 
 #

Modified: stable/12/sys/dev/pwm/pwmbus.c
==============================================================================
--- head/sys/dev/pwm/pwmbus.c	Wed Dec 12 21:25:52 2018	(r342007)
+++ stable/12/sys/dev/pwm/pwmbus.c	Wed Jun 26 15:34:35 2019	(r349415)
@@ -138,7 +138,7 @@ pwmbus_detach(device_t dev)
 }
 
 static int
-pwmbus_channel_config(device_t bus, int channel, uint64_t period, uint64_t duty)
+pwmbus_channel_config(device_t bus, int channel, unsigned int period, unsigned int duty)
 {
 	struct pwmbus_softc *sc;
 
@@ -151,7 +151,7 @@ pwmbus_channel_config(device_t bus, int channel, uint6
 }
 
 static int
-pwmbus_channel_get_config(device_t bus, int channel, uint64_t *period, uint64_t *duty)
+pwmbus_channel_get_config(device_t bus, int channel, unsigned int *period, unsigned int *duty)
 {
 	struct pwmbus_softc *sc;
 

Modified: stable/12/sys/dev/pwm/pwmbus_if.m
==============================================================================
--- head/sys/dev/pwm/pwmbus_if.m	Wed Dec 12 21:25:52 2018	(r342007)
+++ stable/12/sys/dev/pwm/pwmbus_if.m	Wed Jun 26 15:34:35 2019	(r349415)
@@ -59,8 +59,8 @@ HEADER {
 METHOD int channel_config {
 	device_t bus;
 	int channel;
-	uint64_t period;
-	uint64_t duty;
+	unsigned int period;
+	unsigned int duty;
 };
 
 #
@@ -70,8 +70,8 @@ METHOD int channel_config {
 METHOD int channel_get_config {
 	device_t bus;
 	int channel;
-	uint64_t *period;
-	uint64_t *duty;
+	unsigned int *period;
+	unsigned int *duty;
 };
 
 #

Copied: stable/12/sys/dts/arm64/overlays/sun50i-a64-opp.dtso (from r341268, head/sys/dts/arm64/overlays/sun50i-a64-opp.dtso)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/dts/arm64/overlays/sun50i-a64-opp.dtso	Wed Jun 26 15:34:35 2019	(r349415, copy of r341268, head/sys/dts/arm64/overlays/sun50i-a64-opp.dtso)
@@ -0,0 +1,72 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "allwinner,sun50i-a64";
+};
+
+&{/} {
+	cpu0_opp_table: opp_table0 {
+		compatible = "operating-points-v2";
+		opp-shared;
+
+		opp-648000000 {
+			opp-hz = /bits/ 64 <648000000>;
+			opp-microvolt = <1040000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-816000000 {
+			opp-hz = /bits/ 64 <816000000>;
+			opp-microvolt = <1100000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-912000000 {
+			opp-hz = /bits/ 64 <912000000>;
+			opp-microvolt = <1120000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-960000000 {
+			opp-hz = /bits/ 64 <960000000>;
+			opp-microvolt = <1160000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-1008000000 {
+			opp-hz = /bits/ 64 <1008000000>;
+			opp-microvolt = <1200000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-1056000000 {
+			opp-hz = /bits/ 64 <1056000000>;
+			opp-microvolt = <1240000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-1104000000 {
+			opp-hz = /bits/ 64 <1104000000>;
+			opp-microvolt = <1260000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+		opp-1152000000 {
+			opp-hz = /bits/ 64 <1152000000>;
+			opp-microvolt = <1300000>;
+			clock-latency-ns = <244144>; /* 8 32k periods */
+		};
+	};
+};
+
+&{/cpus/cpu@0} {
+	operating-points-v2 = <&cpu0_opp_table>;
+	clocks = <&ccu 1>;
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&{/cpus/cpu@1} {
+	operating-points-v2 = <&cpu0_opp_table>;
+};
+
+&{/cpus/cpu@2} {
+	operating-points-v2 = <&cpu0_opp_table>;
+};
+
+&{/cpus/cpu@3} {
+	operating-points-v2 = <&cpu0_opp_table>;
+};

Copied: stable/12/sys/dts/arm64/overlays/sun50i-a64-pwm.dtso (from r342007, head/sys/dts/arm64/overlays/sun50i-a64-pwm.dtso)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/dts/arm64/overlays/sun50i-a64-pwm.dtso	Wed Jun 26 15:34:35 2019	(r349415, copy of r342007, head/sys/dts/arm64/overlays/sun50i-a64-pwm.dtso)
@@ -0,0 +1,26 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "allwinner,sun50i-a64";
+};
+
+&{/soc} {
+	pwm: pwm@1c21400 {
+		compatible = "allwinner,sun50i-a64-pwm",
+			     "allwinner,sun5i-a13-pwm";
+		reg = <0x01c21400 0x400>;
+		clocks = <&osc24M>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pwm_pin>;
+		#pwm-cells = <3>;
+		status = "disabled";
+	};
+};
+
+&{/soc/pinctrl@1c20800} {
+	pwm_pin: pwm_pin {
+		pins = "PD22";
+		function = "pwm";
+	};
+};

Copied: stable/12/sys/dts/arm64/overlays/sun50i-a64-rpwm.dtso (from r342007, head/sys/dts/arm64/overlays/sun50i-a64-rpwm.dtso)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/dts/arm64/overlays/sun50i-a64-rpwm.dtso	Wed Jun 26 15:34:35 2019	(r349415, copy of r342007, head/sys/dts/arm64/overlays/sun50i-a64-rpwm.dtso)
@@ -0,0 +1,26 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "allwinner,sun50i-a64";
+};
+
+&{/soc} {
+	r_pwm: pwm@1f03800 {
+		compatible = "allwinner,sun50i-a64-pwm",
+			     "allwinner,sun5i-a13-pwm";
+		reg = <0x01f03800 0x400>;
+		clocks = <&osc24M>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&r_pwm_pin>;
+		#pwm-cells = <3>;
+		status = "okay";
+	};
+};
+
+&{/soc/pinctrl@1f02c00} {
+	r_pwm_pin: pwm {
+		pins = "PL10";
+		function = "s_pwm";
+	};
+};

Modified: stable/12/sys/modules/dtb/allwinner/Makefile
==============================================================================
--- stable/12/sys/modules/dtb/allwinner/Makefile	Wed Jun 26 15:28:21 2019	(r349414)
+++ stable/12/sys/modules/dtb/allwinner/Makefile	Wed Jun 26 15:34:35 2019	(r349415)
@@ -44,7 +44,10 @@ DTS=	\
 	allwinner/sun50i-a64-sopine-baseboard.dts \
 	allwinner/sun50i-h5-orangepi-pc2.dts
 
-DTSO=	sun50i-a64-sid.dtso \
+DTSO=	sun50i-a64-opp.dtso \
+	sun50i-a64-pwm.dtso \
+	sun50i-a64-rpwm.dtso \
+	sun50i-a64-sid.dtso \
 	sun50i-a64-ths.dtso \
 	sun50i-a64-timer.dtso
 

Copied and modified: stable/12/sys/sys/pwm.h (from r342007, head/sys/sys/pwm.h)
==============================================================================
--- head/sys/sys/pwm.h	Wed Dec 12 21:25:52 2018	(r342007, copy source)
+++ stable/12/sys/sys/pwm.h	Wed Jun 26 15:34:35 2019	(r349415)
@@ -35,8 +35,8 @@
 
 struct pwm_state {
 	int		channel;
-	uint64_t	period;
-	uint64_t	duty;
+	unsigned int	period;
+	unsigned int	duty;
 	uint32_t	flags;
 	bool		enable;
 };

Modified: stable/12/usr.sbin/Makefile
==============================================================================
--- stable/12/usr.sbin/Makefile	Wed Jun 26 15:28:21 2019	(r349414)
+++ stable/12/usr.sbin/Makefile	Wed Jun 26 15:34:35 2019	(r349415)
@@ -67,6 +67,7 @@ SUBDIR=	adduser \
 	pstat \
 	pw \
 	pwd_mkdb \
+	pwm \
 	quot \
 	rarpd \
 	rmt \

Modified: stable/12/usr.sbin/pwm/pwm.8
==============================================================================
--- head/usr.sbin/pwm/pwm.8	Wed Dec 12 21:25:52 2018	(r342007)
+++ stable/12/usr.sbin/pwm/pwm.8	Wed Jun 26 15:34:35 2019	(r349415)
@@ -67,7 +67,7 @@ Show the configuration of the pwm channel
 .It Fl p Ar period
 Configure the period (in nanoseconds) of the pwm channel
 .It Fl d Ar duty
-Configure the duty (in nanoseconds) of the pwm channel
+Configure the duty (in nanoseconds or percentage) of the pwm channel
 .El
 .Sh EXAMPLES
 .Bl -bullet
@@ -76,9 +76,13 @@ Show the configuration of the pwm channel:
 .Pp
 pwm -f /dev/pwmc0 -C
 .It
-Configure a 50000 ns period and a 25000 duty cycles:
+Configure a 50000 ns period and a 25000 duty cycle:
 .Pp
 pwm -f /dev/pwmc0 -p 50000 -d 25000
+.It
+Configure a 50% duty cycle:
+.Pp
+pwm -f /dev/pwmc0 -d 50%
 .El
 .Sh SEE ALSO
 .Xr pwm 9 ,

Modified: stable/12/usr.sbin/pwm/pwm.c
==============================================================================
--- head/usr.sbin/pwm/pwm.c	Wed Dec 12 21:25:52 2018	(r342007)
+++ stable/12/usr.sbin/pwm/pwm.c	Wed Jun 26 15:34:35 2019	(r349415)
@@ -71,6 +71,7 @@ main(int argc, char *argv[])
 	int action, ch;
 	cap_rights_t right_ioctl;
 	const unsigned long pwm_ioctls[] = {PWMGETSTATE, PWMSETSTATE, PWMMAXCHANNEL};
+	char *percent;
 
 	action = 0;
 	fd = -1;
@@ -104,7 +105,9 @@ main(int argc, char *argv[])
 			if (action & ~(PWM_PERIOD | PWM_DUTY))
 				usage();
 			action = PWM_DUTY;
-			duty = strtol(optarg, NULL, 10);
+			duty = strtol(optarg, &percent, 10);
+			if (*percent != '\0' && *percent != '%')
+				usage();
 			break;
 		case 'c':
 			if (channel != -1)
@@ -190,17 +193,21 @@ main(int argc, char *argv[])
 		}
 		break;
 	case PWM_SHOW_CONFIG:
-		printf("period: %ju\nduty: %ju\nenabled:%d\n",
-		    (uintmax_t) state.period,
-		    (uintmax_t) state.duty,
+		printf("period: %u\nduty: %u\nenabled:%d\n",
+		    state.period,
+		    state.duty,
 		    state.enable);
 		break;
 	case PWM_PERIOD:
 	case PWM_DUTY:
 		if (period != -1)
 			state.period = period;
-		if (duty != -1)
-			state.duty = duty;
+		if (duty != -1) {
+			if (*percent != '\0')
+				state.duty = state.period * duty / 100;
+			else
+				state.duty = duty;
+		}
 		if (ioctl(fd, PWMSETSTATE, &state) == -1) {
 			fprintf(stderr,
 			  "Cannot configure the pwm controller\n");



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