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/of_address.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 */
30 mutex_unlock(&dev
->lock
);
35 void tah_detach(struct platform_device
*ofdev
, int channel
)
37 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
39 mutex_lock(&dev
->lock
);
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
;
51 out_be32(&p
->mr
, TAH_MR_SR
);
53 while ((in_be32(&p
->mr
) & TAH_MR_SR
) && n
)
57 printk(KERN_ERR
"%pOF: reset timeout\n", ofdev
->dev
.of_node
);
59 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
61 TAH_MR_CVR
| TAH_MR_ST_768
| TAH_MR_TFS_10KB
| TAH_MR_DTFP
|
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);
78 hdr
->index
= 0; /* for now, are there chips with more than one
79 * zmii ? if yes, then we'll add a cell_index
82 memcpy_fromio(regs
, dev
->base
, sizeof(struct tah_regs
));
86 static int tah_probe(struct platform_device
*ofdev
)
88 struct device_node
*np
= ofdev
->dev
.of_node
;
89 struct tah_instance
*dev
;
94 dev
= kzalloc(sizeof(struct tah_instance
), GFP_KERNEL
);
98 mutex_init(&dev
->lock
);
102 if (of_address_to_resource(np
, 0, ®s
)) {
103 printk(KERN_ERR
"%pOF: Can't get registers address\n", np
);
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
);
115 platform_set_drvdata(ofdev
, dev
);
117 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
120 printk(KERN_INFO
"TAH %pOF initialized\n", ofdev
->dev
.of_node
);
131 static int tah_remove(struct platform_device
*ofdev
)
133 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
135 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
= tah_remove
,
164 int __init
tah_init(void)
166 return platform_driver_register(&tah_driver
);
171 platform_driver_unregister(&tah_driver
);