aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/cadence
diff options
context:
space:
mode:
authorJamie Iles <jamie@jamieiles.com>2011-03-09 11:22:54 -0500
committerJamie Iles <jamie@jamieiles.com>2011-11-22 10:21:18 -0500
commit70c9f3d4372ffa90775603e9c4e055a26a9b83e1 (patch)
tree8aa2e511bbd307b14f6f88c8ccf9680e887f378f /drivers/net/ethernet/cadence
parentf75ba50bdc2bcfab591bdf903312557033d0ac68 (diff)
macb: support higher rate GEM MDIO clock divisors
GEM devices support larger clock divisors and have a different range of divisors. Program the MDIO clock divisors based on the device type. Signed-off-by: Jamie Iles <jamie@jamieiles.com> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com> Tested-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'drivers/net/ethernet/cadence')
-rw-r--r--drivers/net/ethernet/cadence/macb.c55
-rw-r--r--drivers/net/ethernet/cadence/macb.h11
2 files changed, 55 insertions, 11 deletions
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 4e61a8610d6a..c5c3eb450c1b 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -793,6 +793,48 @@ static void macb_reset_hw(struct macb *bp)
793 macb_readl(bp, ISR); 793 macb_readl(bp, ISR);
794} 794}
795 795
796static u32 gem_mdc_clk_div(struct macb *bp)
797{
798 u32 config;
799 unsigned long pclk_hz = clk_get_rate(bp->pclk);
800
801 if (pclk_hz <= 20000000)
802 config = GEM_BF(CLK, GEM_CLK_DIV8);
803 else if (pclk_hz <= 40000000)
804 config = GEM_BF(CLK, GEM_CLK_DIV16);
805 else if (pclk_hz <= 80000000)
806 config = GEM_BF(CLK, GEM_CLK_DIV32);
807 else if (pclk_hz <= 120000000)
808 config = GEM_BF(CLK, GEM_CLK_DIV48);
809 else if (pclk_hz <= 160000000)
810 config = GEM_BF(CLK, GEM_CLK_DIV64);
811 else
812 config = GEM_BF(CLK, GEM_CLK_DIV96);
813
814 return config;
815}
816
817static u32 macb_mdc_clk_div(struct macb *bp)
818{
819 u32 config;
820 unsigned long pclk_hz;
821
822 if (macb_is_gem(bp))
823 return gem_mdc_clk_div(bp);
824
825 pclk_hz = clk_get_rate(bp->pclk);
826 if (pclk_hz <= 20000000)
827 config = MACB_BF(CLK, MACB_CLK_DIV8);
828 else if (pclk_hz <= 40000000)
829 config = MACB_BF(CLK, MACB_CLK_DIV16);
830 else if (pclk_hz <= 80000000)
831 config = MACB_BF(CLK, MACB_CLK_DIV32);
832 else
833 config = MACB_BF(CLK, MACB_CLK_DIV64);
834
835 return config;
836}
837
796static void macb_init_hw(struct macb *bp) 838static void macb_init_hw(struct macb *bp)
797{ 839{
798 u32 config; 840 u32 config;
@@ -800,7 +842,7 @@ static void macb_init_hw(struct macb *bp)
800 macb_reset_hw(bp); 842 macb_reset_hw(bp);
801 __macb_set_hwaddr(bp); 843 __macb_set_hwaddr(bp);
802 844
803 config = macb_readl(bp, NCFGR) & MACB_BF(CLK, -1L); 845 config = macb_mdc_clk_div(bp);
804 config |= MACB_BIT(PAE); /* PAuse Enable */ 846 config |= MACB_BIT(PAE); /* PAuse Enable */
805 config |= MACB_BIT(DRFCS); /* Discard Rx FCS */ 847 config |= MACB_BIT(DRFCS); /* Discard Rx FCS */
806 config |= MACB_BIT(BIG); /* Receive oversized frames */ 848 config |= MACB_BIT(BIG); /* Receive oversized frames */
@@ -1119,7 +1161,6 @@ static int __init macb_probe(struct platform_device *pdev)
1119 struct net_device *dev; 1161 struct net_device *dev;
1120 struct macb *bp; 1162 struct macb *bp;
1121 struct phy_device *phydev; 1163 struct phy_device *phydev;
1122 unsigned long pclk_hz;
1123 u32 config; 1164 u32 config;
1124 int err = -ENXIO; 1165 int err = -ENXIO;
1125 1166
@@ -1183,15 +1224,7 @@ static int __init macb_probe(struct platform_device *pdev)
1183 dev->base_addr = regs->start; 1224 dev->base_addr = regs->start;
1184 1225
1185 /* Set MII management clock divider */ 1226 /* Set MII management clock divider */
1186 pclk_hz = clk_get_rate(bp->pclk); 1227 config = macb_mdc_clk_div(bp);
1187 if (pclk_hz <= 20000000)
1188 config = MACB_BF(CLK, MACB_CLK_DIV8);
1189 else if (pclk_hz <= 40000000)
1190 config = MACB_BF(CLK, MACB_CLK_DIV16);
1191 else if (pclk_hz <= 80000000)
1192 config = MACB_BF(CLK, MACB_CLK_DIV32);
1193 else
1194 config = MACB_BF(CLK, MACB_CLK_DIV64);
1195 macb_writel(bp, NCFGR, config); 1228 macb_writel(bp, NCFGR, config);
1196 1229
1197 macb_get_hwaddr(bp); 1230 macb_get_hwaddr(bp);
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index d50057c244b2..354ed8f77884 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -135,6 +135,9 @@
135#define MACB_IRXFCS_OFFSET 19 135#define MACB_IRXFCS_OFFSET 19
136#define MACB_IRXFCS_SIZE 1 136#define MACB_IRXFCS_SIZE 1
137 137
138/* GEM specific NCFGR bitfields. */
139#define GEM_CLK_OFFSET 18
140#define GEM_CLK_SIZE 3
138/* Bitfields in NSR */ 141/* Bitfields in NSR */
139#define MACB_NSR_LINK_OFFSET 0 142#define MACB_NSR_LINK_OFFSET 0
140#define MACB_NSR_LINK_SIZE 1 143#define MACB_NSR_LINK_SIZE 1
@@ -249,6 +252,14 @@
249#define MACB_CLK_DIV32 2 252#define MACB_CLK_DIV32 2
250#define MACB_CLK_DIV64 3 253#define MACB_CLK_DIV64 3
251 254
255/* GEM specific constants for CLK. */
256#define GEM_CLK_DIV8 0
257#define GEM_CLK_DIV16 1
258#define GEM_CLK_DIV32 2
259#define GEM_CLK_DIV48 3
260#define GEM_CLK_DIV64 4
261#define GEM_CLK_DIV96 5
262
252/* Constants for MAN register */ 263/* Constants for MAN register */
253#define MACB_MAN_SOF 1 264#define MACB_MAN_SOF 1
254#define MACB_MAN_WRITE 1 265#define MACB_MAN_WRITE 1