2 * drivers/net/ethernet/ibm/emac/tah.c
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
9 * Based on the arch/ppc version of the driver:
11 * Copyright 2004 MontaVista Software, Inc.
12 * Matt Porter <mporter@kernel.crashing.org>
14 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
21 #include <linux/of_address.h>
27 int tah_attach(struct platform_device
*ofdev
, int channel
)
29 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
31 mutex_lock(&dev
->lock
);
32 /* Reset has been done at probe() time... nothing else to do for now */
34 mutex_unlock(&dev
->lock
);
39 void tah_detach(struct platform_device
*ofdev
, int channel
)
41 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
43 mutex_lock(&dev
->lock
);
45 mutex_unlock(&dev
->lock
);
48 void tah_reset(struct platform_device
*ofdev
)
50 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
51 struct tah_regs __iomem
*p
= dev
->base
;
55 out_be32(&p
->mr
, TAH_MR_SR
);
57 while ((in_be32(&p
->mr
) & TAH_MR_SR
) && n
)
61 printk(KERN_ERR
"%s: reset timeout\n",
62 ofdev
->dev
.of_node
->full_name
);
64 /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
66 TAH_MR_CVR
| TAH_MR_ST_768
| TAH_MR_TFS_10KB
| TAH_MR_DTFP
|
70 int tah_get_regs_len(struct platform_device
*ofdev
)
72 return sizeof(struct emac_ethtool_regs_subhdr
) +
73 sizeof(struct tah_regs
);
76 void *tah_dump_regs(struct platform_device
*ofdev
, void *buf
)
78 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
79 struct emac_ethtool_regs_subhdr
*hdr
= buf
;
80 struct tah_regs
*regs
= (struct tah_regs
*)(hdr
+ 1);
83 hdr
->index
= 0; /* for now, are there chips with more than one
84 * zmii ? if yes, then we'll add a cell_index
87 memcpy_fromio(regs
, dev
->base
, sizeof(struct tah_regs
));
91 static int tah_probe(struct platform_device
*ofdev
)
93 struct device_node
*np
= ofdev
->dev
.of_node
;
94 struct tah_instance
*dev
;
99 dev
= kzalloc(sizeof(struct tah_instance
), GFP_KERNEL
);
103 mutex_init(&dev
->lock
);
107 if (of_address_to_resource(np
, 0, ®s
)) {
108 printk(KERN_ERR
"%s: Can't get registers address\n",
114 dev
->base
= (struct tah_regs __iomem
*)ioremap(regs
.start
,
115 sizeof(struct tah_regs
));
116 if (dev
->base
== NULL
) {
117 printk(KERN_ERR
"%s: Can't map device registers!\n",
122 platform_set_drvdata(ofdev
, dev
);
124 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
128 "TAH %s initialized\n", ofdev
->dev
.of_node
->full_name
);
139 static int tah_remove(struct platform_device
*ofdev
)
141 struct tah_instance
*dev
= platform_get_drvdata(ofdev
);
143 WARN_ON(dev
->users
!= 0);
151 static struct of_device_id tah_match
[] =
154 .compatible
= "ibm,tah",
156 /* For backward compat with old DT */
163 static struct platform_driver tah_driver
= {
166 .owner
= THIS_MODULE
,
167 .of_match_table
= tah_match
,
170 .remove
= tah_remove
,
173 int __init
tah_init(void)
175 return platform_driver_register(&tah_driver
);
180 platform_driver_unregister(&tah_driver
);