Lines Matching +full:ctrl +full:- +full:module

1 // SPDX-License-Identifier: GPL-2.0
17 #include <linux/module.h>
18 #include <linux/mdio-bitbang.h>
44 static void mdiobb_send_bit(struct mdiobb_ctrl *ctrl, int val) in mdiobb_send_bit() argument
46 const struct mdiobb_ops *ops = ctrl->ops; in mdiobb_send_bit()
48 ops->set_mdio_data(ctrl, val); in mdiobb_send_bit()
50 ops->set_mdc(ctrl, 1); in mdiobb_send_bit()
52 ops->set_mdc(ctrl, 0); in mdiobb_send_bit()
56 static int mdiobb_get_bit(struct mdiobb_ctrl *ctrl) in mdiobb_get_bit() argument
58 const struct mdiobb_ops *ops = ctrl->ops; in mdiobb_get_bit()
61 ops->set_mdc(ctrl, 1); in mdiobb_get_bit()
63 ops->set_mdc(ctrl, 0); in mdiobb_get_bit()
65 return ops->get_mdio_data(ctrl); in mdiobb_get_bit()
69 static void mdiobb_send_num(struct mdiobb_ctrl *ctrl, u16 val, int bits) in mdiobb_send_num() argument
73 for (i = bits - 1; i >= 0; i--) in mdiobb_send_num()
74 mdiobb_send_bit(ctrl, (val >> i) & 1); in mdiobb_send_num()
78 static u16 mdiobb_get_num(struct mdiobb_ctrl *ctrl, int bits) in mdiobb_get_num() argument
83 for (i = bits - 1; i >= 0; i--) { in mdiobb_get_num()
85 ret |= mdiobb_get_bit(ctrl); in mdiobb_get_num()
94 static void mdiobb_cmd(struct mdiobb_ctrl *ctrl, int op, u8 phy, u8 reg) in mdiobb_cmd() argument
96 const struct mdiobb_ops *ops = ctrl->ops; in mdiobb_cmd()
99 ops->set_mdio_dir(ctrl, 1); in mdiobb_cmd()
111 mdiobb_send_bit(ctrl, 1); in mdiobb_cmd()
116 mdiobb_send_bit(ctrl, 0); in mdiobb_cmd()
118 mdiobb_send_bit(ctrl, 0); in mdiobb_cmd()
120 mdiobb_send_bit(ctrl, 1); in mdiobb_cmd()
121 mdiobb_send_bit(ctrl, (op >> 1) & 1); in mdiobb_cmd()
122 mdiobb_send_bit(ctrl, (op >> 0) & 1); in mdiobb_cmd()
124 mdiobb_send_num(ctrl, phy, 5); in mdiobb_cmd()
125 mdiobb_send_num(ctrl, reg, 5); in mdiobb_cmd()
134 static int mdiobb_cmd_addr(struct mdiobb_ctrl *ctrl, int phy, u32 addr) in mdiobb_cmd_addr() argument
138 mdiobb_cmd(ctrl, MDIO_C45_ADDR, phy, dev_addr); in mdiobb_cmd_addr()
141 mdiobb_send_bit(ctrl, 1); in mdiobb_cmd_addr()
142 mdiobb_send_bit(ctrl, 0); in mdiobb_cmd_addr()
144 mdiobb_send_num(ctrl, reg, 16); in mdiobb_cmd_addr()
146 ctrl->ops->set_mdio_dir(ctrl, 0); in mdiobb_cmd_addr()
147 mdiobb_get_bit(ctrl); in mdiobb_cmd_addr()
154 struct mdiobb_ctrl *ctrl = bus->priv; in mdiobb_read() local
158 reg = mdiobb_cmd_addr(ctrl, phy, reg); in mdiobb_read()
159 mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg); in mdiobb_read()
161 mdiobb_cmd(ctrl, MDIO_READ, phy, reg); in mdiobb_read()
163 ctrl->ops->set_mdio_dir(ctrl, 0); in mdiobb_read()
168 if (mdiobb_get_bit(ctrl) != 0 && in mdiobb_read()
169 !(bus->phy_ignore_ta_mask & (1 << phy))) { in mdiobb_read()
170 /* PHY didn't drive TA low -- flush any bits it in mdiobb_read()
174 mdiobb_get_bit(ctrl); in mdiobb_read()
179 ret = mdiobb_get_num(ctrl, 16); in mdiobb_read()
180 mdiobb_get_bit(ctrl); in mdiobb_read()
186 struct mdiobb_ctrl *ctrl = bus->priv; in mdiobb_write() local
189 reg = mdiobb_cmd_addr(ctrl, phy, reg); in mdiobb_write()
190 mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg); in mdiobb_write()
192 mdiobb_cmd(ctrl, MDIO_WRITE, phy, reg); in mdiobb_write()
195 mdiobb_send_bit(ctrl, 1); in mdiobb_write()
196 mdiobb_send_bit(ctrl, 0); in mdiobb_write()
198 mdiobb_send_num(ctrl, val, 16); in mdiobb_write()
200 ctrl->ops->set_mdio_dir(ctrl, 0); in mdiobb_write()
201 mdiobb_get_bit(ctrl); in mdiobb_write()
205 struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl) in alloc_mdio_bitbang() argument
213 __module_get(ctrl->ops->owner); in alloc_mdio_bitbang()
215 bus->read = mdiobb_read; in alloc_mdio_bitbang()
216 bus->write = mdiobb_write; in alloc_mdio_bitbang()
217 bus->priv = ctrl; in alloc_mdio_bitbang()
225 struct mdiobb_ctrl *ctrl = bus->priv; in free_mdio_bitbang() local
227 module_put(ctrl->ops->owner); in free_mdio_bitbang()