aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ibm_newemac/tah.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-08-22 23:56:01 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:51:52 -0400
commit1d3bb996481e116f5f2b127cbd29b83365d2cf62 (patch)
treeb612a1dbf51c920fb5a9758a6d35f9ed37eb927f /drivers/net/ibm_newemac/tah.c
parent03233b90b0977d577322a6e1ddd56d9cc570d406 (diff)
Device tree aware EMAC driver
Based on BenH's earlier work, this is a new version of the EMAC driver for the built-in ethernet found on PowerPC 4xx embedded CPUs. The same ASIC is also found in the Axon bridge chip. This new version is designed to work in the arch/powerpc tree, using the device tree to probe the device, rather than the old and ugly arch/ppc OCP layer. This driver is designed to sit alongside the old driver (that lies in drivers/net/ibm_emac and this one in drivers/net/ibm_newemac). The old driver is left in place to support arch/ppc until arch/ppc itself reaches its final demise (not too long now, with luck). This driver still has a number of things that could do with cleaning up, but I think they can be fixed up after merging. Specifically: - Should be adjusted to properly use the dma mapping API. Axon needs this. - Probe logic needs reworking, in conjuction with the general probing code for of_platform devices. The dependencies here between EMAC, MAL, ZMII etc. make this complicated. At present, it usually works, because we initialize and register the sub-drivers before the EMAC driver itself, and (being in driver code) runs after the devices themselves have been instantiated from the device tree. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net/ibm_newemac/tah.c')
-rw-r--r--drivers/net/ibm_newemac/tah.c173
1 files changed, 173 insertions, 0 deletions
diff --git a/drivers/net/ibm_newemac/tah.c b/drivers/net/ibm_newemac/tah.c
new file mode 100644
index 000000000000..e05c7e81efb6
--- /dev/null
+++ b/drivers/net/ibm_newemac/tah.c
@@ -0,0 +1,173 @@
1/*
2 * drivers/net/ibm_newemac/tah.c
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
5 *
6 * Copyright 2004 MontaVista Software, Inc.
7 * Matt Porter <mporter@kernel.crashing.org>
8 *
9 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16#include <asm/io.h>
17
18#include "emac.h"
19#include "core.h"
20
21int __devinit tah_attach(struct of_device *ofdev, int channel)
22{
23 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
24
25 mutex_lock(&dev->lock);
26 /* Reset has been done at probe() time... nothing else to do for now */
27 ++dev->users;
28 mutex_unlock(&dev->lock);
29
30 return 0;
31}
32
33void __devexit tah_detach(struct of_device *ofdev, int channel)
34{
35 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
36
37 mutex_lock(&dev->lock);
38 --dev->users;
39 mutex_unlock(&dev->lock);
40}
41
42void tah_reset(struct of_device *ofdev)
43{
44 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
45 struct tah_regs *p = dev->base;
46 int n;
47
48 /* Reset TAH */
49 out_be32(&p->mr, TAH_MR_SR);
50 n = 100;
51 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
52 --n;
53
54 if (unlikely(!n))
55 printk(KERN_ERR "%s: reset timeout\n", ofdev->node->full_name);
56
57 /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */
58 out_be32(&p->mr,
59 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
60 TAH_MR_DIG);
61}
62
63int tah_get_regs_len(struct of_device *ofdev)
64{
65 return sizeof(struct emac_ethtool_regs_subhdr) +
66 sizeof(struct tah_regs);
67}
68
69void *tah_dump_regs(struct of_device *ofdev, void *buf)
70{
71 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
72 struct emac_ethtool_regs_subhdr *hdr = buf;
73 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
74
75 hdr->version = 0;
76 hdr->index = 0; /* for now, are there chips with more than one
77 * zmii ? if yes, then we'll add a cell_index
78 * like we do for emac
79 */
80 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
81 return regs + 1;
82}
83
84static int __devinit tah_probe(struct of_device *ofdev,
85 const struct of_device_id *match)
86{
87 struct device_node *np = ofdev->node;
88 struct tah_instance *dev;
89 struct resource regs;
90 int rc;
91
92 rc = -ENOMEM;
93 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
94 if (dev == NULL) {
95 printk(KERN_ERR "%s: could not allocate TAH device!\n",
96 np->full_name);
97 goto err_gone;
98 }
99
100 mutex_init(&dev->lock);
101 dev->ofdev = ofdev;
102
103 rc = -ENXIO;
104 if (of_address_to_resource(np, 0, &regs)) {
105 printk(KERN_ERR "%s: Can't get registers address\n",
106 np->full_name);
107 goto err_free;
108 }
109
110 rc = -ENOMEM;
111 dev->base = (struct tah_regs *)ioremap(regs.start,
112 sizeof(struct tah_regs));
113 if (dev->base == NULL) {
114 printk(KERN_ERR "%s: Can't map device registers!\n",
115 np->full_name);
116 goto err_free;
117 }
118
119 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
120 tah_reset(ofdev);
121
122 printk(KERN_INFO
123 "TAH %s initialized\n", ofdev->node->full_name);
124 wmb();
125 dev_set_drvdata(&ofdev->dev, dev);
126
127 return 0;
128
129 err_free:
130 kfree(dev);
131 err_gone:
132 return rc;
133}
134
135static int __devexit tah_remove(struct of_device *ofdev)
136{
137 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
138
139 dev_set_drvdata(&ofdev->dev, NULL);
140
141 WARN_ON(dev->users != 0);
142
143 iounmap(dev->base);
144 kfree(dev);
145
146 return 0;
147}
148
149static struct of_device_id tah_match[] =
150{
151 {
152 .type = "tah",
153 },
154 {},
155};
156
157static struct of_platform_driver tah_driver = {
158 .name = "emac-tah",
159 .match_table = tah_match,
160
161 .probe = tah_probe,
162 .remove = tah_remove,
163};
164
165int __init tah_init(void)
166{
167 return of_register_platform_driver(&tah_driver);
168}
169
170void tah_exit(void)
171{
172 of_unregister_platform_driver(&tah_driver);
173}