Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Combined Ethernet driver for Motorola MPC8xx and MPC82xx. |
| 3 | * |
Vitaly Bordug | 9b8ee8e | 2007-09-18 20:05:35 +0400 | [diff] [blame] | 4 | * Copyright (c) 2003 Intracom S.A. |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 5 | * by Pantelis Antoniou <panto@intracom.gr> |
Vitaly Bordug | 9b8ee8e | 2007-09-18 20:05:35 +0400 | [diff] [blame] | 6 | * |
| 7 | * 2005 (c) MontaVista Software, Inc. |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 8 | * Vitaly Bordug <vbordug@ru.mvista.com> |
| 9 | * |
Vitaly Bordug | 9b8ee8e | 2007-09-18 20:05:35 +0400 | [diff] [blame] | 10 | * This file is licensed under the terms of the GNU General Public License |
| 11 | * version 2. This program is licensed "as is" without any warranty of any |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 12 | * kind, whether express or implied. |
| 13 | */ |
| 14 | |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/kernel.h> |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 18 | #include <linux/string.h> |
| 19 | #include <linux/ptrace.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/ioport.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/interrupt.h> |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/skbuff.h> |
| 29 | #include <linux/spinlock.h> |
| 30 | #include <linux/mii.h> |
| 31 | #include <linux/ethtool.h> |
| 32 | #include <linux/bitops.h> |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 34 | |
| 35 | #include <asm/pgtable.h> |
| 36 | #include <asm/irq.h> |
| 37 | #include <asm/uaccess.h> |
| 38 | |
| 39 | #include "fs_enet.h" |
| 40 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 41 | static int bitbang_prep_bit(u8 **datp, u8 *mskp, |
| 42 | struct fs_mii_bit *mii_bit) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 43 | { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 44 | void *dat; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 45 | int adv; |
| 46 | u8 msk; |
| 47 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 48 | dat = (void*) mii_bit->offset; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 49 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 50 | adv = mii_bit->bit >> 3; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 51 | dat = (char *)dat + adv; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 52 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 53 | msk = 1 << (7 - (mii_bit->bit & 7)); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 54 | |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 55 | *datp = dat; |
| 56 | *mskp = msk; |
| 57 | |
| 58 | return 0; |
| 59 | } |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 60 | |
| 61 | static inline void bb_set(u8 *p, u8 m) |
| 62 | { |
| 63 | out_8(p, in_8(p) | m); |
| 64 | } |
| 65 | |
| 66 | static inline void bb_clr(u8 *p, u8 m) |
| 67 | { |
| 68 | out_8(p, in_8(p) & ~m); |
| 69 | } |
| 70 | |
| 71 | static inline int bb_read(u8 *p, u8 m) |
| 72 | { |
| 73 | return (in_8(p) & m) != 0; |
| 74 | } |
| 75 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 76 | static inline void mdio_active(struct bb_info *bitbang) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 77 | { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 78 | bb_set(bitbang->mdio_dir, bitbang->mdio_dir_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 81 | static inline void mdio_tristate(struct bb_info *bitbang ) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 82 | { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 83 | bb_clr(bitbang->mdio_dir, bitbang->mdio_dir_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 86 | static inline int mdio_read(struct bb_info *bitbang ) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 87 | { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 88 | return bb_read(bitbang->mdio_dat, bitbang->mdio_dat_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 91 | static inline void mdio(struct bb_info *bitbang , int what) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 92 | { |
| 93 | if (what) |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 94 | bb_set(bitbang->mdio_dat, bitbang->mdio_dat_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 95 | else |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 96 | bb_clr(bitbang->mdio_dat, bitbang->mdio_dat_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 99 | static inline void mdc(struct bb_info *bitbang , int what) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 100 | { |
| 101 | if (what) |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 102 | bb_set(bitbang->mdc_dat, bitbang->mdc_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 103 | else |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 104 | bb_clr(bitbang->mdc_dat, bitbang->mdc_msk); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 107 | static inline void mii_delay(struct bb_info *bitbang ) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 108 | { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 109 | udelay(bitbang->delay); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* Utility to send the preamble, address, and register (common to read and write). */ |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 113 | static void bitbang_pre(struct bb_info *bitbang , int read, u8 addr, u8 reg) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 114 | { |
| 115 | int j; |
| 116 | |
| 117 | /* |
| 118 | * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure. |
| 119 | * The IEEE spec says this is a PHY optional requirement. The AMD |
| 120 | * 79C874 requires one after power up and one after a MII communications |
| 121 | * error. This means that we are doing more preambles than we need, |
| 122 | * but it is safer and will be much more robust. |
| 123 | */ |
| 124 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 125 | mdio_active(bitbang); |
| 126 | mdio(bitbang, 1); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 127 | for (j = 0; j < 32; j++) { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 128 | mdc(bitbang, 0); |
| 129 | mii_delay(bitbang); |
| 130 | mdc(bitbang, 1); |
| 131 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* send the start bit (01) and the read opcode (10) or write (10) */ |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 135 | mdc(bitbang, 0); |
| 136 | mdio(bitbang, 0); |
| 137 | mii_delay(bitbang); |
| 138 | mdc(bitbang, 1); |
| 139 | mii_delay(bitbang); |
| 140 | mdc(bitbang, 0); |
| 141 | mdio(bitbang, 1); |
| 142 | mii_delay(bitbang); |
| 143 | mdc(bitbang, 1); |
| 144 | mii_delay(bitbang); |
| 145 | mdc(bitbang, 0); |
| 146 | mdio(bitbang, read); |
| 147 | mii_delay(bitbang); |
| 148 | mdc(bitbang, 1); |
| 149 | mii_delay(bitbang); |
| 150 | mdc(bitbang, 0); |
| 151 | mdio(bitbang, !read); |
| 152 | mii_delay(bitbang); |
| 153 | mdc(bitbang, 1); |
| 154 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 155 | |
| 156 | /* send the PHY address */ |
| 157 | for (j = 0; j < 5; j++) { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 158 | mdc(bitbang, 0); |
| 159 | mdio(bitbang, (addr & 0x10) != 0); |
| 160 | mii_delay(bitbang); |
| 161 | mdc(bitbang, 1); |
| 162 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 163 | addr <<= 1; |
| 164 | } |
| 165 | |
| 166 | /* send the register address */ |
| 167 | for (j = 0; j < 5; j++) { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 168 | mdc(bitbang, 0); |
| 169 | mdio(bitbang, (reg & 0x10) != 0); |
| 170 | mii_delay(bitbang); |
| 171 | mdc(bitbang, 1); |
| 172 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 173 | reg <<= 1; |
| 174 | } |
| 175 | } |
| 176 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 177 | static int fs_enet_mii_bb_read(struct mii_bus *bus , int phy_id, int location) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 178 | { |
| 179 | u16 rdreg; |
| 180 | int ret, j; |
| 181 | u8 addr = phy_id & 0xff; |
| 182 | u8 reg = location & 0xff; |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 183 | struct bb_info* bitbang = bus->priv; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 184 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 185 | bitbang_pre(bitbang, 1, addr, reg); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 186 | |
| 187 | /* tri-state our MDIO I/O pin so we can read */ |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 188 | mdc(bitbang, 0); |
| 189 | mdio_tristate(bitbang); |
| 190 | mii_delay(bitbang); |
| 191 | mdc(bitbang, 1); |
| 192 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 193 | |
| 194 | /* check the turnaround bit: the PHY should be driving it to zero */ |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 195 | if (mdio_read(bitbang) != 0) { |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 196 | /* PHY didn't drive TA low */ |
| 197 | for (j = 0; j < 32; j++) { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 198 | mdc(bitbang, 0); |
| 199 | mii_delay(bitbang); |
| 200 | mdc(bitbang, 1); |
| 201 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 202 | } |
| 203 | ret = -1; |
| 204 | goto out; |
| 205 | } |
| 206 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 207 | mdc(bitbang, 0); |
| 208 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 209 | |
| 210 | /* read 16 bits of register data, MSB first */ |
| 211 | rdreg = 0; |
| 212 | for (j = 0; j < 16; j++) { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 213 | mdc(bitbang, 1); |
| 214 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 215 | rdreg <<= 1; |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 216 | rdreg |= mdio_read(bitbang); |
| 217 | mdc(bitbang, 0); |
| 218 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 221 | mdc(bitbang, 1); |
| 222 | mii_delay(bitbang); |
| 223 | mdc(bitbang, 0); |
| 224 | mii_delay(bitbang); |
| 225 | mdc(bitbang, 1); |
| 226 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 227 | |
| 228 | ret = rdreg; |
| 229 | out: |
| 230 | return ret; |
| 231 | } |
| 232 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 233 | static int fs_enet_mii_bb_write(struct mii_bus *bus, int phy_id, int location, u16 val) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 234 | { |
| 235 | int j; |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 236 | struct bb_info* bitbang = bus->priv; |
| 237 | |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 238 | u8 addr = phy_id & 0xff; |
| 239 | u8 reg = location & 0xff; |
| 240 | u16 value = val & 0xffff; |
| 241 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 242 | bitbang_pre(bitbang, 0, addr, reg); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 243 | |
| 244 | /* send the turnaround (10) */ |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 245 | mdc(bitbang, 0); |
| 246 | mdio(bitbang, 1); |
| 247 | mii_delay(bitbang); |
| 248 | mdc(bitbang, 1); |
| 249 | mii_delay(bitbang); |
| 250 | mdc(bitbang, 0); |
| 251 | mdio(bitbang, 0); |
| 252 | mii_delay(bitbang); |
| 253 | mdc(bitbang, 1); |
| 254 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 255 | |
| 256 | /* write 16 bits of register data, MSB first */ |
| 257 | for (j = 0; j < 16; j++) { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 258 | mdc(bitbang, 0); |
| 259 | mdio(bitbang, (value & 0x8000) != 0); |
| 260 | mii_delay(bitbang); |
| 261 | mdc(bitbang, 1); |
| 262 | mii_delay(bitbang); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 263 | value <<= 1; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Tri-state the MDIO line. |
| 268 | */ |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 269 | mdio_tristate(bitbang); |
| 270 | mdc(bitbang, 0); |
| 271 | mii_delay(bitbang); |
| 272 | mdc(bitbang, 1); |
| 273 | mii_delay(bitbang); |
| 274 | return 0; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 275 | } |
| 276 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 277 | static int fs_enet_mii_bb_reset(struct mii_bus *bus) |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 278 | { |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 279 | /*nothing here - dunno how to reset it*/ |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int fs_mii_bitbang_init(struct bb_info *bitbang, struct fs_mii_bb_platform_info* fmpi) |
| 284 | { |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 285 | int r; |
| 286 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 287 | bitbang->delay = fmpi->delay; |
| 288 | |
| 289 | r = bitbang_prep_bit(&bitbang->mdio_dir, |
| 290 | &bitbang->mdio_dir_msk, |
| 291 | &fmpi->mdio_dir); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 292 | if (r != 0) |
| 293 | return r; |
| 294 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 295 | r = bitbang_prep_bit(&bitbang->mdio_dat, |
| 296 | &bitbang->mdio_dat_msk, |
| 297 | &fmpi->mdio_dat); |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 298 | if (r != 0) |
| 299 | return r; |
| 300 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 301 | r = bitbang_prep_bit(&bitbang->mdc_dat, |
| 302 | &bitbang->mdc_msk, |
| 303 | &fmpi->mdc_dat); |
| 304 | if (r != 0) |
| 305 | return r; |
Pantelis Antoniou | 48257c4 | 2005-10-28 16:25:58 -0400 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 309 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 310 | static int __devinit fs_enet_mdio_probe(struct device *dev) |
| 311 | { |
| 312 | struct platform_device *pdev = to_platform_device(dev); |
| 313 | struct fs_mii_bb_platform_info *pdata; |
| 314 | struct mii_bus *new_bus; |
| 315 | struct bb_info *bitbang; |
| 316 | int err = 0; |
| 317 | |
| 318 | if (NULL == dev) |
| 319 | return -EINVAL; |
| 320 | |
| 321 | new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); |
| 322 | |
| 323 | if (NULL == new_bus) |
| 324 | return -ENOMEM; |
| 325 | |
| 326 | bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL); |
| 327 | |
| 328 | if (NULL == bitbang) |
| 329 | return -ENOMEM; |
| 330 | |
| 331 | new_bus->name = "BB MII Bus", |
| 332 | new_bus->read = &fs_enet_mii_bb_read, |
| 333 | new_bus->write = &fs_enet_mii_bb_write, |
| 334 | new_bus->reset = &fs_enet_mii_bb_reset, |
| 335 | new_bus->id = pdev->id; |
| 336 | |
| 337 | new_bus->phy_mask = ~0x9; |
| 338 | pdata = (struct fs_mii_bb_platform_info *)pdev->dev.platform_data; |
| 339 | |
| 340 | if (NULL == pdata) { |
| 341 | printk(KERN_ERR "gfar mdio %d: Missing platform data!\n", pdev->id); |
| 342 | return -ENODEV; |
| 343 | } |
| 344 | |
| 345 | /*set up workspace*/ |
| 346 | fs_mii_bitbang_init(bitbang, pdata); |
| 347 | |
| 348 | new_bus->priv = bitbang; |
| 349 | |
| 350 | new_bus->irq = pdata->irq; |
| 351 | |
| 352 | new_bus->dev = dev; |
| 353 | dev_set_drvdata(dev, new_bus); |
| 354 | |
| 355 | err = mdiobus_register(new_bus); |
| 356 | |
| 357 | if (0 != err) { |
| 358 | printk (KERN_ERR "%s: Cannot register as MDIO bus\n", |
| 359 | new_bus->name); |
| 360 | goto bus_register_fail; |
| 361 | } |
| 362 | |
| 363 | return 0; |
| 364 | |
| 365 | bus_register_fail: |
| 366 | kfree(bitbang); |
| 367 | kfree(new_bus); |
| 368 | |
| 369 | return err; |
| 370 | } |
| 371 | |
Vitaly Bordug | 5b4b845 | 2006-08-14 23:00:30 -0700 | [diff] [blame] | 372 | static int fs_enet_mdio_remove(struct device *dev) |
| 373 | { |
| 374 | struct mii_bus *bus = dev_get_drvdata(dev); |
| 375 | |
| 376 | mdiobus_unregister(bus); |
| 377 | |
| 378 | dev_set_drvdata(dev, NULL); |
| 379 | |
| 380 | iounmap((void *) (&bus->priv)); |
| 381 | bus->priv = NULL; |
| 382 | kfree(bus); |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static struct device_driver fs_enet_bb_mdio_driver = { |
| 388 | .name = "fsl-bb-mdio", |
| 389 | .bus = &platform_bus_type, |
| 390 | .probe = fs_enet_mdio_probe, |
| 391 | .remove = fs_enet_mdio_remove, |
| 392 | }; |
| 393 | |
| 394 | int fs_enet_mdio_bb_init(void) |
| 395 | { |
| 396 | return driver_register(&fs_enet_bb_mdio_driver); |
| 397 | } |
| 398 | |
| 399 | void fs_enet_mdio_bb_exit(void) |
| 400 | { |
| 401 | driver_unregister(&fs_enet_bb_mdio_driver); |
| 402 | } |
| 403 | |