xref: /freebsd/share/man/man4/pwmc.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1*a161bab8SIan Lepore.\"
2*a161bab8SIan Lepore.\" Copyright (c) 2019 Ian Lepore <ian@freebsd.org>
3*a161bab8SIan Lepore.\"
4*a161bab8SIan Lepore.\" Redistribution and use in source and binary forms, with or without
5*a161bab8SIan Lepore.\" modification, are permitted provided that the following conditions
6*a161bab8SIan Lepore.\" are met:
7*a161bab8SIan Lepore.\"
8*a161bab8SIan Lepore.\" 1. Redistributions of source code must retain the above copyright
9*a161bab8SIan Lepore.\"    notice, this list of conditions and the following disclaimer.
10*a161bab8SIan Lepore.\" 2. Redistributions in binary form must reproduce the above copyright
11*a161bab8SIan Lepore.\"    notice, this list of conditions and the following disclaimer in the
12*a161bab8SIan Lepore.\"    documentation and/or other materials provided with the distribution.
13*a161bab8SIan Lepore.\"
14*a161bab8SIan Lepore.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15*a161bab8SIan Lepore.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*a161bab8SIan Lepore.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*a161bab8SIan Lepore.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18*a161bab8SIan Lepore.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*a161bab8SIan Lepore.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*a161bab8SIan Lepore.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*a161bab8SIan Lepore.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*a161bab8SIan Lepore.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*a161bab8SIan Lepore.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*a161bab8SIan Lepore.\"
25*a161bab8SIan Lepore.Dd June 17, 2019
26*a161bab8SIan Lepore.Dt PWMC 4
27*a161bab8SIan Lepore.Os
28*a161bab8SIan Lepore.Sh NAME
29*a161bab8SIan Lepore.Nm pwmc
30*a161bab8SIan Lepore.Nd PWM (Pulse Width Modulation) control device driver
31*a161bab8SIan Lepore.Sh SYNOPSIS
32*a161bab8SIan LeporeTo compile this driver into the kernel,
33*a161bab8SIan Leporeplace the following lines in your
34*a161bab8SIan Leporekernel configuration file:
35*a161bab8SIan Lepore.Bd -ragged -offset indent
36*a161bab8SIan Lepore.Cd "device pwmbus"
37*a161bab8SIan Lepore.Cd "device pwmc"
38*a161bab8SIan Lepore.Ed
39*a161bab8SIan Lepore.Pp
40*a161bab8SIan LeporeAlternatively, to load the driver as a
41*a161bab8SIan Leporemodule at boot time, place the following line in
42*a161bab8SIan Lepore.Xr loader.conf 5 :
43*a161bab8SIan Lepore.Bd -literal -offset indent
44*a161bab8SIan Leporepwmc_load="YES"
45*a161bab8SIan Lepore.Ed
46*a161bab8SIan Lepore.Sh DESCRIPTION
47*a161bab8SIan LeporeThe
48*a161bab8SIan Lepore.Nm
49*a161bab8SIan Leporedriver provides device-control access to a channel of PWM hardware.
50*a161bab8SIan LeporeEach instance of a
51*a161bab8SIan Lepore.Nm
52*a161bab8SIan Leporedevice is associated with a single PWM output channel.
53*a161bab8SIan Lepore.Pp
54*a161bab8SIan LeporeSome PWM hardware is organized with multiple channels sharing a
55*a161bab8SIan Leporecommon clock or other resources.
56*a161bab8SIan LeporeIn such cases, a separate
57*a161bab8SIan Lepore.Nm
58*a161bab8SIan Leporeinstance will exist for each channel, but changing the period or
59*a161bab8SIan Leporeduty cycle of any one channel may affect other channels within the
60*a161bab8SIan Leporehardware which share the same resources.
61*a161bab8SIan LeporeConsult the documentation for the underlying PWM hardware device driver
62*a161bab8SIan Leporefor details on channels that share resources.
63*a161bab8SIan Lepore.Pp
64*a161bab8SIan LeporeAn instance of
65*a161bab8SIan Lepore.Nm
66*a161bab8SIan Leporecreates a character device named
67*a161bab8SIan Lepore.Pa /dev/pwm/pwmcX.Y
68*a161bab8SIan Leporewhere
69*a161bab8SIan Lepore.Va X
70*a161bab8SIan Leporeis a sequential number assigned to each PWM hardware controller
71*a161bab8SIan Leporeas it is discovered by the system, and
72*a161bab8SIan Lepore.Va Y
73*a161bab8SIan Leporeis the channel number within that hardware controller.
74*a161bab8SIan LeporeThe driver can be configured to create aliases that point to the
75*a161bab8SIan Lepore.Pa pwmcX.Y
76*a161bab8SIan Leporeentries, in effect creating named channels.
77*a161bab8SIan Lepore.Pp
78*a161bab8SIan LeporeThe
79*a161bab8SIan Lepore.Nm
80*a161bab8SIan Leporedriver provides control of a PWM channel with the following
81*a161bab8SIan Lepore.Xr ioctl 2
82*a161bab8SIan Leporecalls and data structures, defined in
83*a161bab8SIan Lepore.In dev/pwm/pwmc.h :
84*a161bab8SIan Lepore.Bl -tag -width indent
85*a161bab8SIan Lepore.It Dv PWMGETSTATE Pq Vt "struct pwm_state"
86*a161bab8SIan LeporeRetrieve the current state of the channel.
87*a161bab8SIan Lepore.It Dv PWMSETSTATE Pq Vt "struct pwm_state"
88*a161bab8SIan LeporeSet the current state of the channel.
89*a161bab8SIan LeporeAll parameters are updated on every call.
90*a161bab8SIan LeporeTo change just one of the values, use
91*a161bab8SIan Lepore.Dv PWMGETSTATE
92*a161bab8SIan Leporeto get the current state and then submit the same data back with
93*a161bab8SIan Leporejust the appropriate value changed.
94*a161bab8SIan Lepore.El
95*a161bab8SIan Lepore.Pp
96*a161bab8SIan LeporeThe
97*a161bab8SIan Lepore.Va pwm_state
98*a161bab8SIan Leporestructure is defined as follows:
99*a161bab8SIan Lepore.Bd -literal
100*a161bab8SIan Leporestruct pwm_state {
101*a161bab8SIan Lepore	u_int		period;
102*a161bab8SIan Lepore	u_int		duty;
103*a161bab8SIan Lepore	uint32_t	flags;
104*a161bab8SIan Lepore	bool		enable;
105*a161bab8SIan Lepore};
106*a161bab8SIan Lepore.Ed
107*a161bab8SIan Lepore.Bl -tag -width period
108*a161bab8SIan Lepore.It Va period
109*a161bab8SIan LeporeThe duration, in nanoseconds, of one complete on-off cycle.
110*a161bab8SIan Lepore.It Va duty
111*a161bab8SIan LeporeThe duration, in nanoseconds, of the on portion of one cycle.
112*a161bab8SIan Lepore.It Va flags
113*a161bab8SIan LeporeFlags that affect the output signal can be bitwise-ORed together.
114*a161bab8SIan LeporeThe following flags are currently defined:
115*a161bab8SIan Lepore.Pp
116*a161bab8SIan Lepore.Bl -tag -width PWM_POLARITY_INVERTED -compact
117*a161bab8SIan Lepore.It Dv PWM_POLARITY_INVERTED
118*a161bab8SIan LeporeInvert the signal polarity.
119*a161bab8SIan Lepore.El
120*a161bab8SIan Lepore.It Va enable
121*a161bab8SIan Lepore.Va
122*a161bab8SIan LeporeFalse to disable the output signal or true to enable it.
123*a161bab8SIan Lepore.El
124*a161bab8SIan Lepore.Sh HINTS CONFIGURATION
125*a161bab8SIan LeporeOn a
126*a161bab8SIan Lepore.Xr device.hints 5
127*a161bab8SIan Leporebased system, such as
128*a161bab8SIan Lepore.Li MIPS ,
129*a161bab8SIan Leporethese values are configurable for
130*a161bab8SIan Lepore.Nm :
131*a161bab8SIan Lepore.Bl -tag -width indent
132*a161bab8SIan Lepore.It Va hint.pwmc.%d.at
133*a161bab8SIan LeporeThe pwmbus instance the
134*a161bab8SIan Lepore.Nm
135*a161bab8SIan Leporeinstance is attached to.
136*a161bab8SIan Lepore.It Va hint.pwmc.%d.channel
137*a161bab8SIan LeporeThe hardware channel number the instance is attached to.
138*a161bab8SIan LeporeChannel numbers count up from zero.
139*a161bab8SIan Lepore.It Va hint.pwmc.%d.label
140*a161bab8SIan LeporeIf this optional hint is set, the driver creates an alias in
141*a161bab8SIan Lepore.Pa /dev/pwm
142*a161bab8SIan Leporewith the given name, which points to the instance.
143*a161bab8SIan Lepore.El
144*a161bab8SIan Lepore.Sh FDT CONFIGURATION
145*a161bab8SIan LeporeOn an
146*a161bab8SIan Lepore.Xr fdt 4
147*a161bab8SIan Leporebased system, a
148*a161bab8SIan Lepore.Nm
149*a161bab8SIan Leporedevice is described with a child node of the pwm hardware controller node.
150*a161bab8SIan LeporeWhen the hardware supports multiple channels within the controller, it is
151*a161bab8SIan Leporenot necessary to include a
152*a161bab8SIan Lepore.Nm
153*a161bab8SIan Leporechild node for every channel the hardware supports.
154*a161bab8SIan LeporeDefine only the channels you need to control.
155*a161bab8SIan Lepore.Pp
156*a161bab8SIan LeporeThe following properties are required for a
157*a161bab8SIan Lepore.Nm
158*a161bab8SIan Leporedevice node:
159*a161bab8SIan Lepore.Bl -tag -width indent
160*a161bab8SIan Lepore.It Va compatible
161*a161bab8SIan LeporeMust be the string "freebsd,pwmc".
162*a161bab8SIan Lepore.It Va reg
163*a161bab8SIan LeporeThe hardware channel number.
164*a161bab8SIan Lepore.El
165*a161bab8SIan Lepore.Pp
166*a161bab8SIan LeporeThe following properties are optional for the
167*a161bab8SIan Lepore.Nm
168*a161bab8SIan Leporedevice node:
169*a161bab8SIan Lepore.Bl -tag -width indent
170*a161bab8SIan Lepore.It Va label
171*a161bab8SIan LeporeA string containing only characters legal in a file name.
172*a161bab8SIan LeporeThe driver creates an alias with the given name in
173*a161bab8SIan Lepore.Pa /dev/pwm
174*a161bab8SIan Leporewhich points to the instance's
175*a161bab8SIan Lepore.Pa /dev/pwm/pwmcX.Y
176*a161bab8SIan Leporedevice entry.
177*a161bab8SIan Lepore.El
178*a161bab8SIan Lepore.Pp
179*a161bab8SIan LeporeExample of a PWM hardware node containing one
180*a161bab8SIan Lepore.Nm
181*a161bab8SIan Leporechild node:
182*a161bab8SIan Lepore.Bd -literal
183*a161bab8SIan Lepore&ehrpwm0 {
184*a161bab8SIan Lepore    status = "okay";
185*a161bab8SIan Lepore    pinctrl-names = "default";
186*a161bab8SIan Lepore    pinctrl-0 = <&ehrpwm0_AB_pins>;
187*a161bab8SIan Lepore
188*a161bab8SIan Lepore    pwmcontrol@0 {
189*a161bab8SIan Lepore        compatible = "freebsd,pwmc";
190*a161bab8SIan Lepore        reg = <0>;
191*a161bab8SIan Lepore        label = "backlight";
192*a161bab8SIan Lepore    };
193*a161bab8SIan Lepore};
194*a161bab8SIan Lepore.Ed
195*a161bab8SIan Lepore.Sh FILES
196*a161bab8SIan Lepore.Bl -tag -width -compact
197*a161bab8SIan Lepore.It Pa /dev/pwm/pwmc*
198*a161bab8SIan Lepore.El
199*a161bab8SIan Lepore.Sh SEE ALSO
200*a161bab8SIan Lepore.Xr fdt 4 ,
201*a161bab8SIan Lepore.Xr device.hints 5 ,
202*a161bab8SIan Lepore.Xr pwm 8 ,
203*a161bab8SIan Lepore.Xr pwm 9
204*a161bab8SIan Lepore.Sh HISTORY
205*a161bab8SIan LeporeThe
206*a161bab8SIan Lepore.Nm
207*a161bab8SIan Leporedriver
208*a161bab8SIan Leporeappeared in
209*a161bab8SIan Lepore.Fx 13.0 .
210