gpiovar.h revision 1.5
1/* $OpenBSD: gpiovar.h,v 1.5 2008/11/26 14:51:20 mbalmer 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 char *ga_dvname; 64}; 65 66/* GPIO pin map */ 67struct gpio_pinmap { 68 int * pm_map; /* pin map */ 69 int pm_size; /* map size */ 70}; 71 72struct gpio_dev { 73 struct device *sc_dev; /* the gpio device */ 74 LIST_ENTRY(gpio_dev) sc_next; 75}; 76 77struct gpio_name { 78 char gp_name[GPIOPINMAXNAME]; 79 int gp_pin; 80 LIST_ENTRY(gpio_name) gp_next; 81}; 82 83int gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *); 84void gpio_pin_unmap(void *, struct gpio_pinmap *); 85int gpio_pin_read(void *, struct gpio_pinmap *, int); 86void gpio_pin_write(void *, struct gpio_pinmap *, int, int); 87void gpio_pin_ctl(void *, struct gpio_pinmap *, int, int); 88int gpio_pin_caps(void *, struct gpio_pinmap *, int); 89 90int gpio_npins(u_int32_t); 91 92#endif /* !_DEV_GPIO_GPIOVAR_H_ */ 93