[U-Boot] [PATCH 5/9] m68k: add dm fec support

Angelo Dureghello angelo.dureghello at timesys.com
Fri Nov 15 22:54:16 UTC 2019


From: Angelo Durgehello <angelo.dureghello at timesys.com>

Add architecture-related code for dm fec support.

Signed-off-by: Angelo Durgehello <angelo.dureghello at timesys.com>
---
 arch/m68k/cpu/mcf523x/cpu_init.c     |  2 +-
 arch/m68k/cpu/mcf52x2/cpu_init.c     | 19 ++++---
 arch/m68k/cpu/mcf532x/cpu.c          |  1 -
 arch/m68k/cpu/mcf532x/cpu_init.c     | 21 +++++---
 arch/m68k/cpu/mcf5445x/cpu_init.c    | 16 +++---
 arch/m68k/cpu/mcf547x_8x/cpu_init.c  | 12 +++--
 arch/m68k/include/asm/fec.h          | 21 ++++++--
 arch/m68k/include/asm/fsl_mcdmafec.h | 23 ++++----
 arch/m68k/lib/Makefile               |  1 +
 arch/m68k/lib/fec.c                  | 79 ++++++++++++++++++++++++++++
 10 files changed, 151 insertions(+), 44 deletions(-)
 create mode 100644 arch/m68k/lib/fec.c

diff --git a/arch/m68k/cpu/mcf523x/cpu_init.c b/arch/m68k/cpu/mcf523x/cpu_init.c
index 339fbeb429..a6eff09bf8 100644
--- a/arch/m68k/cpu/mcf523x/cpu_init.c
+++ b/arch/m68k/cpu/mcf523x/cpu_init.c
@@ -156,7 +156,7 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
 
diff --git a/arch/m68k/cpu/mcf52x2/cpu_init.c b/arch/m68k/cpu/mcf52x2/cpu_init.c
index f4a3872667..2aac29d162 100644
--- a/arch/m68k/cpu/mcf52x2/cpu_init.c
+++ b/arch/m68k/cpu/mcf52x2/cpu_init.c
@@ -157,7 +157,7 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
 
@@ -304,7 +304,7 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	if (setclear) {
 		/* Enable Ethernet pins */
@@ -425,7 +425,7 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
 
@@ -508,14 +508,17 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
-	struct fec_info_s *info = (struct fec_info_s *) dev->priv;
 	gpio_t *gpio = (gpio_t *)MMAP_GPIO;
+	u32 fec0_base;
+
+	if (fec_get_base_addr(0, &fec0_base))
+		return -1;
 
 	if (setclear) {
 		/* Enable Ethernet pins */
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
+		if (info->iobase == fec0_base) {
 			setbits_be16(&gpio->par_feci2c, 0x0f00);
 			setbits_8(&gpio->par_fec0hl, 0xc0);
 		} else {
@@ -523,7 +526,7 @@ int fecpin_setclear(struct eth_device *dev, int setclear)
 			setbits_8(&gpio->par_fec1hl, 0xc0);
 		}
 	} else {
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
+		if (info->iobase == fec0_base) {
 			clrbits_be16(&gpio->par_feci2c, 0x0f00);
 			clrbits_8(&gpio->par_fec0hl, 0xc0);
 		} else {
@@ -643,7 +646,7 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	if (setclear) {
 		MCFGPIO_PASPAR |= 0x0F00;
diff --git a/arch/m68k/cpu/mcf532x/cpu.c b/arch/m68k/cpu/mcf532x/cpu.c
index a01b5e65a7..fdc34dd16f 100644
--- a/arch/m68k/cpu/mcf532x/cpu.c
+++ b/arch/m68k/cpu/mcf532x/cpu.c
@@ -145,7 +145,6 @@ int watchdog_init(void)
  * create a board-specific function called:
  * 	int board_eth_init(bd_t *bis)
  */
-
 int cpu_eth_init(bd_t *bis)
 {
 	return mcffec_initialize(bis);
diff --git a/arch/m68k/cpu/mcf532x/cpu_init.c b/arch/m68k/cpu/mcf532x/cpu_init.c
index cbf840f76e..65882bc9d1 100644
--- a/arch/m68k/cpu/mcf532x/cpu_init.c
+++ b/arch/m68k/cpu/mcf532x/cpu_init.c
@@ -13,7 +13,7 @@
 #include <asm/immap.h>
 #include <asm/io.h>
 
-#if defined(CONFIG_CMD_NET)
+#if defined(CONFIG_MCFFEC)
 #include <config.h>
 #include <net.h>
 #include <asm/fec.h>
@@ -93,6 +93,7 @@ void cpu_init_f(void)
 int cpu_init_r(void)
 {
 #ifdef CONFIG_MCFFEC
+	u32 fec_mii_base0, fec_mii_base1;
 	ccm_t *ccm = (ccm_t *) MMAP_CCM;
 #endif
 #ifdef CONFIG_MCFRTC
@@ -104,7 +105,10 @@ int cpu_init_r(void)
 
 #endif
 #ifdef CONFIG_MCFFEC
-	if (CONFIG_SYS_FEC0_MIIBASE != CONFIG_SYS_FEC1_MIIBASE)
+	fec_get_mii_base(0, &fec_mii_base0);
+	fec_get_mii_base(1, &fec_mii_base1);
+
+	if (fec_mii_base0 != fec_mii_base1)
 		setbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
 	else
 		clrbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
@@ -167,13 +171,16 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
-	struct fec_info_s *info = (struct fec_info_s *)dev->priv;
+	u32 fec0_base;
+
+	if (fec_get_base_addr(0, &fec0_base))
+		return -1;
 
 	if (setclear) {
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
+		if (info->iobase == fec0_base) {
 			setbits_8(&gpio->par_fec,
 				GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
 			setbits_8(&gpio->par_feci2c,
@@ -185,7 +192,7 @@ int fecpin_setclear(struct eth_device *dev, int setclear)
 				GPIO_PAR_FECI2C_MDC1 | GPIO_PAR_FECI2C_MDIO1);
 		}
 	} else {
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
+		if (info->iobase == fec0_base) {
 			clrbits_8(&gpio->par_fec,
 				GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
 			clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII0_UNMASK);
@@ -328,7 +335,7 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
 
diff --git a/arch/m68k/cpu/mcf5445x/cpu_init.c b/arch/m68k/cpu/mcf5445x/cpu_init.c
index 134510b00f..76a7a3e475 100644
--- a/arch/m68k/cpu/mcf5445x/cpu_init.c
+++ b/arch/m68k/cpu/mcf5445x/cpu_init.c
@@ -401,15 +401,18 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
-#ifdef CONFIG_MCF5445x
-	struct fec_info_s *info = (struct fec_info_s *)dev->priv;
+	u32 fec0_base;
+
+	if (fec_get_base_addr(0, &fec0_base))
+		return -1;
 
+#ifdef CONFIG_MCF5445x
 	if (setclear) {
 #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
+		if (info->iobase == fec0_base)
 			setbits_be16(&gpio->par_feci2c,
 				GPIO_PAR_FECI2C_MDC0_MDC0 |
 				GPIO_PAR_FECI2C_MDIO0_MDIO0);
@@ -422,7 +425,7 @@ int fecpin_setclear(struct eth_device *dev, int setclear)
 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
 #endif
 
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
+		if (info->iobase == fec0_base)
 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
 		else
 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
@@ -430,7 +433,7 @@ int fecpin_setclear(struct eth_device *dev, int setclear)
 		clrbits_be16(&gpio->par_feci2c,
 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
 
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
+		if (info->iobase == fec0_base) {
 #ifdef CONFIG_SYS_FEC_FULL_MII
 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
 #else
@@ -462,4 +465,3 @@ int fecpin_setclear(struct eth_device *dev, int setclear)
 	return 0;
 }
 #endif
-
diff --git a/arch/m68k/cpu/mcf547x_8x/cpu_init.c b/arch/m68k/cpu/mcf547x_8x/cpu_init.c
index 81ffc6c094..0a83c16c27 100644
--- a/arch/m68k/cpu/mcf547x_8x/cpu_init.c
+++ b/arch/m68k/cpu/mcf547x_8x/cpu_init.c
@@ -16,6 +16,7 @@
 #if defined(CONFIG_CMD_NET)
 #include <config.h>
 #include <net.h>
+#include <asm/fec.h>
 #include <asm/fsl_mcdmafec.h>
 #endif
 
@@ -123,18 +124,21 @@ void uart_port_conf(int port)
 }
 
 #if defined(CONFIG_CMD_NET)
-int fecpin_setclear(struct eth_device *dev, int setclear)
+int fecpin_setclear(fec_info_t *info, int setclear)
 {
 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
-	struct fec_info_dma *info = (struct fec_info_dma *)dev->priv;
+	u32 fec0_base;
+
+	if (fec_get_base_addr(0, &fec0_base))
+		return -1;
 
 	if (setclear) {
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
+		if (info->iobase == fec0_base)
 			setbits_be16(&gpio->par_feci2cirq, 0xf000);
 		else
 			setbits_be16(&gpio->par_feci2cirq, 0x0fc0);
 	} else {
-		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
+		if (info->iobase == fec0_base)
 			clrbits_be16(&gpio->par_feci2cirq, 0xf000);
 		else
 			clrbits_be16(&gpio->par_feci2cirq, 0x0fc0);
diff --git a/arch/m68k/include/asm/fec.h b/arch/m68k/include/asm/fec.h
index 5742829c6d..cdb8119d3e 100644
--- a/arch/m68k/include/asm/fec.h
+++ b/arch/m68k/include/asm/fec.h
@@ -95,11 +95,12 @@ struct fec_info_s {
 	int phyname_init;
 	cbd_t *rxbd;		/* Rx BD */
 	cbd_t *txbd;		/* Tx BD */
-	uint rxIdx;
-	uint txIdx;
+	uint rx_idx;
+	uint tx_idx;
 	char *txbuf;
 	int initialized;
-	struct fec_info_s *next;
+	int to_loop;
+	struct mii_dev *bus;
 };
 
 #ifdef CONFIG_MCFFEC
@@ -336,12 +337,22 @@ typedef struct fec {
 #define	FEC_RESET_DELAY			100
 #define FEC_RX_TOUT			100
 
-int fecpin_setclear(struct eth_device *dev, int setclear);
+#ifdef CONFIG_MCF547x_8x
+typedef struct fec_info_dma fec_info_t;
+#define FEC_T fecdma_t
+#else
+typedef struct fec_info_s fec_info_t;
+#define FEC_T fec_t
+#endif
+
+int fecpin_setclear(fec_info_t *info, int setclear);
+int mii_discover_phy(fec_info_t *info);
+int fec_get_base_addr(int fec_idx, u32 *fec_iobase);
+int fec_get_mii_base(int fec_idx, u32 *mii_base);
 
 #ifdef CONFIG_SYS_DISCOVER_PHY
 void __mii_init(void);
 uint mii_send(uint mii_cmd);
-int mii_discover_phy(struct eth_device *dev);
 int mcffec_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg);
 int mcffec_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
 			u16 value);
diff --git a/arch/m68k/include/asm/fsl_mcdmafec.h b/arch/m68k/include/asm/fsl_mcdmafec.h
index c283ad4a95..de6c548faf 100644
--- a/arch/m68k/include/asm/fsl_mcdmafec.h
+++ b/arch/m68k/include/asm/fsl_mcdmafec.h
@@ -72,20 +72,21 @@ struct fec_info_dma {
 	int phyname_init;
 	cbd_t *rxbd;		/* Rx BD */
 	cbd_t *txbd;		/* Tx BD */
-	uint rxIdx;
-	uint txIdx;
+	uint rx_idx;
+	uint tx_idx;
 	char *txbuf;
 	int initialized;
 	struct fec_info_dma *next;
-
-	u16 rxTask;		/* DMA receive Task Number */
-	u16 txTask;		/* DMA Transmit Task Number */
-	u16 rxPri;		/* DMA Receive Priority */
-	u16 txPri;		/* DMA Transmit Priority */
-	u16 rxInit;		/* DMA Receive Initiator */
-	u16 txInit;		/* DMA Transmit Initiator */
-	u16 usedTbdIdx;		/* next transmit BD to clean */
-	u16 cleanTbdNum;	/* the number of available transmit BDs */
+	u16 rx_task;		/* DMA receive Task Number */
+	u16 tx_task;		/* DMA Transmit Task Number */
+	u16 rx_pri;		/* DMA Receive Priority */
+	u16 tx_pri;		/* DMA Transmit Priority */
+	u16 rx_init;		/* DMA Receive Initiator */
+	u16 tx_init;		/* DMA Transmit Initiator */
+	u16 used_tbd_idx;	/* next transmit BD to clean */
+	u16 clean_tbd_num;	/* the number of available transmit BDs */
+	int to_loop;
+	struct mii_dev *bus;
 };
 
 /* Bit definitions and macros for IEVENT */
diff --git a/arch/m68k/lib/Makefile b/arch/m68k/lib/Makefile
index 254a0a3998..a040f40eb8 100644
--- a/arch/m68k/lib/Makefile
+++ b/arch/m68k/lib/Makefile
@@ -12,3 +12,4 @@ obj-y	+= cache.o
 obj-y	+= interrupts.o
 obj-y	+= time.o
 obj-y	+= traps.o
+obj-y   += fec.o
diff --git a/arch/m68k/lib/fec.c b/arch/m68k/lib/fec.c
new file mode 100644
index 0000000000..dde353ad17
--- /dev/null
+++ b/arch/m68k/lib/fec.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) 2019 Angelo Dureghello <angelo.dureghello at timesys.com>
+ */
+
+#include <common.h>
+#include <linux/libfdt.h>
+#include <fdt_support.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if defined(CONFIG_MCFFEC) || defined(CONFIG_FSLDMAFEC)
+static int fec_get_node(int fec_idx)
+{
+	char fec_alias[5] = {"fec"};
+	const char *path;
+	int node;
+
+	if (fec_idx > 1) {
+		puts("Invalid MII base index");
+		return -ENOENT;
+	}
+
+	fec_alias[3] = fec_idx + '0';
+
+	path = fdt_get_alias(gd->fdt_blob, fec_alias);
+	if (!path) {
+		puts("Invalid MII path");
+		return -ENOENT;
+	}
+
+	node = fdt_path_offset(gd->fdt_blob, path);
+	if (node < 0)
+		return -ENOENT;
+
+	return node;
+}
+
+int fec_get_fdt_prop(int fec_idx, const char *prop, u32 *value)
+{
+	int node;
+	const u32 *val;
+
+	node = fec_get_node(fec_idx);
+	if (node < 0)
+		return node;
+
+	val = fdt_getprop(gd->fdt_blob, node, prop, NULL);
+	if (!val)
+		return -ENOENT;
+
+	*value = fdt32_to_cpu(*val);
+
+	return 0;
+}
+
+int fec_get_base_addr(int fec_idx, u32 *fec_iobase)
+{
+	int node;
+	fdt_size_t size;
+	fdt_addr_t addr;
+
+	node = fec_get_node(fec_idx);
+	if (node < 0)
+		return node;
+
+	addr = fdtdec_get_addr_size(gd->fdt_blob, node, "reg", &size);
+
+	*fec_iobase = (u32)addr;
+
+	return 0;
+}
+
+int fec_get_mii_base(int fec_idx, u32 *mii_base)
+{
+	return fec_get_fdt_prop(fec_idx, "mii-base", mii_base);
+}
+
+#endif //CONFIG_MCFFEC || CONFIG_FSLDMAFEC
-- 
2.24.0



More information about the U-Boot mailing list