From owner-p4-projects@FreeBSD.ORG Sat Jul 8 16:38:17 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6652716A4E6; Sat, 8 Jul 2006 16:38:17 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4412716A4E1 for ; Sat, 8 Jul 2006 16:38:17 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0EAFF43D6D for ; Sat, 8 Jul 2006 16:38:15 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k68GcEoA056420 for ; Sat, 8 Jul 2006 16:38:14 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k68GcEEN056414 for perforce@freebsd.org; Sat, 8 Jul 2006 16:38:14 GMT (envelope-from imp@freebsd.org) Date: Sat, 8 Jul 2006 16:38:14 GMT Message-Id: <200607081638.k68GcEEN056414@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 101032 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jul 2006 16:38:17 -0000 http://perforce.freebsd.org/chv.cgi?CH=101032 Change 101032 by imp@imp_lighthouse on 2006/07/08 16:37:48 Enumerate bus using hints, plus cleanup of code. Affected files ... .. //depot/projects/arm/src/sys/dev/spibus/spibus.c#2 edit Differences ... ==== //depot/projects/arm/src/sys/dev/spibus/spibus.c#2 (text+ko) ==== @@ -32,27 +32,42 @@ struct spibus_softc *sc = SPIBUS_SOFTC(dev); sc->dev = dev; - /* XXX need to do isahints trick */ + bus_enumerate_hinted_children(dev); return (bus_generic_attach(dev)); } +/* + * Since this is not a self-enumerating bus, and since we always add + * children in attach, we have to always delete children here. + */ static int spibus_detach(device_t dev) { + int err, ndevs, i; + device_t *devlist; + + if ((err = bus_generic_detach(dev)) != 0) + return (err); + if ((err = device_get_children(dev, &devlist, &ndevs)) != 0) + return (err); + for (i = 0; i < ndevs; i++) + device_delete_child(dev, devlist[i]); + free(devlist, M_TEMP); + return (0); } static int -spibus_suspend(device_t self) +spibus_suspend(device_t dev) { - return (0); + return (bus_generic_suspend(dev)); } static int -spibus_resume(device_t self) +spibus_resume(device_t dev) { - return (0); + return (bus_generic_resume(dev)); } static int @@ -111,6 +126,33 @@ return (0); } +static device_t +spibus_add_child(device_t dev, int order, const char *name, int unit) +{ + device_t child; + struct spibus_ivar *devi; + + child = device_add_child_ordered(dev, order, name, unit); + if (child == NULL) + return (child); + devi = malloc(sizeof(struct spibus_ivar), M_DEVBUF, M_NOWAIT | M_ZERO); + if (devi != NULL) + return (0); + device_set_ivars(child, devi); + return (child); +} + +static void +spibus_hinted_child(device_t bus, const char *dname, int dunit) +{ + device_t child; + struct spibus_ivar *devi; + + child = BUS_ADD_CHILD(bus, 0, dname, dunit); + devi = SPIBUS_IVAR(child); + resource_int_value(dname, dunit, "cs", &devi->cs); +} + static device_method_t spibus_methods[] = { /* Device interface */ DEVMETHOD(device_probe, spibus_probe), @@ -121,12 +163,14 @@ DEVMETHOD(device_resume, spibus_resume), /* Bus interface */ + DEVMETHOD(bus_add_child, spibus_add_child), DEVMETHOD(bus_print_child, spibus_print_child), DEVMETHOD(bus_driver_added, bus_generic_driver_added), DEVMETHOD(bus_probe_nomatch, spibus_probe_nomatch), DEVMETHOD(bus_read_ivar, spibus_read_ivar), DEVMETHOD(bus_child_pnpinfo_str, spibus_child_pnpinfo_str), DEVMETHOD(bus_child_location_str, spibus_child_location_str), + DEVMETHOD(bus_hinted_child, spibus_hinted_child), { 0, 0 } }; @@ -139,6 +183,5 @@ devclass_t spibus_devclass; -/* Maybe we need to have a slot device? */ DRIVER_MODULE(spibus, at91_spi, spibus_driver, spibus_devclass, 0, 0); MODULE_VERSION(spibus, 1);