2009-10-15 06:13:45 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
STMMAC Ethernet Driver -- MDIO bus implementation
|
|
|
|
Provides Bus interface for MII registers
|
|
|
|
|
|
|
|
Copyright (C) 2007-2009 STMicroelectronics Ltd
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms and conditions of the GNU General Public License,
|
|
|
|
version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in
|
|
|
|
the file called "COPYING".
|
|
|
|
|
|
|
|
Author: Carl Shaw <carl.shaw@st.com>
|
|
|
|
Maintainer: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/phy.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-06-16 19:01:34 +08:00
|
|
|
#include <asm/io.h>
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
#include "stmmac.h"
|
|
|
|
|
|
|
|
#define MII_BUSY 0x00000001
|
|
|
|
#define MII_WRITE 0x00000002
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_read
|
|
|
|
* @bus: points to the mii_bus structure
|
|
|
|
* @phyaddr: MII addr reg bits 15-11
|
|
|
|
* @phyreg: MII addr reg bits 10-6
|
|
|
|
* Description: it reads data from the MII register from within the phy device.
|
|
|
|
* For the 7111 GMAC, we must set the bit 0 in the MII address register while
|
|
|
|
* accessing the PHY registers.
|
|
|
|
* Fortunately, it seems this has no drawback for the 7109 MAC.
|
|
|
|
*/
|
|
|
|
static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2010-01-07 07:07:17 +08:00
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
|
|
|
unsigned int mii_data = priv->hw->mii.data;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
int data;
|
|
|
|
u16 regValue = (((phyaddr << 11) & (0x0000F800)) |
|
|
|
|
((phyreg << 6) & (0x000007C0)));
|
2010-11-24 10:37:58 +08:00
|
|
|
regValue |= MII_BUSY | ((priv->plat->clk_csr & 7) << 2);
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2010-08-24 04:40:42 +08:00
|
|
|
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);
|
|
|
|
writel(regValue, priv->ioaddr + mii_address);
|
|
|
|
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
/* Read the data from the MII data register */
|
2010-08-24 04:40:42 +08:00
|
|
|
data = (int)readl(priv->ioaddr + mii_data);
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_write
|
|
|
|
* @bus: points to the mii_bus structure
|
|
|
|
* @phyaddr: MII addr reg bits 15-11
|
|
|
|
* @phyreg: MII addr reg bits 10-6
|
|
|
|
* @phydata: phy data
|
|
|
|
* Description: it writes the data into the MII register from within the device.
|
|
|
|
*/
|
|
|
|
static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg,
|
|
|
|
u16 phydata)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2010-01-07 07:07:17 +08:00
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
|
|
|
unsigned int mii_data = priv->hw->mii.data;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
u16 value =
|
|
|
|
(((phyaddr << 11) & (0x0000F800)) | ((phyreg << 6) & (0x000007C0)))
|
|
|
|
| MII_WRITE;
|
|
|
|
|
2010-11-24 10:37:58 +08:00
|
|
|
value |= MII_BUSY | ((priv->plat->clk_csr & 7) << 2);
|
2010-09-17 11:23:39 +08:00
|
|
|
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
2010-08-24 04:40:42 +08:00
|
|
|
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
/* Set the MII address register to write */
|
2010-08-24 04:40:42 +08:00
|
|
|
writel(phydata, priv->ioaddr + mii_data);
|
|
|
|
writel(value, priv->ioaddr + mii_address);
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
2010-08-24 04:40:42 +08:00
|
|
|
do {} while (((readl(priv->ioaddr + mii_address)) & MII_BUSY) == 1);
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_reset
|
|
|
|
* @bus: points to the mii_bus structure
|
|
|
|
* Description: reset the MII bus
|
|
|
|
*/
|
|
|
|
static int stmmac_mdio_reset(struct mii_bus *bus)
|
|
|
|
{
|
2011-12-21 11:58:19 +08:00
|
|
|
#if defined(CONFIG_STMMAC_PLATFORM)
|
2009-10-15 06:13:45 +08:00
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2010-01-07 07:07:17 +08:00
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
2011-07-20 08:05:23 +08:00
|
|
|
if (priv->plat->mdio_bus_data->phy_reset) {
|
2009-10-15 06:13:45 +08:00
|
|
|
pr_debug("stmmac_mdio_reset: calling phy_reset\n");
|
2011-07-20 08:05:23 +08:00
|
|
|
priv->plat->mdio_bus_data->phy_reset(priv->plat->bsp_priv);
|
2009-10-15 06:13:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a workaround for problems with the STE101P PHY.
|
|
|
|
* It doesn't complete its reset until at least one clock cycle
|
|
|
|
* on MDC, so perform a dummy mdio read.
|
|
|
|
*/
|
2010-08-24 04:40:42 +08:00
|
|
|
writel(0, priv->ioaddr + mii_address);
|
2011-12-21 11:58:19 +08:00
|
|
|
#endif
|
2009-10-15 06:13:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_register
|
|
|
|
* @ndev: net device structure
|
|
|
|
* Description: it registers the MII bus
|
|
|
|
*/
|
|
|
|
int stmmac_mdio_register(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct mii_bus *new_bus;
|
|
|
|
int *irqlist;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2011-07-20 08:05:23 +08:00
|
|
|
struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
|
2009-10-15 06:13:45 +08:00
|
|
|
int addr, found;
|
|
|
|
|
2011-07-20 08:05:23 +08:00
|
|
|
if (!mdio_bus_data)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-15 06:13:45 +08:00
|
|
|
new_bus = mdiobus_alloc();
|
|
|
|
if (new_bus == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-07-20 08:05:23 +08:00
|
|
|
if (mdio_bus_data->irqs)
|
|
|
|
irqlist = mdio_bus_data->irqs;
|
|
|
|
else
|
|
|
|
irqlist = priv->mii_irq;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
new_bus->name = "STMMAC MII Bus";
|
|
|
|
new_bus->read = &stmmac_mdio_read;
|
|
|
|
new_bus->write = &stmmac_mdio_write;
|
|
|
|
new_bus->reset = &stmmac_mdio_reset;
|
2011-07-20 08:05:23 +08:00
|
|
|
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", mdio_bus_data->bus_id);
|
2009-10-15 06:13:45 +08:00
|
|
|
new_bus->priv = ndev;
|
|
|
|
new_bus->irq = irqlist;
|
2011-07-20 08:05:23 +08:00
|
|
|
new_bus->phy_mask = mdio_bus_data->phy_mask;
|
2009-10-15 06:13:45 +08:00
|
|
|
new_bus->parent = priv->device;
|
|
|
|
err = mdiobus_register(new_bus);
|
|
|
|
if (err != 0) {
|
|
|
|
pr_err("%s: Cannot register as MDIO bus\n", new_bus->name);
|
|
|
|
goto bus_register_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->mii = new_bus;
|
|
|
|
|
|
|
|
found = 0;
|
2011-07-20 08:05:23 +08:00
|
|
|
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
|
2009-10-15 06:13:45 +08:00
|
|
|
struct phy_device *phydev = new_bus->phy_map[addr];
|
|
|
|
if (phydev) {
|
2011-07-20 08:05:23 +08:00
|
|
|
int act = 0;
|
|
|
|
char irq_num[4];
|
|
|
|
char *irq_str;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an IRQ was provided to be assigned after
|
|
|
|
* the bus probe, do it here.
|
|
|
|
*/
|
|
|
|
if ((mdio_bus_data->irqs == NULL) &&
|
|
|
|
(mdio_bus_data->probed_phy_irq > 0)) {
|
|
|
|
irqlist[addr] = mdio_bus_data->probed_phy_irq;
|
|
|
|
phydev->irq = mdio_bus_data->probed_phy_irq;
|
2009-10-15 06:13:45 +08:00
|
|
|
}
|
2011-07-20 08:05:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're going to bind the MAC to this PHY bus,
|
|
|
|
* and no PHY number was provided to the MAC,
|
|
|
|
* use the one probed here.
|
|
|
|
*/
|
|
|
|
if ((priv->plat->bus_id == mdio_bus_data->bus_id) &&
|
|
|
|
(priv->plat->phy_addr == -1))
|
|
|
|
priv->plat->phy_addr = addr;
|
|
|
|
|
|
|
|
act = (priv->plat->bus_id == mdio_bus_data->bus_id) &&
|
|
|
|
(priv->plat->phy_addr == addr);
|
|
|
|
switch (phydev->irq) {
|
|
|
|
case PHY_POLL:
|
|
|
|
irq_str = "POLL";
|
|
|
|
break;
|
|
|
|
case PHY_IGNORE_INTERRUPT:
|
|
|
|
irq_str = "IGNORE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(irq_num, "%d", phydev->irq);
|
|
|
|
irq_str = irq_num;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pr_info("%s: PHY ID %08x at %d IRQ %s (%s)%s\n",
|
|
|
|
ndev->name, phydev->phy_id, addr,
|
|
|
|
irq_str, dev_name(&phydev->dev),
|
|
|
|
act ? " active" : "");
|
2009-10-15 06:13:45 +08:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
pr_warning("%s: No PHY found\n", ndev->name);
|
|
|
|
|
|
|
|
return 0;
|
2011-07-20 08:05:23 +08:00
|
|
|
|
2009-10-15 06:13:45 +08:00
|
|
|
bus_register_fail:
|
2011-07-20 08:05:23 +08:00
|
|
|
mdiobus_free(new_bus);
|
2009-10-15 06:13:45 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_unregister
|
|
|
|
* @ndev: net device structure
|
|
|
|
* Description: it unregisters the MII bus
|
|
|
|
*/
|
|
|
|
int stmmac_mdio_unregister(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
|
|
|
|
|
|
|
mdiobus_unregister(priv->mii);
|
|
|
|
priv->mii->priv = NULL;
|
2011-07-20 08:05:23 +08:00
|
|
|
mdiobus_free(priv->mii);
|
|
|
|
priv->mii = NULL;
|
2009-10-15 06:13:45 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|