David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/ibm_newemac/tah.c |
| 3 | * |
| 4 | * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. |
| 5 | * |
Benjamin Herrenschmidt | 17cf803 | 2007-12-05 11:14:33 +1100 | [diff] [blame] | 6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. |
| 7 | * <benh@kernel.crashing.org> |
| 8 | * |
| 9 | * Based on the arch/ppc version of the driver: |
| 10 | * |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 11 | * Copyright 2004 MontaVista Software, Inc. |
| 12 | * Matt Porter <mporter@kernel.crashing.org> |
| 13 | * |
| 14 | * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net> |
| 15 | * |
| 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. |
| 20 | */ |
| 21 | #include <asm/io.h> |
| 22 | |
| 23 | #include "emac.h" |
| 24 | #include "core.h" |
| 25 | |
| 26 | int __devinit tah_attach(struct of_device *ofdev, int channel) |
| 27 | { |
| 28 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); |
| 29 | |
| 30 | mutex_lock(&dev->lock); |
| 31 | /* Reset has been done at probe() time... nothing else to do for now */ |
| 32 | ++dev->users; |
| 33 | mutex_unlock(&dev->lock); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
Josh Boyer | 51d4a1c | 2008-04-22 10:46:43 +1000 | [diff] [blame] | 38 | void tah_detach(struct of_device *ofdev, int channel) |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 39 | { |
| 40 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); |
| 41 | |
| 42 | mutex_lock(&dev->lock); |
| 43 | --dev->users; |
| 44 | mutex_unlock(&dev->lock); |
| 45 | } |
| 46 | |
| 47 | void tah_reset(struct of_device *ofdev) |
| 48 | { |
| 49 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); |
Al Viro | eb4d84f | 2007-10-14 19:36:10 +0100 | [diff] [blame] | 50 | struct tah_regs __iomem *p = dev->base; |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 51 | int n; |
| 52 | |
| 53 | /* Reset TAH */ |
| 54 | out_be32(&p->mr, TAH_MR_SR); |
| 55 | n = 100; |
| 56 | while ((in_be32(&p->mr) & TAH_MR_SR) && n) |
| 57 | --n; |
| 58 | |
| 59 | if (unlikely(!n)) |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 60 | printk(KERN_ERR "%s: reset timeout\n", |
| 61 | ofdev->dev.of_node->full_name); |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 62 | |
| 63 | /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */ |
| 64 | out_be32(&p->mr, |
| 65 | TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP | |
| 66 | TAH_MR_DIG); |
| 67 | } |
| 68 | |
| 69 | int tah_get_regs_len(struct of_device *ofdev) |
| 70 | { |
| 71 | return sizeof(struct emac_ethtool_regs_subhdr) + |
| 72 | sizeof(struct tah_regs); |
| 73 | } |
| 74 | |
| 75 | void *tah_dump_regs(struct of_device *ofdev, void *buf) |
| 76 | { |
| 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); |
| 80 | |
| 81 | hdr->version = 0; |
| 82 | hdr->index = 0; /* for now, are there chips with more than one |
| 83 | * zmii ? if yes, then we'll add a cell_index |
| 84 | * like we do for emac |
| 85 | */ |
| 86 | memcpy_fromio(regs, dev->base, sizeof(struct tah_regs)); |
| 87 | return regs + 1; |
| 88 | } |
| 89 | |
| 90 | static int __devinit tah_probe(struct of_device *ofdev, |
| 91 | const struct of_device_id *match) |
| 92 | { |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 93 | struct device_node *np = ofdev->dev.of_node; |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 94 | struct tah_instance *dev; |
| 95 | struct resource regs; |
| 96 | int rc; |
| 97 | |
| 98 | rc = -ENOMEM; |
| 99 | dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL); |
| 100 | if (dev == NULL) { |
| 101 | printk(KERN_ERR "%s: could not allocate TAH device!\n", |
| 102 | np->full_name); |
| 103 | goto err_gone; |
| 104 | } |
| 105 | |
| 106 | mutex_init(&dev->lock); |
| 107 | dev->ofdev = ofdev; |
| 108 | |
| 109 | rc = -ENXIO; |
| 110 | if (of_address_to_resource(np, 0, ®s)) { |
| 111 | printk(KERN_ERR "%s: Can't get registers address\n", |
| 112 | np->full_name); |
| 113 | goto err_free; |
| 114 | } |
| 115 | |
| 116 | rc = -ENOMEM; |
Al Viro | eb4d84f | 2007-10-14 19:36:10 +0100 | [diff] [blame] | 117 | dev->base = (struct tah_regs __iomem *)ioremap(regs.start, |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 118 | sizeof(struct tah_regs)); |
| 119 | if (dev->base == NULL) { |
| 120 | printk(KERN_ERR "%s: Can't map device registers!\n", |
| 121 | np->full_name); |
| 122 | goto err_free; |
| 123 | } |
| 124 | |
Valentine Barshak | d09e18b | 2007-12-05 11:14:32 +1100 | [diff] [blame] | 125 | dev_set_drvdata(&ofdev->dev, dev); |
| 126 | |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 127 | /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */ |
| 128 | tah_reset(ofdev); |
| 129 | |
| 130 | printk(KERN_INFO |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 131 | "TAH %s initialized\n", ofdev->dev.of_node->full_name); |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 132 | wmb(); |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | |
| 136 | err_free: |
| 137 | kfree(dev); |
| 138 | err_gone: |
| 139 | return rc; |
| 140 | } |
| 141 | |
| 142 | static int __devexit tah_remove(struct of_device *ofdev) |
| 143 | { |
| 144 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); |
| 145 | |
| 146 | dev_set_drvdata(&ofdev->dev, NULL); |
| 147 | |
| 148 | WARN_ON(dev->users != 0); |
| 149 | |
| 150 | iounmap(dev->base); |
| 151 | kfree(dev); |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static struct of_device_id tah_match[] = |
| 157 | { |
| 158 | { |
Stefan Roese | cdb3469 | 2008-03-13 16:59:43 +0100 | [diff] [blame] | 159 | .compatible = "ibm,tah", |
| 160 | }, |
| 161 | /* For backward compat with old DT */ |
| 162 | { |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 163 | .type = "tah", |
| 164 | }, |
| 165 | {}, |
| 166 | }; |
| 167 | |
| 168 | static struct of_platform_driver tah_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame^] | 169 | .driver = { |
| 170 | .name = "emac-tah", |
| 171 | .owner = THIS_MODULE, |
| 172 | .of_match_table = tah_match, |
| 173 | }, |
David Gibson | 1d3bb99 | 2007-08-23 13:56:01 +1000 | [diff] [blame] | 174 | .probe = tah_probe, |
| 175 | .remove = tah_remove, |
| 176 | }; |
| 177 | |
| 178 | int __init tah_init(void) |
| 179 | { |
| 180 | return of_register_platform_driver(&tah_driver); |
| 181 | } |
| 182 | |
| 183 | void tah_exit(void) |
| 184 | { |
| 185 | of_unregister_platform_driver(&tah_driver); |
| 186 | } |