2 * drivers/net/ibm_newemac/tah.c
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
6 * Copyright 2004 MontaVista Software, Inc.
7 * Matt Porter <mporter@kernel.crashing.org>
9 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
21 int __devinit
tah_attach(struct of_device
*ofdev
, int channel
)
23 struct tah_instance
*dev
= dev_get_drvdata(&ofdev
->dev
);
25 mutex_lock(&dev
->lock
);
26 /* Reset has been done at probe() time... nothing else to do for now */
28 mutex_unlock(&dev
->lock
);
33 void __devexit
tah_detach(struct of_device
*ofdev
, int channel
)
35 struct tah_instance
*dev
= dev_get_drvdata(&ofdev
->dev
);
37 mutex_lock(&dev
->lock
);
39 mutex_unlock(&dev
->lock
);
42 void tah_reset(struct of_device
*ofdev
)
44 struct tah_instance
*dev
= dev_get_drvdata(&ofdev
->dev
);
45 struct tah_regs __iomem
*p
= dev
->base
;
49 out_be32(&p
->mr
, TAH_MR_SR
);
51 while ((in_be32(&p
->mr
) & TAH_MR_SR
) && n
)
55 printk(KERN_ERR
"%s: reset timeout\n", ofdev
->node
->full_name
);
57 /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */
59 TAH_MR_CVR
| TAH_MR_ST_768
| TAH_MR_TFS_10KB
| TAH_MR_DTFP
|
63 int tah_get_regs_len(struct of_device
*ofdev
)
65 return sizeof(struct emac_ethtool_regs_subhdr
) +
66 sizeof(struct tah_regs
);
69 void *tah_dump_regs(struct of_device
*ofdev
, void *buf
)
71 struct tah_instance
*dev
= dev_get_drvdata(&ofdev
->dev
);
72 struct emac_ethtool_regs_subhdr
*hdr
= buf
;
73 struct tah_regs
*regs
= (struct tah_regs
*)(hdr
+ 1);
76 hdr
->index
= 0; /* for now, are there chips with more than one
77 * zmii ? if yes, then we'll add a cell_index
80 memcpy_fromio(regs
, dev
->base
, sizeof(struct tah_regs
));
84 static int __devinit
tah_probe(struct of_device
*ofdev
,
85 const struct of_device_id
*match
)
87 struct device_node
*np
= ofdev
->node
;
88 struct tah_instance
*dev
;
93 dev
= kzalloc(sizeof(struct tah_instance
), GFP_KERNEL
);
95 printk(KERN_ERR
"%s: could not allocate TAH device!\n",
100 mutex_init(&dev
->lock
);
104 if (of_address_to_resource(np
, 0, ®s
)) {
105 printk(KERN_ERR
"%s: Can't get registers address\n",
111 dev
->base
= (struct tah_regs __iomem
*)ioremap(regs
.start
,
112 sizeof(struct tah_regs
));
113 if (dev
->base
== NULL
) {
114 printk(KERN_ERR
"%s: Can't map device registers!\n",
119 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
123 "TAH %s initialized\n", ofdev
->node
->full_name
);
125 dev_set_drvdata(&ofdev
->dev
, dev
);
135 static int __devexit
tah_remove(struct of_device
*ofdev
)
137 struct tah_instance
*dev
= dev_get_drvdata(&ofdev
->dev
);
139 dev_set_drvdata(&ofdev
->dev
, NULL
);
141 WARN_ON(dev
->users
!= 0);
149 static struct of_device_id tah_match
[] =
157 static struct of_platform_driver tah_driver
= {
159 .match_table
= tah_match
,
162 .remove
= tah_remove
,
165 int __init
tah_init(void)
167 return of_register_platform_driver(&tah_driver
);
172 of_unregister_platform_driver(&tah_driver
);