Do not attach gpiosim(4) at root, but make it a pseudo device.

With help from Matthias Drochner, thanks!
This commit is contained in:
mbalmer 2009-07-27 17:40:57 +00:00
parent f4e46459c3
commit 9d8b69b23a
3 changed files with 30 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.gpio,v 1.5 2009/07/25 16:17:10 mbalmer Exp $ # $NetBSD: files.gpio,v 1.6 2009/07/27 17:40:57 mbalmer Exp $
define gpio {[offset = -1], [mask = 0]} define gpio {[offset = -1], [mask = 0]}
@ -7,9 +7,8 @@ attach gpio at gpiobus
file dev/gpio/gpio.c gpio needs-flag file dev/gpio/gpio.c gpio needs-flag
# GPIO simulator # GPIO simulator
device gpiosim: gpiobus defpseudodev gpiosim: gpiobus
attach gpiosim at root file dev/gpio/gpiosim.c gpiosim
file dev/gpio/gpiosim.c gpiosim needs-flag
# 1-Wire bus bit-banging # 1-Wire bus bit-banging
device gpioow: onewirebus, onewire_bitbang device gpioow: onewirebus, onewire_bitbang

View File

@ -1,4 +1,4 @@
/* $NetBSD: gpiosim.c,v 1.2 2009/07/26 13:45:20 mbalmer Exp $ */ /* $NetBSD: gpiosim.c,v 1.3 2009/07/27 17:40:58 mbalmer Exp $ */
/* $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $ */ /* $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $ */
/* /*
@ -41,6 +41,7 @@ struct gpiosim_softc {
}; };
int gpiosim_match(device_t, cfdata_t, void *); int gpiosim_match(device_t, cfdata_t, void *);
void gpiosimattach(int);
void gpiosim_attach(device_t, device_t, void *); void gpiosim_attach(device_t, device_t, void *);
int gpiosim_detach(device_t, int); int gpiosim_detach(device_t, int);
int gpiosim_activate(device_t, enum devact); int gpiosim_activate(device_t, enum devact);
@ -61,6 +62,26 @@ gpiosim_match(device_t parent, cfdata_t match, void *aux)
return 1; return 1;
} }
void
gpiosimattach(int num)
{
cfdata_t cf;
int n, err;
err = config_cfattach_attach(gpiosim_cd.cd_name, &gpiosim_ca);
if (err)
printf("%s: unable to register cfattach\n", gpiosim_cd.cd_name);
for (n = 0; n < num; n++) {
cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK);
cf->cf_name = "gpiosim";
cf->cf_atname = "gpiosim";
cf->cf_unit = n;
cf->cf_fstate = FSTATE_NOTFOUND;
config_attach_pseudo(cf);
}
}
void void
gpiosim_attach(device_t parent, device_t self, void *aux) gpiosim_attach(device_t parent, device_t self, void *aux)
{ {
@ -70,6 +91,8 @@ gpiosim_attach(device_t parent, device_t self, void *aux)
sc->sc_dev = self; sc->sc_dev = self;
printf("%s", device_xname(sc->sc_dev));
/* initialize pin array */ /* initialize pin array */
for (i = 0; i < GPIOSIM_NPINS; i++) { for (i = 0; i < GPIOSIM_NPINS; i++) {
sc->sc_gpio_pins[i].pin_num = i; sc->sc_gpio_pins[i].pin_num = i;
@ -118,7 +141,7 @@ gpiosim_attach(device_t parent, device_t self, void *aux)
gpiosim_sysctl, 0, sc, 0, gpiosim_sysctl, 0, sc, 0,
CTL_CREATE, CTL_EOL); CTL_CREATE, CTL_EOL);
printf("\n"); printf(": simulating %d pins\n", GPIOSIM_NPINS);
config_found_ia(self, "gpiobus", &gba, gpiobus_print); config_found_ia(self, "gpiobus", &gba, gpiobus_print);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.395 2009/07/25 16:23:39 mbalmer Exp $ */ /* $NetBSD: init_main.c,v 1.396 2009/07/27 17:40:57 mbalmer Exp $ */
/*- /*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -97,7 +97,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.395 2009/07/25 16:23:39 mbalmer Exp $"); __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.396 2009/07/27 17:40:57 mbalmer Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
#include "opt_ipsec.h" #include "opt_ipsec.h"
@ -119,7 +119,6 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.395 2009/07/25 16:23:39 mbalmer Exp
#include "sysmon_taskq.h" #include "sysmon_taskq.h"
#include "sysmon_wdog.h" #include "sysmon_wdog.h"
#include "veriexec.h" #include "veriexec.h"
#include "gpiosim.h"
#include <sys/param.h> #include <sys/param.h>
#include <sys/acct.h> #include <sys/acct.h>
@ -473,9 +472,6 @@ main(void)
ssp_init(); ssp_init();
configure2(); configure2();
#if NGPIOSIM > 0
config_rootfound("gpiosim", NULL);
#endif
/* Now timer is working. Enable preemption. */ /* Now timer is working. Enable preemption. */
kpreempt_enable(); kpreempt_enable();