1213237Sgonzo#-
2213237Sgonzo# Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org>
3213237Sgonzo# All rights reserved.
4213237Sgonzo#
5213237Sgonzo# Redistribution and use in source and binary forms, with or without
6213237Sgonzo# modification, are permitted provided that the following conditions
7213237Sgonzo# are met:
8213237Sgonzo# 1. Redistributions of source code must retain the above copyright
9213237Sgonzo#    notice, this list of conditions and the following disclaimer.
10213237Sgonzo# 2. Redistributions in binary form must reproduce the above copyright
11213237Sgonzo#    notice, this list of conditions and the following disclaimer in the
12213237Sgonzo#    documentation and/or other materials provided with the distribution.
13213237Sgonzo#
14213237Sgonzo# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15213237Sgonzo# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16213237Sgonzo# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17213237Sgonzo# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18213237Sgonzo# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19213237Sgonzo# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20213237Sgonzo# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21213237Sgonzo# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22213237Sgonzo# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23213237Sgonzo# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24213237Sgonzo# SUCH DAMAGE.
25213237Sgonzo#
26213237Sgonzo# $FreeBSD: releng/10.2/sys/dev/gpio/gpio_if.m 278786 2015-02-14 21:16:19Z loos $
27213237Sgonzo#
28213237Sgonzo
29213237Sgonzo#include <sys/bus.h>
30213237Sgonzo#include <sys/gpio.h>
31213237Sgonzo
32213237SgonzoINTERFACE gpio;
33213237Sgonzo
34266135SloosCODE {
35278786Sloos	static int
36266135Sloos	gpio_default_map_gpios(device_t bus, phandle_t dev,
37266135Sloos	    phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin,
38266135Sloos	    uint32_t *flags)
39266135Sloos	{
40266135Sloos		/* Propagate up the bus hierarchy until someone handles it. */  
41266135Sloos		if (device_get_parent(bus) != NULL)
42266135Sloos			return (GPIO_MAP_GPIOS(device_get_parent(bus), dev,
43266135Sloos			    gparent, gcells, gpios, pin, flags));
44266135Sloos
45266135Sloos		/* If that fails, then assume the FreeBSD defaults. */
46266135Sloos		*pin = gpios[0];
47266135Sloos		if (gcells == 2 || gcells == 3)
48266135Sloos			*flags = gpios[gcells - 1];
49266135Sloos
50266135Sloos		return (0);
51266135Sloos	}
52266135Sloos};
53266135Sloos
54266135SloosHEADER {
55266135Sloos	#include <dev/ofw/openfirm.h>
56266135Sloos};
57266135Sloos
58213237Sgonzo#
59278786Sloos# Get maximum pin number
60213237Sgonzo#
61213237SgonzoMETHOD int pin_max {
62213237Sgonzo	device_t dev;
63278786Sloos	int *maxpin;
64213237Sgonzo};
65213237Sgonzo
66213237Sgonzo#
67213237Sgonzo# Set value of pin specifed by pin_num 
68213237Sgonzo#
69213237SgonzoMETHOD int pin_set {
70213237Sgonzo	device_t dev;
71213237Sgonzo	uint32_t pin_num;
72213237Sgonzo	uint32_t pin_value;
73213237Sgonzo};
74213237Sgonzo
75213237Sgonzo#
76213237Sgonzo# Get value of pin specifed by pin_num 
77213237Sgonzo#
78213237SgonzoMETHOD int pin_get {
79213237Sgonzo	device_t dev;
80213237Sgonzo	uint32_t pin_num;
81213237Sgonzo	uint32_t *pin_value;
82213237Sgonzo};
83213237Sgonzo
84213237Sgonzo#
85213237Sgonzo# Toggle value of pin specifed by pin_num 
86213237Sgonzo#
87213237SgonzoMETHOD int pin_toggle {
88213237Sgonzo	device_t dev;
89213237Sgonzo	uint32_t pin_num;
90213237Sgonzo};
91213237Sgonzo
92213237Sgonzo#
93213237Sgonzo# Get pin capabilities
94213237Sgonzo#
95213237SgonzoMETHOD int pin_getcaps {
96213237Sgonzo	device_t dev;
97213237Sgonzo	uint32_t pin_num;
98213237Sgonzo	uint32_t *caps;
99213237Sgonzo};
100213237Sgonzo
101213237Sgonzo#
102213237Sgonzo# Get pin flags
103213237Sgonzo#
104213237SgonzoMETHOD int pin_getflags {
105213237Sgonzo	device_t dev;
106213237Sgonzo	uint32_t pin_num;
107213237Sgonzo	uint32_t *flags;
108213237Sgonzo};
109213237Sgonzo
110213237Sgonzo#
111213237Sgonzo# Get pin name
112213237Sgonzo#
113213237SgonzoMETHOD int pin_getname {
114213237Sgonzo	device_t dev;
115213237Sgonzo	uint32_t pin_num;
116213237Sgonzo	char *name;
117213237Sgonzo};
118213237Sgonzo
119213237Sgonzo#
120213237Sgonzo# Set current configuration and capabilities
121213237Sgonzo#
122213237SgonzoMETHOD int pin_setflags {
123213237Sgonzo	device_t dev;
124213237Sgonzo	uint32_t pin_num;
125213237Sgonzo	uint32_t flags;
126213237Sgonzo};
127266135Sloos
128266135Sloos#
129266135Sloos# Allow the GPIO controller to map the gpio-specifier on its own.
130266135Sloos#
131266135SloosMETHOD int map_gpios {
132266135Sloos        device_t bus;
133266135Sloos        phandle_t dev;
134266135Sloos        phandle_t gparent;
135266135Sloos        int gcells;
136266135Sloos        pcell_t *gpios;
137266135Sloos        uint32_t *pin;
138266135Sloos        uint32_t *flags;
139266135Sloos} DEFAULT gpio_default_map_gpios;
140