TA的每日心情 | 开心 7 天前 |
---|
签到天数: 597 天 连续签到: 1 天 [LV.9]以坛为家II
|
【百度大脑AI计算盒FZ5C】firmware power 驱动代码分析
# 设备树
- zynqmp_power: zynqmp-power {
- u-boot,dm-pre-reloc;
- compatible = "xlnx,zynqmp-power";
- interrupt-parent = <&gic>;
- interrupts = <0 35 4>;
- mboxes = <&ipi_mailbox_pmu1 0>,
- <&ipi_mailbox_pmu1 1>;
- mbox-names = "tx", "rx";
- };
复制代码# match table
- static const struct of_device_id pm_of_match[] = {
- { .compatible = "xlnx,zynqmp-power", },
- { /* end of table */ },
- };
- MODULE_DEVICE_TABLE(of, pm_of_match);
复制代码# driver
- static struct platform_driver zynqmp_pm_platform_driver = {
- .probe = zynqmp_pm_probe,
- .remove = zynqmp_pm_remove,
- .driver = {
- .name = "zynqmp_power",
- .of_match_table = pm_of_match,
- },
- };
- module_platform_driver(zynqmp_pm_platform_driver);
复制代码# probe:调用了 eemi_ops 的两个方法,创建工作堆列,用到了 mailbox,收到 mailbox 消息添加工作队列,回复消息
- static int zynqmp_pm_probe(struct platform_device *pdev)
- {
- int ret, irq;
- u32 pm_api_version;
- struct mbox_client *client;
- eemi_ops = zynqmp_pm_get_eemi_ops();
- if (IS_ERR(eemi_ops))
- return PTR_ERR(eemi_ops);
- if (!eemi_ops->get_api_version || !eemi_ops->init_finalize)
- return -ENXIO;
- eemi_ops->init_finalize();
- eemi_ops->get_api_version(&pm_api_version);
- /* Check PM API version number */
- if (pm_api_version < ZYNQMP_PM_VERSION)
- return -ENODEV;
- if (of_find_property(pdev->dev.of_node, "mboxes", NULL)) {
- zynqmp_pm_init_suspend_work =
- devm_kzalloc(&pdev->dev,
- sizeof(struct zynqmp_pm_work_struct),
- GFP_KERNEL);
- if (!zynqmp_pm_init_suspend_work)
- return -ENOMEM;
- INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
- zynqmp_pm_init_suspend_work_fn);
- client = devm_kzalloc(&pdev->dev, sizeof(*client), GFP_KERNEL);
- if (!client)
- return -ENOMEM;
- client->dev = &pdev->dev;
- client->rx_callback = ipi_receive_callback;
- rx_chan = mbox_request_channel_byname(client, "rx");
- if (IS_ERR(rx_chan)) {
- dev_err(&pdev->dev, "Failed to request rx channel\n");
- return IS_ERR(rx_chan);
- }
- } else if (of_find_property(pdev->dev.of_node, "interrupts", NULL)) {
- irq = platform_get_irq(pdev, 0);
- if (irq <= 0)
- return -ENXIO;
- ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
- zynqmp_pm_isr,
- IRQF_NO_SUSPEND | IRQF_ONESHOT,
- dev_name(&pdev->dev),
- &pdev->dev);
- if (ret) {
- dev_err(&pdev->dev, "devm_request_threaded_irq '%d' "
- "failed with %d\n", irq, ret);
- return ret;
- }
- } else {
- dev_err(&pdev->dev, "Required property not found in DT node\n");
- return -ENOENT;
- }
- ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_suspend_mode.attr);
- if (ret) {
- dev_err(&pdev->dev, "unable to create sysfs interface\n");
- return ret;
- }
- return 0;
- }
复制代码# 总结:仅初始化,确认版本,调用了 firmware 驱动
# power 是自己实现的功能,通过 mailbox 传递消息,通过工作队列调整电源状态。更深层面是不是继续调用 firmware 方法,暂时未知
|
|