blob: 32cb6c9007c55c959f36eb6bc58a7e8d53236ebe [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 */
Rob Herring5af50732013-09-17 14:28:33 -050021#include <linux/of_address.h>
David Gibson1d3bb992007-08-23 13:56:01 +100022#include <asm/io.h>
23
24#include "emac.h"
25#include "core.h"
26
Bill Pembertonfe17dc12012-12-03 09:23:13 -050027int tah_attach(struct platform_device *ofdev, int channel)
David Gibson1d3bb992007-08-23 13:56:01 +100028{
Jingoo Han8513fbd2013-05-23 00:52:31 +000029 struct tah_instance *dev = platform_get_drvdata(ofdev);
David Gibson1d3bb992007-08-23 13:56:01 +100030
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
Grant Likely2dc11582010-08-06 09:25:50 -060039void tah_detach(struct platform_device *ofdev, int channel)
David Gibson1d3bb992007-08-23 13:56:01 +100040{
Jingoo Han8513fbd2013-05-23 00:52:31 +000041 struct tah_instance *dev = platform_get_drvdata(ofdev);
David Gibson1d3bb992007-08-23 13:56:01 +100042
43 mutex_lock(&dev->lock);
44 --dev->users;
45 mutex_unlock(&dev->lock);
46}
47
Grant Likely2dc11582010-08-06 09:25:50 -060048void tah_reset(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +100049{
Jingoo Han8513fbd2013-05-23 00:52:31 +000050 struct tah_instance *dev = platform_get_drvdata(ofdev);
Al Viroeb4d84f2007-10-14 19:36:10 +010051 struct tah_regs __iomem *p = dev->base;
David Gibson1d3bb992007-08-23 13:56:01 +100052 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))
Grant Likely61c7a082010-04-13 16:12:29 -070061 printk(KERN_ERR "%s: reset timeout\n",
62 ofdev->dev.of_node->full_name);
David Gibson1d3bb992007-08-23 13:56:01 +100063
Lucas De Marchi25985ed2011-03-30 22:57:33 -030064 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
David Gibson1d3bb992007-08-23 13:56:01 +100065 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
Grant Likely2dc11582010-08-06 09:25:50 -060070int tah_get_regs_len(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +100071{
72 return sizeof(struct emac_ethtool_regs_subhdr) +
73 sizeof(struct tah_regs);
74}
75
Grant Likely2dc11582010-08-06 09:25:50 -060076void *tah_dump_regs(struct platform_device *ofdev, void *buf)
David Gibson1d3bb992007-08-23 13:56:01 +100077{
Jingoo Han8513fbd2013-05-23 00:52:31 +000078 struct tah_instance *dev = platform_get_drvdata(ofdev);
David Gibson1d3bb992007-08-23 13:56:01 +100079 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
Bill Pembertonfe17dc12012-12-03 09:23:13 -050091static int tah_probe(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +100092{
Grant Likely61c7a082010-04-13 16:12:29 -070093 struct device_node *np = ofdev->dev.of_node;
David Gibson1d3bb992007-08-23 13:56:01 +100094 struct tah_instance *dev;
95 struct resource regs;
96 int rc;
97
98 rc = -ENOMEM;
99 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
Joe Perchese404dec2012-01-29 12:56:23 +0000100 if (dev == NULL)
David Gibson1d3bb992007-08-23 13:56:01 +1000101 goto err_gone;
David Gibson1d3bb992007-08-23 13:56:01 +1000102
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;
Al Viroeb4d84f2007-10-14 19:36:10 +0100114 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
David Gibson1d3bb992007-08-23 13:56:01 +1000115 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
Jingoo Han8513fbd2013-05-23 00:52:31 +0000122 platform_set_drvdata(ofdev, dev);
Valentine Barshakd09e18b2007-12-05 11:14:32 +1100123
David Gibson1d3bb992007-08-23 13:56:01 +1000124 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
125 tah_reset(ofdev);
126
127 printk(KERN_INFO
Grant Likely61c7a082010-04-13 16:12:29 -0700128 "TAH %s initialized\n", ofdev->dev.of_node->full_name);
David Gibson1d3bb992007-08-23 13:56:01 +1000129 wmb();
David Gibson1d3bb992007-08-23 13:56:01 +1000130
131 return 0;
132
133 err_free:
134 kfree(dev);
135 err_gone:
136 return rc;
137}
138
Bill Pembertonfe17dc12012-12-03 09:23:13 -0500139static int tah_remove(struct platform_device *ofdev)
David Gibson1d3bb992007-08-23 13:56:01 +1000140{
Jingoo Han8513fbd2013-05-23 00:52:31 +0000141 struct tah_instance *dev = platform_get_drvdata(ofdev);
David Gibson1d3bb992007-08-23 13:56:01 +1000142
143 WARN_ON(dev->users != 0);
144
145 iounmap(dev->base);
146 kfree(dev);
147
148 return 0;
149}
150
Fabian Frederick47b61662015-03-17 19:40:25 +0100151static const struct of_device_id tah_match[] =
David Gibson1d3bb992007-08-23 13:56:01 +1000152{
153 {
Stefan Roesecdb34692008-03-13 16:59:43 +0100154 .compatible = "ibm,tah",
155 },
156 /* For backward compat with old DT */
157 {
David Gibson1d3bb992007-08-23 13:56:01 +1000158 .type = "tah",
159 },
160 {},
161};
162
Grant Likely74888762011-02-22 21:05:51 -0700163static struct platform_driver tah_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700164 .driver = {
165 .name = "emac-tah",
Grant Likely40182942010-04-13 16:13:02 -0700166 .of_match_table = tah_match,
167 },
David Gibson1d3bb992007-08-23 13:56:01 +1000168 .probe = tah_probe,
169 .remove = tah_remove,
170};
171
172int __init tah_init(void)
173{
Grant Likely74888762011-02-22 21:05:51 -0700174 return platform_driver_register(&tah_driver);
David Gibson1d3bb992007-08-23 13:56:01 +1000175}
176
177void tah_exit(void)
178{
Grant Likely74888762011-02-22 21:05:51 -0700179 platform_driver_unregister(&tah_driver);
David Gibson1d3bb992007-08-23 13:56:01 +1000180}