Lines Matching +full:reg +full:- +full:data
1 // SPDX-License-Identifier: GPL-2.0+
28 #include <linux/mdio-bitbang.h>
32 * This timeout definition is a worst-case ultra defensive measure against
110 static void davinci_mdio_init_clk(struct davinci_mdio_data *data) in davinci_mdio_init_clk() argument
114 mdio_in = clk_get_rate(data->clk); in davinci_mdio_init_clk()
115 div = (mdio_in / data->pdata.bus_freq) - 1; in davinci_mdio_init_clk()
119 data->clk_div = div; in davinci_mdio_init_clk()
123 * 32 bits of transferred data in davinci_mdio_init_clk()
130 * In the worst case, we could be kicking off a user-access immediately in davinci_mdio_init_clk()
131 * after the mdio bus scan state-machine triggered its own read. If in davinci_mdio_init_clk()
135 data->access_time = usecs_to_jiffies(access_time * 4); in davinci_mdio_init_clk()
136 if (!data->access_time) in davinci_mdio_init_clk()
137 data->access_time = 1; in davinci_mdio_init_clk()
140 static void davinci_mdio_enable(struct davinci_mdio_data *data) in davinci_mdio_enable() argument
143 writel(data->clk_div | CONTROL_ENABLE, &data->regs->control); in davinci_mdio_enable()
146 static void davinci_mdio_disable(struct davinci_mdio_data *data) in davinci_mdio_disable() argument
148 u32 reg; in davinci_mdio_disable() local
151 reg = readl(&data->regs->control); in davinci_mdio_disable()
153 reg &= ~CONTROL_CLKDIV; in davinci_mdio_disable()
154 reg |= data->clk_div; in davinci_mdio_disable()
156 reg &= ~CONTROL_ENABLE; in davinci_mdio_disable()
157 writel(reg, &data->regs->control); in davinci_mdio_disable()
160 static void davinci_mdio_enable_manual_mode(struct davinci_mdio_data *data) in davinci_mdio_enable_manual_mode() argument
162 u32 reg; in davinci_mdio_enable_manual_mode() local
164 reg = readl(&data->regs->poll); in davinci_mdio_enable_manual_mode()
165 reg |= MDIO_MANUALMODE; in davinci_mdio_enable_manual_mode()
166 writel(reg, &data->regs->poll); in davinci_mdio_enable_manual_mode()
171 struct davinci_mdio_data *data; in davinci_set_mdc() local
172 u32 reg; in davinci_set_mdc() local
174 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_set_mdc()
175 reg = readl(&data->regs->manualif); in davinci_set_mdc()
178 reg |= MDIO_MAN_MDCLK_O; in davinci_set_mdc()
180 reg &= ~MDIO_MAN_MDCLK_O; in davinci_set_mdc()
182 writel(reg, &data->regs->manualif); in davinci_set_mdc()
187 struct davinci_mdio_data *data; in davinci_set_mdio_dir() local
188 u32 reg; in davinci_set_mdio_dir() local
190 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_set_mdio_dir()
191 reg = readl(&data->regs->manualif); in davinci_set_mdio_dir()
194 reg |= MDIO_MAN_OE; in davinci_set_mdio_dir()
196 reg &= ~MDIO_MAN_OE; in davinci_set_mdio_dir()
198 writel(reg, &data->regs->manualif); in davinci_set_mdio_dir()
203 struct davinci_mdio_data *data; in davinci_set_mdio_data() local
204 u32 reg; in davinci_set_mdio_data() local
206 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_set_mdio_data()
207 reg = readl(&data->regs->manualif); in davinci_set_mdio_data()
210 reg |= MDIO_MAN_PIN; in davinci_set_mdio_data()
212 reg &= ~MDIO_MAN_PIN; in davinci_set_mdio_data()
214 writel(reg, &data->regs->manualif); in davinci_set_mdio_data()
219 struct davinci_mdio_data *data; in davinci_get_mdio_data() local
220 unsigned long reg; in davinci_get_mdio_data() local
222 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_get_mdio_data()
223 reg = readl(&data->regs->manualif); in davinci_get_mdio_data()
224 return test_bit(MDIO_PIN, ®); in davinci_get_mdio_data()
227 static int davinci_mdiobb_read_c22(struct mii_bus *bus, int phy, int reg) in davinci_mdiobb_read_c22() argument
231 ret = pm_runtime_resume_and_get(bus->parent); in davinci_mdiobb_read_c22()
235 ret = mdiobb_read_c22(bus, phy, reg); in davinci_mdiobb_read_c22()
237 pm_runtime_mark_last_busy(bus->parent); in davinci_mdiobb_read_c22()
238 pm_runtime_put_autosuspend(bus->parent); in davinci_mdiobb_read_c22()
243 static int davinci_mdiobb_write_c22(struct mii_bus *bus, int phy, int reg, in davinci_mdiobb_write_c22() argument
248 ret = pm_runtime_resume_and_get(bus->parent); in davinci_mdiobb_write_c22()
252 ret = mdiobb_write_c22(bus, phy, reg, val); in davinci_mdiobb_write_c22()
254 pm_runtime_mark_last_busy(bus->parent); in davinci_mdiobb_write_c22()
255 pm_runtime_put_autosuspend(bus->parent); in davinci_mdiobb_write_c22()
261 int reg) in davinci_mdiobb_read_c45() argument
265 ret = pm_runtime_resume_and_get(bus->parent); in davinci_mdiobb_read_c45()
269 ret = mdiobb_read_c45(bus, phy, devad, reg); in davinci_mdiobb_read_c45()
271 pm_runtime_mark_last_busy(bus->parent); in davinci_mdiobb_read_c45()
272 pm_runtime_put_autosuspend(bus->parent); in davinci_mdiobb_read_c45()
278 int reg, u16 val) in davinci_mdiobb_write_c45() argument
282 ret = pm_runtime_resume_and_get(bus->parent); in davinci_mdiobb_write_c45()
286 ret = mdiobb_write_c45(bus, phy, devad, reg, val); in davinci_mdiobb_write_c45()
288 pm_runtime_mark_last_busy(bus->parent); in davinci_mdiobb_write_c45()
289 pm_runtime_put_autosuspend(bus->parent); in davinci_mdiobb_write_c45()
294 static int davinci_mdio_common_reset(struct davinci_mdio_data *data) in davinci_mdio_common_reset() argument
299 ret = pm_runtime_resume_and_get(data->dev); in davinci_mdio_common_reset()
303 if (data->manual_mode) { in davinci_mdio_common_reset()
304 davinci_mdio_disable(data); in davinci_mdio_common_reset()
305 davinci_mdio_enable_manual_mode(data); in davinci_mdio_common_reset()
309 msleep(PHY_MAX_ADDR * data->access_time); in davinci_mdio_common_reset()
312 ver = readl(&data->regs->version); in davinci_mdio_common_reset()
313 dev_info(data->dev, in davinci_mdio_common_reset()
316 data->pdata.bus_freq); in davinci_mdio_common_reset()
318 if (data->skip_scan) in davinci_mdio_common_reset()
322 phy_mask = readl(&data->regs->alive); in davinci_mdio_common_reset()
325 dev_info(data->dev, "detected phy mask %x\n", ~phy_mask); in davinci_mdio_common_reset()
329 dev_warn(data->dev, "no live phy, scanning all\n"); in davinci_mdio_common_reset()
332 data->bus->phy_mask = phy_mask; in davinci_mdio_common_reset()
335 pm_runtime_mark_last_busy(data->dev); in davinci_mdio_common_reset()
336 pm_runtime_put_autosuspend(data->dev); in davinci_mdio_common_reset()
343 struct davinci_mdio_data *data = bus->priv; in davinci_mdio_reset() local
345 return davinci_mdio_common_reset(data); in davinci_mdio_reset()
350 struct mdiobb_ctrl *ctrl = bus->priv; in davinci_mdiobb_reset()
351 struct davinci_mdio_data *data; in davinci_mdiobb_reset() local
353 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_mdiobb_reset()
355 return davinci_mdio_common_reset(data); in davinci_mdiobb_reset()
359 static inline int wait_for_user_access(struct davinci_mdio_data *data) in wait_for_user_access() argument
361 struct davinci_mdio_regs __iomem *regs = data->regs; in wait_for_user_access()
363 u32 reg; in wait_for_user_access() local
366 reg = readl(®s->user[0].access); in wait_for_user_access()
367 if ((reg & USERACCESS_GO) == 0) in wait_for_user_access()
370 reg = readl(®s->control); in wait_for_user_access()
371 if ((reg & CONTROL_IDLE) == 0) { in wait_for_user_access()
381 dev_warn(data->dev, "resetting idled controller\n"); in wait_for_user_access()
382 davinci_mdio_enable(data); in wait_for_user_access()
383 return -EAGAIN; in wait_for_user_access()
386 reg = readl(®s->user[0].access); in wait_for_user_access()
387 if ((reg & USERACCESS_GO) == 0) in wait_for_user_access()
390 dev_err(data->dev, "timed out waiting for user access\n"); in wait_for_user_access()
391 return -ETIMEDOUT; in wait_for_user_access()
395 static inline int wait_for_idle(struct davinci_mdio_data *data) in wait_for_idle() argument
397 struct davinci_mdio_regs __iomem *regs = data->regs; in wait_for_idle()
400 ret = readl_poll_timeout(®s->control, val, val & CONTROL_IDLE, in wait_for_idle()
403 dev_err(data->dev, "timed out waiting for idle\n"); in wait_for_idle()
410 struct davinci_mdio_data *data = bus->priv; in davinci_mdio_read() local
411 u32 reg; in davinci_mdio_read() local
415 return -EINVAL; in davinci_mdio_read()
417 ret = pm_runtime_resume_and_get(data->dev); in davinci_mdio_read()
421 reg = (USERACCESS_GO | USERACCESS_READ | (phy_reg << 21) | in davinci_mdio_read()
425 ret = wait_for_user_access(data); in davinci_mdio_read()
426 if (ret == -EAGAIN) in davinci_mdio_read()
431 writel(reg, &data->regs->user[0].access); in davinci_mdio_read()
433 ret = wait_for_user_access(data); in davinci_mdio_read()
434 if (ret == -EAGAIN) in davinci_mdio_read()
439 reg = readl(&data->regs->user[0].access); in davinci_mdio_read()
440 ret = (reg & USERACCESS_ACK) ? (reg & USERACCESS_DATA) : -EIO; in davinci_mdio_read()
444 pm_runtime_mark_last_busy(data->dev); in davinci_mdio_read()
445 pm_runtime_put_autosuspend(data->dev); in davinci_mdio_read()
452 struct davinci_mdio_data *data = bus->priv; in davinci_mdio_write() local
453 u32 reg; in davinci_mdio_write() local
457 return -EINVAL; in davinci_mdio_write()
459 ret = pm_runtime_resume_and_get(data->dev); in davinci_mdio_write()
463 reg = (USERACCESS_GO | USERACCESS_WRITE | (phy_reg << 21) | in davinci_mdio_write()
467 ret = wait_for_user_access(data); in davinci_mdio_write()
468 if (ret == -EAGAIN) in davinci_mdio_write()
473 writel(reg, &data->regs->user[0].access); in davinci_mdio_write()
475 ret = wait_for_user_access(data); in davinci_mdio_write()
476 if (ret == -EAGAIN) in davinci_mdio_write()
481 pm_runtime_mark_last_busy(data->dev); in davinci_mdio_write()
482 pm_runtime_put_autosuspend(data->dev); in davinci_mdio_write()
487 static int davinci_mdio_probe_dt(struct mdio_platform_data *data, in davinci_mdio_probe_dt() argument
490 struct device_node *node = pdev->dev.of_node; in davinci_mdio_probe_dt()
494 return -EINVAL; in davinci_mdio_probe_dt()
497 dev_err(&pdev->dev, "Missing bus_freq property in the DT.\n"); in davinci_mdio_probe_dt()
498 return -EINVAL; in davinci_mdio_probe_dt()
500 data->bus_freq = prop; in davinci_mdio_probe_dt()
514 { .family = "AM62X", .data = &am65_mdio_soc_data },
515 { .family = "AM64X", .data = &am65_mdio_soc_data },
516 { .family = "AM65X", .data = &am65_mdio_soc_data },
517 { .family = "J7200", .data = &am65_mdio_soc_data },
518 { .family = "J721E", .data = &am65_mdio_soc_data },
519 { .family = "J721S2", .data = &am65_mdio_soc_data },
530 { .compatible = "ti,cpsw-mdio", .data = &of_cpsw_mdio_data},
546 struct mdio_platform_data *pdata = dev_get_platdata(&pdev->dev); in davinci_mdio_probe()
547 struct device *dev = &pdev->dev; in davinci_mdio_probe()
548 struct davinci_mdio_data *data; in davinci_mdio_probe() local
552 int autosuspend_delay_ms = -1; in davinci_mdio_probe()
554 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in davinci_mdio_probe()
555 if (!data) in davinci_mdio_probe()
556 return -ENOMEM; in davinci_mdio_probe()
558 data->manual_mode = false; in davinci_mdio_probe()
559 data->bb_ctrl.ops = &davinci_mdiobb_ops; in davinci_mdio_probe()
561 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in davinci_mdio_probe()
565 if (soc_match_data && soc_match_data->data) { in davinci_mdio_probe()
567 soc_match_data->data; in davinci_mdio_probe()
569 data->manual_mode = socdata->manual_mode; in davinci_mdio_probe()
573 if (data->manual_mode) in davinci_mdio_probe()
574 data->bus = alloc_mdio_bitbang(&data->bb_ctrl); in davinci_mdio_probe()
576 data->bus = devm_mdiobus_alloc(dev); in davinci_mdio_probe()
578 if (!data->bus) { in davinci_mdio_probe()
580 return -ENOMEM; in davinci_mdio_probe()
583 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in davinci_mdio_probe()
586 ret = davinci_mdio_probe_dt(&data->pdata, pdev); in davinci_mdio_probe()
589 snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s", pdev->name); in davinci_mdio_probe()
591 of_mdio_data = of_device_get_match_data(&pdev->dev); in davinci_mdio_probe()
594 of_mdio_data->autosuspend_delay_ms; in davinci_mdio_probe()
597 data->pdata = pdata ? (*pdata) : default_pdata; in davinci_mdio_probe()
598 snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x", in davinci_mdio_probe()
599 pdev->name, pdev->id); in davinci_mdio_probe()
602 data->bus->name = dev_name(dev); in davinci_mdio_probe()
604 if (data->manual_mode) { in davinci_mdio_probe()
605 data->bus->read = davinci_mdiobb_read_c22; in davinci_mdio_probe()
606 data->bus->write = davinci_mdiobb_write_c22; in davinci_mdio_probe()
607 data->bus->read_c45 = davinci_mdiobb_read_c45; in davinci_mdio_probe()
608 data->bus->write_c45 = davinci_mdiobb_write_c45; in davinci_mdio_probe()
609 data->bus->reset = davinci_mdiobb_reset; in davinci_mdio_probe()
613 data->bus->read = davinci_mdio_read; in davinci_mdio_probe()
614 data->bus->write = davinci_mdio_write; in davinci_mdio_probe()
615 data->bus->reset = davinci_mdio_reset; in davinci_mdio_probe()
616 data->bus->priv = data; in davinci_mdio_probe()
618 data->bus->parent = dev; in davinci_mdio_probe()
620 data->clk = devm_clk_get(dev, "fck"); in davinci_mdio_probe()
621 if (IS_ERR(data->clk)) { in davinci_mdio_probe()
623 return PTR_ERR(data->clk); in davinci_mdio_probe()
626 dev_set_drvdata(dev, data); in davinci_mdio_probe()
627 data->dev = dev; in davinci_mdio_probe()
631 return -EINVAL; in davinci_mdio_probe()
632 data->regs = devm_ioremap(dev, res->start, resource_size(res)); in davinci_mdio_probe()
633 if (!data->regs) in davinci_mdio_probe()
634 return -ENOMEM; in davinci_mdio_probe()
636 davinci_mdio_init_clk(data); in davinci_mdio_probe()
638 pm_runtime_set_autosuspend_delay(&pdev->dev, autosuspend_delay_ms); in davinci_mdio_probe()
639 pm_runtime_use_autosuspend(&pdev->dev); in davinci_mdio_probe()
640 pm_runtime_enable(&pdev->dev); in davinci_mdio_probe()
647 if (dev->of_node && of_get_child_count(dev->of_node)) in davinci_mdio_probe()
648 data->skip_scan = true; in davinci_mdio_probe()
650 ret = of_mdiobus_register(data->bus, dev->of_node); in davinci_mdio_probe()
656 phy = mdiobus_get_phy(data->bus, addr); in davinci_mdio_probe()
659 phy->mdio.addr, phydev_name(phy), in davinci_mdio_probe()
660 phy->drv ? phy->drv->name : "unknown"); in davinci_mdio_probe()
667 pm_runtime_dont_use_autosuspend(&pdev->dev); in davinci_mdio_probe()
668 pm_runtime_disable(&pdev->dev); in davinci_mdio_probe()
674 struct davinci_mdio_data *data = platform_get_drvdata(pdev); in davinci_mdio_remove() local
676 if (data->bus) { in davinci_mdio_remove()
677 mdiobus_unregister(data->bus); in davinci_mdio_remove()
679 if (data->manual_mode) in davinci_mdio_remove()
680 free_mdio_bitbang(data->bus); in davinci_mdio_remove()
683 pm_runtime_dont_use_autosuspend(&pdev->dev); in davinci_mdio_remove()
684 pm_runtime_disable(&pdev->dev); in davinci_mdio_remove()
690 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_runtime_suspend() local
694 ctrl = readl(&data->regs->control); in davinci_mdio_runtime_suspend()
696 writel(ctrl, &data->regs->control); in davinci_mdio_runtime_suspend()
698 if (!data->manual_mode) in davinci_mdio_runtime_suspend()
699 wait_for_idle(data); in davinci_mdio_runtime_suspend()
706 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_runtime_resume() local
708 if (data->manual_mode) { in davinci_mdio_runtime_resume()
709 davinci_mdio_disable(data); in davinci_mdio_runtime_resume()
710 davinci_mdio_enable_manual_mode(data); in davinci_mdio_runtime_resume()
712 davinci_mdio_enable(data); in davinci_mdio_runtime_resume()
721 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_suspend() local
724 data->active_in_suspend = !pm_runtime_status_suspended(dev); in davinci_mdio_suspend()
725 if (data->active_in_suspend) in davinci_mdio_suspend()
738 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_resume() local
743 if (data->active_in_suspend) in davinci_mdio_resume()