Lines Matching +full:x +full:- +full:mask +full:-
1 // SPDX-License-Identifier: GPL-2.0
3 * Simple memory-mapped device MDIO MUX driver
11 #include <linux/mdio-mux.h>
22 unsigned int mask; member
28 * This function is called by the mdio-mux layer when it thinks the mdio bus
32 * s->mask).
37 * The first time this function is called, current_child == -1.
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()
54 uint8_t x, y; in mdio_mux_mmioreg_switch_fn() local
56 x = ioread8(p); in mdio_mux_mmioreg_switch_fn()
57 y = (x & ~s->mask) | desired_child; in mdio_mux_mmioreg_switch_fn()
58 if (x != y) { 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()
66 uint16_t x, y; in mdio_mux_mmioreg_switch_fn() local
68 x = ioread16(p); in mdio_mux_mmioreg_switch_fn()
69 y = (x & ~s->mask) | desired_child; in mdio_mux_mmioreg_switch_fn()
70 if (x != y) { 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()
78 uint32_t x, y; in mdio_mux_mmioreg_switch_fn() local
80 x = ioread32(p); in mdio_mux_mmioreg_switch_fn()
81 y = (x & ~s->mask) | desired_child; in mdio_mux_mmioreg_switch_fn()
82 if (x != y) { 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()
140 * set any bits outside of the 'mask'. in mdio_mux_mmioreg_probe()
146 dev_err(&pdev->dev, "mdio-mux child node %pOF is " in mdio_mux_mmioreg_probe()
149 return -ENODEV; in mdio_mux_mmioreg_probe()
151 if ((u32)reg & ~s->mask) { in mdio_mux_mmioreg_probe()
152 dev_err(&pdev->dev, "mdio-mux child node %pOF has " in mdio_mux_mmioreg_probe()
156 return -ENODEV; in mdio_mux_mmioreg_probe()
160 ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node, in mdio_mux_mmioreg_probe()
162 &s->mux_handle, s, NULL); in mdio_mux_mmioreg_probe()
164 return dev_err_probe(&pdev->dev, ret, in mdio_mux_mmioreg_probe()
165 "failed to register mdio-mux bus %pOF\n", np); in mdio_mux_mmioreg_probe()
167 pdev->dev.platform_data = s; in mdio_mux_mmioreg_probe()
174 struct mdio_mux_mmioreg_state *s = dev_get_platdata(&pdev->dev); in mdio_mux_mmioreg_remove()
176 mdio_mux_uninit(s->mux_handle); in mdio_mux_mmioreg_remove()
183 .compatible = "mdio-mux-mmioreg",
191 .name = "mdio-mux-mmioreg",
201 MODULE_DESCRIPTION("Memory-mapped device MDIO MUX driver");