Files
2026-08-24 10:03:24 +08:00

65 lines
1.0 KiB
C

/*
* Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
*
* SPDX-License-Identifier: MIT
*/
#include <stdio.h>
#include <interrupt.h>
#include <irq.h>
#include <common.h>
#include <n200_func.h>
#include "mac.h"
#include "phy.h"
#define DRV_NAME_PREFIX "EPHY: "
int xPhyReadId(uint32_t *phyId)
{
int ret;
uint32_t tmp = 0;
ret = xMdioRead(ETH_PHY_ADDR, EPHY_ID1);
if (ret < 0)
return ret;
tmp |= ret;
ret = xMdioRead(ETH_PHY_ADDR, EPHY_ID2);
if (ret < 0)
return ret;
tmp |= ret << 16;
*phyId = tmp;
return 0;
}
int xPhyReadLinkStatus(bool *status)
{
int ret;
ret = xMdioRead(ETH_PHY_ADDR, EPHY_BMSR);
if (ret < 0)
return ret;
*status = (bool)!!(ret & EPHY_BMSR_LSTATUS);
return 0;
}
static void prvPhyRegDump(void)
{
uint8_t addr;
int ret;
printf(DRV_NAME_PREFIX "REG DUMP:\n");
for (addr = 0; addr < 32; addr++) {
ret = xMdioRead(ETH_PHY_ADDR, addr);
if (ret < 0) {
printf(DRV_NAME_PREFIX "MDIO READ FAIL\n");
continue;
}
printf(DRV_NAME_PREFIX " [%2d] = 0x%04x\n", (int)addr, ret);
}
}