1/*- 2 * Copyright (C) 2008 MARVELL INTERNATIONAL LTD. 3 * All rights reserved. 4 * 5 * Developed by Semihalf. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 20 unchanged lines hidden (view full) --- 29 * SUCH DAMAGE. 30 */ 31 32#ifdef HAVE_KERNEL_OPTION_HEADERS 33#include "opt_device_polling.h" 34#endif 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/dev/mge/if_mge.c 232518 2012-03-04 19:22:52Z raj $"); |
38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/endian.h> 42#include <sys/mbuf.h> 43#include <sys/lock.h> 44#include <sys/mutex.h> 45#include <sys/kernel.h> --- 28 unchanged lines hidden (view full) --- 74#include <dev/ofw/ofw_bus_subr.h> 75 76#include <dev/mge/if_mgevar.h> 77#include <arm/mv/mvreg.h> 78#include <arm/mv/mvvar.h> 79 80#include "miibus_if.h" 81 |
82static int mge_probe(device_t dev); 83static int mge_attach(device_t dev); 84static int mge_detach(device_t dev); 85static int mge_shutdown(device_t dev); 86static int mge_suspend(device_t dev); 87static int mge_resume(device_t dev); 88 89static int mge_miibus_readreg(device_t dev, int phy, int reg); --- 537 unchanged lines hidden (view full) --- 627 struct ifnet *ifp; 628 uint8_t hwaddr[ETHER_ADDR_LEN]; 629 int i, error, phy; 630 631 sc = device_get_softc(dev); 632 sc->dev = dev; 633 sc->node = ofw_bus_get_node(dev); 634 |
635 /* Set chip version-dependent parameters */ 636 mge_ver_params(sc); 637 |
638 /* Get phy address and used softc from fdt */ 639 if (fdt_get_phyaddr(sc->node, sc->dev, &phy, (void **)&sc->phy_sc) != 0) |
640 return (ENXIO); 641 642 /* Initialize mutexes */ 643 mtx_init(&sc->transmit_lock, device_get_nameunit(dev), "mge TX lock", MTX_DEF); 644 mtx_init(&sc->receive_lock, device_get_nameunit(dev), "mge RX lock", MTX_DEF); 645 646 /* Allocate IO and IRQ resources */ 647 error = bus_alloc_resources(dev, res_spec, sc->res); --- 635 unchanged lines hidden (view full) --- 1283static int 1284mge_miibus_readreg(device_t dev, int phy, int reg) 1285{ 1286 struct mge_softc *sc; 1287 uint32_t retries; 1288 1289 sc = device_get_softc(dev); 1290 |
1291 MGE_WRITE(sc->phy_sc, MGE_REG_SMI, 0x1fffffff & |
1292 (MGE_SMI_READ | (reg << 21) | (phy << 16))); 1293 1294 retries = MGE_SMI_READ_RETRIES; |
1295 while (--retries && 1296 !(MGE_READ(sc->phy_sc, MGE_REG_SMI) & MGE_SMI_READVALID)) |
1297 DELAY(MGE_SMI_READ_DELAY); 1298 1299 if (retries == 0) 1300 device_printf(dev, "Timeout while reading from PHY\n"); 1301 |
1302 return (MGE_READ(sc->phy_sc, MGE_REG_SMI) & 0xffff); |
1303} 1304 1305static int 1306mge_miibus_writereg(device_t dev, int phy, int reg, int value) 1307{ 1308 struct mge_softc *sc; 1309 uint32_t retries; 1310 1311 sc = device_get_softc(dev); 1312 |
1313 MGE_WRITE(sc->phy_sc, MGE_REG_SMI, 0x1fffffff & |
1314 (MGE_SMI_WRITE | (reg << 21) | (phy << 16) | (value & 0xffff))); 1315 1316 retries = MGE_SMI_WRITE_RETRIES; |
1317 while (--retries && MGE_READ(sc->phy_sc, MGE_REG_SMI) & MGE_SMI_BUSY) |
1318 DELAY(MGE_SMI_WRITE_DELAY); 1319 1320 if (retries == 0) 1321 device_printf(dev, "Timeout while writing to PHY\n"); 1322 return (0); 1323} 1324 1325static int --- 519 unchanged lines hidden --- |