mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-18 18:59:44 +00:00
83d290c56f
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
120 lines
3 KiB
C
120 lines
3 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* pic32_mdio.c: PIC32 MDIO/MII driver, part of pic32_eth.c.
|
|
*
|
|
* Copyright 2015 Microchip Inc.
|
|
* Purna Chandra Mandal <purna.mandal@microchip.com>
|
|
*/
|
|
#include <common.h>
|
|
#include <phy.h>
|
|
#include <miiphy.h>
|
|
#include <errno.h>
|
|
#include <wait_bit.h>
|
|
#include <asm/io.h>
|
|
#include "pic32_eth.h"
|
|
|
|
static int pic32_mdio_write(struct mii_dev *bus,
|
|
int addr, int dev_addr,
|
|
int reg, u16 value)
|
|
{
|
|
u32 v;
|
|
struct pic32_mii_regs *mii_regs = bus->priv;
|
|
|
|
/* Wait for the previous operation to finish */
|
|
wait_for_bit_le32(&mii_regs->mind.raw, MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, true);
|
|
|
|
/* Put phyaddr and regaddr into MIIMADD */
|
|
v = (addr << MIIMADD_PHYADDR_SHIFT) | (reg & MIIMADD_REGADDR);
|
|
writel(v, &mii_regs->madr.raw);
|
|
|
|
/* Initiate a write command */
|
|
writel(value, &mii_regs->mwtd.raw);
|
|
|
|
/* Wait 30 clock cycles for busy flag to be set */
|
|
udelay(12);
|
|
|
|
/* Wait for write to complete */
|
|
wait_for_bit_le32(&mii_regs->mind.raw, MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, true);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pic32_mdio_read(struct mii_dev *bus, int addr, int devaddr, int reg)
|
|
{
|
|
u32 v;
|
|
struct pic32_mii_regs *mii_regs = bus->priv;
|
|
|
|
/* Wait for the previous operation to finish */
|
|
wait_for_bit_le32(&mii_regs->mind.raw, MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, true);
|
|
|
|
/* Put phyaddr and regaddr into MIIMADD */
|
|
v = (addr << MIIMADD_PHYADDR_SHIFT) | (reg & MIIMADD_REGADDR);
|
|
writel(v, &mii_regs->madr.raw);
|
|
|
|
/* Initiate a read command */
|
|
writel(MIIMCMD_READ, &mii_regs->mcmd.raw);
|
|
|
|
/* Wait 30 clock cycles for busy flag to be set */
|
|
udelay(12);
|
|
|
|
/* Wait for read to complete */
|
|
wait_for_bit_le32(&mii_regs->mind.raw,
|
|
MIIMIND_NOTVALID | MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, false);
|
|
|
|
/* Clear the command register */
|
|
writel(0, &mii_regs->mcmd.raw);
|
|
|
|
/* Grab the value read from the PHY */
|
|
v = readl(&mii_regs->mrdd.raw);
|
|
return v;
|
|
}
|
|
|
|
static int pic32_mdio_reset(struct mii_dev *bus)
|
|
{
|
|
struct pic32_mii_regs *mii_regs = bus->priv;
|
|
|
|
/* Reset MII (due to new addresses) */
|
|
writel(MIIMCFG_RSTMGMT, &mii_regs->mcfg.raw);
|
|
|
|
/* Wait for the operation to finish */
|
|
wait_for_bit_le32(&mii_regs->mind.raw, MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, true);
|
|
|
|
/* Clear reset bit */
|
|
writel(0, &mii_regs->mcfg);
|
|
|
|
/* Wait for the operation to finish */
|
|
wait_for_bit_le32(&mii_regs->mind.raw, MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, true);
|
|
|
|
/* Set the MII Management Clock (MDC) - no faster than 2.5 MHz */
|
|
writel(MIIMCFG_CLKSEL_DIV40, &mii_regs->mcfg.raw);
|
|
|
|
/* Wait for the operation to finish */
|
|
wait_for_bit_le32(&mii_regs->mind.raw, MIIMIND_BUSY,
|
|
false, CONFIG_SYS_HZ, true);
|
|
return 0;
|
|
}
|
|
|
|
int pic32_mdio_init(const char *name, ulong ioaddr)
|
|
{
|
|
struct mii_dev *bus;
|
|
|
|
bus = mdio_alloc();
|
|
if (!bus) {
|
|
printf("Failed to allocate PIC32-MDIO bus\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
bus->read = pic32_mdio_read;
|
|
bus->write = pic32_mdio_write;
|
|
bus->reset = pic32_mdio_reset;
|
|
strncpy(bus->name, name, sizeof(bus->name));
|
|
bus->priv = (void *)ioaddr;
|
|
|
|
return mdio_register(bus);
|
|
}
|