Re: [U-Boot] [PATCH] net: macb: Add support for Xilinx Zynq SoC

2017-08-28 Thread Joe Hershberger
On Tue, Aug 22, 2017 at 10:25 PM, Wilson Lee  wrote:
> Although Xilinx Zynq SoC was using MACB similar hardware. However,
> U-boot MACB driver was not supporting Xilinx Zynq SoC. This patch is
> to add support for the Xilinx Zynq SoC to the existing MACB network
> driver.
>
> This patch is to add Zynq GEM DMA Config, provide callback
> function for different linkspeed for case of using Xilinx Zynq
> Programmable Logic as GMII to RGMII convertor.
>
> This patch convert the return value to use error codes.
>
> Signed-off-by: Wilson Lee 
> Cc: Chen Yee Chew 
> Cc: Keng Soon Cheah 
> Cc: Joe Hershberger 
> Cc: Wenyou Yang 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] net: macb: Add support for Xilinx Zynq SoC

2017-08-23 Thread Wilson Lee
Although Xilinx Zynq SoC was using MACB similar hardware. However,
U-boot MACB driver was not supporting Xilinx Zynq SoC. This patch is
to add support for the Xilinx Zynq SoC to the existing MACB network
driver.

This patch is to add Zynq GEM DMA Config, provide callback
function for different linkspeed for case of using Xilinx Zynq
Programmable Logic as GMII to RGMII convertor.

This patch convert the return value to use error codes.

Signed-off-by: Wilson Lee 
Cc: Chen Yee Chew 
Cc: Keng Soon Cheah 
Cc: Joe Hershberger 
Cc: Wenyou Yang 
---

 drivers/net/Kconfig |  7 +
 drivers/net/macb.c  | 91 ++---
 drivers/net/macb.h  |  1 +
 3 files changed, 87 insertions(+), 12 deletions(-)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 5ceea44..6c54f93 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -177,6 +177,13 @@ config MACB
  GEM (Gigabit Ethernet MAC) found in some ARM SoC devices.
  Say Y to include support for the MACB/GEM chip.
 
+config MACB_ZYNQ
+   bool "Cadence MACB/GEM Ethernet Interface for Xilinx Zynq"
+   depends on MACB
+   help
+ The Cadence MACB ethernet interface was used on Zynq platform.
+ Say Y to enable support for the MACB/GEM in Zynq chip.
+
 config PCH_GBE
bool "Intel Platform Controller Hub EG20T GMAC driver"
depends on DM_ETH && DM_PCI
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index f9373db..e62aefc 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -52,6 +52,22 @@ DECLARE_GLOBAL_DATA_PTR;
 #define MACB_TX_TIMEOUT1000
 #define MACB_AUTONEG_TIMEOUT   500
 
+#ifdef CONFIG_MACB_ZYNQ
+/* INCR4 AHB bursts */
+#define MACB_ZYNQ_GEM_DMACR_BLENGTH0x0004
+/* Use full configured addressable space (8 Kb) */
+#define MACB_ZYNQ_GEM_DMACR_RXSIZE 0x0300
+/* Use full configured addressable space (4 Kb) */
+#define MACB_ZYNQ_GEM_DMACR_TXSIZE 0x0400
+/* Set RXBUF with use of 128 byte */
+#define MACB_ZYNQ_GEM_DMACR_RXBUF  0x0002
+#define MACB_ZYNQ_GEM_DMACR_INIT \
+   (MACB_ZYNQ_GEM_DMACR_BLENGTH | \
+   MACB_ZYNQ_GEM_DMACR_RXSIZE | \
+   MACB_ZYNQ_GEM_DMACR_TXSIZE | \
+   MACB_ZYNQ_GEM_DMACR_RXBUF)
+#endif
+
 struct macb_dma_desc {
u32 addr;
u32 ctrl;
@@ -461,13 +477,25 @@ static int macb_phy_find(struct macb_device *macb, const 
char *name)
phy_id = macb_mdio_read(macb, MII_PHYSID1);
if (phy_id != 0x) {
printf("%s: PHY present at %d\n", name, i);
-   return 1;
+   return 0;
}
}
 
/* PHY isn't up to snuff */
printf("%s: PHY not found\n", name);
 
+   return -ENODEV;
+}
+
+/**
+ * macb_linkspd_cb - Linkspeed change callback function
+ * @regs:  Base Register of MACB devices
+ * @speed: Linkspeed
+ * Returns 0 when operation success and negative errno number
+ * when operation failed.
+ */
+int __weak macb_linkspd_cb(void *regs, unsigned int speed)
+{
return 0;
 }
 
@@ -483,18 +511,20 @@ static int macb_phy_init(struct macb_device *macb, const 
char *name)
u32 ncfgr;
u16 phy_id, status, adv, lpa;
int media, speed, duplex;
+   int ret;
int i;
 
arch_get_mdio_control(name);
/* Auto-detect phy_addr */
-   if (!macb_phy_find(macb, name))
-   return 0;
+   ret = macb_phy_find(macb, name);
+   if (ret)
+   return ret;
 
/* Check if the PHY is up to snuff... */
phy_id = macb_mdio_read(macb, MII_PHYSID1);
if (phy_id == 0x) {
printf("%s: No PHY present\n", name);
-   return 0;
+   return -ENODEV;
}
 
 #ifdef CONFIG_PHYLIB
@@ -530,7 +560,7 @@ static int macb_phy_init(struct macb_device *macb, const 
char *name)
if (!(status & BMSR_LSTATUS)) {
printf("%s: link down (status: 0x%04x)\n",
   name, status);
-   return 0;
+   return -ENETDOWN;
}
 
/* First check for GMAC and that it is GiB capable */
@@ -554,7 +584,11 @@ static int macb_phy_init(struct macb_device *macb, const 
char *name)
 
macb_writel(macb, NCFGR, ncfgr);
 
-   return 1;
+   ret = macb_linkspd_cb(macb->regs, _1000BASET);
+   if (ret)
+   return ret;
+
+   return 0;
}
}
 
@@ -573,13 +607,21 @@ static int macb_phy_init(struct macb_device *macb, const 
char *name)
 
ncfgr = macb_readl(macb, NCFGR);