Linux 3.11-rc3
[cris-mirror.git] / drivers / net / ethernet / ibm / emac / tah.c
blobc231a4a32c4dc90d341b10c67c194c1025e4c686
1 /*
2 * drivers/net/ethernet/ibm/emac/tah.c
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
9 * Based on the arch/ppc version of the driver:
11 * Copyright 2004 MontaVista Software, Inc.
12 * Matt Porter <mporter@kernel.crashing.org>
14 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
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.
21 #include <asm/io.h>
23 #include "emac.h"
24 #include "core.h"
26 int tah_attach(struct platform_device *ofdev, int channel)
28 struct tah_instance *dev = platform_get_drvdata(ofdev);
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);
35 return 0;
38 void tah_detach(struct platform_device *ofdev, int channel)
40 struct tah_instance *dev = platform_get_drvdata(ofdev);
42 mutex_lock(&dev->lock);
43 --dev->users;
44 mutex_unlock(&dev->lock);
47 void tah_reset(struct platform_device *ofdev)
49 struct tah_instance *dev = platform_get_drvdata(ofdev);
50 struct tah_regs __iomem *p = dev->base;
51 int n;
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;
59 if (unlikely(!n))
60 printk(KERN_ERR "%s: reset timeout\n",
61 ofdev->dev.of_node->full_name);
63 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
64 out_be32(&p->mr,
65 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
66 TAH_MR_DIG);
69 int tah_get_regs_len(struct platform_device *ofdev)
71 return sizeof(struct emac_ethtool_regs_subhdr) +
72 sizeof(struct tah_regs);
75 void *tah_dump_regs(struct platform_device *ofdev, void *buf)
77 struct tah_instance *dev = platform_get_drvdata(ofdev);
78 struct emac_ethtool_regs_subhdr *hdr = buf;
79 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
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
86 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
87 return regs + 1;
90 static int tah_probe(struct platform_device *ofdev)
92 struct device_node *np = ofdev->dev.of_node;
93 struct tah_instance *dev;
94 struct resource regs;
95 int rc;
97 rc = -ENOMEM;
98 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
99 if (dev == NULL)
100 goto err_gone;
102 mutex_init(&dev->lock);
103 dev->ofdev = ofdev;
105 rc = -ENXIO;
106 if (of_address_to_resource(np, 0, &regs)) {
107 printk(KERN_ERR "%s: Can't get registers address\n",
108 np->full_name);
109 goto err_free;
112 rc = -ENOMEM;
113 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
114 sizeof(struct tah_regs));
115 if (dev->base == NULL) {
116 printk(KERN_ERR "%s: Can't map device registers!\n",
117 np->full_name);
118 goto err_free;
121 platform_set_drvdata(ofdev, dev);
123 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
124 tah_reset(ofdev);
126 printk(KERN_INFO
127 "TAH %s initialized\n", ofdev->dev.of_node->full_name);
128 wmb();
130 return 0;
132 err_free:
133 kfree(dev);
134 err_gone:
135 return rc;
138 static int tah_remove(struct platform_device *ofdev)
140 struct tah_instance *dev = platform_get_drvdata(ofdev);
142 WARN_ON(dev->users != 0);
144 iounmap(dev->base);
145 kfree(dev);
147 return 0;
150 static struct of_device_id tah_match[] =
153 .compatible = "ibm,tah",
155 /* For backward compat with old DT */
157 .type = "tah",
162 static struct platform_driver tah_driver = {
163 .driver = {
164 .name = "emac-tah",
165 .owner = THIS_MODULE,
166 .of_match_table = tah_match,
168 .probe = tah_probe,
169 .remove = tah_remove,
172 int __init tah_init(void)
174 return platform_driver_register(&tah_driver);
177 void tah_exit(void)
179 platform_driver_unregister(&tah_driver);