Lines Matching +full:mdio +full:- +full:mux +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0
3 * Simple memory-mapped device MDIO MUX driver
11 #include <linux/mdio-mux.h>
26 * MDIO multiplexing switch function
28 * This function is called by the mdio-mux layer when it thinks the mdio bus
31 * 'current_child' is the current value of the mux register (masked via
32 * s->mask).
34 * 'desired_child' is the value of the 'reg' property of the target child MDIO
37 * The first time this function is called, current_child == -1.
39 * If current_child == desired_child, then the mux is already set to the
48 void __iomem *p = ioremap(s->phys, s->iosize); in mdio_mux_mmioreg_switch_fn()
50 return -ENOMEM; in mdio_mux_mmioreg_switch_fn()
52 switch (s->iosize) { in mdio_mux_mmioreg_switch_fn()
57 y = (x & ~s->mask) | desired_child; in mdio_mux_mmioreg_switch_fn()
59 iowrite8((x & ~s->mask) | desired_child, p); in mdio_mux_mmioreg_switch_fn()
60 pr_debug("%s: %02x -> %02x\n", __func__, x, y); in mdio_mux_mmioreg_switch_fn()
69 y = (x & ~s->mask) | desired_child; in mdio_mux_mmioreg_switch_fn()
71 iowrite16((x & ~s->mask) | desired_child, p); in mdio_mux_mmioreg_switch_fn()
72 pr_debug("%s: %04x -> %04x\n", __func__, x, y); in mdio_mux_mmioreg_switch_fn()
81 y = (x & ~s->mask) | desired_child; in mdio_mux_mmioreg_switch_fn()
83 iowrite32((x & ~s->mask) | desired_child, p); in mdio_mux_mmioreg_switch_fn()
84 pr_debug("%s: %08x -> %08x\n", __func__, x, y); in mdio_mux_mmioreg_switch_fn()
99 struct device_node *np2, *np = pdev->dev.of_node; in mdio_mux_mmioreg_probe()
105 dev_dbg(&pdev->dev, "probing node %pOF\n", np); in mdio_mux_mmioreg_probe()
107 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); in mdio_mux_mmioreg_probe()
109 return -ENOMEM; in mdio_mux_mmioreg_probe()
113 dev_err(&pdev->dev, "could not obtain memory map for node %pOF\n", in mdio_mux_mmioreg_probe()
117 s->phys = res.start; in mdio_mux_mmioreg_probe()
119 s->iosize = resource_size(&res); in mdio_mux_mmioreg_probe()
120 if (s->iosize != sizeof(uint8_t) && in mdio_mux_mmioreg_probe()
121 s->iosize != sizeof(uint16_t) && in mdio_mux_mmioreg_probe()
122 s->iosize != sizeof(uint32_t)) { in mdio_mux_mmioreg_probe()
123 dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); in mdio_mux_mmioreg_probe()
124 return -EINVAL; in mdio_mux_mmioreg_probe()
127 iprop = of_get_property(np, "mux-mask", &len); in mdio_mux_mmioreg_probe()
129 dev_err(&pdev->dev, "missing or invalid mux-mask property\n"); in mdio_mux_mmioreg_probe()
130 return -ENODEV; in mdio_mux_mmioreg_probe()
132 if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) { in mdio_mux_mmioreg_probe()
133 dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); in mdio_mux_mmioreg_probe()
134 return -EINVAL; in mdio_mux_mmioreg_probe()
136 s->mask = be32_to_cpup(iprop); in mdio_mux_mmioreg_probe()
139 * Verify that the 'reg' property of each child MDIO bus does not in mdio_mux_mmioreg_probe()
145 dev_err(&pdev->dev, "mdio-mux child node %pOF is " in mdio_mux_mmioreg_probe()
148 return -ENODEV; in mdio_mux_mmioreg_probe()
150 if (be32_to_cpup(iprop) & ~s->mask) { in mdio_mux_mmioreg_probe()
151 dev_err(&pdev->dev, "mdio-mux child node %pOF has " in mdio_mux_mmioreg_probe()
155 return -ENODEV; in mdio_mux_mmioreg_probe()
159 ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node, in mdio_mux_mmioreg_probe()
161 &s->mux_handle, s, NULL); in mdio_mux_mmioreg_probe()
163 return dev_err_probe(&pdev->dev, ret, in mdio_mux_mmioreg_probe()
164 "failed to register mdio-mux bus %pOF\n", np); in mdio_mux_mmioreg_probe()
166 pdev->dev.platform_data = s; in mdio_mux_mmioreg_probe()
173 struct mdio_mux_mmioreg_state *s = dev_get_platdata(&pdev->dev); in mdio_mux_mmioreg_remove()
175 mdio_mux_uninit(s->mux_handle); in mdio_mux_mmioreg_remove()
182 .compatible = "mdio-mux-mmioreg",
190 .name = "mdio-mux-mmioreg",
200 MODULE_DESCRIPTION("Memory-mapped device MDIO MUX driver");