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