Lines Matching +full:mdio +full:- +full:parent +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2014-2015 Hisilicon Limited.
23 #define MDIO_DRV_NAME "Hi-HNS_MDIO"
24 #define MDIO_BUS_NAME "Hisilicon MII Bus"
38 u8 __iomem *vbase; /* mdio reg base address */
43 /* mdio reg */
101 mdio_write_reg((a)->vbase, (reg), (value))
126 mdio_set_reg_field((dev)->vbase, (reg), (mask), (shift), (val))
137 mdio_get_reg_field((dev)->vbase, (reg), (mask), (shift))
140 mdio_get_reg_field((dev)->vbase, (reg), 0x1ull, (bit))
153 regmap_write(mdio_dev->subctrl_vbase, cfg_reg, set_val); in mdio_sc_cfg_reg_write()
155 for (time_cnt = MDIO_TIMEOUT; time_cnt; time_cnt--) { in mdio_sc_cfg_reg_write()
156 ret = regmap_read(mdio_dev->subctrl_vbase, st_reg, ®_value); in mdio_sc_cfg_reg_write()
166 return -EBUSY; in mdio_sc_cfg_reg_write()
171 static int hns_mdio_wait_ready(struct mii_bus *bus) in hns_mdio_wait_ready() argument
173 struct hns_mdio_device *mdio_dev = bus->priv; in hns_mdio_wait_ready()
187 return -ETIMEDOUT; in hns_mdio_wait_ready()
209 * hns_mdio_write - access phy register
210 * @bus: mdio bus
217 static int hns_mdio_write(struct mii_bus *bus, in hns_mdio_write() argument
221 struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv; in hns_mdio_write()
228 dev_dbg(&bus->dev, "mdio write %s,base is %p\n", in hns_mdio_write()
229 bus->id, mdio_dev->vbase); in hns_mdio_write()
230 dev_dbg(&bus->dev, "phy id=%d, is_c45=%d, devad=%d, reg=%#x, write data=%d\n", in hns_mdio_write()
234 ret = hns_mdio_wait_ready(bus); in hns_mdio_write()
236 dev_err(&bus->dev, "MDIO bus is busy\n"); in hns_mdio_write()
244 /* config the cmd-reg to write addr*/ in hns_mdio_write()
252 ret = hns_mdio_wait_ready(bus); in hns_mdio_write()
254 dev_err(&bus->dev, "MDIO bus is busy\n"); in hns_mdio_write()
272 * hns_mdio_read - access phy register
273 * @bus: mdio bus
279 static int hns_mdio_read(struct mii_bus *bus, int phy_id, int regnum) in hns_mdio_read() argument
286 struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv; in hns_mdio_read()
288 dev_dbg(&bus->dev, "mdio read %s,base is %p\n", in hns_mdio_read()
289 bus->id, mdio_dev->vbase); in hns_mdio_read()
290 dev_dbg(&bus->dev, "phy id=%d, is_c45=%d, devad=%d, reg=%#x!\n", in hns_mdio_read()
294 ret = hns_mdio_wait_ready(bus); in hns_mdio_read()
296 dev_err(&bus->dev, "MDIO bus is busy\n"); in hns_mdio_read()
307 /* Step 2; config the cmd-reg to write addr*/ in hns_mdio_read()
312 ret = hns_mdio_wait_ready(bus); in hns_mdio_read()
314 dev_err(&bus->dev, "MDIO bus is busy\n"); in hns_mdio_read()
324 ret = hns_mdio_wait_ready(bus); in hns_mdio_read()
326 dev_err(&bus->dev, "MDIO bus is busy\n"); in hns_mdio_read()
332 dev_err(&bus->dev, " ERROR! MDIO Read failed!\n"); in hns_mdio_read()
333 return -EBUSY; in hns_mdio_read()
344 * hns_mdio_reset - reset mdio bus
345 * @bus: mdio bus
349 static int hns_mdio_reset(struct mii_bus *bus) in hns_mdio_reset() argument
351 struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv; in hns_mdio_reset()
355 if (dev_of_node(bus->parent)) { in hns_mdio_reset()
356 if (!mdio_dev->subctrl_vbase) { in hns_mdio_reset()
357 dev_err(&bus->dev, "mdio sys ctl reg has not maped\n"); in hns_mdio_reset()
358 return -ENODEV; in hns_mdio_reset()
361 sc_reg = &mdio_dev->sc_reg; in hns_mdio_reset()
363 ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_req, in hns_mdio_reset()
364 0x1, sc_reg->mdio_reset_st, 0x1, in hns_mdio_reset()
367 dev_err(&bus->dev, "MDIO reset fail\n"); in hns_mdio_reset()
372 ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_dis, in hns_mdio_reset()
373 0x1, sc_reg->mdio_clk_st, 0x1, in hns_mdio_reset()
376 dev_err(&bus->dev, "MDIO dis clk fail\n"); in hns_mdio_reset()
381 ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_dreq, in hns_mdio_reset()
382 0x1, sc_reg->mdio_reset_st, 0x1, in hns_mdio_reset()
385 dev_err(&bus->dev, "MDIO dis clk fail\n"); in hns_mdio_reset()
390 ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_en, in hns_mdio_reset()
391 0x1, sc_reg->mdio_clk_st, 0x1, in hns_mdio_reset()
394 dev_err(&bus->dev, "MDIO en clk fail\n"); in hns_mdio_reset()
395 } else if (is_acpi_node(bus->parent->fwnode)) { in hns_mdio_reset()
398 s = acpi_evaluate_object(ACPI_HANDLE(bus->parent), in hns_mdio_reset()
401 dev_err(&bus->dev, "Reset failed, return:%#x\n", s); in hns_mdio_reset()
402 ret = -EBUSY; in hns_mdio_reset()
407 dev_err(&bus->dev, "Can not get cfg data from DT or ACPI\n"); in hns_mdio_reset()
408 ret = -ENXIO; in hns_mdio_reset()
414 * hns_mdio_probe - probe mdio device
415 * @pdev: mdio platform device
423 int ret = -ENODEV; in hns_mdio_probe()
427 return -ENODEV; in hns_mdio_probe()
430 mdio_dev = devm_kzalloc(&pdev->dev, sizeof(*mdio_dev), GFP_KERNEL); in hns_mdio_probe()
432 return -ENOMEM; in hns_mdio_probe()
434 new_bus = devm_mdiobus_alloc(&pdev->dev); in hns_mdio_probe()
436 dev_err(&pdev->dev, "mdiobus_alloc fail!\n"); in hns_mdio_probe()
437 return -ENOMEM; in hns_mdio_probe()
440 new_bus->name = MDIO_BUS_NAME; in hns_mdio_probe()
441 new_bus->read = hns_mdio_read; in hns_mdio_probe()
442 new_bus->write = hns_mdio_write; in hns_mdio_probe()
443 new_bus->reset = hns_mdio_reset; in hns_mdio_probe()
444 new_bus->priv = mdio_dev; in hns_mdio_probe()
445 new_bus->parent = &pdev->dev; in hns_mdio_probe()
447 mdio_dev->vbase = devm_platform_ioremap_resource(pdev, 0); in hns_mdio_probe()
448 if (IS_ERR(mdio_dev->vbase)) { in hns_mdio_probe()
449 ret = PTR_ERR(mdio_dev->vbase); in hns_mdio_probe()
454 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii", in hns_mdio_probe()
455 dev_name(&pdev->dev)); in hns_mdio_probe()
456 if (dev_of_node(&pdev->dev)) { in hns_mdio_probe()
459 ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node, in hns_mdio_probe()
460 "subctrl-vbase", in hns_mdio_probe()
465 mdio_dev->subctrl_vbase = in hns_mdio_probe()
467 if (IS_ERR(mdio_dev->subctrl_vbase)) { in hns_mdio_probe()
468 dev_warn(&pdev->dev, "syscon_node_to_regmap error\n"); in hns_mdio_probe()
469 mdio_dev->subctrl_vbase = NULL; in hns_mdio_probe()
472 mdio_dev->sc_reg.mdio_clk_en = in hns_mdio_probe()
474 mdio_dev->sc_reg.mdio_clk_dis = in hns_mdio_probe()
476 mdio_dev->sc_reg.mdio_reset_req = in hns_mdio_probe()
478 mdio_dev->sc_reg.mdio_reset_dreq = in hns_mdio_probe()
480 mdio_dev->sc_reg.mdio_clk_st = in hns_mdio_probe()
482 mdio_dev->sc_reg.mdio_reset_st = in hns_mdio_probe()
486 mdio_dev->sc_reg.mdio_clk_en = in hns_mdio_probe()
488 mdio_dev->sc_reg.mdio_clk_dis = in hns_mdio_probe()
490 mdio_dev->sc_reg.mdio_reset_req = in hns_mdio_probe()
492 mdio_dev->sc_reg.mdio_reset_dreq = in hns_mdio_probe()
494 mdio_dev->sc_reg.mdio_clk_st = in hns_mdio_probe()
496 mdio_dev->sc_reg.mdio_reset_st = in hns_mdio_probe()
501 dev_warn(&pdev->dev, "find syscon ret = %#x\n", ret); in hns_mdio_probe()
502 mdio_dev->subctrl_vbase = NULL; in hns_mdio_probe()
505 ret = of_mdiobus_register(new_bus, pdev->dev.of_node); in hns_mdio_probe()
506 } else if (is_acpi_node(pdev->dev.fwnode)) { in hns_mdio_probe()
508 memset(new_bus->irq, PHY_POLL, 4 * PHY_MAX_ADDR); in hns_mdio_probe()
511 new_bus->phy_mask = ~0; in hns_mdio_probe()
513 /* Register the MDIO bus */ in hns_mdio_probe()
516 dev_err(&pdev->dev, "Can not get cfg data from DT or ACPI\n"); in hns_mdio_probe()
517 ret = -ENXIO; in hns_mdio_probe()
521 dev_err(&pdev->dev, "Cannot register as MDIO bus!\n"); in hns_mdio_probe()
530 * hns_mdio_remove - remove mdio device
531 * @pdev: mdio platform device
537 struct mii_bus *bus; in hns_mdio_remove() local
539 bus = platform_get_drvdata(pdev); in hns_mdio_remove()
541 mdiobus_unregister(bus); in hns_mdio_remove()
547 {.compatible = "hisilicon,mdio"},
548 {.compatible = "hisilicon,hns-mdio"},
573 MODULE_DESCRIPTION("Hisilicon HNS MDIO driver");