Home | History | Annotate | Line # | Download | only in gpio
gpiovar.h revision 1.5
      1 /* $NetBSD: gpiovar.h,v 1.5 2008/04/29 14:07:36 cegger 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_gc_open)(void *, device_t);
     28 	void    (*gp_gc_close)(void *, device_t);
     29 	int	(*gp_pin_read)(void *, int);
     30 	void	(*gp_pin_write)(void *, int, int);
     31 	void	(*gp_pin_ctl)(void *, int, int);
     32 } *gpio_chipset_tag_t;
     33 
     34 /* GPIO pin description */
     35 typedef struct gpio_pin {
     36 	int	pin_num;		/* number */
     37 	int	pin_caps;		/* capabilities */
     38 	int	pin_flags;		/* current configuration */
     39 	int	pin_state;		/* current state */
     40 	int	pin_mapped;		/* is mapped */
     41 } gpio_pin_t;
     42 
     43 /* Attach GPIO framework to the controller */
     44 struct gpiobus_attach_args {
     45 	gpio_chipset_tag_t	gba_gc;		/* underlying controller */
     46 	gpio_pin_t		*gba_pins;	/* pins array */
     47 	int			gba_npins;	/* total number of pins */
     48 };
     49 
     50 int gpiobus_print(void *, const char *);
     51 
     52 /* GPIO framework private methods */
     53 #define gpiobus_open(gc, dev) \
     54     ((gc)->gp_gc_open ? ((gc)->gp_gc_open((gc)->gp_cookie, dev)) : 0)
     55 #define gpiobus_close(gc, dev) \
     56     ((gc)->gp_gc_close ? ((gc)->gp_gc_close((gc)->gp_cookie, dev)) : 0)
     57 #define gpiobus_pin_read(gc, pin) \
     58     ((gc)->gp_pin_read((gc)->gp_cookie, (pin)))
     59 #define gpiobus_pin_write(gc, pin, value) \
     60     ((gc)->gp_pin_write((gc)->gp_cookie, (pin), (value)))
     61 #define gpiobus_pin_ctl(gc, pin, flags) \
     62     ((gc)->gp_pin_ctl((gc)->gp_cookie, (pin), (flags)))
     63 
     64 /* Attach devices connected to the GPIO pins */
     65 struct gpio_attach_args {
     66 	void *			ga_gpio;
     67 	int			ga_offset;
     68 	u_int32_t		ga_mask;
     69 };
     70 
     71 /* GPIO pin map */
     72 struct gpio_pinmap {
     73 	int *	pm_map;			/* pin map */
     74 	int	pm_size;		/* map size */
     75 };
     76 
     77 int	gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *);
     78 void	gpio_pin_unmap(void *, struct gpio_pinmap *);
     79 int	gpio_pin_read(void *, struct gpio_pinmap *, int);
     80 void	gpio_pin_write(void *, struct gpio_pinmap *, int, int);
     81 void	gpio_pin_ctl(void *, struct gpio_pinmap *, int, int);
     82 int	gpio_pin_caps(void *, struct gpio_pinmap *, int);
     83 
     84 int	gpio_npins(u_int32_t);
     85 
     86 #endif	/* !_DEV_GPIO_GPIOVAR_H_ */
     87