Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Jul 2006 16:38:14 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 101032 for review
Message-ID:  <200607081638.k68GcEEN056414@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607081638.k68GcEEN056414>