xref: /freebsd/share/man/man4/pwmc.4 (revision f126890a)
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.Dd June 17, 2019
26.Dt PWMC 4
27.Os
28.Sh NAME
29.Nm pwmc
30.Nd PWM (Pulse Width Modulation) control device driver
31.Sh SYNOPSIS
32To compile this driver into the kernel,
33place the following lines in your
34kernel configuration file:
35.Bd -ragged -offset indent
36.Cd "device pwmbus"
37.Cd "device pwmc"
38.Ed
39.Pp
40Alternatively, to load the driver as a
41module at boot time, place the following line in
42.Xr loader.conf 5 :
43.Bd -literal -offset indent
44pwmc_load="YES"
45.Ed
46.Sh DESCRIPTION
47The
48.Nm
49driver provides device-control access to a channel of PWM hardware.
50Each instance of a
51.Nm
52device is associated with a single PWM output channel.
53.Pp
54Some PWM hardware is organized with multiple channels sharing a
55common clock or other resources.
56In such cases, a separate
57.Nm
58instance will exist for each channel, but changing the period or
59duty cycle of any one channel may affect other channels within the
60hardware which share the same resources.
61Consult the documentation for the underlying PWM hardware device driver
62for details on channels that share resources.
63.Pp
64An instance of
65.Nm
66creates a character device named
67.Pa /dev/pwm/pwmcX.Y
68where
69.Va X
70is a sequential number assigned to each PWM hardware controller
71as it is discovered by the system, and
72.Va Y
73is the channel number within that hardware controller.
74The driver can be configured to create aliases that point to the
75.Pa pwmcX.Y
76entries, in effect creating named channels.
77.Pp
78The
79.Nm
80driver provides control of a PWM channel with the following
81.Xr ioctl 2
82calls and data structures, defined in
83.In dev/pwm/pwmc.h :
84.Bl -tag -width indent
85.It Dv PWMGETSTATE Pq Vt "struct pwm_state"
86Retrieve the current state of the channel.
87.It Dv PWMSETSTATE Pq Vt "struct pwm_state"
88Set the current state of the channel.
89All parameters are updated on every call.
90To change just one of the values, use
91.Dv PWMGETSTATE
92to get the current state and then submit the same data back with
93just the appropriate value changed.
94.El
95.Pp
96The
97.Va pwm_state
98structure is defined as follows:
99.Bd -literal
100struct pwm_state {
101	u_int		period;
102	u_int		duty;
103	uint32_t	flags;
104	bool		enable;
105};
106.Ed
107.Bl -tag -width period
108.It Va period
109The duration, in nanoseconds, of one complete on-off cycle.
110.It Va duty
111The duration, in nanoseconds, of the on portion of one cycle.
112.It Va flags
113Flags that affect the output signal can be bitwise-ORed together.
114The following flags are currently defined:
115.Pp
116.Bl -tag -width PWM_POLARITY_INVERTED -compact
117.It Dv PWM_POLARITY_INVERTED
118Invert the signal polarity.
119.El
120.It Va enable
121.Va
122False to disable the output signal or true to enable it.
123.El
124.Sh HINTS CONFIGURATION
125On a
126.Xr device.hints 5
127based system, such as
128.Li MIPS ,
129these values are configurable for
130.Nm :
131.Bl -tag -width indent
132.It Va hint.pwmc.%d.at
133The pwmbus instance the
134.Nm
135instance is attached to.
136.It Va hint.pwmc.%d.channel
137The hardware channel number the instance is attached to.
138Channel numbers count up from zero.
139.It Va hint.pwmc.%d.label
140If this optional hint is set, the driver creates an alias in
141.Pa /dev/pwm
142with the given name, which points to the instance.
143.El
144.Sh FDT CONFIGURATION
145On an
146.Xr fdt 4
147based system, a
148.Nm
149device is described with a child node of the pwm hardware controller node.
150When the hardware supports multiple channels within the controller, it is
151not necessary to include a
152.Nm
153child node for every channel the hardware supports.
154Define only the channels you need to control.
155.Pp
156The following properties are required for a
157.Nm
158device node:
159.Bl -tag -width indent
160.It Va compatible
161Must be the string "freebsd,pwmc".
162.It Va reg
163The hardware channel number.
164.El
165.Pp
166The following properties are optional for the
167.Nm
168device node:
169.Bl -tag -width indent
170.It Va label
171A string containing only characters legal in a file name.
172The driver creates an alias with the given name in
173.Pa /dev/pwm
174which points to the instance's
175.Pa /dev/pwm/pwmcX.Y
176device entry.
177.El
178.Pp
179Example of a PWM hardware node containing one
180.Nm
181child node:
182.Bd -literal
183&ehrpwm0 {
184    status = "okay";
185    pinctrl-names = "default";
186    pinctrl-0 = <&ehrpwm0_AB_pins>;
187
188    pwmcontrol@0 {
189        compatible = "freebsd,pwmc";
190        reg = <0>;
191        label = "backlight";
192    };
193};
194.Ed
195.Sh FILES
196.Bl -tag -width -compact
197.It Pa /dev/pwm/pwmc*
198.El
199.Sh SEE ALSO
200.Xr fdt 4 ,
201.Xr device.hints 5 ,
202.Xr pwm 8 ,
203.Xr pwm 9
204.Sh HISTORY
205The
206.Nm
207driver
208appeared in
209.Fx 13.0 .
210