Home | History | Annotate | Line # | Download | only in gpio
gpiovar.h revision 1.14.2.1
      1  1.14.2.1      yamt /* $NetBSD: gpiovar.h,v 1.14.2.1 2012/04/17 00:07:30 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.6    dyoung #include <sys/device.h>
     24       1.6    dyoung 
     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.5    cegger 	int	(*gp_gc_open)(void *, device_t);
     30       1.5    cegger 	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.12   mbalmer 	int			pin_num;	/* number */
     39      1.12   mbalmer 	int			pin_caps;	/* capabilities */
     40      1.12   mbalmer 	int			pin_flags;	/* current configuration */
     41      1.12   mbalmer 	int			pin_state;	/* current state */
     42      1.12   mbalmer 	int			pin_mapped;	/* is mapped */
     43      1.12   mbalmer 	gpio_chipset_tag_t	pin_gc;		/* reference the controller */
     44       1.1  jmcneill } gpio_pin_t;
     45       1.1  jmcneill 
     46       1.1  jmcneill /* Attach GPIO framework to the controller */
     47       1.1  jmcneill struct gpiobus_attach_args {
     48      1.12   mbalmer 	gpio_chipset_tag_t	 gba_gc;	/* underlying controller */
     49       1.1  jmcneill 	gpio_pin_t		*gba_pins;	/* pins array */
     50      1.12   mbalmer 	int			 gba_npins;	/* total number of pins */
     51       1.1  jmcneill };
     52       1.1  jmcneill 
     53       1.1  jmcneill int gpiobus_print(void *, const char *);
     54       1.1  jmcneill 
     55       1.1  jmcneill /* GPIO framework private methods */
     56       1.5    cegger #define gpiobus_open(gc, dev) \
     57       1.5    cegger     ((gc)->gp_gc_open ? ((gc)->gp_gc_open((gc)->gp_cookie, dev)) : 0)
     58       1.5    cegger #define gpiobus_close(gc, dev) \
     59       1.7  gmcgarry     ((gc)->gp_gc_close ? ((gc)->gp_gc_close((gc)->gp_cookie, dev)), 1 : 0)
     60       1.1  jmcneill #define gpiobus_pin_read(gc, pin) \
     61       1.1  jmcneill     ((gc)->gp_pin_read((gc)->gp_cookie, (pin)))
     62       1.1  jmcneill #define gpiobus_pin_write(gc, pin, value) \
     63       1.1  jmcneill     ((gc)->gp_pin_write((gc)->gp_cookie, (pin), (value)))
     64       1.1  jmcneill #define gpiobus_pin_ctl(gc, pin, flags) \
     65       1.1  jmcneill     ((gc)->gp_pin_ctl((gc)->gp_cookie, (pin), (flags)))
     66       1.1  jmcneill 
     67       1.1  jmcneill /* Attach devices connected to the GPIO pins */
     68       1.1  jmcneill struct gpio_attach_args {
     69      1.11   mbalmer 	void		*ga_gpio;
     70      1.11   mbalmer 	int		 ga_offset;
     71      1.12   mbalmer 	uint32_t	 ga_mask;
     72      1.11   mbalmer 	char		*ga_dvname;
     73      1.14   mbalmer 	uint32_t	 ga_flags;
     74       1.4       riz };
     75       1.4       riz 
     76       1.4       riz /* GPIO pin map */
     77       1.4       riz struct gpio_pinmap {
     78      1.11   mbalmer 	int		*pm_map;		/* pin map */
     79      1.11   mbalmer 	int		 pm_size;		/* map size */
     80       1.1  jmcneill };
     81       1.1  jmcneill 
     82       1.8   mbalmer struct gpio_dev {
     83       1.9   mbalmer 	device_t		sc_dev;	/* the gpio device */
     84       1.8   mbalmer 	LIST_ENTRY(gpio_dev)	sc_next;
     85       1.8   mbalmer };
     86       1.8   mbalmer 
     87       1.8   mbalmer struct gpio_name {
     88       1.8   mbalmer 	char			gp_name[GPIOMAXNAME];
     89       1.8   mbalmer 	int			gp_pin;
     90       1.8   mbalmer 	LIST_ENTRY(gpio_name)	gp_next;
     91       1.8   mbalmer };
     92       1.8   mbalmer 
     93      1.12   mbalmer int	gpio_pin_can_map(void *, int, uint32_t);
     94      1.12   mbalmer int	gpio_pin_map(void *, int, uint32_t, struct gpio_pinmap *);
     95       1.4       riz void	gpio_pin_unmap(void *, struct gpio_pinmap *);
     96       1.4       riz int	gpio_pin_read(void *, struct gpio_pinmap *, int);
     97       1.4       riz void	gpio_pin_write(void *, struct gpio_pinmap *, int, int);
     98       1.4       riz void	gpio_pin_ctl(void *, struct gpio_pinmap *, int, int);
     99       1.4       riz int	gpio_pin_caps(void *, struct gpio_pinmap *, int);
    100      1.12   mbalmer int	gpio_npins(uint32_t);
    101      1.12   mbalmer 
    102      1.12   mbalmer int	gpio_lock(void *);
    103      1.12   mbalmer void	gpio_unlock(void *);
    104       1.4       riz 
    105       1.1  jmcneill #endif	/* !_DEV_GPIO_GPIOVAR_H_ */
    106