From patchwork Thu Feb 1 12:42:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 868229 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="NeUmxeXC"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zXKWr33smz9t4B for ; Thu, 1 Feb 2018 23:42:30 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 7177AC21E33; Thu, 1 Feb 2018 12:42:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2E661C21CB1; Thu, 1 Feb 2018 12:42:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9A8FBC21DA5; Thu, 1 Feb 2018 12:42:18 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by lists.denx.de (Postfix) with ESMTPS id 2D459C21CB1 for ; Thu, 1 Feb 2018 12:42:18 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id b21so5385325wme.4 for ; Thu, 01 Feb 2018 04:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=6zEE20MUavE6DWP602+nT6wytECpR+p+956Jd9MT3X4=; b=NeUmxeXCf/LABWoT/Hj5Q2qfkdDnD9u2scx54gynubBK+nGQVSxj0Iey3ImGnn/bih wVA1x5mBqTWtl+Q2QoLsNNwAxiKU1nBlljkFp+pA0H+Tu9ALO3zE3I4xHilhBvyJ5Zw+ 8BexiI5SUPvCW1X+Dz8GHgvSPVSyo8/0pEhDL0dR2eXdJdpUQ5dd+CQroOHB00HLJFPB /myzME/WvbxDC5tVX8JZhOCvugn3QX/dnm4W2EKxc7F/Vdu9l/jYfdNVTlsJQwrDioTE a58UCE0FsyeThk74PSfdo360kiwWJoeLPh0a4KkmJZsPEFUpaWwoXurD/jg6wFGDGCQQ SSAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=6zEE20MUavE6DWP602+nT6wytECpR+p+956Jd9MT3X4=; b=RsX87c+/1SnmHNWKHTuMfUaQVz8XpfZZys22qfnq601aekqTCyyho28XFyYJPyfeF9 B4k22hFwtiFRrnhHoDBTNYWCu0pm0yB3E3xFZHj9NfG+QZ5Ff7B7RG7SKrdHE6Bn94bG gl5c1YidlQfDUbmbplubmsedmyjRCDfzSR6DewhEg/TNtVcVsq19N2qOuongSZhsvItI PYukePehNF2fRiVtBZ0RsVAeN6XwdfRPOgQ3eDrOnufyyrMRoVGwg2qREMEAodI81ltp k4qteyyuwVOCOKq7snOo2+1oSG0H+cTv3tKODoKsz+R+hoYqMiddYWc0WFPTpS+Vq6lk d6kQ== X-Gm-Message-State: AKwxytdl0KutCCoJ7Meg9w1DqRQXcNBUBoS6LmN0Pd1ersxCMiNPaiRY +eaLc+JjuTCMM5/bzbuHozD9gQAQ X-Google-Smtp-Source: AH8x225j+fDoKMndzPv7RIttUeuqc6RRr+/AANMlGg5picHkrYaQCWdL+uiOZKTfu7CMJoJBtS9XnQ== X-Received: by 10.28.99.137 with SMTP id x131mr25173261wmb.12.1517488937481; Thu, 01 Feb 2018 04:42:17 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id s127sm2218107wmf.28.2018.02.01.04.42.16 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 01 Feb 2018 04:42:16 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Joe Hershberger Date: Thu, 1 Feb 2018 13:42:15 +0100 Message-Id: <2737289a73dd79d27bd30a6c062afb6e3e55eb3b.1517488933.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 Cc: tgorochowik@antmicro.com Subject: [U-Boot] [RFC PATCH] net: gem: Add support for more PHYs on MDIO bus X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Find out MDIO bus and enable MDIO access to it if this is done via different controller. Signed-off-by: Michal Simek Signed-off-by: Tomasz Gorochowik --- Hi Joe, this is the code I have hacked a year ago for ZynqMP where we can have configuration that 4 gems are enabled but they share the same MDIO bus which can be assigned to only gem. Normally recommendation is that you should assign it to IP which is required for boot and this is suitable I would say for almost everybody. But for testing purpose it will be good to support sharing mdio bus between others IPs. This hack is "enabling" this for others gem but not across different ethernet drivers. And my question is if there is any solution which can be used now for handling it. Or even this should work even now but we do something wrong. I am refreshing this topic based on communication with Tomasz Gorochowik when he wanted to separate mdio part but it is not compatible with solution used in Linux which is pattern we should follow. Note: I tested it only on zcu102 with the standard configuration but Tomasz confirmed that this is still working with shared mdio bus. Thanks, Michal --- drivers/net/zynq_gem.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c index 2cc49bca922a..33245ec36e67 100644 --- a/drivers/net/zynq_gem.c +++ b/drivers/net/zynq_gem.c @@ -177,6 +177,7 @@ struct zynq_gem_priv { int phyaddr; int init; struct zynq_gem_regs *iobase; + struct zynq_gem_regs *mdiobase; phy_interface_t interface; struct phy_device *phydev; int phy_of_handle; @@ -189,7 +190,7 @@ static u32 phy_setup_op(struct zynq_gem_priv *priv, u32 phy_addr, u32 regnum, u32 op, u16 *data) { u32 mgtcr; - struct zynq_gem_regs *regs = priv->iobase; + struct zynq_gem_regs *regs = priv->mdiobase; int err; err = wait_for_bit_le32(®s->nwsr, ZYNQ_GEM_NWSR_MDIOIDLE_MASK, @@ -314,7 +315,7 @@ static int zynq_phy_init(struct udevice *dev) { int ret; struct zynq_gem_priv *priv = dev_get_priv(dev); - struct zynq_gem_regs *regs = priv->iobase; + struct zynq_gem_regs *regs_mdio = priv->mdiobase; const u32 supported = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Half | @@ -323,7 +324,7 @@ static int zynq_phy_init(struct udevice *dev) SUPPORTED_1000baseT_Full; /* Enable only MDIO bus */ - writel(ZYNQ_GEM_NWCTRL_MDEN_MASK, ®s->nwctrl); + writel(ZYNQ_GEM_NWCTRL_MDEN_MASK, ®s_mdio->nwctrl); if (priv->interface != PHY_INTERFACE_MODE_SGMII) { ret = phy_detection(dev); @@ -355,6 +356,7 @@ static int zynq_gem_init(struct udevice *dev) unsigned long clk_rate = 0; struct zynq_gem_priv *priv = dev_get_priv(dev); struct zynq_gem_regs *regs = priv->iobase; + struct zynq_gem_regs *regs_mdio = priv->mdiobase; struct emac_bd *dummy_tx_bd = &priv->tx_bd[TX_FREE_DESC]; struct emac_bd *dummy_rx_bd = &priv->tx_bd[TX_FREE_DESC + 2]; @@ -397,7 +399,7 @@ static int zynq_gem_init(struct udevice *dev) writel(ZYNQ_GEM_DMACR_INIT, ®s->dmacr); /* Setup for Network Control register, MDIO, Rx and Tx enable */ - setbits_le32(®s->nwctrl, ZYNQ_GEM_NWCTRL_MDEN_MASK); + setbits_le32(®s_mdio->nwctrl, ZYNQ_GEM_NWCTRL_MDEN_MASK); /* Disable the second priority queue */ dummy_tx_bd->addr = 0; @@ -623,6 +625,7 @@ static int zynq_gem_probe(struct udevice *dev) void *bd_space; struct zynq_gem_priv *priv = dev_get_priv(dev); int ret; + char name[MDIO_NAME_LEN]; /* Align rxbuffers to ARCH_DMA_MINALIGN */ priv->rxbuffers = memalign(ARCH_DMA_MINALIGN, RX_BUF * PKTSIZE_ALIGN); @@ -648,6 +651,9 @@ static int zynq_gem_probe(struct udevice *dev) priv->bus->write = zynq_gem_miiphy_write; priv->bus->priv = priv; + snprintf(name, MDIO_NAME_LEN, "gem%lx", (ulong)priv->iobase); + strncpy(priv->bus->name, name, MDIO_NAME_LEN); + ret = mdio_register_seq(priv->bus, dev->seq); if (ret) return ret; @@ -682,6 +688,8 @@ static int zynq_gem_ofdata_to_platdata(struct udevice *dev) struct zynq_gem_priv *priv = dev_get_priv(dev); int node = dev_of_offset(dev); const char *phy_mode; + fdt_addr_t addr; + int parent; pdata->iobase = (phys_addr_t)devfdt_get_addr(dev); priv->iobase = (struct zynq_gem_regs *)pdata->iobase; @@ -690,10 +698,24 @@ static int zynq_gem_ofdata_to_platdata(struct udevice *dev) priv->phy_of_handle = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle"); - if (priv->phy_of_handle > 0) + if (priv->phy_of_handle > 0) { priv->phyaddr = fdtdec_get_int(gd->fdt_blob, priv->phy_of_handle, "reg", -1); + parent = fdt_parent_offset(gd->fdt_blob, priv->phy_of_handle); + addr = fdtdec_get_addr(gd->fdt_blob, parent, "reg"); + + if (addr == FDT_ADDR_T_NONE) { + printf("MDIO bus not found %x %x, %x\n", + node, priv->phy_of_handle, parent); + return -ENODEV; + } + + priv->mdiobase = (struct zynq_gem_regs *)addr; + } else { + priv->mdiobase = priv->iobase; + } + phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); if (phy_mode) pdata->phy_interface = phy_get_interface_by_name(phy_mode); @@ -706,8 +728,9 @@ static int zynq_gem_ofdata_to_platdata(struct udevice *dev) priv->int_pcs = fdtdec_get_bool(gd->fdt_blob, node, "is-internal-pcspma"); - printf("ZYNQ GEM: %lx, phyaddr %x, interface %s\n", (ulong)priv->iobase, - priv->phyaddr, phy_string_for_interface(priv->interface)); + printf("ZYNQ GEM: %lx, mdio bus %lx, phyaddr %d, interface %s\n", + (ulong)priv->iobase, (ulong)priv->mdiobase, priv->phyaddr, + phy_string_for_interface(priv->interface)); return 0; }