blob: 872912ef518d163f6a4df7108e53fad0bb658afc [file] [log] [blame]
David Gibson1d3bb992007-08-23 13:56:01 +10001/*
Paul Gortmaker3396c782012-01-27 13:36:01 +00002 * drivers/net/ethernet/ibm/emac/tah.c
David Gibson1d3bb992007-08-23 13:56:01 +10003 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
5 *
Benjamin Herrenschmidt17cf8032007-12-05 11:14:33 +11006 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
David Gibson1d3bb992007-08-23 13:56:01 +100011 * 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
Grant Likely2dc11582010-08-06 09:25:50 -060026int __devinit tah_attach(struct platform_device *ofdev, int channel)
David Gibson1d3bb992007-08-23 13:56:01 +100027{
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
Grant Likely2dc11582010-08-06 09:25:50 -060038void tah_detach(struct platform_device *ofdev, int channel)
David Gibson1d3bb992007-08-23 13:56:01 +100039{
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
Grant Likely2dc11582010-08-06 09:25:50 -060047void tah_reset(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +100048{
49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
Al Viroeb4d84f2007-10-14 19:36:10 +010050 struct tah_regs __iomem *p = dev->base;
David Gibson1d3bb992007-08-23 13:56:01 +100051 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))
Grant Likely61c7a082010-04-13 16:12:29 -070060 printk(KERN_ERR "%s: reset timeout\n",
61 ofdev->dev.of_node->full_name);
David Gibson1d3bb992007-08-23 13:56:01 +100062
Lucas De Marchi25985ed2011-03-30 22:57:33 -030063 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
David Gibson1d3bb992007-08-23 13:56:01 +100064 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
Grant Likely2dc11582010-08-06 09:25:50 -060069int tah_get_regs_len(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +100070{
71 return sizeof(struct emac_ethtool_regs_subhdr) +
72 sizeof(struct tah_regs);
73}
74
Grant Likely2dc11582010-08-06 09:25:50 -060075void *tah_dump_regs(struct platform_device *ofdev, void *buf)
David Gibson1d3bb992007-08-23 13:56:01 +100076{
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
Grant Likely74888762011-02-22 21:05:51 -070090static int __devinit tah_probe(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +100091{
Grant Likely61c7a082010-04-13 16:12:29 -070092 struct device_node *np = ofdev->dev.of_node;
David Gibson1d3bb992007-08-23 13:56:01 +100093 struct tah_instance *dev;
94 struct resource regs;
95 int rc;
96
97 rc = -ENOMEM;
98 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
Joe Perchese404dec2012-01-29 12:56:23 +000099 if (dev == NULL)
David Gibson1d3bb992007-08-23 13:56:01 +1000100 goto err_gone;
David Gibson1d3bb992007-08-23 13:56:01 +1000101
102 mutex_init(&dev->lock);
103 dev->ofdev = ofdev;
104
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;
110 }
111
112 rc = -ENOMEM;
Al Viroeb4d84f2007-10-14 19:36:10 +0100113 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
David Gibson1d3bb992007-08-23 13:56:01 +1000114 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;
119 }
120
Valentine Barshakd09e18b2007-12-05 11:14:32 +1100121 dev_set_drvdata(&ofdev->dev, dev);
122
David Gibson1d3bb992007-08-23 13:56:01 +1000123 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
124 tah_reset(ofdev);
125
126 printk(KERN_INFO
Grant Likely61c7a082010-04-13 16:12:29 -0700127 "TAH %s initialized\n", ofdev->dev.of_node->full_name);
David Gibson1d3bb992007-08-23 13:56:01 +1000128 wmb();
David Gibson1d3bb992007-08-23 13:56:01 +1000129
130 return 0;
131
132 err_free:
133 kfree(dev);
134 err_gone:
135 return rc;
136}
137
Grant Likely2dc11582010-08-06 09:25:50 -0600138static int __devexit tah_remove(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +1000139{
140 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
141
142 dev_set_drvdata(&ofdev->dev, NULL);
143
144 WARN_ON(dev->users != 0);
145
146 iounmap(dev->base);
147 kfree(dev);
148
149 return 0;
150}
151
152static struct of_device_id tah_match[] =
153{
154 {
Stefan Roesecdb34692008-03-13 16:59:43 +0100155 .compatible = "ibm,tah",
156 },
157 /* For backward compat with old DT */
158 {
David Gibson1d3bb992007-08-23 13:56:01 +1000159 .type = "tah",
160 },
161 {},
162};
163
Grant Likely74888762011-02-22 21:05:51 -0700164static struct platform_driver tah_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700165 .driver = {
166 .name = "emac-tah",
167 .owner = THIS_MODULE,
168 .of_match_table = tah_match,
169 },
David Gibson1d3bb992007-08-23 13:56:01 +1000170 .probe = tah_probe,
171 .remove = tah_remove,
172};
173
174int __init tah_init(void)
175{
Grant Likely74888762011-02-22 21:05:51 -0700176 return platform_driver_register(&tah_driver);
David Gibson1d3bb992007-08-23 13:56:01 +1000177}
178
179void tah_exit(void)
180{
Grant Likely74888762011-02-22 21:05:51 -0700181 platform_driver_unregister(&tah_driver);
David Gibson1d3bb992007-08-23 13:56:01 +1000182}