reg = <0x10007000 0x1000>;
fake-host-hwaddr = [00 00 66 44 22 77];
phy-handle = <ðphy1>;
+ phy-mode = "2500base-x";
};
dsa_eth0: dsa-test-eth {
int board_init(void)
{
#ifdef CONFIG_ETH_DESIGNWARE
- const char *phy_mode;
- int node;
+ ofnode node;
- node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,stm32-dwmac");
- if (node < 0)
+ node = ofnode_by_compatible(ofnode_null(), "st,stm32-dwmac");
+ if (!ofnode_valid(node))
return -1;
- phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
-
- switch (phy_get_interface_by_name(phy_mode)) {
+ switch (ofnode_read_phy_mode(node)) {
case PHY_INTERFACE_MODE_RMII:
STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
break;
STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL;
break;
default:
- printf("PHY interface %s not supported !\n", phy_mode);
+ printf("Unsupported PHY interface!\n");
}
#endif
return args.node;
}
+
+phy_interface_t ofnode_read_phy_mode(ofnode node)
+{
+ const char *mode;
+ int i;
+
+ assert(ofnode_valid(node));
+
+ mode = ofnode_read_string(node, "phy-mode");
+ if (!mode)
+ mode = ofnode_read_string(node, "phy-connection-type");
+
+ if (!mode)
+ return PHY_INTERFACE_MODE_NONE;
+
+ for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++)
+ if (!strcmp(mode, phy_interface_strings[i]))
+ return i;
+
+ debug("%s: Invalid PHY interface '%s'\n", __func__, mode);
+
+ return PHY_INTERFACE_MODE_NONE;
+}
{
return ofnode_get_phy_node(dev_ofnode(dev));
}
+
+phy_interface_t dev_read_phy_mode(const struct udevice *dev)
+{
+ return ofnode_read_phy_mode(dev_ofnode(dev));
+}
static int ag7xxx_eth_of_to_plat(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- const char *phy_mode;
int ret;
pdata->iobase = dev_read_addr(dev);
if (ret <= 0)
return ret;
- phy_mode = fdt_getprop(gd->fdt_blob, ret, "phy-mode", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
return 0;
}
static int altera_tse_of_to_plat(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- const char *phy_mode;
-
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
return 0;
}
struct eth_pdata *pdata = dev_get_plat(dev);
struct bcm6348_eth_priv *priv = dev_get_priv(dev);
struct ofnode_phandle_args phy;
- const char *phy_mode;
int ret, i;
/* get base address */
pdata->iobase = (phys_addr_t) priv->base;
/* get phy mode */
- pdata->phy_interface = PHY_INTERFACE_MODE_NONE;
- phy_mode = dev_read_string(dev, "phy-mode");
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -ENODEV;
struct eth_pdata *pdata = dev_get_plat(dev);
struct bcmgenet_eth_priv *priv = dev_get_priv(dev);
struct ofnode_phandle_args phy_node;
- const char *phy_mode;
int ret;
pdata->iobase = dev_read_addr(dev);
/* Get phy mode from DT */
- pdata->phy_interface = -1;
- phy_mode = dev_read_string(dev, "phy-mode");
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
&phy_node);
struct dw_eth_dev *priv = dev_get_priv(dev);
#endif
struct eth_pdata *pdata = &dw_pdata->eth_pdata;
- const char *phy_mode;
#if CONFIG_IS_ENABLED(DM_GPIO)
int reset_flags = GPIOD_IS_OUT;
#endif
int ret = 0;
pdata->iobase = dev_read_addr(dev);
- pdata->phy_interface = -1;
- phy_mode = dev_read_string(dev, "phy-mode");
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0);
int config_mac;
int config_mac_mdio;
unsigned int axi_bus_width;
- phy_interface_t (*interface)(struct udevice *dev);
+ phy_interface_t (*interface)(const struct udevice *dev);
struct eqos_ops *ops;
};
return ret;
}
-static phy_interface_t eqos_get_interface_stm32(struct udevice *dev)
-{
- const char *phy_mode;
- phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
-
- debug("%s(dev=%p):\n", __func__, dev);
-
- phy_mode = dev_read_prop(dev, "phy-mode", NULL);
- if (phy_mode)
- interface = phy_get_interface_by_name(phy_mode);
-
- return interface;
-}
-
-static phy_interface_t eqos_get_interface_tegra186(struct udevice *dev)
+static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev)
{
return PHY_INTERFACE_MODE_MII;
}
return 0;
}
-static phy_interface_t eqos_get_interface_imx(struct udevice *dev)
-{
- const char *phy_mode;
- phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
-
- debug("%s(dev=%p):\n", __func__, dev);
-
- phy_mode = dev_read_prop(dev, "phy-mode", NULL);
- if (phy_mode)
- interface = phy_get_interface_by_name(phy_mode);
-
- return interface;
-}
-
static int eqos_remove_resources_tegra186(struct udevice *dev)
{
struct eqos_priv *eqos = dev_get_priv(dev);
.config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV,
.config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300,
.axi_bus_width = EQOS_AXI_WIDTH_64,
- .interface = eqos_get_interface_stm32,
+ .interface = dev_read_phy_mode,
.ops = &eqos_stm32_ops
};
.config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
.config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300,
.axi_bus_width = EQOS_AXI_WIDTH_64,
- .interface = eqos_get_interface_imx,
+ .interface = dev_read_phy_mode,
.ops = &eqos_imx_ops
};
int ret = 0;
struct eth_pdata *pdata = dev_get_plat(dev);
struct fec_priv *priv = dev_get_priv(dev);
- const char *phy_mode;
pdata->iobase = dev_read_addr(dev);
priv->eth = (struct ethernet_regs *)pdata->iobase;
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
#ifdef CONFIG_DM_REGULATOR
device_get_supply_regulator(dev, "phy-supply", &priv->phy_supply);
return 0;
}
#else /* CONFIG_DM_ETH */
-#ifdef CONFIG_PHYLIB
-phy_interface_t fman_read_sys_if(struct udevice *dev)
-{
- const char *if_str;
-
- if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type");
- debug("MAC system interface mode %s\n", if_str);
-
- return phy_get_interface_by_name(if_str);
-}
-#endif
static int fm_eth_bind(struct udevice *dev)
{
reg = (void *)(uintptr_t)dev_read_addr(dev);
fm_eth->mac_type = dev_get_driver_data(dev);
#ifdef CONFIG_PHYLIB
- fm_eth->enet_if = fman_read_sys_if(dev);
+ fm_eth->enet_if = dev_read_phy_mode(dev);
#else
fm_eth->enet_if = PHY_INTERFACE_MODE_SGMII;
printf("%s: warning - unable to determine interface type\n", __func__);
static void enetc_start_pcs(struct udevice *dev)
{
struct enetc_priv *priv = dev_get_priv(dev);
- const char *if_str;
-
- priv->if_type = PHY_INTERFACE_MODE_NONE;
/* register internal MDIO for debug purposes */
if (enetc_read_port(priv, ENETC_PCAPR0) & ENETC_PCAPRO_MDIO) {
return;
}
- if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode");
- if (if_str)
- priv->if_type = phy_get_interface_by_name(if_str);
- else
+ priv->if_type = dev_read_phy_mode(dev);
+ if (priv->if_type == PHY_INTERFACE_MODE_NONE) {
enetc_dbg(dev,
"phy-mode property not found, defaulting to SGMII\n");
- if (priv->if_type < 0)
- priv->if_type = PHY_INTERFACE_MODE_NONE;
+ priv->if_type = PHY_INTERFACE_MODE_SGMII;
+ }
switch (priv->if_type) {
case PHY_INTERFACE_MODE_SGMII:
{
struct eth_pdata *pdata = dev_get_plat(dev);
struct ftgmac100_data *priv = dev_get_priv(dev);
- const char *phy_mode;
pdata->iobase = dev_read_addr(dev);
- pdata->phy_interface = -1;
- phy_mode = dev_read_string(dev, "phy-mode");
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode);
+
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0);
static int higmac_of_to_plat(struct udevice *dev)
{
struct higmac_priv *priv = dev_get_priv(dev);
- int phyintf = PHY_INTERFACE_MODE_NONE;
- const char *phy_mode;
ofnode phy_node;
priv->base = dev_remap_addr_index(dev, 0);
priv->macif_ctrl = dev_remap_addr_index(dev, 1);
- phy_mode = dev_read_string(dev, "phy-mode");
- if (phy_mode)
- phyintf = phy_get_interface_by_name(phy_mode);
- if (phyintf == PHY_INTERFACE_MODE_NONE)
+ priv->phyintf = dev_read_phy_mode(dev);
+ if (priv->phyintf == PHY_INTERFACE_MODE_NONE)
return -ENODEV;
- priv->phyintf = phyintf;
phy_node = dev_read_subnode(dev, "phy");
if (!ofnode_valid(phy_node)) {
return fdtdec_get_uint(gd->fdt_blob, port_node, "reg", -1);
}
-static const char *ldpaa_eth_get_phy_mode_str(struct udevice *dev)
-{
- int port_node = dev_of_offset(dev);
- const char *phy_mode_str;
-
- phy_mode_str = fdt_getprop(gd->fdt_blob, port_node,
- "phy-connection-type", NULL);
- if (phy_mode_str)
- return phy_mode_str;
-
- phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL);
- return phy_mode_str;
-}
-
static int ldpaa_eth_bind(struct udevice *dev)
{
- const char *phy_mode_str = NULL;
uint32_t dpmac_id;
char eth_name[16];
int phy_mode = -1;
- phy_mode_str = ldpaa_eth_get_phy_mode_str(dev);
- if (phy_mode_str)
- phy_mode = phy_get_interface_by_name(phy_mode_str);
- if (phy_mode == -1) {
+ phy_mode = dev_read_phy_mode(dev);
+ if (phy_mode == PHY_INTERFACE_MODE_NONE) {
dev_err(dev, "incorrect phy mode\n");
return -EINVAL;
}
return -EINVAL;
}
- sprintf(eth_name, "DPMAC%d@%s", dpmac_id, phy_mode_str);
+ sprintf(eth_name, "DPMAC%d@%s", dpmac_id,
+ phy_string_for_interface(phy_mode));
device_set_name(dev, eth_name);
return 0;
static int ldpaa_eth_of_to_plat(struct udevice *dev)
{
struct ldpaa_eth_priv *priv = dev_get_priv(dev);
- const char *phy_mode_str;
priv->dpmac_id = ldpaa_eth_get_dpmac_id(dev);
- phy_mode_str = ldpaa_eth_get_phy_mode_str(dev);
- priv->phy_mode = phy_get_interface_by_name(phy_mode_str);
+ priv->phy_mode = dev_read_phy_mode(dev);
return 0;
}
struct eth_pdata *pdata = dev_get_plat(dev);
struct macb_device *macb = dev_get_priv(dev);
struct ofnode_phandle_args phandle_args;
- const char *phy_mode;
int ret;
- phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-
- if (phy_mode)
- macb->phy_interface = phy_get_interface_by_name(phy_mode);
- if (macb->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ macb->phy_interface = dev_read_phy_mode(dev);
+ if (macb->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
/* Read phyaddr from DT */
if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
ofnode node)
{
ofnode subnode;
- const char *str;
- int mode, speed, ret;
+ int speed, ret;
u32 phy_addr;
- str = ofnode_read_string(node, "phy-mode");
- if (str) {
- mode = phy_get_interface_by_name(str);
- if (mode < 0) {
- dev_err(priv->dev, "mt7620_eth: invalid phy-mode\n");
- return -EINVAL;
- }
-
- switch (mode) {
- case PHY_INTERFACE_MODE_MII:
- case PHY_INTERFACE_MODE_RMII:
- case PHY_INTERFACE_MODE_RGMII:
- case PHY_INTERFACE_MODE_NONE:
- break;
- default:
- dev_err(priv->dev,
- "mt7620_eth: unsupported phy-mode\n");
- return -ENOTSUPP;
- }
+ priv->port_cfg[idx].mode = ofnode_read_phy_mode(node);
- priv->port_cfg[idx].mode = mode;
- } else {
- priv->port_cfg[idx].mode = PHY_INTERFACE_MODE_NONE;
+ switch (priv->port_cfg[idx].mode) {
+ case PHY_INTERFACE_MODE_MII:
+ case PHY_INTERFACE_MODE_RMII:
+ case PHY_INTERFACE_MODE_RGMII:
+ case PHY_INTERFACE_MODE_NONE:
+ break;
+ default:
+ dev_err(priv->dev, "mt7620_eth: unsupported phy-mode\n");
+ return -ENOTSUPP;
}
subnode = ofnode_find_subnode(node, "fixed-link");
priv->gmac_id = dev_read_u32_default(dev, "mediatek,gmac-id", 0);
/* Interface mode is required */
- str = dev_read_string(dev, "phy-mode");
- if (str) {
- pdata->phy_interface = phy_get_interface_by_name(str);
- priv->phy_interface = pdata->phy_interface;
- } else {
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ priv->phy_interface = pdata->phy_interface;
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) {
printf("error: phy-mode is not set\n");
return -EINVAL;
}
struct mvgbe_device *dmvgbe = dev_get_priv(dev);
void *blob = (void *)gd->fdt_blob;
int node = dev_of_offset(dev);
- const char *phy_mode;
int fl_node;
int pnode;
unsigned long addr;
"marvell,kirkwood-eth-port");
/* Get phy-mode / phy_interface from DT */
- phy_mode = fdt_getprop(gd->fdt_blob, pnode, "phy-mode", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- else
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
pdata->phy_interface = PHY_INTERFACE_MODE_GMII;
dmvgbe->phy_interface = pdata->phy_interface;
static int mvneta_of_to_plat(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- const char *phy_mode;
pdata->iobase = dev_read_addr(dev);
/* Get phy-mode / phy_interface from DT */
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
return 0;
}
static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
{
int port_node = dev_of_offset(dev);
- const char *phy_mode_str;
int phy_node;
u32 id;
u32 phyaddr = 0;
- int phy_mode = -1;
int fixed_link = 0;
int ret;
phyaddr = PHY_MAX_ADDR;
}
- phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL);
- if (phy_mode_str)
- phy_mode = phy_get_interface_by_name(phy_mode_str);
- if (phy_mode == -1) {
+ port->phy_interface = dev_read_phy_mode(dev);
+ if (port->phy_interface == PHY_INTERFACE_MODE_NONE) {
dev_err(dev, "incorrect phy mode\n");
return -EINVAL;
}
port->first_rxq = port->id * rxq_number;
else
port->first_rxq = port->id * port->priv->max_port_rxqs;
- port->phy_interface = phy_mode;
port->phyaddr = phyaddr;
return 0;
*/
struct phy_device *fixed_phy_create(ofnode node)
{
- phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
struct phy_device *phydev;
- const char *if_str;
ofnode subnode;
- if_str = ofnode_read_string(node, "phy-mode");
- if (!if_str) {
- if_str = ofnode_read_string(node, "phy-connection-type");
- }
- if (if_str) {
- interface = phy_get_interface_by_name(if_str);
- }
-
subnode = ofnode_find_subnode(node, "fixed-link");
if (!ofnode_valid(subnode)) {
return NULL;
}
- phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface);
+ phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false,
+ ofnode_read_phy_mode(node));
if (phydev)
phydev->node = subnode;
return 0;
}
-
-int phy_get_interface_by_name(const char *str)
-{
- int i;
-
- for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) {
- if (!strcmp(str, phy_interface_strings[i]))
- return i;
- }
-
- return -1;
-}
{
struct eth_pdata *pdata = dev_get_plat(dev);
struct pic32eth_dev *priv = dev_get_priv(dev);
- const char *phy_mode;
void __iomem *iobase;
fdt_addr_t addr;
fdt_size_t size;
pdata->iobase = (phys_addr_t)addr;
/* get phy mode */
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
/* get phy addr */
offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev),
static int qe_uec_of_to_plat(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- const char *phy_mode;
pdata->iobase = (phys_addr_t)devfdt_get_addr(dev);
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
- "phy-connection-type", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
return 0;
}
int ravb_of_to_plat(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- const char *phy_mode;
const fdt32_t *cell;
- int ret = 0;
pdata->iobase = dev_read_addr(dev);
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
pdata->max_speed = 1000;
cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL);
sprintf(bb_miiphy_buses[0].name, dev->name);
- return ret;
+ return 0;
}
static const struct udevice_id ravb_ids[] = {
int sh_ether_of_to_plat(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- const char *phy_mode;
const fdt32_t *cell;
- int ret = 0;
pdata->iobase = dev_read_addr(dev);
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
pdata->max_speed = 1000;
cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL);
sprintf(bb_miiphy_buses[0].name, dev->name);
- return ret;
+ return 0;
}
static const struct udevice_id sh_ether_ids[] = {
struct eth_pdata *pdata = dev_get_plat(dev);
struct ave_private *priv = dev_get_priv(dev);
struct ofnode_phandle_args args;
- const char *phy_mode;
const u32 *valp;
int ret, nc, nr;
const char *name;
return -EINVAL;
pdata->iobase = dev_read_addr(dev);
- pdata->phy_interface = -1;
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
- NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode);
+
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
pdata->max_speed = 0;
valp = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed",
struct eth_pdata *pdata = dev_get_plat(dev);
struct netsec_priv *priv = dev_get_priv(dev);
struct ofnode_phandle_args phandle_args;
- const char *phy_mode;
pdata->iobase = dev_read_addr_index(dev, 0);
priv->eeprom_base = dev_read_addr_index(dev, 1) - EERPROM_MAP_OFFSET;
- pdata->phy_interface = -1;
- phy_mode = dev_read_prop(dev, "phy-mode", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- pr_err("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
&phandle_args))
struct sun8i_eth_pdata *sun8i_pdata = dev_get_plat(dev);
struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
struct emac_eth_dev *priv = dev_get_priv(dev);
- const char *phy_mode;
const fdt32_t *reg;
int node = dev_of_offset(dev);
int offset = 0;
}
priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
- phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
-
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
printf("phy interface%d\n", pdata->phy_interface);
-
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
if (priv->variant == H3_EMAC) {
ret = sun8i_handle_internal_phy(dev, priv);
struct eth_pdata *pdata = dev_get_plat(dev);
struct am65_cpsw_priv *priv = dev_get_priv(dev);
struct ofnode_phandle_args out_args;
- const char *phy_mode;
int ret = 0;
dev_read_u32(dev, "reg", &priv->port_id);
- phy_mode = dev_read_string(dev, "phy-mode");
- if (phy_mode) {
- pdata->phy_interface =
- phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- dev_err(dev, "Invalid PHY mode '%s', port %u\n",
- phy_mode, priv->port_id);
- ret = -EINVAL;
- goto out;
- }
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) {
+ dev_err(dev, "Invalid PHY mode, port %u\n", priv->port_id);
+ return -EINVAL;
}
dev_read_u32(dev, "max-speed", (u32 *)&pdata->max_speed);
{
struct ofnode_phandle_args out_args;
struct cpsw_slave_data *slave_data;
- const char *phy_mode;
u32 phy_id[2];
int ret;
slave_data = &data->slave_data[slave_index];
- phy_mode = ofnode_read_string(subnode, "phy-mode");
- if (phy_mode)
- slave_data->phy_if = phy_get_interface_by_name(phy_mode);
+ slave_data->phy_if = ofnode_read_phy_mode(subnode);
ret = ofnode_parse_phandle_with_args(subnode, "phy-handle",
NULL, 0, 0, &out_args);
}
pdata->phy_interface = data->slave_data[data->active_slave].phy_if;
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__,
- phy_string_for_interface(pdata->phy_interface));
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
return 0;
}
int phy;
int dma_count;
u32 dma_channel[8];
- const char *phy_mode;
priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1);
priv->net_rx_buffs.rx_flow = priv->slave_port * 8;
priv->sgmii_link_type = SGMII_LINK_MAC_PHY;
priv->has_mdio = true;
} else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) {
- phy_mode = fdt_getprop(fdt, slave, "phy-mode", NULL);
- if (phy_mode) {
- priv->phy_if = phy_get_interface_by_name(phy_mode);
- if (priv->phy_if != PHY_INTERFACE_MODE_RGMII &&
- priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID &&
- priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID &&
- priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) {
- pr_err("invalid phy-mode\n");
- return -EINVAL;
- }
- } else {
+ priv->phy_if = ofnode_read_phy_mode(offset_to_ofnode(slave));
+ if (priv->phy_if == PHY_INTERFACE_MODE_NONE)
priv->phy_if = PHY_INTERFACE_MODE_RGMII;
- }
pdata->phy_interface = priv->phy_if;
+
+ if (priv->phy_if != PHY_INTERFACE_MODE_RGMII &&
+ priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID &&
+ priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID &&
+ priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) {
+ pr_err("invalid phy-mode\n");
+ return -EINVAL;
+ }
+
priv->has_mdio = true;
}
struct ofnode_phandle_args phandle_args;
u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
struct tsec_data *data;
- const char *phy_mode;
ofnode parent, child;
fdt_addr_t reg;
u32 max_speed;
priv->tbiaddr = tbiaddr;
- phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
- if (!phy_mode)
- phy_mode = dev_read_prop(dev, "phy-mode", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1)
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
pdata->phy_interface = tsec_get_interface(priv);
priv->interface = pdata->phy_interface;
struct eth_pdata *pdata = &plat->eth_pdata;
int node = dev_of_offset(dev);
int offset = 0;
- const char *phy_mode;
pdata->iobase = dev_read_addr(dev);
plat->mactype = dev_get_driver_data(dev);
plat->phy_of_handle = offset;
}
- phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- printf("%s: Invalid PHY interface '%s'\n", __func__,
- phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node,
"xlnx,eth-hasnobuf");
struct eth_pdata *pdata = dev_get_plat(dev);
struct zynq_gem_priv *priv = dev_get_priv(dev);
struct ofnode_phandle_args phandle_args;
- const char *phy_mode;
pdata->iobase = (phys_addr_t)dev_read_addr(dev);
priv->iobase = (struct zynq_gem_regs *)pdata->iobase;
}
}
- phy_mode = dev_read_prop(dev, "phy-mode", NULL);
- if (phy_mode)
- pdata->phy_interface = phy_get_interface_by_name(phy_mode);
- if (pdata->phy_interface == -1) {
- debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+ pdata->phy_interface = dev_read_phy_mode(dev);
+ if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
return -EINVAL;
- }
priv->interface = pdata->phy_interface;
priv->int_pcs = dev_read_bool(dev, "is-internal-pcspma");
#include <dm/of.h>
#include <dm/of_access.h>
#include <log.h>
+#include <phy_interface.h>
/* Enable checks to protect against invalid calls */
#undef OF_CHECKS
*/
ofnode ofnode_get_phy_node(ofnode eth_node);
+/**
+ * ofnode_read_phy_mode() - Read PHY connection type from a MAC node
+ *
+ * This function parses the "phy-mode" / "phy-connection-type" property and
+ * returns the corresponding PHY interface type.
+ *
+ * @mac_node: ofnode containing the property
+ * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on
+ * error
+ */
+phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
+
#endif
*/
ofnode dev_get_phy_node(const struct udevice *dev);
+/**
+ * dev_read_phy_mode() - Read PHY connection type from a MAC
+ *
+ * This function parses the "phy-mode" / "phy-connection-type" property and
+ * returns the corresponding PHY interface type.
+ *
+ * @dev: device representing the MAC
+ * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on
+ * error
+ */
+phy_interface_t dev_read_phy_mode(const struct udevice *dev);
+
#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
#include <asm/global_data.h>
return ofnode_get_phy_node(dev_ofnode(dev));
}
+static inline phy_interface_t dev_read_phy_mode(const struct udevice *dev)
+{
+ return ofnode_read_phy_mode(dev_ofnode(dev));
+}
+
#endif /* CONFIG_DM_DEV_READ_INLINE */
/**
int board_phy_config(struct phy_device *phydev);
int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
-/**
- * phy_get_interface_by_name() - Look up a PHY interface name
- *
- * @str: PHY interface name, e.g. "mii"
- * @return: PHY_INTERFACE_MODE_... value, or -1 if not found
- */
-int phy_get_interface_by_name(const char *str);
-
/**
* phy_interface_is_rgmii - Convenience function for testing if a PHY interface
* is RGMII (all variants)
#include <dm/uclass-internal.h>
#include <linux/compat.h>
-/* DT node properties for MAC-PHY interface */
-static const char * const phy_mode_str[] = {
- "phy-mode", "phy-connection-type"
-};
-
void dm_mdio_probe_devices(void)
{
struct udevice *it;
/* Connect to a PHY linked in eth DT node */
struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
{
- const char *if_str;
phy_interface_t interface;
struct phy_device *phy;
- int i;
if (!dev_has_ofnode(ethdev)) {
debug("%s: supplied eth dev has no DT node!\n", ethdev->name);
return NULL;
}
- interface = PHY_INTERFACE_MODE_NONE;
- for (i = 0; i < ARRAY_SIZE(phy_mode_str); i++) {
- if_str = dev_read_string(ethdev, phy_mode_str[i]);
- if (if_str) {
- interface = phy_get_interface_by_name(if_str);
- break;
- }
- }
- if (interface < 0)
- interface = PHY_INTERFACE_MODE_NONE;
+ interface = dev_read_phy_mode(ethdev);
if (interface == PHY_INTERFACE_MODE_NONE)
dev_dbg(ethdev, "can't find interface mode, default to NONE\n");
static int dm_test_ofnode_get_phy(struct unit_test_state *uts)
{
ofnode eth_node, phy_node;
+ phy_interface_t mode;
u32 reg;
eth_node = ofnode_path("/phy-test-eth");
ut_assert(ofnode_valid(eth_node));
+ mode = ofnode_read_phy_mode(eth_node);
+ ut_assert(mode == PHY_INTERFACE_MODE_2500BASEX);
+
phy_node = ofnode_get_phy_node(eth_node);
ut_assert(ofnode_valid(phy_node));