aboutsummaryrefslogtreecommitdiff
path: root/share/man/man9/fdt_pinctrl.9
blob: 6c50488ca2ce4afe014288aed5b3c1c9798a6d0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
.\" -*- nroff -*-
.\"
.\" Copyright (c) 2018 Oleksandr Tymoshenko
.\"
.\" All rights reserved.
.\"
.\" This program is free software.
.\"
.\" 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.
.\"
.Dd June 23, 2018
.Dt fdt_pinctrl 9
.Os
.Sh NAME
.Nm fdt_pinctrl
.Nd helper functions for FDT pinmux controller drivers
.Sh SYNOPSIS
.In dev/fdt/fdt_pinctrl.h
.Ft int
.Fn fdt_pinctrl_configure "device_t client" "u_int index"
.Ft int
.Fn fdt_pinctrl_configure_by_name "device_t client" "const char * name"
.Ft int
.Fn fdt_pinctrl_register "device_t pinctrl" "const char *pinprop"
.Ft int
.Fn fdt_pinctrl_configure_tree "device_t pinctrl"
.Sh DESCRIPTION
.Xr fdt_pinctrl 4
provides an API for manipulating I/O pin configurations on
pinmux controllers and pinmux clients.
On the controller side, the standard newbus probe and
attach methods are implemented.
As part of handling attach, it calls the
.Fn fdt_pinctrl_register
function to register itself as a pinmux controller.
Then
.Fn fdt_pinctrl_configure_tree
is used to walk the device tree and configure pins specified by the pinctrl-0
property for all active devices.
The driver also implements the
.Fn fdt_pinctrl_configure
method, which allows client devices to change their
pin configurations after startup.
If a client device requires a pin configuration change at some
point of its lifecycle, it uses the
.Fn fdt_pinctrl_configure
or
.Fn fdt_pinctrl_configure_by_name
functions.
.Pp
.Fn fdt_pinctrl_configure
is used by client device
.Fa client
to request a pin configuration
described by the pinctrl-N property with index
.Fa index .
.Pp
.Fn fdt_pinctrl_configure_by_name
is used by client device
.Fa client
to request the pin configuration with name
.Fa name .
.Pp
.Fn fdt_pinctrl_register
registers a pinctrl driver so that it can be used by other devices which call
.Fn fdt_pinctrl_configure
or
.Fn fdt_pinctrl_configure_by_name .
It also registers each child node of the pinctrl driver's node which contains
a property with the name given in
.Fa pinprop .
If
.Fa pinprop
is
.Dv NULL ,
every descendant node is registered.
It is possible for the driver to register itself
as a pinmux controller for more than one pin property type
by calling
.Fn fdt_pinctrl_register
multiple types.
.Pp
.Fn fdt_pinctrl_configure_tree
walks through enabled devices in the device tree.
If the pinctrl-0 property contains references
to child nodes of the specified pinctrl device,
their pins are configured.
.Sh EXAMPLES
.Bd -literal
static int
foo_configure_pins(device_t dev, phandle_t cfgxref)
{
	phandle_t cfgnode;
	uint32_t *pins, *functions;
	int npins, nfunctions;

	cfgnode = OF_node_from_xref(cfgxref);
	pins = NULL;
	npins = OF_getencprop_alloc_multi(cfgnode, "foo,pins", sizeof(*pins),
	    (void **)&pins);
	functions = NULL;
	nfunctions = OF_getencprop_alloc_multi(cfgnode, "foo,functions",
	    sizeof(*functions), (void **)&functions);
	...
}

static int
foo_is_gpio(device_t dev, device_t gpiodev, bool *is_gpio)
{
	return (foo_is_pin_func_gpio(is_gpio));
}

static int
foo_set_flags(device_t dev, device_t gpiodev, uint32_t pin, uint32_t flags)
{
	int rv;

	rv = foo_is_pin_func_gpio(is_gpio);
	if (rv != 0)
		return (rv);
	foo_set_flags(pin, flags);
	return (0);
}

static int
foo_get_flags(device_t dev, device_t gpiodev, uint32_t pin, uint32_t *flags)
{
	int rv;

	rv = foo_is_pin_func_gpio(is_gpio);
	if (rv != 0)
		return (rv);
	foo_get_flags(pin, flags);
	return (0);
}

static int
foo_attach(device_t dev)
{
	...

	fdt_pinctrl_register(dev, "foo,pins");
	/*
	 * It is possible to register more than one pinprop handler
	 */
	fdt_pinctrl_register(dev, "bar,pins");
	fdt_pinctrl_configure_tree(dev);

	return (0);
}

static device_method_t foo_methods[] = {
	...

	/* fdt_pinctrl interface */
	DEVMETHOD(fdt_pinctrl_configure, foo_configure_pins),
	DEVMETHOD(fdt_pinctrl_is_gpio, foo_is_gpio),
	DEVMETHOD(fdt_pinctrl_set_flags, foo_set_flags),
	DEVMETHOD(fdt_pinctrl_get_flags, foo_get_flags),

	/* Terminate method list */
	DEVMETHOD_END
};

DRIVER_MODULE(foo, simplebus, foo_driver, foo_devclass, NULL, NULL);
.Ed
.Sh SEE ALSO
.Xr fdt_pinctrl 4
.Sh AUTHORS
This manual page was written by
.An Oleksandr Tymoshenko .