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

1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/mdio-mux.h>
39 #define MDIO_STAT_DONE 1
47 #define MDIO_RATE_ADJ_DIVIDENT 1
62 /* Disable external mdio master access */ in mdio_mux_iproc_config()
63 val = readl(md->base + MDIO_SCAN_CTRL_OFFSET); in mdio_mux_iproc_config()
65 writel(val, md->base + MDIO_SCAN_CTRL_OFFSET); in mdio_mux_iproc_config()
67 if (md->core_clk) { in mdio_mux_iproc_config()
68 /* use rate adjust regs to derive the mdio's operating in mdio_mux_iproc_config()
71 divisor = clk_get_rate(md->core_clk) / MDIO_OPERATING_FREQUENCY; in mdio_mux_iproc_config()
72 divisor = divisor / (MDIO_RATE_ADJ_DIVIDENT + 1); in mdio_mux_iproc_config()
75 writel(val, md->base + MDIO_RATE_ADJ_EXT_OFFSET); in mdio_mux_iproc_config()
76 writel(val, md->base + MDIO_RATE_ADJ_INT_OFFSET); in mdio_mux_iproc_config()
89 /* start_miim_ops- Program and start MDIO transaction over mdio bus.
124 ret = iproc_mdio_wait_for_idle(base, 1); in start_miim_ops()
136 struct iproc_mdiomux_desc *md = bus->priv; in iproc_mdiomux_read()
139 ret = start_miim_ops(md->base, phyid, reg, 0, MDIO_CTRL_READ_OP); in iproc_mdiomux_read()
141 dev_err(&bus->dev, "mdiomux read operation failed!!!"); in iproc_mdiomux_read()
149 struct iproc_mdiomux_desc *md = bus->priv; in iproc_mdiomux_write()
153 ret = start_miim_ops(md->base, phyid, reg, val, MDIO_CTRL_WRITE_OP); in iproc_mdiomux_write()
155 dev_err(&bus->dev, "mdiomux write operation failed!!!"); in iproc_mdiomux_write()
169 bus_id = bus_dir ? desired_child : (desired_child - EXT_BUS_START_ADDR); in mdio_mux_iproc_switch_fn()
171 param = (bus_dir ? 1 : 0) << MDIO_PARAM_INTERNAL_SEL; in mdio_mux_iproc_switch_fn()
174 writel(param, md->base + MDIO_PARAM_OFFSET); in mdio_mux_iproc_switch_fn()
185 md = devm_kzalloc(&pdev->dev, sizeof(*md), GFP_KERNEL); in mdio_mux_iproc_probe()
187 return -ENOMEM; in mdio_mux_iproc_probe()
188 md->dev = &pdev->dev; in mdio_mux_iproc_probe()
190 md->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in mdio_mux_iproc_probe()
191 if (IS_ERR(md->base)) in mdio_mux_iproc_probe()
192 return PTR_ERR(md->base); in mdio_mux_iproc_probe()
193 if (res->start & 0xfff) { in mdio_mux_iproc_probe()
197 dev_info(&pdev->dev, "fix base address in dt-blob\n"); in mdio_mux_iproc_probe()
198 res->start &= ~0xfff; in mdio_mux_iproc_probe()
199 res->end = res->start + MDIO_REG_ADDR_SPACE_SIZE - 1; in mdio_mux_iproc_probe()
202 md->mii_bus = devm_mdiobus_alloc(&pdev->dev); in mdio_mux_iproc_probe()
203 if (!md->mii_bus) { in mdio_mux_iproc_probe()
204 dev_err(&pdev->dev, "mdiomux bus alloc failed\n"); in mdio_mux_iproc_probe()
205 return -ENOMEM; in mdio_mux_iproc_probe()
208 md->core_clk = devm_clk_get(&pdev->dev, NULL); in mdio_mux_iproc_probe()
209 if (md->core_clk == ERR_PTR(-ENOENT) || in mdio_mux_iproc_probe()
210 md->core_clk == ERR_PTR(-EINVAL)) in mdio_mux_iproc_probe()
211 md->core_clk = NULL; in mdio_mux_iproc_probe()
212 else if (IS_ERR(md->core_clk)) in mdio_mux_iproc_probe()
213 return PTR_ERR(md->core_clk); in mdio_mux_iproc_probe()
215 rc = clk_prepare_enable(md->core_clk); in mdio_mux_iproc_probe()
217 dev_err(&pdev->dev, "failed to enable core clk\n"); in mdio_mux_iproc_probe()
221 bus = md->mii_bus; in mdio_mux_iproc_probe()
222 bus->priv = md; in mdio_mux_iproc_probe()
223 bus->name = "iProc MDIO mux bus"; in mdio_mux_iproc_probe()
224 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", pdev->name, pdev->id); in mdio_mux_iproc_probe()
225 bus->parent = &pdev->dev; in mdio_mux_iproc_probe()
226 bus->read = iproc_mdiomux_read; in mdio_mux_iproc_probe()
227 bus->write = iproc_mdiomux_write; in mdio_mux_iproc_probe()
229 bus->phy_mask = ~0; in mdio_mux_iproc_probe()
230 bus->dev.of_node = pdev->dev.of_node; in mdio_mux_iproc_probe()
233 dev_err(&pdev->dev, "mdiomux registration failed\n"); in mdio_mux_iproc_probe()
239 rc = mdio_mux_init(md->dev, md->dev->of_node, mdio_mux_iproc_switch_fn, in mdio_mux_iproc_probe()
240 &md->mux_handle, md, md->mii_bus); in mdio_mux_iproc_probe()
242 dev_info(md->dev, "mdiomux initialization failed\n"); in mdio_mux_iproc_probe()
248 dev_info(md->dev, "iProc mdiomux registered\n"); in mdio_mux_iproc_probe()
254 clk_disable_unprepare(md->core_clk); in mdio_mux_iproc_probe()
262 mdio_mux_uninit(md->mux_handle); in mdio_mux_iproc_remove()
263 mdiobus_unregister(md->mii_bus); in mdio_mux_iproc_remove()
264 clk_disable_unprepare(md->core_clk); in mdio_mux_iproc_remove()
274 clk_disable_unprepare(md->core_clk); in mdio_mux_iproc_suspend()
284 rc = clk_prepare_enable(md->core_clk); in mdio_mux_iproc_resume()
286 dev_err(md->dev, "failed to enable core clk\n"); in mdio_mux_iproc_resume()
300 .compatible = "brcm,mdio-mux-iproc",
308 .name = "mdio-mux-iproc",
318 MODULE_DESCRIPTION("iProc MDIO Mux Bus Driver");