Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / gpio / gpiovar.h
blobd2e0af7997347f08aa37c4269a6a14d00babe0f3
1 /* $NetBSD: gpiovar.h,v 1.9 2009/07/25 16:30:44 mbalmer Exp $ */
2 /* $OpenBSD: gpiovar.h,v 1.3 2006/01/14 12:33:49 grange Exp $ */
4 /*
5 * Copyright (c) 2004, 2006 Alexander Yurchenko <grange@openbsd.org>
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.
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.
20 #ifndef _DEV_GPIO_GPIOVAR_H_
21 #define _DEV_GPIO_GPIOVAR_H_
23 #include <sys/device.h>
25 /* GPIO controller description */
26 typedef struct gpio_chipset_tag {
27 void *gp_cookie;
29 int (*gp_gc_open)(void *, device_t);
30 void (*gp_gc_close)(void *, device_t);
31 int (*gp_pin_read)(void *, int);
32 void (*gp_pin_write)(void *, int, int);
33 void (*gp_pin_ctl)(void *, int, int);
34 } *gpio_chipset_tag_t;
36 /* GPIO pin description */
37 typedef struct gpio_pin {
38 int pin_num; /* number */
39 int pin_caps; /* capabilities */
40 int pin_flags; /* current configuration */
41 int pin_state; /* current state */
42 int pin_mapped; /* is mapped */
43 } gpio_pin_t;
45 /* Attach GPIO framework to the controller */
46 struct gpiobus_attach_args {
47 gpio_chipset_tag_t gba_gc; /* underlying controller */
48 gpio_pin_t *gba_pins; /* pins array */
49 int gba_npins; /* total number of pins */
52 int gpiobus_print(void *, const char *);
54 /* GPIO framework private methods */
55 #define gpiobus_open(gc, dev) \
56 ((gc)->gp_gc_open ? ((gc)->gp_gc_open((gc)->gp_cookie, dev)) : 0)
57 #define gpiobus_close(gc, dev) \
58 ((gc)->gp_gc_close ? ((gc)->gp_gc_close((gc)->gp_cookie, dev)), 1 : 0)
59 #define gpiobus_pin_read(gc, pin) \
60 ((gc)->gp_pin_read((gc)->gp_cookie, (pin)))
61 #define gpiobus_pin_write(gc, pin, value) \
62 ((gc)->gp_pin_write((gc)->gp_cookie, (pin), (value)))
63 #define gpiobus_pin_ctl(gc, pin, flags) \
64 ((gc)->gp_pin_ctl((gc)->gp_cookie, (pin), (flags)))
66 /* Attach devices connected to the GPIO pins */
67 struct gpio_attach_args {
68 void * ga_gpio;
69 int ga_offset;
70 u_int32_t ga_mask;
71 char *ga_dvname;
74 /* GPIO pin map */
75 struct gpio_pinmap {
76 int * pm_map; /* pin map */
77 int pm_size; /* map size */
80 struct gpio_dev {
81 device_t sc_dev; /* the gpio device */
82 LIST_ENTRY(gpio_dev) sc_next;
85 struct gpio_name {
86 char gp_name[GPIOMAXNAME];
87 int gp_pin;
88 LIST_ENTRY(gpio_name) gp_next;
91 int gpio_pin_can_map(void *, int, u_int32_t);
92 int gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *);
93 void gpio_pin_unmap(void *, struct gpio_pinmap *);
94 int gpio_pin_read(void *, struct gpio_pinmap *, int);
95 void gpio_pin_write(void *, struct gpio_pinmap *, int, int);
96 void gpio_pin_ctl(void *, struct gpio_pinmap *, int, int);
97 int gpio_pin_caps(void *, struct gpio_pinmap *, int);
99 int gpio_npins(u_int32_t);
101 #endif /* !_DEV_GPIO_GPIOVAR_H_ */