1 // SPDX-License-Identifier: GPL-2.0-or-later
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.
10 * Based on the arch/ppc version of the driver:
12 * Copyright 2004 MontaVista Software, Inc.
17 #include <linux/mod_devicetable.h>
18 #include <linux/of_address.h>
19 #include <linux/platform_device.h>
25 int tah_attach(struct platform_device *ofdev, int channel)
27 struct tah_instance *dev = platform_get_drvdata(ofdev);
29 mutex_lock(&dev->lock);
30 /* Reset has been done at probe() time... nothing else to do for now */
32 mutex_unlock(&dev->lock);
37 void tah_detach(struct platform_device *ofdev, int channel)
39 struct tah_instance *dev = platform_get_drvdata(ofdev);
41 mutex_lock(&dev->lock);
43 mutex_unlock(&dev->lock);
46 void tah_reset(struct platform_device *ofdev)
48 struct tah_instance *dev = platform_get_drvdata(ofdev);
49 struct tah_regs __iomem *p = dev->base;
53 out_be32(&p->mr, TAH_MR_SR);
55 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
59 printk(KERN_ERR "%pOF: reset timeout\n", ofdev->dev.of_node);
61 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
63 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
67 int tah_get_regs_len(struct platform_device *ofdev)
69 return sizeof(struct emac_ethtool_regs_subhdr) +
70 sizeof(struct tah_regs);
73 void *tah_dump_regs(struct platform_device *ofdev, void *buf)
75 struct tah_instance *dev = platform_get_drvdata(ofdev);
76 struct emac_ethtool_regs_subhdr *hdr = buf;
77 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
80 hdr->index = 0; /* for now, are there chips with more than one
81 * zmii ? if yes, then we'll add a cell_index
84 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
88 static int tah_probe(struct platform_device *ofdev)
90 struct device_node *np = ofdev->dev.of_node;
91 struct tah_instance *dev;
96 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
100 mutex_init(&dev->lock);
104 if (of_address_to_resource(np, 0, ®s)) {
105 printk(KERN_ERR "%pOF: Can't get registers address\n", np);
110 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
111 sizeof(struct tah_regs));
112 if (dev->base == NULL) {
113 printk(KERN_ERR "%pOF: Can't map device registers!\n", np);
117 platform_set_drvdata(ofdev, dev);
119 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
122 printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
133 static void tah_remove(struct platform_device *ofdev)
135 struct tah_instance *dev = platform_get_drvdata(ofdev);
137 WARN_ON(dev->users != 0);
143 static const struct of_device_id tah_match[] =
146 .compatible = "ibm,tah",
148 /* For backward compat with old DT */
155 static struct platform_driver tah_driver = {
158 .of_match_table = tah_match,
161 .remove_new = tah_remove,
164 int __init tah_init(void)
166 return platform_driver_register(&tah_driver);
171 platform_driver_unregister(&tah_driver);