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