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 *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 return dev_err_probe(&pdev->dev, ret, in mdio_mux_mmioreg_probe()
115 s->phys = res.start; in mdio_mux_mmioreg_probe()
117 s->iosize = resource_size(&res); in mdio_mux_mmioreg_probe()
118 if (s->iosize != sizeof(uint8_t) && in mdio_mux_mmioreg_probe()
119 s->iosize != sizeof(uint16_t) && in mdio_mux_mmioreg_probe()
120 s->iosize != sizeof(uint32_t)) in mdio_mux_mmioreg_probe()
121 return dev_err_probe(&pdev->dev, -EINVAL, in mdio_mux_mmioreg_probe()
122 "only 8/16/32-bit registers are supported\n"); in mdio_mux_mmioreg_probe()
124 iprop = of_get_property(np, "mux-mask", &len); in mdio_mux_mmioreg_probe()
126 return dev_err_probe(&pdev->dev, -ENODEV, in mdio_mux_mmioreg_probe()
127 "missing or invalid mux-mask property\n"); in mdio_mux_mmioreg_probe()
128 if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) in mdio_mux_mmioreg_probe()
129 return dev_err_probe(&pdev->dev, -EINVAL, in mdio_mux_mmioreg_probe()
130 "only 8/16/32-bit registers are supported\n"); in mdio_mux_mmioreg_probe()
131 s->mask = be32_to_cpup(iprop); in mdio_mux_mmioreg_probe()
134 * Verify that the 'reg' property of each child MDIO bus does not in mdio_mux_mmioreg_probe()
141 return dev_err_probe(&pdev->dev, -ENODEV, in mdio_mux_mmioreg_probe()
142 "mdio-mux child node %pOF is missing a 'reg' property\n", in mdio_mux_mmioreg_probe()
144 if ((u32)reg & ~s->mask) in mdio_mux_mmioreg_probe()
145 return dev_err_probe(&pdev->dev, -ENODEV, in mdio_mux_mmioreg_probe()
146 "mdio-mux child node %pOF has a 'reg' value with unmasked bits\n", in mdio_mux_mmioreg_probe()
150 ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node, in mdio_mux_mmioreg_probe()
152 &s->mux_handle, s, NULL); in mdio_mux_mmioreg_probe()
154 return dev_err_probe(&pdev->dev, ret, in mdio_mux_mmioreg_probe()
155 "failed to register mdio-mux bus %pOF\n", np); in mdio_mux_mmioreg_probe()
157 pdev->dev.platform_data = s; in mdio_mux_mmioreg_probe()
164 struct mdio_mux_mmioreg_state *s = dev_get_platdata(&pdev->dev); in mdio_mux_mmioreg_remove()
166 mdio_mux_uninit(s->mux_handle); in mdio_mux_mmioreg_remove()
171 .compatible = "mdio-mux-mmioreg",
179 .name = "mdio-mux-mmioreg",
189 MODULE_DESCRIPTION("Memory-mapped device MDIO MUX driver");