drivers: clean-up prom.h implicit includes
[linux-2.6-block.git] / drivers / net / ethernet / ibm / emac / tah.c
CommitLineData
1d3bb996 1/*
3396c782 2 * drivers/net/ethernet/ibm/emac/tah.c
1d3bb996
DG
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
5 *
17cf803a
BH
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
1d3bb996
DG
11 * Copyright 2004 MontaVista Software, Inc.
12 * Matt Porter <mporter@kernel.crashing.org>
13 *
14 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
20 */
5af50730 21#include <linux/of_address.h>
1d3bb996
DG
22#include <asm/io.h>
23
24#include "emac.h"
25#include "core.h"
26
fe17dc1e 27int tah_attach(struct platform_device *ofdev, int channel)
1d3bb996 28{
8513fbd8 29 struct tah_instance *dev = platform_get_drvdata(ofdev);
1d3bb996
DG
30
31 mutex_lock(&dev->lock);
32 /* Reset has been done at probe() time... nothing else to do for now */
33 ++dev->users;
34 mutex_unlock(&dev->lock);
35
36 return 0;
37}
38
2dc11581 39void tah_detach(struct platform_device *ofdev, int channel)
1d3bb996 40{
8513fbd8 41 struct tah_instance *dev = platform_get_drvdata(ofdev);
1d3bb996
DG
42
43 mutex_lock(&dev->lock);
44 --dev->users;
45 mutex_unlock(&dev->lock);
46}
47
2dc11581 48void tah_reset(struct platform_device *ofdev)
1d3bb996 49{
8513fbd8 50 struct tah_instance *dev = platform_get_drvdata(ofdev);
eb4d84f1 51 struct tah_regs __iomem *p = dev->base;
1d3bb996
DG
52 int n;
53
54 /* Reset TAH */
55 out_be32(&p->mr, TAH_MR_SR);
56 n = 100;
57 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
58 --n;
59
60 if (unlikely(!n))
61c7a080
GL
61 printk(KERN_ERR "%s: reset timeout\n",
62 ofdev->dev.of_node->full_name);
1d3bb996 63
25985edc 64 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
1d3bb996
DG
65 out_be32(&p->mr,
66 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
67 TAH_MR_DIG);
68}
69
2dc11581 70int tah_get_regs_len(struct platform_device *ofdev)
1d3bb996
DG
71{
72 return sizeof(struct emac_ethtool_regs_subhdr) +
73 sizeof(struct tah_regs);
74}
75
2dc11581 76void *tah_dump_regs(struct platform_device *ofdev, void *buf)
1d3bb996 77{
8513fbd8 78 struct tah_instance *dev = platform_get_drvdata(ofdev);
1d3bb996
DG
79 struct emac_ethtool_regs_subhdr *hdr = buf;
80 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
81
82 hdr->version = 0;
83 hdr->index = 0; /* for now, are there chips with more than one
84 * zmii ? if yes, then we'll add a cell_index
85 * like we do for emac
86 */
87 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
88 return regs + 1;
89}
90
fe17dc1e 91static int tah_probe(struct platform_device *ofdev)
1d3bb996 92{
61c7a080 93 struct device_node *np = ofdev->dev.of_node;
1d3bb996
DG
94 struct tah_instance *dev;
95 struct resource regs;
96 int rc;
97
98 rc = -ENOMEM;
99 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
e404decb 100 if (dev == NULL)
1d3bb996 101 goto err_gone;
1d3bb996
DG
102
103 mutex_init(&dev->lock);
104 dev->ofdev = ofdev;
105
106 rc = -ENXIO;
107 if (of_address_to_resource(np, 0, &regs)) {
108 printk(KERN_ERR "%s: Can't get registers address\n",
109 np->full_name);
110 goto err_free;
111 }
112
113 rc = -ENOMEM;
eb4d84f1 114 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
1d3bb996
DG
115 sizeof(struct tah_regs));
116 if (dev->base == NULL) {
117 printk(KERN_ERR "%s: Can't map device registers!\n",
118 np->full_name);
119 goto err_free;
120 }
121
8513fbd8 122 platform_set_drvdata(ofdev, dev);
d09e18bc 123
1d3bb996
DG
124 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
125 tah_reset(ofdev);
126
127 printk(KERN_INFO
61c7a080 128 "TAH %s initialized\n", ofdev->dev.of_node->full_name);
1d3bb996 129 wmb();
1d3bb996
DG
130
131 return 0;
132
133 err_free:
134 kfree(dev);
135 err_gone:
136 return rc;
137}
138
fe17dc1e 139static int tah_remove(struct platform_device *ofdev)
1d3bb996 140{
8513fbd8 141 struct tah_instance *dev = platform_get_drvdata(ofdev);
1d3bb996
DG
142
143 WARN_ON(dev->users != 0);
144
145 iounmap(dev->base);
146 kfree(dev);
147
148 return 0;
149}
150
151static struct of_device_id tah_match[] =
152{
cdb34697
SR
153 {
154 .compatible = "ibm,tah",
155 },
156 /* For backward compat with old DT */
1d3bb996
DG
157 {
158 .type = "tah",
159 },
160 {},
161};
162
74888760 163static struct platform_driver tah_driver = {
4018294b
GL
164 .driver = {
165 .name = "emac-tah",
166 .owner = THIS_MODULE,
167 .of_match_table = tah_match,
168 },
1d3bb996
DG
169 .probe = tah_probe,
170 .remove = tah_remove,
171};
172
173int __init tah_init(void)
174{
74888760 175 return platform_driver_register(&tah_driver);
1d3bb996
DG
176}
177
178void tah_exit(void)
179{
74888760 180 platform_driver_unregister(&tah_driver);
1d3bb996 181}