PERFORCE change 89170 for review
Warner Losh
imp at FreeBSD.org
Wed Jan 4 11:51:50 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=89170
Change 89170 by imp at imp_hammer on 2006/01/04 19:51:43
Frame out the MIIBUS support. Still needs the actual registers
accesses added, however.
Affected files ...
.. //depot/projects/arm/src/sys/arm/at91/if_ate.c#3 edit
Differences ...
==== //depot/projects/arm/src/sys/arm/at91/if_ate.c#3 (text+ko) ====
@@ -52,21 +52,37 @@
#include <net/bpf.h>
#include <net/bpfdesc.h>
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+
+#include "miibus_if.h"
+
struct ate_softc
{
struct ifnet *ifp;
struct mtx sc_mtx;
device_t dev;
+ device_t miibus;
void *intrhand;
struct resource *irq_res;
- int irq_rid;
- struct resource *port_res;
- int port_rid;
+ struct resource *mem_res;
// XXX bogus
int intr;
};
+static inline uint32_t
+RD4(struct ate_softc *sc, bus_offset_t off)
+{
+ return bus_read_4(sc->mem_res, off);
+}
+
+static inline void
+WR4(struct ate_softc *sc, bus_offset_t off, uint32_t val)
+{
+ bus_write_4(sc->mem_res, off, val);
+}
+
#define ATE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define ATE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
#define ATE_LOCK_INIT(_sc) \
@@ -98,7 +114,7 @@
/* helper routines */
static int ate_activate(device_t dev);
-static int ate_deactivate(device_t dev);
+static void ate_deactivate(device_t dev);
/*
* The AT91 family of products has the ethernet called EMAC. However,
@@ -171,13 +187,44 @@
static int
ate_activate(device_t dev)
{
- return EINVAL; /* XXX */
+ struct ate_softc *sc;
+ int rid;
+
+ sc = device_get_softc(dev);
+ rid = 0;
+ sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
+ RF_ACTIVE);
+ if (sc->mem_res == NULL)
+ goto errout;
+ rid = 0;
+ sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
+ RF_ACTIVE);
+ if (sc->mem_res == NULL)
+ goto errout;
+ return (0);
+errout:;
+ ate_deactivate(dev);
+ return (ENOMEM);
}
-static int
+static void
ate_deactivate(device_t dev)
{
- return EINVAL; /* XXX */
+ struct ate_softc *sc;
+
+ sc = device_get_softc(dev);
+ if (sc->intrhand)
+ bus_teardown_intr(dev, sc->irq_res, sc->intrhand);
+ sc->intrhand = 0;
+ if (sc->mem_res)
+ bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid,
+ sc->mem_res);
+ sc->mem_res = 0;
+ if (sc->irq_res)
+ bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid,
+ sc->irq_res);
+ sc->irq_res = 0;
+ return;
}
static void
@@ -199,6 +246,7 @@
ATE_ASSERT_LOCKED(sc);
+// XXX don't forget RMII vs MII
/* Insert code here */
sc->intr++;
}
@@ -299,12 +347,51 @@
return (error);
}
+static void
+ate_child_detached(device_t dev, device_t child)
+{
+ struct ate_softc *sc;
+
+ sc = device_get_softc(dev);
+ if (child == sc->miibus)
+ sc->miibus = NULL;
+}
+
+/*
+ * MII bus support routines.
+ */
+static int
+ate_miibus_readreg(device_t dev, int phy, int reg)
+{
+ struct ate_softc *sc;
+
+ sc = device_get_softc(dev);
+
+
+ return (0);
+}
+
+static void
+ate_miibus_writereg(device_t dev, int phy, int reg, int data)
+{
+ struct ate_softc *sc;
+
+ sc = device_get_softc(dev);
+}
+
static device_method_t ate_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ate_probe),
DEVMETHOD(device_attach, ate_attach),
DEVMETHOD(device_detach, ate_detach),
+ /* Bus interface */
+ DEVMETHOD(bus_child_detached, ate_child_detached),
+
+ /* MII interface */
+ DEVMETHOD(miibus_readreg, ate_miibus_readreg),
+ DEVMETHOD(miibus_writereg, ate_miibus_writereg),
+
{ 0, 0 }
};
@@ -315,4 +402,6 @@
};
DRIVER_MODULE(ate, atemelarm, ate_driver, ate_devclass, 0, 0);
+DRIVER_MODULE(miibus, ate, miibus_driver, miibus_devclass, 0, 0);
+MODULE_DEPEND(ate, miibus, 1, 1, 1);
MODULE_DEPEND(ate, ether, 1, 1, 1);
More information about the p4-projects
mailing list