xref: /freebsd/sys/dev/fdt/fdt_pinctrl_if.m (revision 94292d7e954acbb0f81f804972a4b19170b687d5)
1b8ed20dbSIan Lepore#-
2b8ed20dbSIan Lepore# Copyright (c) 2014 Ian Lepore
3b8ed20dbSIan Lepore# All rights reserved.
4b8ed20dbSIan Lepore#
5b8ed20dbSIan Lepore# Redistribution and use in source and binary forms, with or without
6b8ed20dbSIan Lepore# modification, are permitted provided that the following conditions
7b8ed20dbSIan Lepore# are met:
8b8ed20dbSIan Lepore# 1. Redistributions of source code must retain the above copyright
9b8ed20dbSIan Lepore#    notice, this list of conditions and the following disclaimer.
10b8ed20dbSIan Lepore# 2. Redistributions in binary form must reproduce the above copyright
11b8ed20dbSIan Lepore#    notice, this list of conditions and the following disclaimer in the
12b8ed20dbSIan Lepore#    documentation and/or other materials provided with the distribution.
13b8ed20dbSIan Lepore#
14b8ed20dbSIan Lepore# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15b8ed20dbSIan Lepore# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16b8ed20dbSIan Lepore# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17b8ed20dbSIan Lepore# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18b8ed20dbSIan Lepore# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19b8ed20dbSIan Lepore# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20b8ed20dbSIan Lepore# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21b8ed20dbSIan Lepore# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22b8ed20dbSIan Lepore# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23b8ed20dbSIan Lepore# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24b8ed20dbSIan Lepore# SUCH DAMAGE.
25b8ed20dbSIan Lepore#
26b8ed20dbSIan Lepore# $FreeBSD$
27b8ed20dbSIan Lepore#
28b8ed20dbSIan Lepore
29b8ed20dbSIan Lepore#include <sys/types.h>
30413d07eaSEmmanuel Vadot#include <sys/bus.h>
31b8ed20dbSIan Lepore#include <dev/ofw/openfirm.h>
32b8ed20dbSIan Lepore
33b8ed20dbSIan Lepore#
34b8ed20dbSIan Lepore# This is the interface that fdt_pinctrl drivers provide to other drivers.
35b8ed20dbSIan Lepore#
36b8ed20dbSIan Lepore
37b8ed20dbSIan LeporeINTERFACE fdt_pinctrl;
38b8ed20dbSIan Lepore
39*94292d7eSEmmanuel VadotCODE {
40*94292d7eSEmmanuel Vadot	static int
41*94292d7eSEmmanuel Vadot	fdt_pinctrl_default_is_gpio(device_t pinctrl, device_t gpio, bool *is_gpio)
42*94292d7eSEmmanuel Vadot	{
43*94292d7eSEmmanuel Vadot
44*94292d7eSEmmanuel Vadot		return (EOPNOTSUPP);
45*94292d7eSEmmanuel Vadot	}
46*94292d7eSEmmanuel Vadot
47*94292d7eSEmmanuel Vadot	static int
48*94292d7eSEmmanuel Vadot	fdt_pinctrl_default_set_flags(device_t pinctrl, device_t gpio, uint32_t pin,
49*94292d7eSEmmanuel Vadot	    uint32_t flags)
50*94292d7eSEmmanuel Vadot	{
51*94292d7eSEmmanuel Vadot
52*94292d7eSEmmanuel Vadot		return (EOPNOTSUPP);
53*94292d7eSEmmanuel Vadot	}
54*94292d7eSEmmanuel Vadot
55*94292d7eSEmmanuel Vadot	static int
56*94292d7eSEmmanuel Vadot	fdt_pinctrl_default_get_flags(device_t pinctrl, device_t gpio, uint32_t pin,
57*94292d7eSEmmanuel Vadot	    uint32_t *flags)
58*94292d7eSEmmanuel Vadot	{
59*94292d7eSEmmanuel Vadot
60*94292d7eSEmmanuel Vadot		return (EOPNOTSUPP);
61*94292d7eSEmmanuel Vadot	}
62*94292d7eSEmmanuel Vadot};
63*94292d7eSEmmanuel Vadot
64413d07eaSEmmanuel Vadot# Needed for timestamping device probe/attach calls
65413d07eaSEmmanuel VadotHEADER {
66413d07eaSEmmanuel Vadot	#include <sys/tslog.h>
67413d07eaSEmmanuel Vadot}
68413d07eaSEmmanuel Vadot
69b8ed20dbSIan Lepore#
70b8ed20dbSIan Lepore# Set pins to the specified configuration.  The cfgxref arg is an xref phandle
71b8ed20dbSIan Lepore# to a descendent node (child, grandchild, ...) of the pinctrl device node.
72b8ed20dbSIan Lepore# Returns 0 on success or a standard errno value.
73b8ed20dbSIan Lepore#
74413d07eaSEmmanuel VadotPROLOG {
75413d07eaSEmmanuel Vadot	TSENTER2(device_get_name(pinctrl));
76413d07eaSEmmanuel Vadot}
77413d07eaSEmmanuel VadotEPILOG {
78413d07eaSEmmanuel Vadot	TSEXIT2(device_get_name(pinctrl));
79413d07eaSEmmanuel Vadot}
80b8ed20dbSIan LeporeMETHOD int configure {
81b8ed20dbSIan Lepore	device_t	pinctrl;
82b8ed20dbSIan Lepore	phandle_t	cfgxref;
83b8ed20dbSIan Lepore};
84b8ed20dbSIan Lepore
85*94292d7eSEmmanuel Vadot
86*94292d7eSEmmanuel Vadot#
87*94292d7eSEmmanuel Vadot# Test if the pin is in gpio mode
88*94292d7eSEmmanuel Vadot# Called from a gpio device
89*94292d7eSEmmanuel Vadot#
90*94292d7eSEmmanuel VadotMETHOD int is_gpio {
91*94292d7eSEmmanuel Vadot	device_t pinctrl;
92*94292d7eSEmmanuel Vadot	device_t gpio;
93*94292d7eSEmmanuel Vadot	uint32_t pin;
94*94292d7eSEmmanuel Vadot	bool *is_gpio;
95*94292d7eSEmmanuel Vadot} DEFAULT fdt_pinctrl_default_is_gpio;
96*94292d7eSEmmanuel Vadot
97*94292d7eSEmmanuel Vadot#
98*94292d7eSEmmanuel Vadot# Set the flags of a pin
99*94292d7eSEmmanuel Vadot# Called from a gpio device
100*94292d7eSEmmanuel Vadot#
101*94292d7eSEmmanuel VadotMETHOD int set_flags {
102*94292d7eSEmmanuel Vadot	device_t pinctrl;
103*94292d7eSEmmanuel Vadot	device_t gpio;
104*94292d7eSEmmanuel Vadot	uint32_t pin;
105*94292d7eSEmmanuel Vadot	uint32_t flags;
106*94292d7eSEmmanuel Vadot} DEFAULT fdt_pinctrl_default_set_flags;
107*94292d7eSEmmanuel Vadot
108*94292d7eSEmmanuel Vadot#
109*94292d7eSEmmanuel Vadot# Get the flags of a pin
110*94292d7eSEmmanuel Vadot# Called from a gpio device
111*94292d7eSEmmanuel Vadot#
112*94292d7eSEmmanuel VadotMETHOD int get_flags {
113*94292d7eSEmmanuel Vadot	device_t pinctrl;
114*94292d7eSEmmanuel Vadot	device_t gpio;
115*94292d7eSEmmanuel Vadot	uint32_t pin;
116*94292d7eSEmmanuel Vadot	uint32_t *flags;
117*94292d7eSEmmanuel Vadot} DEFAULT fdt_pinctrl_default_get_flags;
118