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