16b34b16eSOleksandr Tymoshenko#- 26b34b16eSOleksandr Tymoshenko# Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org> 36b34b16eSOleksandr Tymoshenko# All rights reserved. 46b34b16eSOleksandr Tymoshenko# 56b34b16eSOleksandr Tymoshenko# Redistribution and use in source and binary forms, with or without 66b34b16eSOleksandr Tymoshenko# modification, are permitted provided that the following conditions 76b34b16eSOleksandr Tymoshenko# are met: 86b34b16eSOleksandr Tymoshenko# 1. Redistributions of source code must retain the above copyright 96b34b16eSOleksandr Tymoshenko# notice, this list of conditions and the following disclaimer. 106b34b16eSOleksandr Tymoshenko# 2. Redistributions in binary form must reproduce the above copyright 116b34b16eSOleksandr Tymoshenko# notice, this list of conditions and the following disclaimer in the 126b34b16eSOleksandr Tymoshenko# documentation and/or other materials provided with the distribution. 136b34b16eSOleksandr Tymoshenko# 146b34b16eSOleksandr Tymoshenko# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 156b34b16eSOleksandr Tymoshenko# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 166b34b16eSOleksandr Tymoshenko# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 176b34b16eSOleksandr Tymoshenko# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 186b34b16eSOleksandr Tymoshenko# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 196b34b16eSOleksandr Tymoshenko# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 206b34b16eSOleksandr Tymoshenko# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 216b34b16eSOleksandr Tymoshenko# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 226b34b16eSOleksandr Tymoshenko# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 236b34b16eSOleksandr Tymoshenko# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 246b34b16eSOleksandr Tymoshenko# SUCH DAMAGE. 256b34b16eSOleksandr Tymoshenko# 266b34b16eSOleksandr Tymoshenko# $FreeBSD$ 276b34b16eSOleksandr Tymoshenko# 286b34b16eSOleksandr Tymoshenko 296b34b16eSOleksandr Tymoshenko#include <sys/bus.h> 306b34b16eSOleksandr Tymoshenko#include <sys/gpio.h> 316b34b16eSOleksandr Tymoshenko 326b34b16eSOleksandr TymoshenkoINTERFACE gpio; 336b34b16eSOleksandr Tymoshenko 34*8d250595SLuiz Otavio O SouzaCODE { 35*8d250595SLuiz Otavio O Souza static gpio_map_gpios_t gpio_default_map_gpios; 36*8d250595SLuiz Otavio O Souza 37*8d250595SLuiz Otavio O Souza int 38*8d250595SLuiz Otavio O Souza gpio_default_map_gpios(device_t bus, phandle_t dev, 39*8d250595SLuiz Otavio O Souza phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin, 40*8d250595SLuiz Otavio O Souza uint32_t *flags) 41*8d250595SLuiz Otavio O Souza { 42*8d250595SLuiz Otavio O Souza /* Propagate up the bus hierarchy until someone handles it. */ 43*8d250595SLuiz Otavio O Souza if (device_get_parent(bus) != NULL) 44*8d250595SLuiz Otavio O Souza return (GPIO_MAP_GPIOS(device_get_parent(bus), dev, 45*8d250595SLuiz Otavio O Souza gparent, gcells, gpios, pin, flags)); 46*8d250595SLuiz Otavio O Souza 47*8d250595SLuiz Otavio O Souza /* If that fails, then assume the FreeBSD defaults. */ 48*8d250595SLuiz Otavio O Souza *pin = gpios[0]; 49*8d250595SLuiz Otavio O Souza if (gcells == 2 || gcells == 3) 50*8d250595SLuiz Otavio O Souza *flags = gpios[gcells - 1]; 51*8d250595SLuiz Otavio O Souza 52*8d250595SLuiz Otavio O Souza return (0); 53*8d250595SLuiz Otavio O Souza } 54*8d250595SLuiz Otavio O Souza}; 55*8d250595SLuiz Otavio O Souza 56*8d250595SLuiz Otavio O SouzaHEADER { 57*8d250595SLuiz Otavio O Souza #include <dev/ofw/openfirm.h> 58*8d250595SLuiz Otavio O Souza}; 59*8d250595SLuiz Otavio O Souza 606b34b16eSOleksandr Tymoshenko# 616b34b16eSOleksandr Tymoshenko# Get total number of pins 626b34b16eSOleksandr Tymoshenko# 636b34b16eSOleksandr TymoshenkoMETHOD int pin_max { 646b34b16eSOleksandr Tymoshenko device_t dev; 656b34b16eSOleksandr Tymoshenko int *npins; 666b34b16eSOleksandr Tymoshenko}; 676b34b16eSOleksandr Tymoshenko 686b34b16eSOleksandr Tymoshenko# 696b34b16eSOleksandr Tymoshenko# Set value of pin specifed by pin_num 706b34b16eSOleksandr Tymoshenko# 716b34b16eSOleksandr TymoshenkoMETHOD int pin_set { 726b34b16eSOleksandr Tymoshenko device_t dev; 736b34b16eSOleksandr Tymoshenko uint32_t pin_num; 746b34b16eSOleksandr Tymoshenko uint32_t pin_value; 756b34b16eSOleksandr Tymoshenko}; 766b34b16eSOleksandr Tymoshenko 776b34b16eSOleksandr Tymoshenko# 786b34b16eSOleksandr Tymoshenko# Get value of pin specifed by pin_num 796b34b16eSOleksandr Tymoshenko# 806b34b16eSOleksandr TymoshenkoMETHOD int pin_get { 816b34b16eSOleksandr Tymoshenko device_t dev; 826b34b16eSOleksandr Tymoshenko uint32_t pin_num; 836b34b16eSOleksandr Tymoshenko uint32_t *pin_value; 846b34b16eSOleksandr Tymoshenko}; 856b34b16eSOleksandr Tymoshenko 866b34b16eSOleksandr Tymoshenko# 876b34b16eSOleksandr Tymoshenko# Toggle value of pin specifed by pin_num 886b34b16eSOleksandr Tymoshenko# 896b34b16eSOleksandr TymoshenkoMETHOD int pin_toggle { 906b34b16eSOleksandr Tymoshenko device_t dev; 916b34b16eSOleksandr Tymoshenko uint32_t pin_num; 926b34b16eSOleksandr Tymoshenko}; 936b34b16eSOleksandr Tymoshenko 946b34b16eSOleksandr Tymoshenko# 956b34b16eSOleksandr Tymoshenko# Get pin capabilities 966b34b16eSOleksandr Tymoshenko# 976b34b16eSOleksandr TymoshenkoMETHOD int pin_getcaps { 986b34b16eSOleksandr Tymoshenko device_t dev; 996b34b16eSOleksandr Tymoshenko uint32_t pin_num; 1006b34b16eSOleksandr Tymoshenko uint32_t *caps; 1016b34b16eSOleksandr Tymoshenko}; 1026b34b16eSOleksandr Tymoshenko 1036b34b16eSOleksandr Tymoshenko# 1046b34b16eSOleksandr Tymoshenko# Get pin flags 1056b34b16eSOleksandr Tymoshenko# 1066b34b16eSOleksandr TymoshenkoMETHOD int pin_getflags { 1076b34b16eSOleksandr Tymoshenko device_t dev; 1086b34b16eSOleksandr Tymoshenko uint32_t pin_num; 1096b34b16eSOleksandr Tymoshenko uint32_t *flags; 1106b34b16eSOleksandr Tymoshenko}; 1116b34b16eSOleksandr Tymoshenko 1126b34b16eSOleksandr Tymoshenko# 1136b34b16eSOleksandr Tymoshenko# Get pin name 1146b34b16eSOleksandr Tymoshenko# 1156b34b16eSOleksandr TymoshenkoMETHOD int pin_getname { 1166b34b16eSOleksandr Tymoshenko device_t dev; 1176b34b16eSOleksandr Tymoshenko uint32_t pin_num; 1186b34b16eSOleksandr Tymoshenko char *name; 1196b34b16eSOleksandr Tymoshenko}; 1206b34b16eSOleksandr Tymoshenko 1216b34b16eSOleksandr Tymoshenko# 1226b34b16eSOleksandr Tymoshenko# Set current configuration and capabilities 1236b34b16eSOleksandr Tymoshenko# 1246b34b16eSOleksandr TymoshenkoMETHOD int pin_setflags { 1256b34b16eSOleksandr Tymoshenko device_t dev; 1266b34b16eSOleksandr Tymoshenko uint32_t pin_num; 1276b34b16eSOleksandr Tymoshenko uint32_t flags; 1286b34b16eSOleksandr Tymoshenko}; 129*8d250595SLuiz Otavio O Souza 130*8d250595SLuiz Otavio O Souza# 131*8d250595SLuiz Otavio O Souza# Allow the GPIO controller to map the gpio-specifier on its own. 132*8d250595SLuiz Otavio O Souza# 133*8d250595SLuiz Otavio O SouzaMETHOD int map_gpios { 134*8d250595SLuiz Otavio O Souza device_t bus; 135*8d250595SLuiz Otavio O Souza phandle_t dev; 136*8d250595SLuiz Otavio O Souza phandle_t gparent; 137*8d250595SLuiz Otavio O Souza int gcells; 138*8d250595SLuiz Otavio O Souza pcell_t *gpios; 139*8d250595SLuiz Otavio O Souza uint32_t *pin; 140*8d250595SLuiz Otavio O Souza uint32_t *flags; 141*8d250595SLuiz Otavio O Souza} DEFAULT gpio_default_map_gpios; 142