u-boot/cmd/sjainfo.c

116 lines
2.3 KiB
C

/*
* sja1105.c
*
* Functions for NXP SJA1105 Ethernet Switch
*
* Copyright (C) 2018-2019 NetModule AG - http://www.netmodule.com/
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <dm.h>
#include <spi.h>
#include <sja1105.h>
#if !defined(CONFIG_SPL_BUILD)
#define SJA_NUM_PORTS 5
#define SJA_REG_MST_ADDR 0x0200
#define SJA_REG_MST_INCR 0x02
#define SJA_REG_RXF_ADDR 0x0406
#define SJA_REG_RXF_INCR 0x10
#define SJA_REG_TXF_ADDR 0x0402
#define SJA_REG_TXF_INCR 0x10
struct sja1105_stat
{
uint32_t mst;
uint32_t rxf;
uint32_t txf;
};
static int read_stat(struct spi_slave *spi, struct sja1105_stat *s, int n)
{
int ret = 0;
if (!ret) ret = sja1105_read_reg(spi, SJA_REG_MST_ADDR + SJA_REG_MST_INCR * n, &s->mst);
if (!ret) ret = sja1105_read_reg(spi, SJA_REG_RXF_ADDR + SJA_REG_RXF_INCR * n, &s->txf);
if (!ret) ret = sja1105_read_reg(spi, SJA_REG_TXF_ADDR + SJA_REG_TXF_INCR * n, &s->rxf);
return ret;
}
static int do_sjainfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
struct udevice *dev;
struct spi_slave *spi;
struct sja1105_stat s[SJA_NUM_PORTS] = { 0 };
int i;
int ret;
/* Get sja1105 device */
ret = uclass_get_device_by_name(UCLASS_MISC, "sja1105", &dev);
if (ret)
{
printf("sjainfo: switch not found\n");
return 1;
}
/* Try to claim SPI bus */
spi = dev_get_parent_priv(dev);
if (!spi)
{
printf("sja1105: switch SPI bus not found\n");
return 1;
}
ret = spi_claim_bus(spi);
if (ret)
{
printf("sja1105: unable to claim SPI bus\n");
return 1;
}
/* Read stats */
for (i = 0; i < SJA_NUM_PORTS && !ret; i++)
{
ret = read_stat(spi, &s[i], i);
}
if (ret)
{
printf("sjainfo: could not read port %d status registers\n", i);
goto exit;
}
printf("Port MAC Stat\t\tRx\tTx\n");
printf("0 (UM) : %08x\t\t%u\t%u\n", s[0].mst, s[0].rxf, s[0].txf);
printf("1 (BroadR-0) : %08x\t\t%u\t%u\n", s[1].mst, s[1].rxf, s[1].txf);
printf("2 (BroadR-1) : %08x\t\t%u\t%u\n", s[2].mst, s[2].rxf, s[2].txf);
printf("3 (100bTx) : %08x\t\t%u\t%u\n", s[3].mst, s[3].rxf, s[3].txf);
printf("4 (CPU) : %08x\t\t%u\t%u\n", s[4].mst, s[4].rxf, s[4].txf);
/* Done */
exit:
/* Release SPI bus */
spi_release_bus(spi);
return 0;
}
U_BOOT_CMD(
sjainfo, 1, 1, do_sjainfo,
"Show SJA1105 ethernet switch information",
""
);
#endif