2 * drivers/net/ibm_newemac/tah.c
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
9 * Based on the arch/ppc version of the driver:
11 * Copyright 2004 MontaVista Software, Inc.
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.
26 int __devinit tah_attach(struct platform_device *ofdev, int channel)
28 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
30 mutex_lock(&dev->lock);
31 /* Reset has been done at probe() time... nothing else to do for now */
33 mutex_unlock(&dev->lock);
38 void tah_detach(struct platform_device *ofdev, int channel)
40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
42 mutex_lock(&dev->lock);
44 mutex_unlock(&dev->lock);
47 void tah_reset(struct platform_device *ofdev)
49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
50 struct tah_regs __iomem *p = dev->base;
54 out_be32(&p->mr, TAH_MR_SR);
56 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
60 printk(KERN_ERR "%s: reset timeout\n",
61 ofdev->dev.of_node->full_name);
63 /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */
65 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
69 int tah_get_regs_len(struct platform_device *ofdev)
71 return sizeof(struct emac_ethtool_regs_subhdr) +
72 sizeof(struct tah_regs);
75 void *tah_dump_regs(struct platform_device *ofdev, void *buf)
77 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
78 struct emac_ethtool_regs_subhdr *hdr = buf;
79 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
82 hdr->index = 0; /* for now, are there chips with more than one
83 * zmii ? if yes, then we'll add a cell_index
86 memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
90 static int __devinit tah_probe(struct platform_device *ofdev,
91 const struct of_device_id *match)
93 struct device_node *np = ofdev->dev.of_node;
94 struct tah_instance *dev;
99 dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
101 printk(KERN_ERR "%s: could not allocate TAH device!\n",
106 mutex_init(&dev->lock);
110 if (of_address_to_resource(np, 0, ®s)) {
111 printk(KERN_ERR "%s: Can't get registers address\n",
117 dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
118 sizeof(struct tah_regs));
119 if (dev->base == NULL) {
120 printk(KERN_ERR "%s: Can't map device registers!\n",
125 dev_set_drvdata(&ofdev->dev, dev);
127 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
131 "TAH %s initialized\n", ofdev->dev.of_node->full_name);
142 static int __devexit tah_remove(struct platform_device *ofdev)
144 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
146 dev_set_drvdata(&ofdev->dev, NULL);
148 WARN_ON(dev->users != 0);
156 static struct of_device_id tah_match[] =
159 .compatible = "ibm,tah",
161 /* For backward compat with old DT */
168 static struct of_platform_driver tah_driver = {
171 .owner = THIS_MODULE,
172 .of_match_table = tah_match,
175 .remove = tah_remove,
178 int __init tah_init(void)
180 return of_register_platform_driver(&tah_driver);
185 of_unregister_platform_driver(&tah_driver);