Lines Matching +full:mdio +full:- +full:mux +full:- +full:multiplexer

1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/mdio-mux.h>
13 #define DRV_DESCRIPTION "MDIO bus multiplexer driver"
40 struct mdio_mux_child_bus *cb = bus->priv; in mdio_mux_read()
41 struct mdio_mux_parent_bus *pb = cb->parent; in mdio_mux_read()
44 mutex_lock_nested(&pb->mii_bus->mdio_lock, MDIO_MUTEX_MUX); in mdio_mux_read()
45 r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data); in mdio_mux_read()
49 pb->current_child = cb->bus_number; in mdio_mux_read()
51 r = pb->mii_bus->read(pb->mii_bus, phy_id, regnum); in mdio_mux_read()
53 mutex_unlock(&pb->mii_bus->mdio_lock); in mdio_mux_read()
64 struct mdio_mux_child_bus *cb = bus->priv; in mdio_mux_write()
65 struct mdio_mux_parent_bus *pb = cb->parent; in mdio_mux_write()
69 mutex_lock_nested(&pb->mii_bus->mdio_lock, MDIO_MUTEX_MUX); in mdio_mux_write()
70 r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data); in mdio_mux_write()
74 pb->current_child = cb->bus_number; in mdio_mux_write()
76 r = pb->mii_bus->write(pb->mii_bus, phy_id, regnum, val); in mdio_mux_write()
78 mutex_unlock(&pb->mii_bus->mdio_lock); in mdio_mux_write()
87 struct mdio_mux_child_bus *cb = pb->children; in mdio_mux_uninit_children()
90 mdiobus_unregister(cb->mii_bus); in mdio_mux_uninit_children()
91 mdiobus_free(cb->mii_bus); in mdio_mux_uninit_children()
92 cb = cb->next; in mdio_mux_uninit_children()
111 return -ENODEV; in mdio_mux_init()
115 "mdio-parent-bus", 0); in mdio_mux_init()
118 return -ENODEV; in mdio_mux_init()
122 ret_val = -EPROBE_DEFER; in mdio_mux_init()
128 get_device(&parent_bus->dev); in mdio_mux_init()
133 ret_val = -ENOMEM; in mdio_mux_init()
137 pb->switch_data = data; in mdio_mux_init()
138 pb->switch_fn = switch_fn; in mdio_mux_init()
139 pb->current_child = -1; in mdio_mux_init()
140 pb->parent_id = parent_count++; in mdio_mux_init()
141 pb->mii_bus = parent_bus; in mdio_mux_init()
143 ret_val = -ENODEV; in mdio_mux_init()
157 ret_val = -ENOMEM; in mdio_mux_init()
160 cb->bus_number = v; in mdio_mux_init()
161 cb->parent = pb; in mdio_mux_init()
163 cb->mii_bus = mdiobus_alloc(); in mdio_mux_init()
164 if (!cb->mii_bus) { in mdio_mux_init()
165 ret_val = -ENOMEM; in mdio_mux_init()
168 cb->mii_bus->priv = cb; in mdio_mux_init()
170 cb->mii_bus->name = "mdio_mux"; in mdio_mux_init()
171 snprintf(cb->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x.%x", in mdio_mux_init()
172 cb->mii_bus->name, pb->parent_id, v); in mdio_mux_init()
173 cb->mii_bus->parent = dev; in mdio_mux_init()
174 cb->mii_bus->read = mdio_mux_read; in mdio_mux_init()
175 cb->mii_bus->write = mdio_mux_write; in mdio_mux_init()
176 r = of_mdiobus_register(cb->mii_bus, child_bus_node); in mdio_mux_init()
178 mdiobus_free(cb->mii_bus); in mdio_mux_init()
179 if (r == -EPROBE_DEFER) { in mdio_mux_init()
185 "Error: Failed to register MDIO bus for child %pOF\n", in mdio_mux_init()
188 cb->next = pb->children; in mdio_mux_init()
189 pb->children = cb; in mdio_mux_init()
192 if (pb->children) { in mdio_mux_init()
203 put_device(&parent_bus->dev); in mdio_mux_init()
215 put_device(&pb->mii_bus->dev); in mdio_mux_uninit()