1 From c562ab80fe383e6fa49dbe38257421cf37f0e4b3 Mon Sep 17 00:00:00 2001
2 From: Kurt Mahan <kmahan@freescale.com>
3 Date: Wed, 31 Oct 2007 17:07:25 -0600
4 Subject: [PATCH] MCF5445x FEC support.
7 Signed-off-by: Kurt Mahan <kmahan@freescale.com>
9 drivers/net/Kconfig | 8 ++-
10 drivers/net/fec.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++----
11 drivers/net/fec.h | 2 +-
12 3 files changed, 198 insertions(+), 19 deletions(-)
14 --- a/drivers/net/Kconfig
15 +++ b/drivers/net/Kconfig
16 @@ -1973,7 +1973,7 @@ config 68360_ENET
19 bool "FEC ethernet controller (of ColdFire CPUs)"
20 - depends on M523x || M527x || M5272 || M528x || M520x
21 + depends on M523x || M527x || M5272 || M528x || M520x || M54455
23 Say Y here if you want to use the built-in 10/100 Fast ethernet
24 controller on some Motorola ColdFire processors.
25 @@ -1985,6 +1985,12 @@ config FEC2
26 Say Y here if you want to use the second built-in 10/100 Fast
27 ethernet controller on some Motorola ColdFire processors.
29 +config FEC_SHARED_PHY
30 + bool "Shared PHY interface(on some ColdFire designs)"
33 + Say Y here if both PHYs are controlled via a single channel.
36 tristate "MPC52xx FEC driver"
37 depends on PPC_MERGE && PPC_MPC52xx && PPC_BESTCOMM_FEC
38 --- a/drivers/net/fec.c
39 +++ b/drivers/net/fec.c
42 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
43 defined(CONFIG_M5272) || defined(CONFIG_M528x) || \
44 - defined(CONFIG_M520x) || defined(CONFIG_M532x)
45 + defined(CONFIG_M520x) || defined(CONFIG_M532x) || \
46 + defined(CONFIG_M54455)
48 #include <asm/coldfire.h>
49 #include <asm/mcfsim.h>
51 @@ -82,6 +84,11 @@ static unsigned int fec_hw[] = {
53 #elif defined(CONFIG_M532x)
54 (MCF_MBAR+0xfc030000),
55 +#elif defined(CONFIG_M54455)
56 + (MCF_MBAR+0xfc030000),
57 +#if defined(CONFIG_FEC2)
58 + (MCF_MBAR+0xfc034000),
61 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec),
63 @@ -172,7 +179,7 @@ typedef struct {
64 * account when setting it.
66 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
67 - defined(CONFIG_M520x) || defined(CONFIG_M532x)
68 + defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_M54455)
69 #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
71 #define OPT_FRAME_SIZE 0
72 @@ -213,6 +220,7 @@ struct fec_enet_private {
74 phy_info_t const *phy;
75 struct work_struct phy_task;
76 + volatile fec_t *phy_hwp;
79 uint mii_phy_task_queued;
80 @@ -349,7 +357,8 @@ fec_enet_start_xmit(struct sk_buff *skb,
81 if (bdp->cbd_bufaddr & 0x3) {
83 index = bdp - fep->tx_bd_base;
84 - memcpy(fep->tx_bounce[index], (void *) bdp->cbd_bufaddr, bdp->cbd_datlen);
85 + memcpy(fep->tx_bounce[index],
86 + (void *)skb->data, bdp->cbd_datlen);
87 bdp->cbd_bufaddr = __pa(fep->tx_bounce[index]);
90 @@ -702,7 +711,7 @@ fec_enet_mii(struct net_device *dev)
93 fep = netdev_priv(dev);
96 mii_reg = ep->fec_mii_data;
98 spin_lock(&fep->lock);
99 @@ -753,7 +762,7 @@ mii_queue(struct net_device *dev, int re
102 mii_head = mii_tail = mip;
103 - fep->hwp->fec_mii_data = regval;
104 + fep->phy_hwp->fec_mii_data = regval;
108 @@ -1151,8 +1160,7 @@ static phy_info_t const phy_info_ks8721b
111 /* ------------------------------------------------------------------------- */
112 -/* register definitions for the DP83848 */
114 +/* register definitions for the DP83848 and DP83849 */
115 #define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
117 static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
118 @@ -1186,27 +1194,50 @@ static void mii_parse_dp8384x_sr2(uint m
119 *s |= PHY_STAT_FAULT;
122 +static phy_cmd_t const phy_cmd_dp8384x_ack_int[] = {
126 +static phy_cmd_t const phy_cmd_dp8384x_shutdown[] = {
130 static phy_info_t phy_info_dp83848= {
136 - (const phy_cmd_t []) { /* config */
137 + .config = (const phy_cmd_t []) { /* config */
138 { mk_mii_read(MII_REG_CR), mii_parse_cr },
139 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
140 { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
143 - (const phy_cmd_t []) { /* startup - enable interrupts */
144 + .startup = (const phy_cmd_t []) { /* startup - enable interrupts */
145 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
146 { mk_mii_read(MII_REG_SR), mii_parse_sr },
149 - (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */
150 + .ack_int = phy_cmd_dp8384x_ack_int,
151 + .shutdown = phy_cmd_dp8384x_shutdown,
154 +static phy_info_t phy_info_dp83849 = {
158 + .config = (const phy_cmd_t []) { /* config */
159 + { mk_mii_read(MII_REG_CR), mii_parse_cr },
160 + { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
161 + { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
164 - (const phy_cmd_t []) { /* shutdown */
165 + .startup = (const phy_cmd_t []) { /* startup - enable interrupts */
166 + { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
167 + { mk_mii_read(MII_REG_SR), mii_parse_sr },
170 + .ack_int = phy_cmd_dp8384x_ack_int,
171 + .shutdown = phy_cmd_dp8384x_shutdown,
174 /* ------------------------------------------------------------------------- */
175 @@ -1218,6 +1249,7 @@ static phy_info_t const * const phy_info
183 @@ -1799,6 +1831,138 @@ static void __inline__ fec_uncache(unsig
185 /* ------------------------------------------------------------------------- */
187 +#elif defined(CONFIG_M54455)
189 + * Code specific for M54455
192 +static void __inline__ fec_request_intrs(struct net_device *dev)
194 + struct fec_enet_private *fep;
196 + static const struct idesc {
198 + unsigned short irq;
200 + { "fec(TXF)", 36 },
201 + { "fec(TXB)", 37 },
202 + { "fec(TXFIFO)", 38 },
203 + { "fec(TXCR)", 39 },
204 + { "fec(RXF)", 40 },
205 + { "fec(RXB)", 41 },
206 + { "fec(MII)", 42 },
208 + { "fec(HBERR)", 44 },
209 + { "fec(GRA)", 45 },
210 + { "fec(EBERR)", 46 },
211 + { "fec(BABT)", 47 },
212 + { "fec(BABR)", 48 },
216 + fep = netdev_priv(dev);
217 + b = (fep->index) ? 77 : 64;
219 + /* Setup interrupt handlers. */
220 + for (idp = id; idp->name; idp++) {
221 + if (request_irq(b+idp->irq, fec_enet_interrupt, 0,
222 + idp->name, dev) != 0)
223 + printk(KERN_ERR "FEC: Could not alloc %s IRQ(%d)!\n",
224 + idp->name, b+idp->irq);
228 + /* Configure RMII */
229 + MCF_GPIO_PAR_FEC = (MCF_GPIO_PAR_FEC &
230 + MCF_GPIO_PAR_FEC_FEC1_MASK) |
231 + MCF_GPIO_PAR_FEC_FEC1_RMII_GPIO;
233 + /* Configure RMII */
234 + MCF_GPIO_PAR_FEC = (MCF_GPIO_PAR_FEC &
235 + MCF_GPIO_PAR_FEC_FEC0_MASK) |
236 + MCF_GPIO_PAR_FEC_FEC0_RMII_GPIO;
239 + /* Set up gpio outputs for MII lines on FEC0 */
240 + MCF_GPIO_PAR_FECI2C |= (0 |
241 + MCF_GPIO_PAR_FECI2C_MDIO0_MDIO0 |
242 + MCF_GPIO_PAR_FECI2C_MDC0_MDC0);
245 +static void __inline__ fec_set_mii(struct net_device *dev,
246 + struct fec_enet_private *fep)
248 + volatile fec_t *fecp;
251 + fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
252 + fecp->fec_x_cntrl = 0x00;
255 + * Set MII speed to 2.5 MHz
257 + fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
258 + fecp->fec_mii_speed = fep->phy_speed;
260 + fec_restart(dev, 0);
263 +static void __inline__ fec_get_mac(struct net_device *dev)
265 + struct fec_enet_private *fep = netdev_priv(dev);
266 + volatile fec_t *fecp;
267 + unsigned char *iap, tmpaddr[ETH_ALEN];
271 + if (FEC_FLASHMAC) {
273 + * Get MAC address from FLASH.
274 + * If it is all 1's or 0's, use the default.
276 + iap = FEC_FLASHMAC;
277 + if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
278 + (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
279 + iap = fec_mac_default;
280 + if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
281 + (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
282 + iap = fec_mac_default;
284 + *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
285 + *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
289 + memcpy(dev->dev_addr, iap, ETH_ALEN);
291 + /* Adjust MAC if using default MAC address */
292 + if (iap == fec_mac_default)
293 + dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] +
297 +static void __inline__ fec_enable_phy_intr(void)
301 +static void __inline__ fec_disable_phy_intr(void)
305 +static void __inline__ fec_phy_ack_intr(void)
309 +static void __inline__ fec_localhw_setup(void)
313 +static void __inline__ fec_uncache(unsigned long addr)
317 +/* ------------------------------------------------------------------------- */
322 @@ -2305,7 +2469,7 @@ fec_set_mac_address(struct net_device *d
326 -/* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
327 +/* Initialize the FEC Ethernet.
330 * XXX: We need to clean up on failure exits here.
331 @@ -2326,7 +2490,7 @@ int __init fec_enet_init(struct net_devi
333 /* Allocate memory for buffer descriptors.
335 - mem_addr = __get_free_page(GFP_KERNEL);
336 + mem_addr = __get_free_page(GFP_DMA);
338 printk("FEC: allocate descriptor memory failed?\n");
340 @@ -2339,6 +2503,11 @@ int __init fec_enet_init(struct net_devi
344 +#ifdef CONFIG_FEC_SHARED_PHY
345 + fep->phy_hwp = (volatile fec_t *) fec_hw[index & ~1];
347 + fep->phy_hwp = fecp;
350 /* Whack a reset. We should wait for this.
352 @@ -2375,7 +2544,7 @@ int __init fec_enet_init(struct net_devi
356 - mem_addr = __get_free_page(GFP_KERNEL);
357 + mem_addr = __get_free_page(GFP_DMA);
358 /* XXX: missing check for allocation failure */
360 fec_uncache(mem_addr);
361 @@ -2400,7 +2569,7 @@ int __init fec_enet_init(struct net_devi
362 bdp = fep->tx_bd_base;
363 for (i=0, j=FEC_ENET_TX_FRPPG; i<TX_RING_SIZE; i++) {
364 if (j >= FEC_ENET_TX_FRPPG) {
365 - mem_addr = __get_free_page(GFP_KERNEL);
366 + mem_addr = __get_free_page(GFP_DMA);
369 mem_addr += FEC_ENET_TX_FRSIZE;
370 @@ -2462,7 +2631,11 @@ int __init fec_enet_init(struct net_devi
371 * remainder of the interface.
373 fep->phy_id_done = 0;
374 +#ifndef CONFIG_FEC_SHARED_PHY
377 + fep->phy_addr = fep->index;
379 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy);
382 --- a/drivers/net/fec.h
383 +++ b/drivers/net/fec.h
385 /****************************************************************************/
387 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
388 - defined(CONFIG_M520x) || defined(CONFIG_M532x)
389 + defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_M54455)
391 * Just figures, Motorola would have to change the offsets for
392 * registers in the same peripheral device on different models