gpiovar.h revision 1.2
1/* $OpenBSD: gpiovar.h,v 1.2 2006/01/05 11:52:24 grange Exp $ */ 2 3/* 4 * Copyright (c) 2004, 2006 Alexander Yurchenko <grange@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#ifndef _DEV_GPIO_GPIOVAR_H_ 20#define _DEV_GPIO_GPIOVAR_H_ 21 22/* GPIO controller description */ 23typedef struct gpio_chipset_tag { 24 void *gp_cookie; 25 26 int (*gp_pin_read)(void *, int); 27 void (*gp_pin_write)(void *, int, int); 28 void (*gp_pin_ctl)(void *, int, int); 29} *gpio_chipset_tag_t; 30 31/* GPIO pin description */ 32typedef struct gpio_pin { 33 int pin_num; /* number */ 34 int pin_caps; /* capabilities */ 35 int pin_flags; /* current configuration */ 36 int pin_state; /* current state */ 37 int pin_mapped; /* is mapped */ 38} gpio_pin_t; 39 40/* Attach GPIO framework to the controller */ 41struct gpiobus_attach_args { 42 const char *gba_name; /* bus name */ 43 gpio_chipset_tag_t gba_gc; /* underlying controller */ 44 gpio_pin_t *gba_pins; /* pins array */ 45 int gba_npins; /* total number of pins */ 46}; 47 48int gpiobus_print(void *, const char *); 49 50/* GPIO framework private methods */ 51#define gpiobus_pin_read(gc, pin) \ 52 ((gc)->gp_pin_read((gc)->gp_cookie, (pin))) 53#define gpiobus_pin_write(gc, pin, value) \ 54 ((gc)->gp_pin_write((gc)->gp_cookie, (pin), (value))) 55#define gpiobus_pin_ctl(gc, pin, flags) \ 56 ((gc)->gp_pin_ctl((gc)->gp_cookie, (pin), (flags))) 57 58/* Attach devices connected to the GPIO pins */ 59struct gpio_attach_args { 60 void * ga_gpio; 61 int ga_offset; 62 u_int32_t ga_mask; 63}; 64 65/* GPIO pin map */ 66struct gpio_pinmap { 67 int * pm_map; /* pin map */ 68 int pm_size; /* map size */ 69}; 70 71int gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *); 72void gpio_pin_unmap(void *, struct gpio_pinmap *); 73int gpio_pin_read(void *, struct gpio_pinmap *, int); 74void gpio_pin_write(void *, struct gpio_pinmap *, int, int); 75void gpio_pin_ctl(void *, struct gpio_pinmap *, int, int); 76 77int gpio_npins(u_int32_t); 78 79#endif /* !_DEV_GPIO_GPIOVAR_H_ */ 80