xref: /openbsd/sys/dev/gpio/gpiovar.h (revision 7d434456)
1 /*	$OpenBSD: gpiovar.h,v 1.6 2011/10/03 20:24:51 matthieu Exp $	*/
2 
3 /*
4  * Copyright (c) 2004, 2006 Alexander Yurchenko <grange@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _DEV_GPIO_GPIOVAR_H_
20 #define _DEV_GPIO_GPIOVAR_H_
21 
22 /* GPIO controller description */
23 typedef struct gpio_chipset_tag {
24 	void	*gp_cookie;
25 
26 	int	(*gp_pin_read)(void *, int);
27 	void	(*gp_pin_write)(void *, int, int);
28 	void	(*gp_pin_ctl)(void *, int, int);
29 } *gpio_chipset_tag_t;
30 
31 /* GPIO pin description */
32 typedef struct gpio_pin {
33 	int	pin_num;		/* number */
34 	int	pin_caps;		/* capabilities */
35 	int	pin_flags;		/* current configuration */
36 	int	pin_state;		/* current state */
37 	int	pin_mapped;		/* is mapped */
38 } gpio_pin_t;
39 
40 /* Attach GPIO framework to the controller */
41 struct gpiobus_attach_args {
42 	const char		*gba_name;	/* bus name */
43 	gpio_chipset_tag_t	gba_gc;		/* underlying controller */
44 	gpio_pin_t		*gba_pins;	/* pins array */
45 	int			gba_npins;	/* total number of pins */
46 };
47 
48 int gpiobus_print(void *, const char *);
49 
50 /* GPIO framework private methods */
51 #define gpiobus_pin_read(gc, pin) \
52     ((gc)->gp_pin_read((gc)->gp_cookie, (pin)))
53 #define gpiobus_pin_write(gc, pin, value) \
54     ((gc)->gp_pin_write((gc)->gp_cookie, (pin), (value)))
55 #define gpiobus_pin_ctl(gc, pin, flags) \
56     ((gc)->gp_pin_ctl((gc)->gp_cookie, (pin), (flags)))
57 
58 /* Attach devices connected to the GPIO pins */
59 struct gpio_attach_args {
60 	void *			ga_gpio;
61 	int			ga_offset;
62 	u_int32_t		ga_mask;
63 	char			*ga_dvname;
64 	u_int32_t		ga_flags;
65 };
66 
67 /* GPIO pin map */
68 struct gpio_pinmap {
69 	int *	pm_map;			/* pin map */
70 	int	pm_size;		/* map size */
71 };
72 
73 struct gpio_dev {
74 	struct device		*sc_dev;	/* the gpio device */
75 	LIST_ENTRY(gpio_dev)	 sc_next;
76 };
77 
78 struct gpio_name {
79 	char			gp_name[GPIOPINMAXNAME];
80 	int			gp_pin;
81 	LIST_ENTRY(gpio_name)	gp_next;
82 };
83 
84 int	gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *);
85 void	gpio_pin_unmap(void *, struct gpio_pinmap *);
86 int	gpio_pin_read(void *, struct gpio_pinmap *, int);
87 void	gpio_pin_write(void *, struct gpio_pinmap *, int, int);
88 void	gpio_pin_ctl(void *, struct gpio_pinmap *, int, int);
89 int	gpio_pin_caps(void *, struct gpio_pinmap *, int);
90 
91 int	gpio_npins(u_int32_t);
92 
93 #endif	/* !_DEV_GPIO_GPIOVAR_H_ */
94