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# 27b8ed20dbSIan Lepore 28b8ed20dbSIan Lepore#include <sys/types.h> 29413d07eaSEmmanuel Vadot#include <sys/bus.h> 30b8ed20dbSIan Lepore#include <dev/ofw/openfirm.h> 31b8ed20dbSIan Lepore 32b8ed20dbSIan Lepore# 33b8ed20dbSIan Lepore# This is the interface that fdt_pinctrl drivers provide to other drivers. 34b8ed20dbSIan Lepore# 35b8ed20dbSIan Lepore 36b8ed20dbSIan LeporeINTERFACE fdt_pinctrl; 37b8ed20dbSIan Lepore 38*94292d7eSEmmanuel VadotCODE { 39*94292d7eSEmmanuel Vadot static int 40*94292d7eSEmmanuel Vadot fdt_pinctrl_default_is_gpio(device_t pinctrl, device_t gpio, bool *is_gpio) 41*94292d7eSEmmanuel Vadot { 42*94292d7eSEmmanuel Vadot 43*94292d7eSEmmanuel Vadot return (EOPNOTSUPP); 44*94292d7eSEmmanuel Vadot } 45*94292d7eSEmmanuel Vadot 46*94292d7eSEmmanuel Vadot static int 47*94292d7eSEmmanuel Vadot fdt_pinctrl_default_set_flags(device_t pinctrl, device_t gpio, uint32_t pin, 48*94292d7eSEmmanuel Vadot uint32_t flags) 49*94292d7eSEmmanuel Vadot { 50*94292d7eSEmmanuel Vadot 51*94292d7eSEmmanuel Vadot return (EOPNOTSUPP); 52*94292d7eSEmmanuel Vadot } 53*94292d7eSEmmanuel Vadot 54*94292d7eSEmmanuel Vadot static int 55*94292d7eSEmmanuel Vadot fdt_pinctrl_default_get_flags(device_t pinctrl, device_t gpio, uint32_t pin, 56*94292d7eSEmmanuel Vadot uint32_t *flags) 57*94292d7eSEmmanuel Vadot { 58*94292d7eSEmmanuel Vadot 59*94292d7eSEmmanuel Vadot return (EOPNOTSUPP); 60*94292d7eSEmmanuel Vadot } 61*94292d7eSEmmanuel Vadot}; 62*94292d7eSEmmanuel Vadot 63413d07eaSEmmanuel Vadot# Needed for timestamping device probe/attach calls 64413d07eaSEmmanuel VadotHEADER { 65413d07eaSEmmanuel Vadot #include <sys/tslog.h> 66413d07eaSEmmanuel Vadot} 67413d07eaSEmmanuel Vadot 68b8ed20dbSIan Lepore# 69b8ed20dbSIan Lepore# Set pins to the specified configuration. The cfgxref arg is an xref phandle 70b8ed20dbSIan Lepore# to a descendent node (child, grandchild, ...) of the pinctrl device node. 71b8ed20dbSIan Lepore# Returns 0 on success or a standard errno value. 72b8ed20dbSIan Lepore# 73413d07eaSEmmanuel VadotPROLOG { 74413d07eaSEmmanuel Vadot TSENTER2(device_get_name(pinctrl)); 75413d07eaSEmmanuel Vadot} 76413d07eaSEmmanuel VadotEPILOG { 77413d07eaSEmmanuel Vadot TSEXIT2(device_get_name(pinctrl)); 78413d07eaSEmmanuel Vadot} 79b8ed20dbSIan LeporeMETHOD int configure { 80b8ed20dbSIan Lepore device_t pinctrl; 81b8ed20dbSIan Lepore phandle_t cfgxref; 82b8ed20dbSIan Lepore}; 83b8ed20dbSIan Lepore 84*94292d7eSEmmanuel Vadot 85*94292d7eSEmmanuel Vadot# 86*94292d7eSEmmanuel Vadot# Test if the pin is in gpio mode 87*94292d7eSEmmanuel Vadot# Called from a gpio device 88*94292d7eSEmmanuel Vadot# 89*94292d7eSEmmanuel VadotMETHOD int is_gpio { 90*94292d7eSEmmanuel Vadot device_t pinctrl; 91*94292d7eSEmmanuel Vadot device_t gpio; 92*94292d7eSEmmanuel Vadot uint32_t pin; 93*94292d7eSEmmanuel Vadot bool *is_gpio; 94*94292d7eSEmmanuel Vadot} DEFAULT fdt_pinctrl_default_is_gpio; 95*94292d7eSEmmanuel Vadot 96*94292d7eSEmmanuel Vadot# 97*94292d7eSEmmanuel Vadot# Set the flags of a pin 98*94292d7eSEmmanuel Vadot# Called from a gpio device 99*94292d7eSEmmanuel Vadot# 100*94292d7eSEmmanuel VadotMETHOD int set_flags { 101*94292d7eSEmmanuel Vadot device_t pinctrl; 102*94292d7eSEmmanuel Vadot device_t gpio; 103*94292d7eSEmmanuel Vadot uint32_t pin; 104*94292d7eSEmmanuel Vadot uint32_t flags; 105*94292d7eSEmmanuel Vadot} DEFAULT fdt_pinctrl_default_set_flags; 106*94292d7eSEmmanuel Vadot 107*94292d7eSEmmanuel Vadot# 108*94292d7eSEmmanuel Vadot# Get the flags of a pin 109*94292d7eSEmmanuel Vadot# Called from a gpio device 110*94292d7eSEmmanuel Vadot# 111*94292d7eSEmmanuel VadotMETHOD int get_flags { 112*94292d7eSEmmanuel Vadot device_t pinctrl; 113*94292d7eSEmmanuel Vadot device_t gpio; 114*94292d7eSEmmanuel Vadot uint32_t pin; 115*94292d7eSEmmanuel Vadot uint32_t *flags; 116*94292d7eSEmmanuel Vadot} DEFAULT fdt_pinctrl_default_get_flags; 117