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.
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>
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 tah_instance
*dev
;
93 dev
= devm_kzalloc(&ofdev
->dev
, sizeof(struct tah_instance
),
98 err
= devm_mutex_init(&ofdev
->dev
, &dev
->lock
);
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 */
115 printk(KERN_INFO
"TAH %pOF initialized\n", ofdev
->dev
.of_node
);
121 static const struct of_device_id tah_match
[] =
124 .compatible
= "ibm,tah",
126 /* For backward compat with old DT */
133 static struct platform_driver tah_driver
= {
136 .of_match_table
= tah_match
,
141 int __init
tah_init(void)
143 return platform_driver_register(&tah_driver
);
148 platform_driver_unregister(&tah_driver
);