* (C) Copyright 2001
* Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
*
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that 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., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier: GPL-2.0+
*/
/*
#include <common.h>
#include <command.h>
-
-#if (CONFIG_COMMANDS & CFG_CMD_MII)
#include <miiphy.h>
-#ifdef CONFIG_TERSE_MII
-/*
- * Display values from last command.
- */
-uint last_op;
-uint last_addr;
-uint last_data;
-uint last_reg;
-
-/*
- * MII device/info/read/write
- *
- * Syntax:
- * mii device {devname}
- * mii info {addr}
- * mii read {addr} {reg}
- * mii write {addr} {reg} {data}
- */
-int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
-{
- char op;
- unsigned char addr, reg;
- unsigned short data;
- int rcode = 0;
- char *devname;
-
-#if defined(CONFIG_8xx) || defined(CONFIG_MCF52x2)
- mii_init ();
-#endif
-
- /*
- * We use the last specified parameters, unless new ones are
- * entered.
- */
- op = last_op;
- addr = last_addr;
- data = last_data;
- reg = last_reg;
-
- if ((flag & CMD_FLAG_REPEAT) == 0) {
- op = argv[1][0];
- if (argc >= 3)
- addr = simple_strtoul (argv[2], NULL, 16);
- if (argc >= 4)
- reg = simple_strtoul (argv[3], NULL, 16);
- if (argc >= 5)
- data = simple_strtoul (argv[4], NULL, 16);
- }
-
- /* use current device */
- devname = miiphy_get_current_dev();
-
- /*
- * check device/read/write/list.
- */
- if (op == 'i') {
- unsigned char j, start, end;
- unsigned int oui;
- unsigned char model;
- unsigned char rev;
-
- /*
- * Look for any and all PHYs. Valid addresses are 0..31.
- */
- if (argc >= 3) {
- start = addr; end = addr + 1;
- } else {
- start = 0; end = 31;
- }
-
- for (j = start; j < end; j++) {
- if (miiphy_info (devname, j, &oui, &model, &rev) == 0) {
- printf ("PHY 0x%02X: "
- "OUI = 0x%04X, "
- "Model = 0x%02X, "
- "Rev = 0x%02X, "
- "%3dbaseT, %s\n",
- j, oui, model, rev,
- miiphy_speed (devname, j),
- (miiphy_duplex (devname, j) == FULL)
- ? "FDX" : "HDX");
- } else {
- puts ("Error reading info from the PHY\n");
- }
- }
- } else if (op == 'r') {
- if (miiphy_read (devname, addr, reg, &data) != 0) {
- puts ("Error reading from the PHY\n");
- rcode = 1;
- } else {
- printf ("%04X\n", data & 0x0000FFFF);
- }
- } else if (op == 'w') {
- if (miiphy_write (devname, addr, reg, data) != 0) {
- puts ("Error writing to the PHY\n");
- rcode = 1;
- }
- } else if (op == 'd') {
- if (argc == 2)
- miiphy_listdev ();
- else
- miiphy_set_current_dev (argv[2]);
- } else {
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- }
-
- /*
- * Save the parameters for repeats.
- */
- last_op = op;
- last_addr = addr;
- last_data = data;
- last_reg = reg;
-
- return rcode;
-}
-
-/***************************************************/
-
-U_BOOT_CMD(
- mii, 5, 1, do_mii,
- "mii - MII utility commands\n",
- "device - list available devices\n"
- "mii device <devname> - set current device\n"
- "mii info <addr> - display MII PHY info\n"
- "mii read <addr> <reg> - read MII PHY <addr> register <reg>\n"
- "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n"
-);
-
-#else /* ! CONFIG_TERSE_MII ================================================= */
-
typedef struct _MII_reg_desc_t {
ushort regno;
char * name;
} MII_reg_desc_t;
-MII_reg_desc_t reg_0_5_desc_tbl[] = {
- { 0, "PHY control register" },
- { 1, "PHY status register" },
- { 2, "PHY ID 1 register" },
- { 3, "PHY ID 2 register" },
- { 4, "Autonegotiation advertisement register" },
- { 5, "Autonegotiation partner abilities register" },
+static const MII_reg_desc_t reg_0_5_desc_tbl[] = {
+ { MII_BMCR, "PHY control register" },
+ { MII_BMSR, "PHY status register" },
+ { MII_PHYSID1, "PHY ID 1 register" },
+ { MII_PHYSID2, "PHY ID 2 register" },
+ { MII_ADVERTISE, "Autonegotiation advertisement register" },
+ { MII_LPA, "Autonegotiation partner abilities register" },
};
typedef struct _MII_field_desc_t {
char * name;
} MII_field_desc_t;
-MII_field_desc_t reg_0_desc_tbl[] = {
+static const MII_field_desc_t reg_0_desc_tbl[] = {
{ 15, 15, 0x01, "reset" },
{ 14, 14, 0x01, "loopback" },
{ 13, 6, 0x81, "speed selection" }, /* special */
{ 5, 0, 0x3f, "(reserved)" }
};
-MII_field_desc_t reg_1_desc_tbl[] = {
+static const MII_field_desc_t reg_1_desc_tbl[] = {
{ 15, 15, 0x01, "100BASE-T4 able" },
{ 14, 14, 0x01, "100BASE-X full duplex able" },
{ 13, 13, 0x01, "100BASE-X half duplex able" },
{ 0, 0, 0x01, "extended capabilities" },
};
-MII_field_desc_t reg_2_desc_tbl[] = {
+static const MII_field_desc_t reg_2_desc_tbl[] = {
{ 15, 0, 0xffff, "OUI portion" },
};
-MII_field_desc_t reg_3_desc_tbl[] = {
+static const MII_field_desc_t reg_3_desc_tbl[] = {
{ 15, 10, 0x3f, "OUI portion" },
{ 9, 4, 0x3f, "manufacturer part number" },
{ 3, 0, 0x0f, "manufacturer rev. number" },
};
-MII_field_desc_t reg_4_desc_tbl[] = {
+static const MII_field_desc_t reg_4_desc_tbl[] = {
{ 15, 15, 0x01, "next page able" },
- { 14, 14, 0x01, "reserved" },
+ { 14, 14, 0x01, "(reserved)" },
{ 13, 13, 0x01, "remote fault" },
- { 12, 12, 0x01, "reserved" },
+ { 12, 12, 0x01, "(reserved)" },
{ 11, 11, 0x01, "asymmetric pause" },
{ 10, 10, 0x01, "pause enable" },
{ 9, 9, 0x01, "100BASE-T4 able" },
{ 4, 0, 0x1f, "xxx to do" },
};
-MII_field_desc_t reg_5_desc_tbl[] = {
+static const MII_field_desc_t reg_5_desc_tbl[] = {
{ 15, 15, 0x01, "next page able" },
{ 14, 14, 0x01, "acknowledge" },
{ 13, 13, 0x01, "remote fault" },
{ 5, 5, 0x01, "10BASE-T able" },
{ 4, 0, 0x1f, "xxx to do" },
};
-
-#define DESC0LEN (sizeof(reg_0_desc_tbl)/sizeof(reg_0_desc_tbl[0]))
-#define DESC1LEN (sizeof(reg_1_desc_tbl)/sizeof(reg_1_desc_tbl[0]))
-#define DESC2LEN (sizeof(reg_2_desc_tbl)/sizeof(reg_2_desc_tbl[0]))
-#define DESC3LEN (sizeof(reg_3_desc_tbl)/sizeof(reg_3_desc_tbl[0]))
-#define DESC4LEN (sizeof(reg_4_desc_tbl)/sizeof(reg_4_desc_tbl[0]))
-#define DESC5LEN (sizeof(reg_5_desc_tbl)/sizeof(reg_5_desc_tbl[0]))
-
typedef struct _MII_field_desc_and_len_t {
- MII_field_desc_t * pdesc;
+ const MII_field_desc_t *pdesc;
ushort len;
} MII_field_desc_and_len_t;
-MII_field_desc_and_len_t desc_and_len_tbl[] = {
- { reg_0_desc_tbl, DESC0LEN },
- { reg_1_desc_tbl, DESC1LEN },
- { reg_2_desc_tbl, DESC2LEN },
- { reg_3_desc_tbl, DESC3LEN },
- { reg_4_desc_tbl, DESC4LEN },
- { reg_5_desc_tbl, DESC5LEN },
+static const MII_field_desc_and_len_t desc_and_len_tbl[] = {
+ { reg_0_desc_tbl, ARRAY_SIZE(reg_0_desc_tbl) },
+ { reg_1_desc_tbl, ARRAY_SIZE(reg_1_desc_tbl) },
+ { reg_2_desc_tbl, ARRAY_SIZE(reg_2_desc_tbl) },
+ { reg_3_desc_tbl, ARRAY_SIZE(reg_3_desc_tbl) },
+ { reg_4_desc_tbl, ARRAY_SIZE(reg_4_desc_tbl) },
+ { reg_5_desc_tbl, ARRAY_SIZE(reg_5_desc_tbl) },
};
static void dump_reg(
ushort regval,
- MII_reg_desc_t * prd,
- MII_field_desc_and_len_t * pdl);
+ const MII_reg_desc_t *prd,
+ const MII_field_desc_and_len_t *pdl);
static int special_field(
ushort regno,
- MII_field_desc_t * pdesc,
+ const MII_field_desc_t *pdesc,
ushort regval);
-void MII_dump_0_to_5(
+static void MII_dump_0_to_5(
ushort regvals[6],
uchar reglo,
uchar reghi)
static void dump_reg(
ushort regval,
- MII_reg_desc_t * prd,
- MII_field_desc_and_len_t * pdl)
+ const MII_reg_desc_t *prd,
+ const MII_field_desc_and_len_t *pdl)
{
ulong i;
ushort mask_in_place;
- MII_field_desc_t * pdesc;
+ const MII_field_desc_t *pdesc;
printf("%u. (%04hx) -- %s --\n",
prd->regno, regval, prd->name);
mask_in_place = pdesc->mask << pdesc->lo;
- printf(" (%04hx:%04hx) %u.",
- mask_in_place,
- regval & mask_in_place,
- prd->regno);
+ printf(" (%04hx:%04x) %u.",
+ mask_in_place,
+ regval & mask_in_place,
+ prd->regno);
if (special_field(prd->regno, pdesc, regval)) {
}
static int special_field(
ushort regno,
- MII_field_desc_t * pdesc,
+ const MII_field_desc_t *pdesc,
ushort regval)
{
- if ((regno == 0) && (pdesc->lo == 6)) {
- ushort speed_bits = regval & PHY_BMCR_SPEED_MASK;
+ if ((regno == MII_BMCR) && (pdesc->lo == 6)) {
+ ushort speed_bits = regval & (BMCR_SPEED1000 | BMCR_SPEED100);
printf("%2u,%2u = b%u%u speed selection = %s Mbps",
6, 13,
(regval >> 6) & 1,
(regval >> 13) & 1,
- speed_bits == PHY_BMCR_1000_MBPS ? "1000" :
- speed_bits == PHY_BMCR_100_MBPS ? "100" :
- speed_bits == PHY_BMCR_10_MBPS ? "10" :
- "???");
+ speed_bits == BMCR_SPEED1000 ? "1000" :
+ speed_bits == BMCR_SPEED100 ? "100" :
+ "10");
return 1;
}
- else if ((regno == 0) && (pdesc->lo == 8)) {
+ else if ((regno == MII_BMCR) && (pdesc->lo == 8)) {
printf("%2u = %5u duplex = %s",
pdesc->lo,
(regval >> pdesc->lo) & 1,
return 1;
}
- else if ((regno == 4) && (pdesc->lo == 0)) {
+ else if ((regno == MII_ADVERTISE) && (pdesc->lo == 0)) {
ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
printf("%2u-%2u = %5u selector = %s",
pdesc->hi, pdesc->lo, sel_bits,
return 1;
}
- else if ((regno == 5) && (pdesc->lo == 0)) {
+ else if ((regno == MII_LPA) && (pdesc->lo == 0)) {
ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
printf("%2u-%2u = %u selector = %s",
pdesc->hi, pdesc->lo, sel_bits,
return 0;
}
-char last_op[2];
-uint last_data;
-uint last_addr_lo;
-uint last_addr_hi;
-uint last_reg_lo;
-uint last_reg_hi;
+static char last_op[2];
+static uint last_data;
+static uint last_addr_lo;
+static uint last_addr_hi;
+static uint last_reg_lo;
+static uint last_reg_hi;
static void extract_range(
char * input,
}
/* ---------------------------------------------------------------- */
-int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+static int do_mii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char op[2];
unsigned char addrlo, addrhi, reglo, reghi;
unsigned char addr, reg;
unsigned short data;
int rcode = 0;
- char *devname;
+ const char *devname;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
-#ifdef CONFIG_8xx
+#if defined(CONFIG_MII_INIT)
mii_init ();
#endif
"OUI = 0x%04X, "
"Model = 0x%02X, "
"Rev = 0x%02X, "
- "%3dbaseT, %s\n",
+ "%3dbase%s, %s\n",
j, oui, model, rev,
miiphy_speed (devname, j),
+ miiphy_is_1000base_x (devname, j)
+ ? "X" : "T",
(miiphy_duplex (devname, j) == FULL)
? "FDX" : "HDX");
- } else {
- puts ("Error reading info from the PHY\n");
}
}
} else if (op[0] == 'r') {
else
miiphy_set_current_dev (argv[2]);
} else {
- printf("Usage:\n%s\n", cmdtp->usage);
- return 1;
+ return CMD_RET_USAGE;
}
/*
U_BOOT_CMD(
mii, 5, 1, do_mii,
- "mii - MII utility commands\n",
+ "MII utility commands",
"device - list available devices\n"
"mii device <devname> - set current device\n"
"mii info <addr> - display MII PHY info\n"
"mii read <addr> <reg> - read MII PHY <addr> register <reg>\n"
"mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n"
"mii dump <addr> <reg> - pretty-print <addr> <reg> (0-5 only)\n"
- "Addr and/or reg may be ranges, e.g. 2-7.\n"
+ "Addr and/or reg may be ranges, e.g. 2-7."
);
-
-#endif /* CONFIG_TERSE_MII */
-
-#endif /* CFG_CMD_MII */