]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/ibm_newemac/tah.c
Fix common misspellings
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ibm_newemac / tah.c
CommitLineData
1d3bb996
DG
1/*
2 * drivers/net/ibm_newemac/tah.c
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 */
21#include <asm/io.h>
22
23#include "emac.h"
24#include "core.h"
25
2dc11581 26int __devinit tah_attach(struct platform_device *ofdev, int channel)
1d3bb996
DG
27{
28 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
29
30 mutex_lock(&dev->lock);
31 /* Reset has been done at probe() time... nothing else to do for now */
32 ++dev->users;
33 mutex_unlock(&dev->lock);
34
35 return 0;
36}
37
2dc11581 38void tah_detach(struct platform_device *ofdev, int channel)
1d3bb996
DG
39{
40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
41
42 mutex_lock(&dev->lock);
43 --dev->users;
44 mutex_unlock(&dev->lock);
45}
46
2dc11581 47void tah_reset(struct platform_device *ofdev)
1d3bb996
DG
48{
49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
eb4d84f1 50 struct tah_regs __iomem *p = dev->base;
1d3bb996
DG
51 int n;
52
53 /* Reset TAH */
54 out_be32(&p->mr, TAH_MR_SR);
55 n = 100;
56 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
57 --n;
58
59 if (unlikely(!n))
61c7a080
GL
60 printk(KERN_ERR "%s: reset timeout\n",
61 ofdev->dev.of_node->full_name);
1d3bb996 62
25985edc 63 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
1d3bb996
DG
64 out_be32(&p->mr,
65 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
66 TAH_MR_DIG);
67}
68
2dc11581 69int tah_get_regs_len(struct platform_device *ofdev)
1d3bb996
DG
70{
71 return sizeof(struct emac_ethtool_regs_subhdr) +
72 sizeof(struct tah_regs);
73}
74
2dc11581 75void *tah_dump_regs(struct platform_device *ofdev, void *buf)
1d3bb996
DG
76{
77 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
78 struct emac_ethtool_regs_subhdr *hdr = buf;
79 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
80
81 hdr->version = 0;
82 hdr->index = 0; /* for now, are there chips with more than one
83 * zmii ? if yes, then we'll add a cell_index
84 * like we do for emac
85 */
86 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
87 return regs + 1;
88}
89
74888760 90static int __devinit tah_probe(struct platform_device *ofdev)
1d3bb996 91{
61c7a080 92 struct device_node *np = ofdev->dev.of_node;
1d3bb996
DG
93 struct tah_instance *dev;
94 struct resource regs;
95 int rc;
96
97 rc = -ENOMEM;
98 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
99 if (dev == NULL) {
100 printk(KERN_ERR "%s: could not allocate TAH device!\n",
101 np->full_name);
102 goto err_gone;
103 }
104
105 mutex_init(&dev->lock);
106 dev->ofdev = ofdev;
107
108 rc = -ENXIO;
109 if (of_address_to_resource(np, 0, &regs)) {
110 printk(KERN_ERR "%s: Can't get registers address\n",
111 np->full_name);
112 goto err_free;
113 }
114
115 rc = -ENOMEM;
eb4d84f1 116 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
1d3bb996
DG
117 sizeof(struct tah_regs));
118 if (dev->base == NULL) {
119 printk(KERN_ERR "%s: Can't map device registers!\n",
120 np->full_name);
121 goto err_free;
122 }
123
d09e18bc
VB
124 dev_set_drvdata(&ofdev->dev, dev);
125
1d3bb996
DG
126 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
127 tah_reset(ofdev);
128
129 printk(KERN_INFO
61c7a080 130 "TAH %s initialized\n", ofdev->dev.of_node->full_name);
1d3bb996 131 wmb();
1d3bb996
DG
132
133 return 0;
134
135 err_free:
136 kfree(dev);
137 err_gone:
138 return rc;
139}
140
2dc11581 141static int __devexit tah_remove(struct platform_device *ofdev)
1d3bb996
DG
142{
143 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
144
145 dev_set_drvdata(&ofdev->dev, NULL);
146
147 WARN_ON(dev->users != 0);
148
149 iounmap(dev->base);
150 kfree(dev);
151
152 return 0;
153}
154
155static struct of_device_id tah_match[] =
156{
cdb34697
SR
157 {
158 .compatible = "ibm,tah",
159 },
160 /* For backward compat with old DT */
1d3bb996
DG
161 {
162 .type = "tah",
163 },
164 {},
165};
166
74888760 167static struct platform_driver tah_driver = {
4018294b
GL
168 .driver = {
169 .name = "emac-tah",
170 .owner = THIS_MODULE,
171 .of_match_table = tah_match,
172 },
1d3bb996
DG
173 .probe = tah_probe,
174 .remove = tah_remove,
175};
176
177int __init tah_init(void)
178{
74888760 179 return platform_driver_register(&tah_driver);
1d3bb996
DG
180}
181
182void tah_exit(void)
183{
74888760 184 platform_driver_unregister(&tah_driver);
1d3bb996 185}