summaryrefslogtreecommitdiffstats
path: root/sys/dev/mge/if_mge.c
diff options
context:
space:
mode:
authorraj <raj@FreeBSD.org>2010-06-13 13:28:53 +0000
committerraj <raj@FreeBSD.org>2010-06-13 13:28:53 +0000
commit48f2ce50e598284d7c79d1111c68cc0e0f7c281d (patch)
tree07c2d0d0d218db6ddf32a8764732a00acfd6ae59 /sys/dev/mge/if_mge.c
parent9195421e5e6821c80ae6593124db55737a827f21 (diff)
downloadFreeBSD-src-48f2ce50e598284d7c79d1111c68cc0e0f7c281d.zip
FreeBSD-src-48f2ce50e598284d7c79d1111c68cc0e0f7c281d.tar.gz
Convert Marvell ARM platforms to FDT convention.
The following systems are involved: - DB-88F5182 - DB-88F5281 - DB-88F6281 - DB-78100 - SheevaPlug This overhaul covers the following major changes: - All integrated peripherals drivers for Marvell ARM SoC, which are currently in the FreeBSD source tree are reworked and adjusted so they derive config data out of the device tree blob (instead of hard coded / tabelarized values). - Since the common FDT infrastrucutre (fdtbus, simplebus) is used we say good by to obio / mbus drivers and numerous hard-coded config data. Note that world needs to be built WITH_FDT for the affected platforms. Reviewed by: imp Sponsored by: The FreeBSD Foundation.
Diffstat (limited to 'sys/dev/mge/if_mge.c')
-rw-r--r--sys/dev/mge/if_mge.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/sys/dev/mge/if_mge.c b/sys/dev/mge/if_mge.c
index 8ae6ede..c710521 100644
--- a/sys/dev/mge/if_mge.c
+++ b/sys/dev/mge/if_mge.c
@@ -69,9 +69,9 @@ __FBSDID("$FreeBSD$");
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
-#ifndef MII_ADDR_BASE
-#define MII_ADDR_BASE 8
-#endif
+#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/mge/if_mgevar.h>
#include <arm/mv/mvreg.h>
@@ -164,7 +164,7 @@ static driver_t mge_driver = {
static devclass_t mge_devclass;
-DRIVER_MODULE(mge, mbus, mge_driver, mge_devclass, 0, 0);
+DRIVER_MODULE(mge, simplebus, mge_driver, mge_devclass, 0, 0);
DRIVER_MODULE(miibus, mge, miibus_driver, miibus_devclass, 0, 0);
MODULE_DEPEND(mge, ether, 1, 1, 1);
MODULE_DEPEND(mge, miibus, 1, 1, 1);
@@ -194,10 +194,30 @@ static void
mge_get_mac_address(struct mge_softc *sc, uint8_t *addr)
{
uint32_t mac_l, mac_h;
+ uint8_t lmac[6];
+ int i, valid;
- /* XXX use currently programmed MAC address; eventually this info will
- * be provided by the loader */
+ /*
+ * Retrieve hw address from the device tree.
+ */
+ i = OF_getprop(sc->node, "local-mac-address", (void *)lmac, 6);
+ if (i == 6) {
+ valid = 0;
+ for (i = 0; i < 6; i++)
+ if (lmac[i] != 0) {
+ valid = 1;
+ break;
+ }
+ if (valid) {
+ bcopy(lmac, addr, 6);
+ return;
+ }
+ }
+
+ /*
+ * Fall back -- use the currently programmed address.
+ */
mac_l = MGE_READ(sc, MGE_MAC_ADDR_L);
mac_h = MGE_READ(sc, MGE_MAC_ADDR_H);
@@ -613,6 +633,7 @@ mge_attach(device_t dev)
sc = device_get_softc(dev);
sc->dev = dev;
+ sc->node = ofw_bus_get_node(dev);
if (device_get_unit(dev) == 0)
sc_mge0 = sc;
@@ -620,6 +641,10 @@ mge_attach(device_t dev)
/* Set chip version-dependent parameters */
mge_ver_params(sc);
+ /* Get phy address from fdt */
+ if (fdt_get_phyaddr(sc->node, &sc->phyaddr) != 0)
+ return (ENXIO);
+
/* Initialize mutexes */
mtx_init(&sc->transmit_lock, device_get_nameunit(dev), "mge TX lock", MTX_DEF);
mtx_init(&sc->receive_lock, device_get_nameunit(dev), "mge RX lock", MTX_DEF);
@@ -1263,19 +1288,12 @@ mge_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
static int
mge_miibus_readreg(device_t dev, int phy, int reg)
{
+ struct mge_softc *sc;
uint32_t retries;
- /*
- * We assume static PHY address <=> device unit mapping:
- * PHY Address = MII_ADDR_BASE + devce unit.
- * This is true for most Marvell boards.
- *
- * Code below grants proper PHY detection on each device
- * unit.
- */
+ sc = device_get_softc(dev);
-
- if ((MII_ADDR_BASE + device_get_unit(dev)) != phy)
+ if (sc->phyaddr != phy)
return (0);
MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff &
@@ -1294,9 +1312,12 @@ mge_miibus_readreg(device_t dev, int phy, int reg)
static int
mge_miibus_writereg(device_t dev, int phy, int reg, int value)
{
+ struct mge_softc *sc;
uint32_t retries;
- if ((MII_ADDR_BASE + device_get_unit(dev)) != phy)
+ sc = device_get_softc(dev);
+
+ if (sc->phyaddr != phy)
return (0);
MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff &
@@ -1315,6 +1336,9 @@ static int
mge_probe(device_t dev)
{
+ if (!ofw_bus_is_compatible(dev, "mrvl,ge"))
+ return (ENXIO);
+
device_set_desc(dev, "Marvell Gigabit Ethernet controller");
return (BUS_PROBE_DEFAULT);
}
OpenPOWER on IntegriCloud