This source file includes following definitions.
- isagpio_match
- isagpio_attach
- isagpio_pin_read
- isagpio_pin_write
- isagpio_pin_ctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34 #include <sys/gpio.h>
35
36 #include <machine/bus.h>
37 #include <machine/intr.h>
38
39 #include <dev/isa/isavar.h>
40
41 #include <dev/gpio/gpiovar.h>
42
43 #define ISAGPIO_IOSIZE 1
44 #define ISAGPIO_NPINS 8
45
46 struct isagpio_softc {
47 struct device sc_dev;
48
49 bus_space_tag_t sc_iot;
50 bus_space_handle_t sc_ioh;
51
52 struct gpio_chipset_tag sc_gpio_gc;
53 struct gpio_pin sc_gpio_pins[ISAGPIO_NPINS];
54 u_int8_t sc_gpio_mask;
55 };
56
57 int isagpio_match(struct device *, void *, void *);
58 void isagpio_attach(struct device *, struct device *, void *);
59 int isagpio_pin_read(void *, int);
60 void isagpio_pin_write(void *, int, int);
61 void isagpio_pin_ctl(void *, int, int);
62
63 struct cfattach isagpio_ca = {
64 sizeof(struct isagpio_softc), isagpio_match, isagpio_attach
65 };
66
67 struct cfdriver isagpio_cd = {
68 NULL, "isagpio", DV_DULL
69 };
70
71 int
72 isagpio_match(struct device *parent, void *match, void *aux)
73 {
74 struct isa_attach_args *ia = aux;
75 bus_space_handle_t ioh;
76
77 if (ia->ia_iobase == -1 || bus_space_map(ia->ia_iot, ia->ia_iobase,
78 ISAGPIO_IOSIZE, 0, &ioh) != 0)
79 return (0);
80
81 bus_space_unmap(ia->ia_iot, ioh, ISAGPIO_IOSIZE);
82 ia->ia_iosize = ISAGPIO_IOSIZE;
83 ia->ipa_nio = 1;
84 ia->ipa_nmem = 0;
85 ia->ipa_nirq = 0;
86 ia->ipa_ndrq = 0;
87
88 return (1);
89 }
90
91 void
92 isagpio_attach(struct device *parent, struct device *self, void *aux)
93 {
94 struct isagpio_softc *sc = (void *)self;
95 struct isa_attach_args *ia = aux;
96 struct gpiobus_attach_args gba;
97 int i;
98
99 if (bus_space_map(ia->ia_iot, ia->ia_iobase, ia->ia_iosize, 0,
100 &sc->sc_ioh) != 0) {
101 printf(": couldn't map I/O space\n");
102 return;
103 }
104
105 printf("\n");
106
107 sc->sc_iot = ia->ia_iot;
108 sc->sc_gpio_mask = 0;
109
110 for (i = 0; i < ISAGPIO_NPINS; i++) {
111 sc->sc_gpio_pins[i].pin_num = i;
112 sc->sc_gpio_pins[i].pin_caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT;
113 sc->sc_gpio_pins[i].pin_state = GPIO_PIN_LOW;
114 }
115
116 sc->sc_gpio_gc.gp_cookie = sc;
117 sc->sc_gpio_gc.gp_pin_read = isagpio_pin_read;
118 sc->sc_gpio_gc.gp_pin_write = isagpio_pin_write;
119 sc->sc_gpio_gc.gp_pin_ctl = isagpio_pin_ctl;
120
121 gba.gba_name = "gpio";
122 gba.gba_gc = &sc->sc_gpio_gc;
123 gba.gba_pins = sc->sc_gpio_pins;
124 gba.gba_npins = ISAGPIO_NPINS;
125
126 (void)config_found(&sc->sc_dev, &gba, gpiobus_print);
127 }
128
129 int
130 isagpio_pin_read(void *arg, int pin)
131 {
132 struct isagpio_softc *sc = arg;
133 u_int8_t mask;
134
135 mask = bus_space_read_1(sc->sc_iot, sc->sc_ioh, 0);
136 return ((mask >> pin) & 0x01);
137 }
138
139 void
140 isagpio_pin_write(void *arg, int pin, int value)
141 {
142 struct isagpio_softc *sc = arg;
143
144 if (value == GPIO_PIN_LOW)
145 sc->sc_gpio_mask &= ~(0x01 << pin);
146 else if (value == GPIO_PIN_HIGH)
147 sc->sc_gpio_mask |= 0x01 << pin;
148 bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, sc->sc_gpio_mask);
149 }
150
151 void
152 isagpio_pin_ctl(void *arg, int pin, int flags)
153 {
154 }