Home | History | Annotate | Line # | Download | only in gpio
gpiovar.h revision 1.15.18.1
      1  1.15.18.1   khorben /* $NetBSD: gpiovar.h,v 1.15.18.1 2013/05/10 01:20:05 khorben 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.15.18.1   khorben 	int		 ga_intr;
     75        1.4       riz };
     76        1.4       riz 
     77        1.4       riz /* GPIO pin map */
     78        1.4       riz struct gpio_pinmap {
     79       1.11   mbalmer 	int		*pm_map;		/* pin map */
     80       1.11   mbalmer 	int		 pm_size;		/* map size */
     81        1.1  jmcneill };
     82        1.1  jmcneill 
     83        1.8   mbalmer struct gpio_dev {
     84        1.9   mbalmer 	device_t		sc_dev;	/* the gpio device */
     85        1.8   mbalmer 	LIST_ENTRY(gpio_dev)	sc_next;
     86        1.8   mbalmer };
     87        1.8   mbalmer 
     88        1.8   mbalmer struct gpio_name {
     89        1.8   mbalmer 	char			gp_name[GPIOMAXNAME];
     90        1.8   mbalmer 	int			gp_pin;
     91        1.8   mbalmer 	LIST_ENTRY(gpio_name)	gp_next;
     92        1.8   mbalmer };
     93        1.8   mbalmer 
     94       1.12   mbalmer int	gpio_pin_can_map(void *, int, uint32_t);
     95       1.12   mbalmer int	gpio_pin_map(void *, int, uint32_t, struct gpio_pinmap *);
     96        1.4       riz void	gpio_pin_unmap(void *, struct gpio_pinmap *);
     97        1.4       riz int	gpio_pin_read(void *, struct gpio_pinmap *, int);
     98        1.4       riz void	gpio_pin_write(void *, struct gpio_pinmap *, int, int);
     99        1.4       riz void	gpio_pin_ctl(void *, struct gpio_pinmap *, int, int);
    100        1.4       riz int	gpio_pin_caps(void *, struct gpio_pinmap *, int);
    101       1.12   mbalmer int	gpio_npins(uint32_t);
    102       1.12   mbalmer 
    103       1.12   mbalmer int	gpio_lock(void *);
    104       1.12   mbalmer void	gpio_unlock(void *);
    105        1.4       riz 
    106        1.1  jmcneill #endif	/* !_DEV_GPIO_GPIOVAR_H_ */
    107