TA的每日心情 | 开心 3 天前 |
---|
签到天数: 597 天 连续签到: 1 天 [LV.9]以坛为家II
|
【百度大脑AI计算盒FZ5C】firmware reset 驱动代码分析
# 设备树
- zynqmp_reset: reset-controller {
- compatible = "xlnx,zynqmp-reset";
- #reset-cells = <1>;
- };
复制代码 # match table
- static const struct of_device_id zynqmp_reset_dt_ids[] = {
- { .compatible = "xlnx,zynqmp-reset", },
- { /* sentinel */ },
- };
复制代码 # driver
- static struct platform_driver zynqmp_reset_driver = {
- .probe = zynqmp_reset_probe,
- .driver = {
- .name = KBUILD_MODNAME,
- .of_match_table = zynqmp_reset_dt_ids,
- },
- };
复制代码 # arch_initcall 级别的
- static int __init zynqmp_reset_init(void)
- {
- return platform_driver_register(&zynqmp_reset_driver);
- }
- arch_initcall(zynqmp_reset_init);
复制代码 # probe:注册的是 priv->rcdev
# firmware ops 挂在了 priv->eemi_ops 上
- static int zynqmp_reset_probe(struct platform_device *pdev)
- {
- struct zynqmp_reset_data *priv;
- priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
- if (!priv)
- return -ENOMEM;
- priv->eemi_ops = zynqmp_pm_get_eemi_ops();
- if (IS_ERR(priv->eemi_ops))
- return PTR_ERR(priv->eemi_ops);
- platform_set_drvdata(pdev, priv);
- priv->rcdev.ops = &zynqmp_reset_ops;
- priv->rcdev.owner = THIS_MODULE;
- priv->rcdev.of_node = pdev->dev.of_node;
- priv->rcdev.nr_resets = ZYNQMP_NR_RESETS;
- return devm_reset_controller_register(&pdev->dev, &priv->rcdev);
- }
复制代码 # rcdev 方法结构体,实现
- struct reset_control_ops {
- int (*reset)(struct reset_controller_dev *rcdev, unsigned long id);
- int (*assert)(struct reset_controller_dev *rcdev, unsigned long id);
- int (*deassert)(struct reset_controller_dev *rcdev, unsigned long id);
- int (*status)(struct reset_controller_dev *rcdev, unsigned long id);
- };
复制代码- static struct reset_control_ops zynqmp_reset_ops = {
- .reset = zynqmp_reset_reset,
- .assert = zynqmp_reset_assert,
- .deassert = zynqmp_reset_deassert,
- .status = zynqmp_reset_status,
- };
复制代码 # 看每一个具体实现:
# zynqmp_reset_reset 具体实现过程:通过 rcdev 获取 priv,再调用 priv->eemi_ops->reset_assert(),最终还是调用了 firmware 的 reset_assert 方法
- static int zynqmp_reset_reset(struct reset_controller_dev *rcdev,
- unsigned long id)
- {
- struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
- return priv->eemi_ops->reset_assert(ZYNQMP_RESET_ID + id,
- PM_RESET_ACTION_PULSE);
- }
复制代码 # zynqmp_reset_assert 同样
- static int zynqmp_reset_assert(struct reset_controller_dev *rcdev,
- unsigned long id)
- {
- struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
- return priv->eemi_ops->reset_assert(ZYNQMP_RESET_ID + id,
- PM_RESET_ACTION_ASSERT);
- }
复制代码 # zynqmp_reset_deassert 同样
- static int zynqmp_reset_deassert(struct reset_controller_dev *rcdev,
- unsigned long id)
- {
- struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
- return priv->eemi_ops->reset_assert(ZYNQMP_RESET_ID + id,
- PM_RESET_ACTION_RELEASE);
- }
复制代码 # zynqmp_reset_status 调用 priv->eemi_ops->reset_get_status(),最终还是调用了 firmware 的 reset_get_status 方法
- static int zynqmp_reset_status(struct reset_controller_dev *rcdev,
- unsigned long id)
- {
- struct zynqmp_reset_data *priv = to_zynqmp_reset_data(rcdev);
- int val, err;
- err = priv->eemi_ops->reset_get_status(ZYNQMP_RESET_ID + id, &val);
- if (err)
- return err;
- return val;
- }
复制代码 # 总结:reset 系统复位功能,注册独立设备 rcdev,有独立 ops,独立 ops 最终调用 firmware 实现
|
|