Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mv643xx_eth: support MII/GMII/RGMII modes for Kirkwood

Support mode switch properly, which is not available before.

If SoC has two Ethernet controllers, by setting both of them into MII
mode, the first controller enters GMII mode, while the second
controller is effectively disabled. This requires configuring (and
maybe enabling) the second controller in the device tree, even though
it cannot be used.

Signed-off-by: David Yang <mmyangfl@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

David Yang and committed by
David S. Miller
d08cb255 63d9e129

+44 -7
+42 -7
drivers/net/ethernet/marvell/mv643xx_eth.c
··· 108 108 #define TXQ_COMMAND 0x0048 109 109 #define TXQ_FIX_PRIO_CONF 0x004c 110 110 #define PORT_SERIAL_CONTROL1 0x004c 111 + #define RGMII_EN 0x00000008 111 112 #define CLK125_BYPASS_EN 0x00000010 112 113 #define TX_BW_RATE 0x0050 113 114 #define TX_BW_MTU 0x0058 ··· 2762 2761 mv643xx_eth_property(pnp, "rx-sram-addr", ppd.rx_sram_addr); 2763 2762 mv643xx_eth_property(pnp, "rx-sram-size", ppd.rx_sram_size); 2764 2763 2764 + of_get_phy_mode(pnp, &ppd.interface); 2765 + 2765 2766 ppd.phy_node = of_parse_phandle(pnp, "phy-handle", 0); 2766 2767 if (!ppd.phy_node) { 2767 2768 ppd.phy_addr = MV643XX_ETH_PHY_NONE; ··· 3095 3092 struct mv643xx_eth_private *mp; 3096 3093 struct net_device *dev; 3097 3094 struct phy_device *phydev = NULL; 3095 + u32 psc1r; 3098 3096 int err, irq; 3099 3097 3100 3098 pd = dev_get_platdata(&pdev->dev); ··· 3123 3119 3124 3120 mp->dev = dev; 3125 3121 3126 - /* Kirkwood resets some registers on gated clocks. Especially 3127 - * CLK125_BYPASS_EN must be cleared but is not available on 3128 - * all other SoCs/System Controllers using this driver. 3129 - */ 3130 3122 if (of_device_is_compatible(pdev->dev.of_node, 3131 - "marvell,kirkwood-eth-port")) 3132 - wrlp(mp, PORT_SERIAL_CONTROL1, 3133 - rdlp(mp, PORT_SERIAL_CONTROL1) & ~CLK125_BYPASS_EN); 3123 + "marvell,kirkwood-eth-port")) { 3124 + psc1r = rdlp(mp, PORT_SERIAL_CONTROL1); 3125 + 3126 + /* Kirkwood resets some registers on gated clocks. Especially 3127 + * CLK125_BYPASS_EN must be cleared but is not available on 3128 + * all other SoCs/System Controllers using this driver. 3129 + */ 3130 + psc1r &= ~CLK125_BYPASS_EN; 3131 + 3132 + /* On Kirkwood with two Ethernet controllers, if both of them 3133 + * have RGMII_EN disabled, the first controller will be in GMII 3134 + * mode and the second one is effectively disabled, instead of 3135 + * two MII interfaces. 3136 + * 3137 + * To enable GMII in the first controller, the second one must 3138 + * also be configured (and may be enabled) with RGMII_EN 3139 + * disabled too, even though it cannot be used at all. 3140 + */ 3141 + switch (pd->interface) { 3142 + /* Use internal to denote second controller being disabled */ 3143 + case PHY_INTERFACE_MODE_INTERNAL: 3144 + case PHY_INTERFACE_MODE_MII: 3145 + case PHY_INTERFACE_MODE_GMII: 3146 + psc1r &= ~RGMII_EN; 3147 + break; 3148 + case PHY_INTERFACE_MODE_RGMII: 3149 + case PHY_INTERFACE_MODE_RGMII_ID: 3150 + case PHY_INTERFACE_MODE_RGMII_RXID: 3151 + case PHY_INTERFACE_MODE_RGMII_TXID: 3152 + psc1r |= RGMII_EN; 3153 + break; 3154 + default: 3155 + /* Unknown; don't touch */ 3156 + break; 3157 + } 3158 + 3159 + wrlp(mp, PORT_SERIAL_CONTROL1, psc1r); 3160 + } 3134 3161 3135 3162 /* 3136 3163 * Start with a default rate, and if there is a clock, allow
+2
include/linux/mv643xx_eth.h
··· 8 8 9 9 #include <linux/mbus.h> 10 10 #include <linux/if_ether.h> 11 + #include <linux/phy.h> 11 12 12 13 #define MV643XX_ETH_SHARED_NAME "mv643xx_eth" 13 14 #define MV643XX_ETH_NAME "mv643xx_eth_port" ··· 60 59 */ 61 60 int speed; 62 61 int duplex; 62 + phy_interface_t interface; 63 63 64 64 /* 65 65 * How many RX/TX queues to use.