2 # Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 gpio_default_get_bus(void)
43 gpio_default_nosupport(void)
50 gpio_default_map_gpios(device_t bus, phandle_t dev,
51 phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin,
54 /* Propagate up the bus hierarchy until someone handles it. */
55 if (device_get_parent(bus) != NULL)
56 return (GPIO_MAP_GPIOS(device_get_parent(bus), dev,
57 gparent, gcells, gpios, pin, flags));
59 /* If that fails, then assume the FreeBSD defaults. */
61 if (gcells == 2 || gcells == 3)
62 *flags = gpios[gcells - 1];
69 #include <dev/ofw/openfirm.h>
73 # Return the gpiobus device reference
75 METHOD device_t get_bus {
77 } DEFAULT gpio_default_get_bus;
80 # Get maximum pin number
88 # Set value of pin specifed by pin_num
97 # Get value of pin specifed by pin_num
106 # Toggle value of pin specifed by pin_num
108 METHOD int pin_toggle {
114 # Get pin capabilities
116 METHOD int pin_getcaps {
125 METHOD int pin_getflags {
134 METHOD int pin_getname {
141 # Set current configuration and capabilities
143 METHOD int pin_setflags {
150 # Allow the GPIO controller to map the gpio-specifier on its own.
152 METHOD int map_gpios {
160 } DEFAULT gpio_default_map_gpios;
163 # Simultaneously read and/or change up to 32 adjacent pins.
164 # If the device cannot change the pins simultaneously, returns EOPNOTSUPP.
166 # More details about using this interface can be found in sys/gpio.h
168 METHOD int pin_access_32 {
172 uint32_t change_pins;
174 } DEFAULT gpio_default_nosupport;
177 # Simultaneously configure up to 32 adjacent pins.
178 # This is intended to change the configuration of all the pins simultaneously,
179 # but unlike pin_access_32, this will not fail if the hardware can't do so.
181 # More details about using this interface can be found in sys/gpio.h
183 METHOD int pin_config_32 {
188 } DEFAULT gpio_default_nosupport;