You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.3 KiB
71 lines
1.3 KiB
7 months ago
|
/*
|
||
|
* Copyright (c) Company 2018-2019. All rights reserved.
|
||
|
* Description: GMAC mdio driver
|
||
|
*/
|
||
|
#include "mdio.h"
|
||
|
#include "util.h"
|
||
|
#include "gmac.h"
|
||
|
|
||
|
static int wait_mdio_ready(const struct gmac_netdev_local *ld)
|
||
|
{
|
||
|
int timeout_us = 1000;
|
||
|
|
||
|
while (--timeout_us && !test_mdio_ready(ld))
|
||
|
udelay(1);
|
||
|
|
||
|
return timeout_us;
|
||
|
}
|
||
|
|
||
|
int gmac_mdio_read(struct mii_bus *bus, int phy, int reg)
|
||
|
{
|
||
|
struct gmac_netdev_local *ld = NULL;
|
||
|
int timeout = 1000;
|
||
|
int val;
|
||
|
|
||
|
if (bus == NULL)
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
ld = bus->priv;
|
||
|
if (ld == NULL)
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
if (!wait_mdio_ready(ld))
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
mdio_start_phyread(ld, (unsigned int)phy, (unsigned int)reg);
|
||
|
|
||
|
while (!wait_mdio_ready(ld) && timeout-- > 0)
|
||
|
udelay(1);
|
||
|
|
||
|
if (timeout <= 0 || !test_mdio_read_data_done(ld))
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
val = mdio_get_phyread_val(ld);
|
||
|
|
||
|
gmac_trace(2, "mdio read phy:%x, reg:%x = %x\n", phy, reg, val); /* trace level 2 */
|
||
|
|
||
|
return val;
|
||
|
}
|
||
|
|
||
|
int gmac_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
|
||
|
{
|
||
|
struct gmac_netdev_local *ld = NULL;
|
||
|
|
||
|
if (bus == NULL)
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
ld = bus->priv;
|
||
|
if (ld == NULL)
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
if (!wait_mdio_ready(ld))
|
||
|
return -ETIMEDOUT;
|
||
|
|
||
|
gmac_trace(2, "mdio write phy:%x, reg:%x = %x\n", phy, reg, val); /* trace level 2 */
|
||
|
|
||
|
mdio_set_phywrite_val(ld, val);
|
||
|
mdio_phywrite(ld, (u32)phy, (u32)reg);
|
||
|
|
||
|
return 0;
|
||
|
}
|