Thu Oct 29 06:50:53 2020 UTC ()
Handle the change in the sparc64 OFW patching, where we now encode the
GPIO pin type in the pin name (only LED types are currently handled).


(jdc)
diff -r1.4 -r1.5 src/sys/dev/i2c/pcagpio.c

cvs diff -r1.4 -r1.5 src/sys/dev/i2c/pcagpio.c (expand / switch to unified diff)

--- src/sys/dev/i2c/pcagpio.c 2020/10/27 20:13:21 1.4
+++ src/sys/dev/i2c/pcagpio.c 2020/10/29 06:50:53 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pcagpio.c,v 1.4 2020/10/27 20:13:21 jdc Exp $ */ 1/* $NetBSD: pcagpio.c,v 1.5 2020/10/29 06:50:53 jdc Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2020 Michael Lorenz 4 * Copyright (c) 2020 Michael Lorenz
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * a driver for Philips Semiconductor PCA9555 GPIO controllers 30 * a driver for Philips Semiconductor PCA9555 GPIO controllers
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.4 2020/10/27 20:13:21 jdc Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: pcagpio.c,v 1.5 2020/10/29 06:50:53 jdc Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#ifdef PCAGPIO_DEBUG 39#ifdef PCAGPIO_DEBUG
40#include <sys/kernel.h> 40#include <sys/kernel.h>
41#endif 41#endif
42#include <sys/conf.h> 42#include <sys/conf.h>
43#include <sys/bus.h> 43#include <sys/bus.h>
44 44
45#include <dev/i2c/i2cvar.h> 45#include <dev/i2c/i2cvar.h>
46#include <dev/led.h> 46#include <dev/led.h>
47 47
@@ -174,44 +174,50 @@ pcagpio_attach(device_t parent, device_t @@ -174,44 +174,50 @@ pcagpio_attach(device_t parent, device_t
174  174
175 printdir(sc->sc_dev->dv_xname, in, sc->sc_dir, 'I'); 175 printdir(sc->sc_dev->dv_xname, in, sc->sc_dir, 'I');
176 printdir(sc->sc_dev->dv_xname, out, ~sc->sc_dir, 'O'); 176 printdir(sc->sc_dev->dv_xname, out, ~sc->sc_dir, 'O');
177 177
178 callout_init(&sc->sc_timer, CALLOUT_MPSAFE); 178 callout_init(&sc->sc_timer, CALLOUT_MPSAFE);
179 callout_reset(&sc->sc_timer, hz*20, pcagpio_timeout, sc); 179 callout_reset(&sc->sc_timer, hz*20, pcagpio_timeout, sc);
180 180
181#endif 181#endif
182 182
183 pins = prop_dictionary_get(dict, "pins"); 183 pins = prop_dictionary_get(dict, "pins");
184 if (pins != NULL) { 184 if (pins != NULL) {
185 int i, num, def; 185 int i, num, def;
186 char name[32]; 186 char name[32];
187 const char *nptr; 187 const char *spptr, *nptr;
188 bool ok = TRUE, act; 188 bool ok = TRUE, act;
189 189
190 for (i = 0; i < prop_array_count(pins); i++) { 190 for (i = 0; i < prop_array_count(pins); i++) {
191 nptr = NULL; 191 nptr = NULL;
192 pin = prop_array_get(pins, i); 192 pin = prop_array_get(pins, i);
193 ok &= prop_dictionary_get_cstring_nocopy(pin, "name", 193 ok &= prop_dictionary_get_cstring_nocopy(pin, "name",
194 &nptr); 194 &nptr);
195 strncpy(name, nptr, 31); 
196 ok &= prop_dictionary_get_uint32(pin, "pin", &num); 195 ok &= prop_dictionary_get_uint32(pin, "pin", &num);
197 ok &= prop_dictionary_get_bool( 196 ok &= prop_dictionary_get_bool( pin, "active_high",
198 pin, "active_high", &act); 197 &act);
199 /* optional default state */ 198 /* optional default state */
200 def = -1; 199 def = -1;
201 prop_dictionary_get_int32(pin, "default_state", &def); 200 prop_dictionary_get_int32(pin, "default_state", &def);
202 if (ok) {  201 if (!ok)
 202 continue;
 203 /* Extract pin type from the name */
 204 spptr = strstr(nptr, " ");
 205 if (spptr == NULL)
 206 continue;
 207 spptr += 1;
 208 strncpy(name, spptr, 31);
 209 if (!strncmp(nptr, "LED ", 4))
203 pcagpio_attach_led(sc, name, num, act, def); 210 pcagpio_attach_led(sc, name, num, act, def);
204 } 
205 } 211 }
206 } 212 }
207} 213}
208 214
209static int 215static int
210pcagpio_detach(device_t self, int flags) 216pcagpio_detach(device_t self, int flags)
211{ 217{
212#ifdef PCAGPIO_DEBUG 218#ifdef PCAGPIO_DEBUG
213 struct pcagpio_softc *sc = device_private(self); 219 struct pcagpio_softc *sc = device_private(self);
214 220
215 callout_halt(&sc->sc_timer, NULL); 221 callout_halt(&sc->sc_timer, NULL);
216 callout_destroy(&sc->sc_timer); 222 callout_destroy(&sc->sc_timer);
217#endif 223#endif