aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/cadence/at91_ether.c
diff options
context:
space:
mode:
authorJoachim Eastwood <manabian@gmail.com>2012-11-07 03:14:57 -0500
committerDavid S. Miller <davem@davemloft.net>2012-11-07 17:44:38 -0500
commit50b5ca168a86de65551b46db3597b326f3e6225a (patch)
tree4a6488688a23bdddb155993a09bd734ada827b70 /drivers/net/ethernet/cadence/at91_ether.c
parented2b97d3537cd64ef9af2a090c8e8d99d99a0e37 (diff)
net/at91_ether: fix comment and style issues
Signed-off-by: Joachim Eastwood <manabian@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/cadence/at91_ether.c')
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.c111
1 files changed, 51 insertions, 60 deletions
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index cf0cf0692197..e7a476cff6c5 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -6,11 +6,6 @@
6 * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc. 6 * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
7 * Initial version by Rick Bronson 01/11/2003 7 * Initial version by Rick Bronson 01/11/2003
8 * 8 *
9 * Intel LXT971A PHY support by Christopher Bahns & David Knickerbocker
10 * (Polaroid Corporation)
11 *
12 * Realtek RTL8201(B)L PHY support by Roman Avramenko <roman@imsystems.ru>
13 *
14 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License 10 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 11 * as published by the Free Software Foundation; either version
@@ -38,22 +33,17 @@
38 33
39#include "macb.h" 34#include "macb.h"
40 35
41#define DRV_NAME "at91_ether"
42#define DRV_VERSION "1.0"
43
44/* 1518 rounded up */ 36/* 1518 rounded up */
45#define MAX_RBUFF_SZ 0x600 37#define MAX_RBUFF_SZ 0x600
46/* max number of receive buffers */ 38/* max number of receive buffers */
47#define MAX_RX_DESCR 9 39#define MAX_RX_DESCR 9
48 40
49/* 41/* Initialize and start the Receiver and Transmit subsystems */
50 * Initialize and start the Receiver and Transmit subsystems
51 */
52static int at91ether_start(struct net_device *dev) 42static int at91ether_start(struct net_device *dev)
53{ 43{
54 struct macb *lp = netdev_priv(dev); 44 struct macb *lp = netdev_priv(dev);
55 unsigned long ctl;
56 dma_addr_t addr; 45 dma_addr_t addr;
46 u32 ctl;
57 int i; 47 int i;
58 48
59 lp->rx_ring = dma_alloc_coherent(&lp->pdev->dev, 49 lp->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
@@ -100,13 +90,11 @@ static int at91ether_start(struct net_device *dev)
100 return 0; 90 return 0;
101} 91}
102 92
103/* 93/* Open the ethernet interface */
104 * Open the ethernet interface
105 */
106static int at91ether_open(struct net_device *dev) 94static int at91ether_open(struct net_device *dev)
107{ 95{
108 struct macb *lp = netdev_priv(dev); 96 struct macb *lp = netdev_priv(dev);
109 unsigned long ctl; 97 u32 ctl;
110 int ret; 98 int ret;
111 99
112 if (!is_valid_ether_addr(dev->dev_addr)) 100 if (!is_valid_ether_addr(dev->dev_addr))
@@ -123,9 +111,13 @@ static int at91ether_open(struct net_device *dev)
123 return ret; 111 return ret;
124 112
125 /* Enable MAC interrupts */ 113 /* Enable MAC interrupts */
126 macb_writel(lp, IER, MACB_BIT(RCOMP) | MACB_BIT(RXUBR) 114 macb_writel(lp, IER, MACB_BIT(RCOMP) |
127 | MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE) | MACB_BIT(TCOMP) 115 MACB_BIT(RXUBR) |
128 | MACB_BIT(ISR_ROVR) | MACB_BIT(HRESP)); 116 MACB_BIT(ISR_TUND) |
117 MACB_BIT(ISR_RLE) |
118 MACB_BIT(TCOMP) |
119 MACB_BIT(ISR_ROVR) |
120 MACB_BIT(HRESP));
129 121
130 /* schedule a link state check */ 122 /* schedule a link state check */
131 phy_start(lp->phy_dev); 123 phy_start(lp->phy_dev);
@@ -135,23 +127,24 @@ static int at91ether_open(struct net_device *dev)
135 return 0; 127 return 0;
136} 128}
137 129
138/* 130/* Close the interface */
139 * Close the interface
140 */
141static int at91ether_close(struct net_device *dev) 131static int at91ether_close(struct net_device *dev)
142{ 132{
143 struct macb *lp = netdev_priv(dev); 133 struct macb *lp = netdev_priv(dev);
144 unsigned long ctl; 134 u32 ctl;
145 135
146 /* Disable Receiver and Transmitter */ 136 /* Disable Receiver and Transmitter */
147 ctl = macb_readl(lp, NCR); 137 ctl = macb_readl(lp, NCR);
148 macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE))); 138 macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE)));
149 139
150 /* Disable MAC interrupts */ 140 /* Disable MAC interrupts */
151 macb_writel(lp, IDR, MACB_BIT(RCOMP) | MACB_BIT(RXUBR) 141 macb_writel(lp, IDR, MACB_BIT(RCOMP) |
152 | MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE) 142 MACB_BIT(RXUBR) |
153 | MACB_BIT(TCOMP) | MACB_BIT(ISR_ROVR) 143 MACB_BIT(ISR_TUND) |
154 | MACB_BIT(HRESP)); 144 MACB_BIT(ISR_RLE) |
145 MACB_BIT(TCOMP) |
146 MACB_BIT(ISR_ROVR) |
147 MACB_BIT(HRESP));
155 148
156 netif_stop_queue(dev); 149 netif_stop_queue(dev);
157 150
@@ -168,9 +161,7 @@ static int at91ether_close(struct net_device *dev)
168 return 0; 161 return 0;
169} 162}
170 163
171/* 164/* Transmit packet */
172 * Transmit packet.
173 */
174static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev) 165static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
175{ 166{
176 struct macb *lp = netdev_priv(dev); 167 struct macb *lp = netdev_priv(dev);
@@ -181,7 +172,8 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
181 /* Store packet information (to free when Tx completed) */ 172 /* Store packet information (to free when Tx completed) */
182 lp->skb = skb; 173 lp->skb = skb;
183 lp->skb_length = skb->len; 174 lp->skb_length = skb->len;
184 lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE); 175 lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len,
176 DMA_TO_DEVICE);
185 177
186 /* Set address of the data in the Transmit Address register */ 178 /* Set address of the data in the Transmit Address register */
187 macb_writel(lp, TAR, lp->skb_physaddr); 179 macb_writel(lp, TAR, lp->skb_physaddr);
@@ -190,16 +182,13 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
190 182
191 } else { 183 } else {
192 netdev_err(dev, "%s called, but device is busy!\n", __func__); 184 netdev_err(dev, "%s called, but device is busy!\n", __func__);
193 return NETDEV_TX_BUSY; /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb) 185 return NETDEV_TX_BUSY;
194 on this skb, he also reports -ENETDOWN and printk's, so either
195 we free and return(0) or don't free and return 1 */
196 } 186 }
197 187
198 return NETDEV_TX_OK; 188 return NETDEV_TX_OK;
199} 189}
200 190
201/* 191/* Extract received frame from buffer descriptors and sent to upper layers.
202 * Extract received frame from buffer descriptors and sent to upper layers.
203 * (Called from interrupt context) 192 * (Called from interrupt context)
204 */ 193 */
205static void at91ether_rx(struct net_device *dev) 194static void at91ether_rx(struct net_device *dev)
@@ -240,24 +229,25 @@ static void at91ether_rx(struct net_device *dev)
240 } 229 }
241} 230}
242 231
243/* 232/* MAC interrupt handler */
244 * MAC interrupt handler
245 */
246static irqreturn_t at91ether_interrupt(int irq, void *dev_id) 233static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
247{ 234{
248 struct net_device *dev = (struct net_device *) dev_id; 235 struct net_device *dev = dev_id;
249 struct macb *lp = netdev_priv(dev); 236 struct macb *lp = netdev_priv(dev);
250 unsigned long intstatus, ctl; 237 u32 intstatus, ctl;
251 238
252 /* MAC Interrupt Status register indicates what interrupts are pending. 239 /* MAC Interrupt Status register indicates what interrupts are pending.
253 It is automatically cleared once read. */ 240 * It is automatically cleared once read.
241 */
254 intstatus = macb_readl(lp, ISR); 242 intstatus = macb_readl(lp, ISR);
255 243
256 if (intstatus & MACB_BIT(RCOMP)) /* Receive complete */ 244 /* Receive complete */
245 if (intstatus & MACB_BIT(RCOMP))
257 at91ether_rx(dev); 246 at91ether_rx(dev);
258 247
259 if (intstatus & MACB_BIT(TCOMP)) { /* Transmit complete */ 248 /* Transmit complete */
260 /* The TCOM bit is set even if the transmission failed. */ 249 if (intstatus & MACB_BIT(TCOMP)) {
250 /* The TCOM bit is set even if the transmission failed */
261 if (intstatus & (MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE))) 251 if (intstatus & (MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE)))
262 lp->stats.tx_errors++; 252 lp->stats.tx_errors++;
263 253
@@ -271,7 +261,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
271 netif_wake_queue(dev); 261 netif_wake_queue(dev);
272 } 262 }
273 263
274 /* Work-around for Errata #11 */ 264 /* Work-around for EMAC Errata section 41.3.1 */
275 if (intstatus & MACB_BIT(RXUBR)) { 265 if (intstatus & MACB_BIT(RXUBR)) {
276 ctl = macb_readl(lp, NCR); 266 ctl = macb_readl(lp, NCR);
277 macb_writel(lp, NCR, ctl & ~MACB_BIT(RE)); 267 macb_writel(lp, NCR, ctl & ~MACB_BIT(RE));
@@ -354,18 +344,17 @@ static int at91ether_get_hwaddr_dt(struct macb *bp)
354} 344}
355#endif 345#endif
356 346
357/* 347/* Detect MAC & PHY and perform ethernet interface initialization */
358 * Detect MAC & PHY and perform ethernet interface initialization
359 */
360static int __init at91ether_probe(struct platform_device *pdev) 348static int __init at91ether_probe(struct platform_device *pdev)
361{ 349{
362 struct macb_platform_data *board_data = pdev->dev.platform_data; 350 struct macb_platform_data *board_data = pdev->dev.platform_data;
363 struct resource *regs; 351 struct resource *regs;
364 struct net_device *dev; 352 struct net_device *dev;
365 struct phy_device *phydev; 353 struct phy_device *phydev;
354 struct pinctrl *pinctrl;
366 struct macb *lp; 355 struct macb *lp;
367 int res; 356 int res;
368 struct pinctrl *pinctrl; 357 u32 reg;
369 358
370 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 359 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
371 if (!regs) 360 if (!regs)
@@ -389,7 +378,8 @@ static int __init at91ether_probe(struct platform_device *pdev)
389 lp->dev = dev; 378 lp->dev = dev;
390 spin_lock_init(&lp->lock); 379 spin_lock_init(&lp->lock);
391 380
392 dev->base_addr = regs->start; /* physical base address */ 381 /* physical base address */
382 dev->base_addr = regs->start;
393 lp->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); 383 lp->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
394 if (!lp->regs) { 384 if (!lp->regs) {
395 res = -ENOMEM; 385 res = -ENOMEM;
@@ -432,10 +422,11 @@ static int __init at91ether_probe(struct platform_device *pdev)
432 422
433 macb_writel(lp, NCR, 0); 423 macb_writel(lp, NCR, 0);
434 424
425 reg = MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG);
435 if (lp->phy_interface == PHY_INTERFACE_MODE_RMII) 426 if (lp->phy_interface == PHY_INTERFACE_MODE_RMII)
436 macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG) | MACB_BIT(RM9200_RMII)); 427 reg |= MACB_BIT(RM9200_RMII);
437 else 428
438 macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG)); 429 macb_writel(lp, NCFGR, reg);
439 430
440 /* Register the network interface */ 431 /* Register the network interface */
441 res = register_netdev(dev); 432 res = register_netdev(dev);
@@ -445,11 +436,13 @@ static int __init at91ether_probe(struct platform_device *pdev)
445 if (macb_mii_init(lp) != 0) 436 if (macb_mii_init(lp) != 0)
446 goto err_out_unregister_netdev; 437 goto err_out_unregister_netdev;
447 438
448 netif_carrier_off(dev); /* will be enabled in open() */ 439 /* will be enabled in open() */
440 netif_carrier_off(dev);
449 441
450 phydev = lp->phy_dev; 442 phydev = lp->phy_dev;
451 netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", 443 netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
452 phydev->drv->name, dev_name(&phydev->dev), phydev->irq); 444 phydev->drv->name, dev_name(&phydev->dev),
445 phydev->irq);
453 446
454 /* Display ethernet banner */ 447 /* Display ethernet banner */
455 netdev_info(dev, "AT91 ethernet at 0x%08lx int=%d (%pM)\n", 448 netdev_info(dev, "AT91 ethernet at 0x%08lx int=%d (%pM)\n",
@@ -486,7 +479,6 @@ static int __devexit at91ether_remove(struct platform_device *pdev)
486} 479}
487 480
488#ifdef CONFIG_PM 481#ifdef CONFIG_PM
489
490static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg) 482static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg)
491{ 483{
492 struct net_device *net_dev = platform_get_drvdata(pdev); 484 struct net_device *net_dev = platform_get_drvdata(pdev);
@@ -514,7 +506,6 @@ static int at91ether_resume(struct platform_device *pdev)
514 } 506 }
515 return 0; 507 return 0;
516} 508}
517
518#else 509#else
519#define at91ether_suspend NULL 510#define at91ether_suspend NULL
520#define at91ether_resume NULL 511#define at91ether_resume NULL
@@ -525,7 +516,7 @@ static struct platform_driver at91ether_driver = {
525 .suspend = at91ether_suspend, 516 .suspend = at91ether_suspend,
526 .resume = at91ether_resume, 517 .resume = at91ether_resume,
527 .driver = { 518 .driver = {
528 .name = DRV_NAME, 519 .name = "at91_ether",
529 .owner = THIS_MODULE, 520 .owner = THIS_MODULE,
530 .of_match_table = of_match_ptr(at91ether_dt_ids), 521 .of_match_table = of_match_ptr(at91ether_dt_ids),
531 }, 522 },
@@ -547,4 +538,4 @@ module_exit(at91ether_exit)
547MODULE_LICENSE("GPL"); 538MODULE_LICENSE("GPL");
548MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver"); 539MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
549MODULE_AUTHOR("Andrew Victor"); 540MODULE_AUTHOR("Andrew Victor");
550MODULE_ALIAS("platform:" DRV_NAME); 541MODULE_ALIAS("platform:at91_ether");