Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 2 | /* |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 3 | * (C) Copyright 2009 Industrie Dial Face S.p.A. |
| 4 | * Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com> |
| 5 | * |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 6 | * (C) Copyright 2001 |
| 7 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This provides a bit-banged interface to the ethernet MII management |
| 12 | * channel. |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
| 16 | #include <ioports.h> |
| 17 | #include <ppc_asm.tmpl> |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 18 | #include <miiphy.h> |
| 19 | |
| 20 | #define BB_MII_RELOCATE(v,off) (v += (v?off:0)) |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | #ifndef CONFIG_BITBANGMII_MULTI |
| 25 | |
| 26 | /* |
| 27 | * If CONFIG_BITBANGMII_MULTI is not defined we use a |
| 28 | * compatibility layer with the previous miiphybb implementation |
| 29 | * based on macros usage. |
| 30 | * |
| 31 | */ |
| 32 | static int bb_mii_init_wrap(struct bb_miiphy_bus *bus) |
| 33 | { |
| 34 | #ifdef MII_INIT |
| 35 | MII_INIT; |
| 36 | #endif |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int bb_mdio_active_wrap(struct bb_miiphy_bus *bus) |
| 41 | { |
| 42 | #ifdef MDIO_DECLARE |
| 43 | MDIO_DECLARE; |
| 44 | #endif |
| 45 | MDIO_ACTIVE; |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int bb_mdio_tristate_wrap(struct bb_miiphy_bus *bus) |
| 50 | { |
| 51 | #ifdef MDIO_DECLARE |
| 52 | MDIO_DECLARE; |
| 53 | #endif |
| 54 | MDIO_TRISTATE; |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static int bb_set_mdio_wrap(struct bb_miiphy_bus *bus, int v) |
| 59 | { |
| 60 | #ifdef MDIO_DECLARE |
| 61 | MDIO_DECLARE; |
| 62 | #endif |
| 63 | MDIO(v); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int bb_get_mdio_wrap(struct bb_miiphy_bus *bus, int *v) |
| 68 | { |
| 69 | #ifdef MDIO_DECLARE |
| 70 | MDIO_DECLARE; |
| 71 | #endif |
| 72 | *v = MDIO_READ; |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static int bb_set_mdc_wrap(struct bb_miiphy_bus *bus, int v) |
| 77 | { |
| 78 | #ifdef MDC_DECLARE |
| 79 | MDC_DECLARE; |
| 80 | #endif |
| 81 | MDC(v); |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static int bb_delay_wrap(struct bb_miiphy_bus *bus) |
| 86 | { |
| 87 | MIIDELAY; |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | struct bb_miiphy_bus bb_miiphy_buses[] = { |
| 92 | { |
| 93 | .name = BB_MII_DEVNAME, |
| 94 | .init = bb_mii_init_wrap, |
| 95 | .mdio_active = bb_mdio_active_wrap, |
| 96 | .mdio_tristate = bb_mdio_tristate_wrap, |
| 97 | .set_mdio = bb_set_mdio_wrap, |
| 98 | .get_mdio = bb_get_mdio_wrap, |
| 99 | .set_mdc = bb_set_mdc_wrap, |
| 100 | .delay = bb_delay_wrap, |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / |
Wolfgang Denk | d61fbcc | 2009-10-28 00:49:47 +0100 | [diff] [blame] | 105 | sizeof(bb_miiphy_buses[0]); |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 106 | #endif |
| 107 | |
Ovidiu Panait | 69d1ddb | 2020-11-28 10:43:17 +0200 | [diff] [blame] | 108 | int bb_miiphy_init(void) |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 109 | { |
| 110 | int i; |
| 111 | |
| 112 | for (i = 0; i < bb_miiphy_buses_num; i++) { |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 113 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 114 | /* Relocate the hook pointers*/ |
| 115 | BB_MII_RELOCATE(bb_miiphy_buses[i].init, gd->reloc_off); |
| 116 | BB_MII_RELOCATE(bb_miiphy_buses[i].mdio_active, gd->reloc_off); |
| 117 | BB_MII_RELOCATE(bb_miiphy_buses[i].mdio_tristate, gd->reloc_off); |
| 118 | BB_MII_RELOCATE(bb_miiphy_buses[i].set_mdio, gd->reloc_off); |
| 119 | BB_MII_RELOCATE(bb_miiphy_buses[i].get_mdio, gd->reloc_off); |
| 120 | BB_MII_RELOCATE(bb_miiphy_buses[i].set_mdc, gd->reloc_off); |
| 121 | BB_MII_RELOCATE(bb_miiphy_buses[i].delay, gd->reloc_off); |
| 122 | #endif |
| 123 | if (bb_miiphy_buses[i].init != NULL) { |
| 124 | bb_miiphy_buses[i].init(&bb_miiphy_buses[i]); |
| 125 | } |
| 126 | } |
Ovidiu Panait | 69d1ddb | 2020-11-28 10:43:17 +0200 | [diff] [blame] | 127 | |
| 128 | return 0; |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Ben Warren | 97824d6 | 2010-07-29 12:56:11 -0700 | [diff] [blame] | 131 | static inline struct bb_miiphy_bus *bb_miiphy_getbus(const char *devname) |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 132 | { |
| 133 | #ifdef CONFIG_BITBANGMII_MULTI |
| 134 | int i; |
| 135 | |
| 136 | /* Search the correct bus */ |
| 137 | for (i = 0; i < bb_miiphy_buses_num; i++) { |
| 138 | if (!strcmp(bb_miiphy_buses[i].name, devname)) { |
| 139 | return &bb_miiphy_buses[i]; |
| 140 | } |
| 141 | } |
| 142 | return NULL; |
| 143 | #else |
| 144 | /* We have just one bitbanging bus */ |
| 145 | return &bb_miiphy_buses[0]; |
| 146 | #endif |
| 147 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 148 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 149 | /***************************************************************************** |
| 150 | * |
| 151 | * Utility to send the preamble, address, and register (common to read |
| 152 | * and write). |
| 153 | */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 154 | static void miiphy_pre(struct bb_miiphy_bus *bus, char read, |
Wolfgang Denk | d61fbcc | 2009-10-28 00:49:47 +0100 | [diff] [blame] | 155 | unsigned char addr, unsigned char reg) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 156 | { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 157 | int j; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 158 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 159 | /* |
| 160 | * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure. |
| 161 | * The IEEE spec says this is a PHY optional requirement. The AMD |
| 162 | * 79C874 requires one after power up and one after a MII communications |
| 163 | * error. This means that we are doing more preambles than we need, |
| 164 | * but it is safer and will be much more robust. |
| 165 | */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 166 | |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 167 | bus->mdio_active(bus); |
| 168 | bus->set_mdio(bus, 1); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 169 | for (j = 0; j < 32; j++) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 170 | bus->set_mdc(bus, 0); |
| 171 | bus->delay(bus); |
| 172 | bus->set_mdc(bus, 1); |
| 173 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 174 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 175 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 176 | /* send the start bit (01) and the read opcode (10) or write (10) */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 177 | bus->set_mdc(bus, 0); |
| 178 | bus->set_mdio(bus, 0); |
| 179 | bus->delay(bus); |
| 180 | bus->set_mdc(bus, 1); |
| 181 | bus->delay(bus); |
| 182 | bus->set_mdc(bus, 0); |
| 183 | bus->set_mdio(bus, 1); |
| 184 | bus->delay(bus); |
| 185 | bus->set_mdc(bus, 1); |
| 186 | bus->delay(bus); |
| 187 | bus->set_mdc(bus, 0); |
| 188 | bus->set_mdio(bus, read); |
| 189 | bus->delay(bus); |
| 190 | bus->set_mdc(bus, 1); |
| 191 | bus->delay(bus); |
| 192 | bus->set_mdc(bus, 0); |
| 193 | bus->set_mdio(bus, !read); |
| 194 | bus->delay(bus); |
| 195 | bus->set_mdc(bus, 1); |
| 196 | bus->delay(bus); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 197 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 198 | /* send the PHY address */ |
| 199 | for (j = 0; j < 5; j++) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 200 | bus->set_mdc(bus, 0); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 201 | if ((addr & 0x10) == 0) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 202 | bus->set_mdio(bus, 0); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 203 | } else { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 204 | bus->set_mdio(bus, 1); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 205 | } |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 206 | bus->delay(bus); |
| 207 | bus->set_mdc(bus, 1); |
| 208 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 209 | addr <<= 1; |
| 210 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 211 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 212 | /* send the register address */ |
| 213 | for (j = 0; j < 5; j++) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 214 | bus->set_mdc(bus, 0); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 215 | if ((reg & 0x10) == 0) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 216 | bus->set_mdio(bus, 0); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 217 | } else { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 218 | bus->set_mdio(bus, 1); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 219 | } |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 220 | bus->delay(bus); |
| 221 | bus->set_mdc(bus, 1); |
| 222 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 223 | reg <<= 1; |
| 224 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 225 | } |
| 226 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 227 | /***************************************************************************** |
| 228 | * |
| 229 | * Read a MII PHY register. |
| 230 | * |
| 231 | * Returns: |
| 232 | * 0 on success |
| 233 | */ |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 234 | int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 235 | { |
Chris Brandt | 7e4d4d1 | 2017-11-03 08:30:13 -0500 | [diff] [blame] | 236 | unsigned short rdreg; /* register working value */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 237 | int v; |
| 238 | int j; /* counter */ |
| 239 | struct bb_miiphy_bus *bus; |
| 240 | |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 241 | bus = bb_miiphy_getbus(miidev->name); |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 242 | if (bus == NULL) { |
| 243 | return -1; |
| 244 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 245 | |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 246 | miiphy_pre (bus, 1, addr, reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 247 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 248 | /* tri-state our MDIO I/O pin so we can read */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 249 | bus->set_mdc(bus, 0); |
| 250 | bus->mdio_tristate(bus); |
| 251 | bus->delay(bus); |
| 252 | bus->set_mdc(bus, 1); |
| 253 | bus->delay(bus); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 254 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 255 | /* check the turnaround bit: the PHY should be driving it to zero */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 256 | bus->get_mdio(bus, &v); |
| 257 | if (v != 0) { |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 258 | /* puts ("PHY didn't drive TA low\n"); */ |
| 259 | for (j = 0; j < 32; j++) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 260 | bus->set_mdc(bus, 0); |
| 261 | bus->delay(bus); |
| 262 | bus->set_mdc(bus, 1); |
| 263 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 264 | } |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 265 | /* There is no PHY, return */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 266 | return -1; |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 267 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 268 | |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 269 | bus->set_mdc(bus, 0); |
| 270 | bus->delay(bus); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 271 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 272 | /* read 16 bits of register data, MSB first */ |
| 273 | rdreg = 0; |
| 274 | for (j = 0; j < 16; j++) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 275 | bus->set_mdc(bus, 1); |
| 276 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 277 | rdreg <<= 1; |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 278 | bus->get_mdio(bus, &v); |
| 279 | rdreg |= (v & 0x1); |
| 280 | bus->set_mdc(bus, 0); |
| 281 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 282 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 283 | |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 284 | bus->set_mdc(bus, 1); |
| 285 | bus->delay(bus); |
| 286 | bus->set_mdc(bus, 0); |
| 287 | bus->delay(bus); |
| 288 | bus->set_mdc(bus, 1); |
| 289 | bus->delay(bus); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 290 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 291 | #ifdef DEBUG |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 292 | printf("miiphy_read(0x%x) @ 0x%x = 0x%04x\n", reg, addr, rdreg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 293 | #endif |
| 294 | |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 295 | return rdreg; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
| 299 | /***************************************************************************** |
| 300 | * |
| 301 | * Write a MII PHY register. |
| 302 | * |
| 303 | * Returns: |
| 304 | * 0 on success |
| 305 | */ |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 306 | int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, |
| 307 | u16 value) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 308 | { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 309 | struct bb_miiphy_bus *bus; |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 310 | int j; /* counter */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 311 | |
Joe Hershberger | 0c33319 | 2016-08-08 11:28:39 -0500 | [diff] [blame] | 312 | bus = bb_miiphy_getbus(miidev->name); |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 313 | if (bus == NULL) { |
| 314 | /* Bus not found! */ |
| 315 | return -1; |
| 316 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 317 | |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 318 | miiphy_pre (bus, 0, addr, reg); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 319 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 320 | /* send the turnaround (10) */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 321 | bus->set_mdc(bus, 0); |
| 322 | bus->set_mdio(bus, 1); |
| 323 | bus->delay(bus); |
| 324 | bus->set_mdc(bus, 1); |
| 325 | bus->delay(bus); |
| 326 | bus->set_mdc(bus, 0); |
| 327 | bus->set_mdio(bus, 0); |
| 328 | bus->delay(bus); |
| 329 | bus->set_mdc(bus, 1); |
| 330 | bus->delay(bus); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 331 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 332 | /* write 16 bits of register data, MSB first */ |
| 333 | for (j = 0; j < 16; j++) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 334 | bus->set_mdc(bus, 0); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 335 | if ((value & 0x00008000) == 0) { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 336 | bus->set_mdio(bus, 0); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 337 | } else { |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 338 | bus->set_mdio(bus, 1); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 339 | } |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 340 | bus->delay(bus); |
| 341 | bus->set_mdc(bus, 1); |
| 342 | bus->delay(bus); |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 343 | value <<= 1; |
| 344 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 345 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 346 | /* |
| 347 | * Tri-state the MDIO line. |
| 348 | */ |
Luigi 'Comio' Mantellini | 466827e | 2009-10-10 12:42:20 +0200 | [diff] [blame] | 349 | bus->mdio_tristate(bus); |
| 350 | bus->set_mdc(bus, 0); |
| 351 | bus->delay(bus); |
| 352 | bus->set_mdc(bus, 1); |
| 353 | bus->delay(bus); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 354 | |
Wolfgang Denk | 7b4e347 | 2005-08-13 02:04:37 +0200 | [diff] [blame] | 355 | return 0; |
Wolfgang Denk | 9235e0c | 2009-10-25 23:00:09 +0100 | [diff] [blame] | 356 | } |