Lines Matching +full:reg +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0+
29 #include <linux/mdio-bitbang.h>
33 * This timeout definition is a worst-case ultra defensive measure against
111 static void davinci_mdio_init_clk(struct davinci_mdio_data *data) in davinci_mdio_init_clk() argument
115 mdio_in = clk_get_rate(data->clk); in davinci_mdio_init_clk()
116 div = (mdio_in / data->pdata.bus_freq) - 1; in davinci_mdio_init_clk()
120 data->clk_div = div; in davinci_mdio_init_clk()
124 * 32 bits of transferred data in davinci_mdio_init_clk()
131 * In the worst case, we could be kicking off a user-access immediately in davinci_mdio_init_clk()
132 * after the mdio bus scan state-machine triggered its own read. If in davinci_mdio_init_clk()
136 data->access_time = usecs_to_jiffies(access_time * 4); in davinci_mdio_init_clk()
137 if (!data->access_time) in davinci_mdio_init_clk()
138 data->access_time = 1; in davinci_mdio_init_clk()
141 static void davinci_mdio_enable(struct davinci_mdio_data *data) in davinci_mdio_enable() argument
144 writel(data->clk_div | CONTROL_ENABLE, &data->regs->control); in davinci_mdio_enable()
147 static void davinci_mdio_disable(struct davinci_mdio_data *data) in davinci_mdio_disable() argument
149 u32 reg; in davinci_mdio_disable() local
152 reg = readl(&data->regs->control); in davinci_mdio_disable()
154 reg &= ~CONTROL_CLKDIV; in davinci_mdio_disable()
155 reg |= data->clk_div; in davinci_mdio_disable()
157 reg &= ~CONTROL_ENABLE; in davinci_mdio_disable()
158 writel(reg, &data->regs->control); in davinci_mdio_disable()
161 static void davinci_mdio_enable_manual_mode(struct davinci_mdio_data *data) in davinci_mdio_enable_manual_mode() argument
163 u32 reg; in davinci_mdio_enable_manual_mode() local
165 reg = readl(&data->regs->poll); in davinci_mdio_enable_manual_mode()
166 reg |= MDIO_MANUALMODE; in davinci_mdio_enable_manual_mode()
167 writel(reg, &data->regs->poll); in davinci_mdio_enable_manual_mode()
172 struct davinci_mdio_data *data; in davinci_set_mdc() local
173 u32 reg; in davinci_set_mdc() local
175 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_set_mdc()
176 reg = readl(&data->regs->manualif); in davinci_set_mdc()
179 reg |= MDIO_MAN_MDCLK_O; in davinci_set_mdc()
181 reg &= ~MDIO_MAN_MDCLK_O; in davinci_set_mdc()
183 writel(reg, &data->regs->manualif); in davinci_set_mdc()
188 struct davinci_mdio_data *data; in davinci_set_mdio_dir() local
189 u32 reg; in davinci_set_mdio_dir() local
191 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_set_mdio_dir()
192 reg = readl(&data->regs->manualif); in davinci_set_mdio_dir()
195 reg |= MDIO_MAN_OE; in davinci_set_mdio_dir()
197 reg &= ~MDIO_MAN_OE; in davinci_set_mdio_dir()
199 writel(reg, &data->regs->manualif); in davinci_set_mdio_dir()
204 struct davinci_mdio_data *data; in davinci_set_mdio_data() local
205 u32 reg; in davinci_set_mdio_data() local
207 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_set_mdio_data()
208 reg = readl(&data->regs->manualif); in davinci_set_mdio_data()
211 reg |= MDIO_MAN_PIN; in davinci_set_mdio_data()
213 reg &= ~MDIO_MAN_PIN; in davinci_set_mdio_data()
215 writel(reg, &data->regs->manualif); in davinci_set_mdio_data()
220 struct davinci_mdio_data *data; in davinci_get_mdio_data() local
221 unsigned long reg; in davinci_get_mdio_data() local
223 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_get_mdio_data()
224 reg = readl(&data->regs->manualif); in davinci_get_mdio_data()
225 return test_bit(MDIO_PIN, &reg); in davinci_get_mdio_data()
228 static int davinci_mdiobb_read(struct mii_bus *bus, int phy, int reg) in davinci_mdiobb_read() argument
232 ret = pm_runtime_resume_and_get(bus->parent); in davinci_mdiobb_read()
236 ret = mdiobb_read(bus, phy, reg); in davinci_mdiobb_read()
238 pm_runtime_mark_last_busy(bus->parent); in davinci_mdiobb_read()
239 pm_runtime_put_autosuspend(bus->parent); in davinci_mdiobb_read()
244 static int davinci_mdiobb_write(struct mii_bus *bus, int phy, int reg, in davinci_mdiobb_write() argument
249 ret = pm_runtime_resume_and_get(bus->parent); in davinci_mdiobb_write()
253 ret = mdiobb_write(bus, phy, reg, val); in davinci_mdiobb_write()
255 pm_runtime_mark_last_busy(bus->parent); in davinci_mdiobb_write()
256 pm_runtime_put_autosuspend(bus->parent); in davinci_mdiobb_write()
261 static int davinci_mdio_common_reset(struct davinci_mdio_data *data) in davinci_mdio_common_reset() argument
266 ret = pm_runtime_resume_and_get(data->dev); in davinci_mdio_common_reset()
270 if (data->manual_mode) { in davinci_mdio_common_reset()
271 davinci_mdio_disable(data); in davinci_mdio_common_reset()
272 davinci_mdio_enable_manual_mode(data); in davinci_mdio_common_reset()
276 msleep(PHY_MAX_ADDR * data->access_time); in davinci_mdio_common_reset()
279 ver = readl(&data->regs->version); in davinci_mdio_common_reset()
280 dev_info(data->dev, in davinci_mdio_common_reset()
283 data->pdata.bus_freq); in davinci_mdio_common_reset()
285 if (data->skip_scan) in davinci_mdio_common_reset()
289 phy_mask = readl(&data->regs->alive); in davinci_mdio_common_reset()
292 dev_info(data->dev, "detected phy mask %x\n", ~phy_mask); in davinci_mdio_common_reset()
296 dev_warn(data->dev, "no live phy, scanning all\n"); in davinci_mdio_common_reset()
299 data->bus->phy_mask = phy_mask; in davinci_mdio_common_reset()
302 pm_runtime_mark_last_busy(data->dev); in davinci_mdio_common_reset()
303 pm_runtime_put_autosuspend(data->dev); in davinci_mdio_common_reset()
310 struct davinci_mdio_data *data = bus->priv; in davinci_mdio_reset() local
312 return davinci_mdio_common_reset(data); in davinci_mdio_reset()
317 struct mdiobb_ctrl *ctrl = bus->priv; in davinci_mdiobb_reset()
318 struct davinci_mdio_data *data; in davinci_mdiobb_reset() local
320 data = container_of(ctrl, struct davinci_mdio_data, bb_ctrl); in davinci_mdiobb_reset()
322 return davinci_mdio_common_reset(data); in davinci_mdiobb_reset()
326 static inline int wait_for_user_access(struct davinci_mdio_data *data) in wait_for_user_access() argument
328 struct davinci_mdio_regs __iomem *regs = data->regs; in wait_for_user_access()
330 u32 reg; in wait_for_user_access() local
333 reg = readl(&regs->user[0].access); in wait_for_user_access()
334 if ((reg & USERACCESS_GO) == 0) in wait_for_user_access()
337 reg = readl(&regs->control); in wait_for_user_access()
338 if ((reg & CONTROL_IDLE) == 0) { in wait_for_user_access()
348 dev_warn(data->dev, "resetting idled controller\n"); in wait_for_user_access()
349 davinci_mdio_enable(data); in wait_for_user_access()
350 return -EAGAIN; in wait_for_user_access()
353 reg = readl(&regs->user[0].access); in wait_for_user_access()
354 if ((reg & USERACCESS_GO) == 0) in wait_for_user_access()
357 dev_err(data->dev, "timed out waiting for user access\n"); in wait_for_user_access()
358 return -ETIMEDOUT; in wait_for_user_access()
362 static inline int wait_for_idle(struct davinci_mdio_data *data) in wait_for_idle() argument
364 struct davinci_mdio_regs __iomem *regs = data->regs; in wait_for_idle()
367 ret = readl_poll_timeout(&regs->control, val, val & CONTROL_IDLE, in wait_for_idle()
370 dev_err(data->dev, "timed out waiting for idle\n"); in wait_for_idle()
377 struct davinci_mdio_data *data = bus->priv; in davinci_mdio_read() local
378 u32 reg; in davinci_mdio_read() local
382 return -EINVAL; in davinci_mdio_read()
384 ret = pm_runtime_resume_and_get(data->dev); in davinci_mdio_read()
388 reg = (USERACCESS_GO | USERACCESS_READ | (phy_reg << 21) | in davinci_mdio_read()
392 ret = wait_for_user_access(data); in davinci_mdio_read()
393 if (ret == -EAGAIN) in davinci_mdio_read()
398 writel(reg, &data->regs->user[0].access); in davinci_mdio_read()
400 ret = wait_for_user_access(data); in davinci_mdio_read()
401 if (ret == -EAGAIN) in davinci_mdio_read()
406 reg = readl(&data->regs->user[0].access); in davinci_mdio_read()
407 ret = (reg & USERACCESS_ACK) ? (reg & USERACCESS_DATA) : -EIO; in davinci_mdio_read()
411 pm_runtime_mark_last_busy(data->dev); in davinci_mdio_read()
412 pm_runtime_put_autosuspend(data->dev); in davinci_mdio_read()
419 struct davinci_mdio_data *data = bus->priv; in davinci_mdio_write() local
420 u32 reg; in davinci_mdio_write() local
424 return -EINVAL; in davinci_mdio_write()
426 ret = pm_runtime_resume_and_get(data->dev); in davinci_mdio_write()
430 reg = (USERACCESS_GO | USERACCESS_WRITE | (phy_reg << 21) | in davinci_mdio_write()
434 ret = wait_for_user_access(data); in davinci_mdio_write()
435 if (ret == -EAGAIN) in davinci_mdio_write()
440 writel(reg, &data->regs->user[0].access); in davinci_mdio_write()
442 ret = wait_for_user_access(data); in davinci_mdio_write()
443 if (ret == -EAGAIN) in davinci_mdio_write()
448 pm_runtime_mark_last_busy(data->dev); in davinci_mdio_write()
449 pm_runtime_put_autosuspend(data->dev); in davinci_mdio_write()
454 static int davinci_mdio_probe_dt(struct mdio_platform_data *data, in davinci_mdio_probe_dt() argument
457 struct device_node *node = pdev->dev.of_node; in davinci_mdio_probe_dt()
461 return -EINVAL; in davinci_mdio_probe_dt()
464 dev_err(&pdev->dev, "Missing bus_freq property in the DT.\n"); in davinci_mdio_probe_dt()
465 return -EINVAL; in davinci_mdio_probe_dt()
467 data->bus_freq = prop; in davinci_mdio_probe_dt()
481 { .family = "AM62X", .revision = "SR1.0", .data = &am65_mdio_soc_data },
482 { .family = "AM64X", .revision = "SR1.0", .data = &am65_mdio_soc_data },
483 { .family = "AM64X", .revision = "SR2.0", .data = &am65_mdio_soc_data },
484 { .family = "AM65X", .revision = "SR1.0", .data = &am65_mdio_soc_data },
485 { .family = "AM65X", .revision = "SR2.0", .data = &am65_mdio_soc_data },
486 { .family = "J7200", .revision = "SR1.0", .data = &am65_mdio_soc_data },
487 { .family = "J7200", .revision = "SR2.0", .data = &am65_mdio_soc_data },
488 { .family = "J721E", .revision = "SR1.0", .data = &am65_mdio_soc_data },
489 { .family = "J721E", .revision = "SR2.0", .data = &am65_mdio_soc_data },
490 { .family = "J721S2", .revision = "SR1.0", .data = &am65_mdio_soc_data},
501 { .compatible = "ti,cpsw-mdio", .data = &of_cpsw_mdio_data},
517 struct mdio_platform_data *pdata = dev_get_platdata(&pdev->dev); in davinci_mdio_probe()
518 struct device *dev = &pdev->dev; in davinci_mdio_probe()
519 struct davinci_mdio_data *data; in davinci_mdio_probe() local
523 int autosuspend_delay_ms = -1; in davinci_mdio_probe()
525 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in davinci_mdio_probe()
526 if (!data) in davinci_mdio_probe()
527 return -ENOMEM; in davinci_mdio_probe()
529 data->manual_mode = false; in davinci_mdio_probe()
530 data->bb_ctrl.ops = &davinci_mdiobb_ops; in davinci_mdio_probe()
532 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in davinci_mdio_probe()
536 if (soc_match_data && soc_match_data->data) { in davinci_mdio_probe()
538 soc_match_data->data; in davinci_mdio_probe()
540 data->manual_mode = socdata->manual_mode; in davinci_mdio_probe()
544 if (data->manual_mode) in davinci_mdio_probe()
545 data->bus = alloc_mdio_bitbang(&data->bb_ctrl); in davinci_mdio_probe()
547 data->bus = devm_mdiobus_alloc(dev); in davinci_mdio_probe()
549 if (!data->bus) { in davinci_mdio_probe()
551 return -ENOMEM; in davinci_mdio_probe()
554 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in davinci_mdio_probe()
557 ret = davinci_mdio_probe_dt(&data->pdata, pdev); in davinci_mdio_probe()
560 snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s", pdev->name); in davinci_mdio_probe()
562 of_mdio_data = of_device_get_match_data(&pdev->dev); in davinci_mdio_probe()
565 of_mdio_data->autosuspend_delay_ms; in davinci_mdio_probe()
568 data->pdata = pdata ? (*pdata) : default_pdata; in davinci_mdio_probe()
569 snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x", in davinci_mdio_probe()
570 pdev->name, pdev->id); in davinci_mdio_probe()
573 data->bus->name = dev_name(dev); in davinci_mdio_probe()
575 if (data->manual_mode) { in davinci_mdio_probe()
576 data->bus->read = davinci_mdiobb_read; in davinci_mdio_probe()
577 data->bus->write = davinci_mdiobb_write; in davinci_mdio_probe()
578 data->bus->reset = davinci_mdiobb_reset; in davinci_mdio_probe()
582 data->bus->read = davinci_mdio_read; in davinci_mdio_probe()
583 data->bus->write = davinci_mdio_write; in davinci_mdio_probe()
584 data->bus->reset = davinci_mdio_reset; in davinci_mdio_probe()
585 data->bus->priv = data; in davinci_mdio_probe()
587 data->bus->parent = dev; in davinci_mdio_probe()
589 data->clk = devm_clk_get(dev, "fck"); in davinci_mdio_probe()
590 if (IS_ERR(data->clk)) { in davinci_mdio_probe()
592 return PTR_ERR(data->clk); in davinci_mdio_probe()
595 dev_set_drvdata(dev, data); in davinci_mdio_probe()
596 data->dev = dev; in davinci_mdio_probe()
600 return -EINVAL; in davinci_mdio_probe()
601 data->regs = devm_ioremap(dev, res->start, resource_size(res)); in davinci_mdio_probe()
602 if (!data->regs) in davinci_mdio_probe()
603 return -ENOMEM; in davinci_mdio_probe()
605 davinci_mdio_init_clk(data); in davinci_mdio_probe()
607 pm_runtime_set_autosuspend_delay(&pdev->dev, autosuspend_delay_ms); in davinci_mdio_probe()
608 pm_runtime_use_autosuspend(&pdev->dev); in davinci_mdio_probe()
609 pm_runtime_enable(&pdev->dev); in davinci_mdio_probe()
616 if (dev->of_node && of_get_child_count(dev->of_node)) in davinci_mdio_probe()
617 data->skip_scan = true; in davinci_mdio_probe()
619 ret = of_mdiobus_register(data->bus, dev->of_node); in davinci_mdio_probe()
625 phy = mdiobus_get_phy(data->bus, addr); in davinci_mdio_probe()
628 phy->mdio.addr, phydev_name(phy), in davinci_mdio_probe()
629 phy->drv ? phy->drv->name : "unknown"); in davinci_mdio_probe()
636 pm_runtime_dont_use_autosuspend(&pdev->dev); in davinci_mdio_probe()
637 pm_runtime_disable(&pdev->dev); in davinci_mdio_probe()
643 struct davinci_mdio_data *data = platform_get_drvdata(pdev); in davinci_mdio_remove() local
645 if (data->bus) { in davinci_mdio_remove()
646 mdiobus_unregister(data->bus); in davinci_mdio_remove()
648 if (data->manual_mode) in davinci_mdio_remove()
649 free_mdio_bitbang(data->bus); in davinci_mdio_remove()
652 pm_runtime_dont_use_autosuspend(&pdev->dev); in davinci_mdio_remove()
653 pm_runtime_disable(&pdev->dev); in davinci_mdio_remove()
661 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_runtime_suspend() local
665 ctrl = readl(&data->regs->control); in davinci_mdio_runtime_suspend()
667 writel(ctrl, &data->regs->control); in davinci_mdio_runtime_suspend()
669 if (!data->manual_mode) in davinci_mdio_runtime_suspend()
670 wait_for_idle(data); in davinci_mdio_runtime_suspend()
677 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_runtime_resume() local
679 if (data->manual_mode) { in davinci_mdio_runtime_resume()
680 davinci_mdio_disable(data); in davinci_mdio_runtime_resume()
681 davinci_mdio_enable_manual_mode(data); in davinci_mdio_runtime_resume()
683 davinci_mdio_enable(data); in davinci_mdio_runtime_resume()
692 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_suspend() local
695 data->active_in_suspend = !pm_runtime_status_suspended(dev); in davinci_mdio_suspend()
696 if (data->active_in_suspend) in davinci_mdio_suspend()
709 struct davinci_mdio_data *data = dev_get_drvdata(dev); in davinci_mdio_resume() local
714 if (data->active_in_suspend) in davinci_mdio_resume()