Skip to content

Commit f20e665

Browse files
Pramod Kumardavem330
authored andcommitted
mdio: mux: Enhanced MDIO mux framework for integrated multiplexers
An integrated multiplexer uses same address space for "muxed bus selection" and "generation of mdio transaction" hence its good to register parent bus from mux driver. Hence added a mechanism where mux driver could register a parent bus and pass it down to framework via mdio_mux_init api. Signed-off-by: Pramod Kumar <pramod.kumar@broadcom.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d46e416 commit f20e665

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

drivers/net/phy/mdio-mux-gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
5555
return PTR_ERR(s->gpios);
5656

5757
r = mdio_mux_init(&pdev->dev,
58-
mdio_mux_gpio_switch_fn, &s->mux_handle, s);
58+
mdio_mux_gpio_switch_fn, &s->mux_handle, s, NULL);
5959

6060
if (r != 0) {
6161
gpiod_put_array(s->gpios);

drivers/net/phy/mdio-mux-mmioreg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
126126
}
127127

128128
ret = mdio_mux_init(&pdev->dev, mdio_mux_mmioreg_switch_fn,
129-
&s->mux_handle, s);
129+
&s->mux_handle, s, NULL);
130130
if (ret) {
131131
dev_err(&pdev->dev, "failed to register mdio-mux bus %s\n",
132132
np->full_name);

drivers/net/phy/mdio-mux.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static int parent_count;
8989
int mdio_mux_init(struct device *dev,
9090
int (*switch_fn)(int cur, int desired, void *data),
9191
void **mux_handle,
92-
void *data)
92+
void *data,
93+
struct mii_bus *mux_bus)
9394
{
9495
struct device_node *parent_bus_node;
9596
struct device_node *child_bus_node;
@@ -101,22 +102,28 @@ int mdio_mux_init(struct device *dev,
101102
if (!dev->of_node)
102103
return -ENODEV;
103104

104-
parent_bus_node = of_parse_phandle(dev->of_node, "mdio-parent-bus", 0);
105+
if (!mux_bus) {
106+
parent_bus_node = of_parse_phandle(dev->of_node,
107+
"mdio-parent-bus", 0);
105108

106-
if (!parent_bus_node)
107-
return -ENODEV;
109+
if (!parent_bus_node)
110+
return -ENODEV;
111+
112+
parent_bus = of_mdio_find_bus(parent_bus_node);
113+
if (!parent_bus) {
114+
ret_val = -EPROBE_DEFER;
115+
goto err_parent_bus;
116+
}
117+
} else {
118+
parent_bus = mux_bus;
119+
}
108120

109121
pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
110122
if (pb == NULL) {
111123
ret_val = -ENOMEM;
112124
goto err_parent_bus;
113125
}
114126

115-
parent_bus = of_mdio_find_bus(parent_bus_node);
116-
if (parent_bus == NULL) {
117-
ret_val = -EPROBE_DEFER;
118-
goto err_parent_bus;
119-
}
120127

121128
pb->switch_data = data;
122129
pb->switch_fn = switch_fn;
@@ -177,7 +184,8 @@ int mdio_mux_init(struct device *dev,
177184
put_device(&pb->mii_bus->dev);
178185

179186
err_parent_bus:
180-
of_node_put(parent_bus_node);
187+
if (!mux_bus)
188+
of_node_put(parent_bus_node);
181189
return ret_val;
182190
}
183191
EXPORT_SYMBOL_GPL(mdio_mux_init);

include/linux/mdio-mux.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
#ifndef __LINUX_MDIO_MUX_H
1111
#define __LINUX_MDIO_MUX_H
1212
#include <linux/device.h>
13+
#include <linux/phy.h>
1314

1415
int mdio_mux_init(struct device *dev,
1516
int (*switch_fn) (int cur, int desired, void *data),
1617
void **mux_handle,
17-
void *data);
18+
void *data,
19+
struct mii_bus *mux_bus);
1820

1921
void mdio_mux_uninit(void *mux_handle);
2022

0 commit comments

Comments
 (0)