WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / ethernet / ibm / emac / tah.c
blob008bbdaf1204e09e8f582d72444a7c7e1d4a46f0
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * drivers/net/ethernet/ibm/emac/tah.c
5 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
7 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
8 * <benh@kernel.crashing.org>
10 * Based on the arch/ppc version of the driver:
12 * Copyright 2004 MontaVista Software, Inc.
13 * Matt Porter <mporter@kernel.crashing.org>
15 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
17 #include <linux/of_address.h>
18 #include <asm/io.h>
20 #include "emac.h"
21 #include "core.h"
23 int tah_attach(struct platform_device *ofdev, int channel)
25 struct tah_instance *dev = platform_get_drvdata(ofdev);
27 mutex_lock(&dev->lock);
28 /* Reset has been done at probe() time... nothing else to do for now */
29 ++dev->users;
30 mutex_unlock(&dev->lock);
32 return 0;
35 void tah_detach(struct platform_device *ofdev, int channel)
37 struct tah_instance *dev = platform_get_drvdata(ofdev);
39 mutex_lock(&dev->lock);
40 --dev->users;
41 mutex_unlock(&dev->lock);
44 void tah_reset(struct platform_device *ofdev)
46 struct tah_instance *dev = platform_get_drvdata(ofdev);
47 struct tah_regs __iomem *p = dev->base;
48 int n;
50 /* Reset TAH */
51 out_be32(&p->mr, TAH_MR_SR);
52 n = 100;
53 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
54 --n;
56 if (unlikely(!n))
57 printk(KERN_ERR "%pOF: reset timeout\n", ofdev->dev.of_node);
59 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
60 out_be32(&p->mr,
61 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
62 TAH_MR_DIG);
65 int tah_get_regs_len(struct platform_device *ofdev)
67 return sizeof(struct emac_ethtool_regs_subhdr) +
68 sizeof(struct tah_regs);
71 void *tah_dump_regs(struct platform_device *ofdev, void *buf)
73 struct tah_instance *dev = platform_get_drvdata(ofdev);
74 struct emac_ethtool_regs_subhdr *hdr = buf;
75 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
77 hdr->version = 0;
78 hdr->index = 0; /* for now, are there chips with more than one
79 * zmii ? if yes, then we'll add a cell_index
80 * like we do for emac
82 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
83 return regs + 1;
86 static int tah_probe(struct platform_device *ofdev)
88 struct device_node *np = ofdev->dev.of_node;
89 struct tah_instance *dev;
90 struct resource regs;
91 int rc;
93 rc = -ENOMEM;
94 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
95 if (dev == NULL)
96 goto err_gone;
98 mutex_init(&dev->lock);
99 dev->ofdev = ofdev;
101 rc = -ENXIO;
102 if (of_address_to_resource(np, 0, &regs)) {
103 printk(KERN_ERR "%pOF: Can't get registers address\n", np);
104 goto err_free;
107 rc = -ENOMEM;
108 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
109 sizeof(struct tah_regs));
110 if (dev->base == NULL) {
111 printk(KERN_ERR "%pOF: Can't map device registers!\n", np);
112 goto err_free;
115 platform_set_drvdata(ofdev, dev);
117 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
118 tah_reset(ofdev);
120 printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
121 wmb();
123 return 0;
125 err_free:
126 kfree(dev);
127 err_gone:
128 return rc;
131 static int tah_remove(struct platform_device *ofdev)
133 struct tah_instance *dev = platform_get_drvdata(ofdev);
135 WARN_ON(dev->users != 0);
137 iounmap(dev->base);
138 kfree(dev);
140 return 0;
143 static const struct of_device_id tah_match[] =
146 .compatible = "ibm,tah",
148 /* For backward compat with old DT */
150 .type = "tah",
155 static struct platform_driver tah_driver = {
156 .driver = {
157 .name = "emac-tah",
158 .of_match_table = tah_match,
160 .probe = tah_probe,
161 .remove = tah_remove,
164 int __init tah_init(void)
166 return platform_driver_register(&tah_driver);
169 void tah_exit(void)
171 platform_driver_unregister(&tah_driver);