20 #include <linux/module.h>
22 #include <linux/types.h>
28 #define MDIO_C45 (1<<15)
29 #define MDIO_C45_ADDR (MDIO_C45 | 0)
30 #define MDIO_C45_READ (MDIO_C45 | 3)
31 #define MDIO_C45_WRITE (MDIO_C45 | 1)
33 #define MDIO_SETUP_TIME 10
34 #define MDIO_HOLD_TIME 10
39 #define MDIO_DELAY 250
44 #define MDIO_READ_DELAY 350
76 for (i = bits - 1; i >= 0; i--)
77 mdiobb_send_bit(ctrl, (val >> i) & 1);
86 for (i = bits - 1; i >= 0; i--) {
88 ret |= mdiobb_get_bit(ctrl);
113 for (i = 0; i < 32; i++)
114 mdiobb_send_bit(ctrl, 1);
119 mdiobb_send_bit(ctrl, 0);
121 mdiobb_send_bit(ctrl, 0);
123 mdiobb_send_bit(ctrl, 1);
124 mdiobb_send_bit(ctrl, (op >> 1) & 1);
125 mdiobb_send_bit(ctrl, (op >> 0) & 1);
127 mdiobb_send_num(ctrl, phy, 5);
128 mdiobb_send_num(ctrl, reg, 5);
139 unsigned int dev_addr = (addr >> 16) & 0x1F;
140 unsigned int reg = addr & 0xFFFF;
144 mdiobb_send_bit(ctrl, 1);
145 mdiobb_send_bit(ctrl, 0);
147 mdiobb_send_num(ctrl, reg, 16);
149 ctrl->
ops->set_mdio_dir(ctrl, 0);
150 mdiobb_get_bit(ctrl);
155 static int mdiobb_read(
struct mii_bus *
bus,
int phy,
int reg)
161 reg = mdiobb_cmd_addr(ctrl, phy, reg);
166 ctrl->
ops->set_mdio_dir(ctrl, 0);
169 if (mdiobb_get_bit(ctrl) != 0) {
173 for (i = 0; i < 32; i++)
174 mdiobb_get_bit(ctrl);
179 ret = mdiobb_get_num(ctrl, 16);
180 mdiobb_get_bit(ctrl);
184 static int mdiobb_write(
struct mii_bus *bus,
int phy,
int reg,
u16 val)
188 if (reg & MII_ADDR_C45) {
189 reg = mdiobb_cmd_addr(ctrl, phy, reg);
195 mdiobb_send_bit(ctrl, 1);
196 mdiobb_send_bit(ctrl, 0);
198 mdiobb_send_num(ctrl, val, 16);
200 ctrl->
ops->set_mdio_dir(ctrl, 0);
201 mdiobb_get_bit(ctrl);
205 static int mdiobb_reset(
struct mii_bus *bus)
217 bus = mdiobus_alloc();
221 __module_get(ctrl->
ops->owner);
223 bus->
read = mdiobb_read;
224 bus->
write = mdiobb_write;
225 bus->
reset = mdiobb_reset;
236 module_put(ctrl->
ops->owner);