diff mbox

[U-Boot,1/2] net: lpc32xx: improve MAC configuration on reset and initialization

Message ID 1436156531-302-2-git-send-email-vz@mleia.com
State Accepted
Delegated to: Joe Hershberger
Headers show

Commit Message

Vladimir Zapolskiy July 6, 2015, 4:22 a.m. UTC
This change rearranges general MAC configuration and PHY specific
configuration of MAC registers (duplex mode and speed), before this
change set bits related to PHY configuration in MAC2 and COMMAND
registers are rewritten by the following writing to the registers.

Without the change auto negotiation on boot quite often is not
completed in reasonable time:

  Waiting for PHY auto negotiation to complete......... TIMEOUT !

Additionally MAC1_SOFT_RESET clear bit is removed since it is done in
preceding lpc32xx_eth_initialize() and in lpc32xx_eth_halt(), instead
added missing MCFG_RESET_MII_MGMT on device initialization.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 drivers/net/lpc32xx_eth.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

Comments

Joe Hershberger Aug. 12, 2015, 7:34 p.m. UTC | #1
Hi Vladimir,

On Sun, Jul 5, 2015 at 11:22 PM, Vladimir Zapolskiy <vz@mleia.com> wrote:
> This change rearranges general MAC configuration and PHY specific
> configuration of MAC registers (duplex mode and speed), before this
> change set bits related to PHY configuration in MAC2 and COMMAND
> registers are rewritten by the following writing to the registers.
>
> Without the change auto negotiation on boot quite often is not
> completed in reasonable time:
>
>   Waiting for PHY auto negotiation to complete......... TIMEOUT !
>
> Additionally MAC1_SOFT_RESET clear bit is removed since it is done in
> preceding lpc32xx_eth_initialize() and in lpc32xx_eth_halt(), instead
> added missing MCFG_RESET_MII_MGMT on device initialization.
>
> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>

Applied to u-boot-net, thanks!
-Joe
diff mbox

Patch

diff --git a/drivers/net/lpc32xx_eth.c b/drivers/net/lpc32xx_eth.c
index 6033392..f883a25 100644
--- a/drivers/net/lpc32xx_eth.c
+++ b/drivers/net/lpc32xx_eth.c
@@ -151,7 +151,7 @@  struct lpc32xx_eth_registers {
 #define SUPP_SPEED 0x00000100
 
 /* MCFG register bitfields/masks and offsets (see Table 292) */
-#define MCFG_CLOCK_SELECT_MASK  0x0000001C
+#define MCFG_RESET_MII_MGMT     0x00008000
 /* divide clock by 28 (see Table 293) */
 #define MCFG_CLOCK_SELECT_DIV28 0x0000001C
 
@@ -459,8 +459,19 @@  static int lpc32xx_eth_init(struct eth_device *dev)
 	struct lpc32xx_eth_buffers *bufs = lpc32xx_eth_device->bufs;
 	int index;
 
-	/* Release SOFT reset to let MII talk to PHY */
-	clrbits_le32(&regs->mac1, MAC1_SOFT_RESET);
+	/* Initial MAC initialization */
+	writel(MAC1_PASS_ALL_RX_FRAMES, &regs->mac1);
+	writel(MAC2_PAD_CRC_ENABLE | MAC2_CRC_ENABLE, &regs->mac2);
+	writel(PKTSIZE_ALIGN, &regs->maxf);
+
+	/* Retries: 15 (0xF). Collision window: 57 (0x37). */
+	writel(0x370F, &regs->clrt);
+
+	/* Set IP gap pt 2 to default 0x12 but pt 1 to non-default 0 */
+	writel(0x0012, &regs->ipgr);
+
+	/* pass runt (smaller than 64 bytes) frames */
+	writel(COMMAND_PASSRUNTFRAME, &regs->command);
 
 	/* Configure Full/Half Duplex mode */
 	if (miiphy_duplex(dev->name, CONFIG_PHY_ADDR) == FULL) {
@@ -477,20 +488,6 @@  static int lpc32xx_eth_init(struct eth_device *dev)
 	else
 		writel(0, &regs->supp);
 
-	/* Initial MAC initialization */
-	writel(MAC1_PASS_ALL_RX_FRAMES, &regs->mac1);
-	writel(MAC2_PAD_CRC_ENABLE | MAC2_CRC_ENABLE, &regs->mac2);
-	writel(PKTSIZE_ALIGN, &regs->maxf);
-
-	/* Retries: 15 (0xF). Collision window: 57 (0x37). */
-	writel(0x370F, &regs->clrt);
-
-	/* Set IP gap pt 2 to default 0x12 but pt 1 to non-default 0 */
-	writel(0x0012, &regs->ipgr);
-
-	/* pass runt (smaller than 64 bytes) frames */
-	writel(COMMAND_PASSRUNTFRAME, &regs->command);
-
 	/* Save station address */
 	writel((unsigned long) (dev->enetaddr[0] |
 		(dev->enetaddr[1] << 8)), &regs->sa2);
@@ -604,7 +601,7 @@  int lpc32xx_eth_initialize(bd_t *bis)
 	 * Set RMII management clock rate. With HCLK at 104 MHz and
 	 * a divider of 28, this will be 3.72 MHz.
 	 */
-
+	writel(MCFG_RESET_MII_MGMT, &regs->mcfg);
 	writel(MCFG_CLOCK_SELECT_DIV28, &regs->mcfg);
 
 	/* Reset all MAC logic */