3 .\" Copyright (c) 2018 Oleksandr Tymoshenko
5 .\" All rights reserved.
7 .\" This program is free software.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 .Nd helper functions for FDT pinmux controller drivers
38 .In dev/fdt/fdt_pinctrl.h
40 .Fn fdt_pinctrl_configure "device_t client" "u_int index"
42 .Fn fdt_pinctrl_configure_by_name "device_t client" "const char * name"
44 .Fn fdt_pinctrl_register "device_t pinctrl" "const char *pinprop"
46 .Fn fdt_pinctrl_configure_tree "device_t pinctrl"
49 provides an API for manipulating I/O pin configurations on
50 pinmux controllers and pinmux clients.
51 On the controller side, the standard newbus probe and
52 attach methods are implemented.
53 As part of handling attach, it calls the
54 .Fn fdt_pinctrl_register
55 function to register itself as a pinmux controller.
57 .Fn fdt_pinctrl_configure_tree
58 is used to walk the device tree and configure pins specified by the pinctrl-0
59 property for all active devices.
60 The driver also implements the
61 .Fn fdt_pinctrl_configure
62 method, which allows client devices to change their
63 pin configurations after startup.
64 If a client device requires a pin configuration change at some
65 point of its lifecycle, it uses the
66 .Fn fdt_pinctrl_configure
68 .Fn fdt_pinctrl_configure_by_name
71 .Fn fdt_pinctrl_configure
72 is used by client device
74 to request a pin configuration
75 described by the pinctrl-N property with index
78 .Fn fdt_pinctrl_configure_by_name
79 is used by client device
81 to request the pin configuration with name
84 .Fn fdt_pinctrl_register
85 registers a pinctrl driver so that it can be used by other devices which call
86 .Fn fdt_pinctrl_configure
88 .Fn fdt_pinctrl_configure_by_name .
89 It also registers each child node of the pinctrl driver's node which contains
90 a property with the name given in
96 every descendant node is registered.
97 It is possible for the driver to register itself
98 as a pinmux controller for more than one pin property type
100 .Fn fdt_pinctrl_register
103 .Fn fdt_pinctrl_configure_tree
104 walks through enabled devices in the device tree.
105 If the pinctrl-0 property contains references
106 to child nodes of the specified pinctrl device,
107 their pins are configured.
111 foo_configure_pins(device_t dev, phandle_t cfgxref)
114 uint32_t *pins, *functions;
115 int npins, nfunctions;
117 cfgnode = OF_node_from_xref(cfgxref);
119 npins = OF_getencprop_alloc_multi(cfgnode, "foo,pins", sizeof(*pins),
122 nfunctions = OF_getencprop_alloc_multi(cfgnode, "foo,functions",
123 sizeof(*functions), (void **)&functions);
128 foo_is_gpio(device_t dev, device_t gpiodev, bool *is_gpio)
130 return (foo_is_pin_func_gpio(is_gpio));
134 foo_set_flags(device_t dev, device_t gpiodev, uint32_t pin, uint32_t flags)
138 rv = foo_is_pin_func_gpio(is_gpio);
141 foo_set_flags(pin, flags);
146 foo_get_flags(device_t dev, device_t gpiodev, uint32_t pin, uint32_t *flags)
150 rv = foo_is_pin_func_gpio(is_gpio);
153 foo_get_flags(pin, flags);
158 foo_attach(device_t dev)
162 fdt_pinctrl_register(dev, "foo,pins");
164 * It is possible to register more than one pinprop handler
166 fdt_pinctrl_register(dev, "bar,pins");
167 fdt_pinctrl_configure_tree(dev);
172 static device_method_t foo_methods[] = {
175 /* fdt_pinctrl interface */
176 DEVMETHOD(fdt_pinctrl_configure, foo_configure_pins),
177 DEVMETHOD(fdt_pinctrl_is_gpio, foo_is_gpio),
178 DEVMETHOD(fdt_pinctrl_set_flags, foo_set_flags),
179 DEVMETHOD(fdt_pinctrl_get_flags, foo_get_flags),
181 /* Terminate method list */
185 DRIVER_MODULE(foo, simplebus, foo_driver, foo_devclass, NULL, NULL);
190 This manual page was written by
191 .An Oleksandr Tymoshenko .