Home | History | Annotate | Line # | Download | only in gpio
gpiovar.h revision 1.4.70.4
      1  1.4.70.4      yamt /* $NetBSD: gpiovar.h,v 1.4.70.4 2009/09/16 13:37:47 yamt Exp $ */
      2       1.4       riz /*	$OpenBSD: gpiovar.h,v 1.3 2006/01/14 12:33:49 grange Exp $	*/
      3       1.4       riz 
      4       1.1  jmcneill /*
      5       1.4       riz  * 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.4.70.2      yamt #include <sys/device.h>
     24  1.4.70.2      yamt 
     25       1.1  jmcneill /* GPIO controller description */
     26       1.1  jmcneill typedef struct gpio_chipset_tag {
     27       1.1  jmcneill 	void	*gp_cookie;
     28       1.1  jmcneill 
     29  1.4.70.1      yamt 	int	(*gp_gc_open)(void *, device_t);
     30  1.4.70.1      yamt 	void    (*gp_gc_close)(void *, device_t);
     31       1.1  jmcneill 	int	(*gp_pin_read)(void *, int);
     32       1.1  jmcneill 	void	(*gp_pin_write)(void *, int, int);
     33       1.1  jmcneill 	void	(*gp_pin_ctl)(void *, int, int);
     34       1.1  jmcneill } *gpio_chipset_tag_t;
     35       1.1  jmcneill 
     36       1.1  jmcneill /* GPIO pin description */
     37       1.1  jmcneill typedef struct gpio_pin {
     38       1.1  jmcneill 	int	pin_num;		/* number */
     39       1.1  jmcneill 	int	pin_caps;		/* capabilities */
     40       1.1  jmcneill 	int	pin_flags;		/* current configuration */
     41       1.1  jmcneill 	int	pin_state;		/* current state */
     42       1.4       riz 	int	pin_mapped;		/* is mapped */
     43       1.1  jmcneill } gpio_pin_t;
     44       1.1  jmcneill 
     45       1.1  jmcneill /* Attach GPIO framework to the controller */
     46       1.1  jmcneill struct gpiobus_attach_args {
     47       1.1  jmcneill 	gpio_chipset_tag_t	gba_gc;		/* underlying controller */
     48       1.1  jmcneill 	gpio_pin_t		*gba_pins;	/* pins array */
     49       1.1  jmcneill 	int			gba_npins;	/* total number of pins */
     50       1.1  jmcneill };
     51       1.1  jmcneill 
     52       1.1  jmcneill int gpiobus_print(void *, const char *);
     53       1.1  jmcneill 
     54       1.1  jmcneill /* GPIO framework private methods */
     55  1.4.70.1      yamt #define gpiobus_open(gc, dev) \
     56  1.4.70.1      yamt     ((gc)->gp_gc_open ? ((gc)->gp_gc_open((gc)->gp_cookie, dev)) : 0)
     57  1.4.70.1      yamt #define gpiobus_close(gc, dev) \
     58  1.4.70.2      yamt     ((gc)->gp_gc_close ? ((gc)->gp_gc_close((gc)->gp_cookie, dev)), 1 : 0)
     59       1.1  jmcneill #define gpiobus_pin_read(gc, pin) \
     60       1.1  jmcneill     ((gc)->gp_pin_read((gc)->gp_cookie, (pin)))
     61       1.1  jmcneill #define gpiobus_pin_write(gc, pin, value) \
     62       1.1  jmcneill     ((gc)->gp_pin_write((gc)->gp_cookie, (pin), (value)))
     63       1.1  jmcneill #define gpiobus_pin_ctl(gc, pin, flags) \
     64       1.1  jmcneill     ((gc)->gp_pin_ctl((gc)->gp_cookie, (pin), (flags)))
     65       1.1  jmcneill 
     66       1.1  jmcneill /* Attach devices connected to the GPIO pins */
     67       1.1  jmcneill struct gpio_attach_args {
     68       1.4       riz 	void *			ga_gpio;
     69       1.4       riz 	int			ga_offset;
     70       1.4       riz 	u_int32_t		ga_mask;
     71  1.4.70.3      yamt 	char			*ga_dvname;
     72       1.4       riz };
     73       1.4       riz 
     74       1.4       riz /* GPIO pin map */
     75       1.4       riz struct gpio_pinmap {
     76       1.4       riz 	int *	pm_map;			/* pin map */
     77       1.4       riz 	int	pm_size;		/* map size */
     78       1.1  jmcneill };
     79       1.1  jmcneill 
     80  1.4.70.3      yamt struct gpio_dev {
     81  1.4.70.3      yamt 	device_t		sc_dev;	/* the gpio device */
     82  1.4.70.3      yamt 	LIST_ENTRY(gpio_dev)	sc_next;
     83  1.4.70.3      yamt };
     84  1.4.70.3      yamt 
     85  1.4.70.3      yamt struct gpio_name {
     86  1.4.70.3      yamt 	char			gp_name[GPIOMAXNAME];
     87  1.4.70.3      yamt 	int			gp_pin;
     88  1.4.70.3      yamt 	LIST_ENTRY(gpio_name)	gp_next;
     89  1.4.70.3      yamt };
     90  1.4.70.3      yamt 
     91  1.4.70.4      yamt int	gpio_pin_can_map(void *, int, u_int32_t);
     92       1.4       riz int	gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *);
     93       1.4       riz void	gpio_pin_unmap(void *, struct gpio_pinmap *);
     94       1.4       riz int	gpio_pin_read(void *, struct gpio_pinmap *, int);
     95       1.4       riz void	gpio_pin_write(void *, struct gpio_pinmap *, int, int);
     96       1.4       riz void	gpio_pin_ctl(void *, struct gpio_pinmap *, int, int);
     97       1.4       riz int	gpio_pin_caps(void *, struct gpio_pinmap *, int);
     98       1.4       riz 
     99       1.4       riz int	gpio_npins(u_int32_t);
    100       1.4       riz 
    101       1.1  jmcneill #endif	/* !_DEV_GPIO_GPIOVAR_H_ */
    102