Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / net / ethernet / ibm / emac / tah.c
blob09f6373ed2f90b0ca6c2e4e6b50af56578005505
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/mod_devicetable.h>
18 #include <linux/of_address.h>
19 #include <linux/platform_device.h>
20 #include <asm/io.h>
22 #include "emac.h"
23 #include "core.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 */
31 ++dev->users;
32 mutex_unlock(&dev->lock);
34 return 0;
37 void tah_detach(struct platform_device *ofdev, int channel)
39 struct tah_instance *dev = platform_get_drvdata(ofdev);
41 mutex_lock(&dev->lock);
42 --dev->users;
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;
50 int n;
52 /* Reset TAH */
53 out_be32(&p->mr, TAH_MR_SR);
54 n = 100;
55 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
56 --n;
58 if (unlikely(!n))
59 printk(KERN_ERR "%pOF: reset timeout\n", ofdev->dev.of_node);
61 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
62 out_be32(&p->mr,
63 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
64 TAH_MR_DIG);
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);
79 hdr->version = 0;
80 hdr->index = 0; /* for now, are there chips with more than one
81 * zmii ? if yes, then we'll add a cell_index
82 * like we do for emac
84 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
85 return regs + 1;
88 static int tah_probe(struct platform_device *ofdev)
90 struct tah_instance *dev;
91 int err;
93 dev = devm_kzalloc(&ofdev->dev, sizeof(struct tah_instance),
94 GFP_KERNEL);
95 if (!dev)
96 return -ENOMEM;
98 err = devm_mutex_init(&ofdev->dev, &dev->lock);
99 if (err)
100 return err;
102 dev->ofdev = ofdev;
104 dev->base = devm_platform_ioremap_resource(ofdev, 0);
105 if (IS_ERR(dev->base)) {
106 dev_err(&ofdev->dev, "can't map device registers");
107 return PTR_ERR(dev->base);
110 platform_set_drvdata(ofdev, dev);
112 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
113 tah_reset(ofdev);
115 printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
116 wmb();
118 return 0;
121 static const struct of_device_id tah_match[] =
124 .compatible = "ibm,tah",
126 /* For backward compat with old DT */
128 .type = "tah",
133 static struct platform_driver tah_driver = {
134 .driver = {
135 .name = "emac-tah",
136 .of_match_table = tah_match,
138 .probe = tah_probe,
141 int __init tah_init(void)
143 return platform_driver_register(&tah_driver);
146 void tah_exit(void)
148 platform_driver_unregister(&tah_driver);