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

1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/mdio-mux.h>
64 /* Disable external mdio master access */ in mdio_mux_iproc_config()
65 val = readl(md->base + MDIO_SCAN_CTRL_OFFSET); in mdio_mux_iproc_config()
67 writel(val, md->base + MDIO_SCAN_CTRL_OFFSET); in mdio_mux_iproc_config()
69 if (md->core_clk) { in mdio_mux_iproc_config()
70 /* use rate adjust regs to derive the mdio's operating in mdio_mux_iproc_config()
73 divisor = clk_get_rate(md->core_clk) / MDIO_OPERATING_FREQUENCY; in mdio_mux_iproc_config()
77 writel(val, md->base + MDIO_RATE_ADJ_EXT_OFFSET); in mdio_mux_iproc_config()
78 writel(val, md->base + MDIO_RATE_ADJ_INT_OFFSET); in mdio_mux_iproc_config()
91 /* start_miim_ops- Program and start MDIO transaction over mdio bus.
138 struct iproc_mdiomux_desc *md = bus->priv; in iproc_mdiomux_read_c22()
141 ret = start_miim_ops(md->base, false, phyid, reg, 0, MDIO_CTRL_READ_OP); in iproc_mdiomux_read_c22()
143 dev_err(&bus->dev, "mdiomux c22 read operation failed!!!"); in iproc_mdiomux_read_c22()
151 struct iproc_mdiomux_desc *md = bus->priv; in iproc_mdiomux_read_c45()
154 ret = start_miim_ops(md->base, true, phyid, reg | devad << 16, 0, in iproc_mdiomux_read_c45()
157 dev_err(&bus->dev, "mdiomux read c45 operation failed!!!"); in iproc_mdiomux_read_c45()
165 struct iproc_mdiomux_desc *md = bus->priv; in iproc_mdiomux_write_c22()
169 ret = start_miim_ops(md->base, false, phyid, reg, val, in iproc_mdiomux_write_c22()
172 dev_err(&bus->dev, "mdiomux write c22 operation failed!!!"); in iproc_mdiomux_write_c22()
180 struct iproc_mdiomux_desc *md = bus->priv; in iproc_mdiomux_write_c45()
184 ret = start_miim_ops(md->base, true, phyid, reg | devad << 16, val, in iproc_mdiomux_write_c45()
187 dev_err(&bus->dev, "mdiomux write c45 operation failed!!!"); in iproc_mdiomux_write_c45()
201 bus_id = bus_dir ? desired_child : (desired_child - EXT_BUS_START_ADDR); in mdio_mux_iproc_switch_fn()
206 writel(param, md->base + MDIO_PARAM_OFFSET); in mdio_mux_iproc_switch_fn()
217 md = devm_kzalloc(&pdev->dev, sizeof(*md), GFP_KERNEL); in mdio_mux_iproc_probe()
219 return -ENOMEM; in mdio_mux_iproc_probe()
220 md->dev = &pdev->dev; in mdio_mux_iproc_probe()
222 md->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in mdio_mux_iproc_probe()
223 if (IS_ERR(md->base)) in mdio_mux_iproc_probe()
224 return PTR_ERR(md->base); in mdio_mux_iproc_probe()
225 if (!IS_ALIGNED(res->start, SZ_4K)) { in mdio_mux_iproc_probe()
229 dev_info(&pdev->dev, "fix base address in dt-blob\n"); in mdio_mux_iproc_probe()
230 res->start = ALIGN_DOWN(res->start, SZ_4K); in mdio_mux_iproc_probe()
231 res->end = res->start + MDIO_REG_ADDR_SPACE_SIZE - 1; in mdio_mux_iproc_probe()
234 md->mii_bus = devm_mdiobus_alloc(&pdev->dev); in mdio_mux_iproc_probe()
235 if (!md->mii_bus) { in mdio_mux_iproc_probe()
236 dev_err(&pdev->dev, "mdiomux bus alloc failed\n"); in mdio_mux_iproc_probe()
237 return -ENOMEM; in mdio_mux_iproc_probe()
240 md->core_clk = devm_clk_get(&pdev->dev, NULL); in mdio_mux_iproc_probe()
241 if (md->core_clk == ERR_PTR(-ENOENT) || in mdio_mux_iproc_probe()
242 md->core_clk == ERR_PTR(-EINVAL)) in mdio_mux_iproc_probe()
243 md->core_clk = NULL; in mdio_mux_iproc_probe()
244 else if (IS_ERR(md->core_clk)) in mdio_mux_iproc_probe()
245 return PTR_ERR(md->core_clk); in mdio_mux_iproc_probe()
247 rc = clk_prepare_enable(md->core_clk); in mdio_mux_iproc_probe()
249 dev_err(&pdev->dev, "failed to enable core clk\n"); in mdio_mux_iproc_probe()
253 bus = md->mii_bus; in mdio_mux_iproc_probe()
254 bus->priv = md; in mdio_mux_iproc_probe()
255 bus->name = "iProc MDIO mux bus"; in mdio_mux_iproc_probe()
256 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", pdev->name, pdev->id); in mdio_mux_iproc_probe()
257 bus->parent = &pdev->dev; in mdio_mux_iproc_probe()
258 bus->read = iproc_mdiomux_read_c22; in mdio_mux_iproc_probe()
259 bus->write = iproc_mdiomux_write_c22; in mdio_mux_iproc_probe()
260 bus->read_c45 = iproc_mdiomux_read_c45; in mdio_mux_iproc_probe()
261 bus->write_c45 = iproc_mdiomux_write_c45; in mdio_mux_iproc_probe()
263 bus->phy_mask = ~0; in mdio_mux_iproc_probe()
264 bus->dev.of_node = pdev->dev.of_node; in mdio_mux_iproc_probe()
267 dev_err(&pdev->dev, "mdiomux registration failed\n"); in mdio_mux_iproc_probe()
273 rc = mdio_mux_init(md->dev, md->dev->of_node, mdio_mux_iproc_switch_fn, in mdio_mux_iproc_probe()
274 &md->mux_handle, md, md->mii_bus); in mdio_mux_iproc_probe()
276 dev_info(md->dev, "mdiomux initialization failed\n"); in mdio_mux_iproc_probe()
282 dev_info(md->dev, "iProc mdiomux registered\n"); in mdio_mux_iproc_probe()
288 clk_disable_unprepare(md->core_clk); in mdio_mux_iproc_probe()
296 mdio_mux_uninit(md->mux_handle); in mdio_mux_iproc_remove()
297 mdiobus_unregister(md->mii_bus); in mdio_mux_iproc_remove()
298 clk_disable_unprepare(md->core_clk); in mdio_mux_iproc_remove()
306 clk_disable_unprepare(md->core_clk); in mdio_mux_iproc_suspend()
316 rc = clk_prepare_enable(md->core_clk); in mdio_mux_iproc_resume()
318 dev_err(md->dev, "failed to enable core clk\n"); in mdio_mux_iproc_resume()
332 .compatible = "brcm,mdio-mux-iproc",
340 .name = "mdio-mux-iproc",
350 MODULE_DESCRIPTION("iProc MDIO Mux Bus Driver");