1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright (c) 2021-2023, Stephan Gerhold <stephan@gerhold.net> */ 3 4 #include <linux/module.h> 5 #include <linux/of.h> 6 #include <linux/of_platform.h> 7 #include <linux/platform_device.h> 8 #include <linux/rpmsg/qcom_smd.h> 9 10 static int rpm_proc_probe(struct platform_device *pdev) 11 { 12 struct qcom_smd_edge *edge = NULL; 13 struct device *dev = &pdev->dev; 14 struct device_node *edge_node; 15 int ret; 16 17 edge_node = of_get_child_by_name(dev->of_node, "smd-edge"); 18 if (edge_node) { 19 edge = qcom_smd_register_edge(dev, edge_node); 20 of_node_put(edge_node); 21 if (IS_ERR(edge)) 22 return dev_err_probe(dev, PTR_ERR(edge), 23 "Failed to register smd-edge\n"); 24 } 25 26 ret = devm_of_platform_populate(dev); 27 if (ret) { 28 dev_err(dev, "Failed to populate child devices: %d\n", ret); 29 goto err; 30 } 31 32 platform_set_drvdata(pdev, edge); 33 return 0; 34 err: 35 if (edge) 36 qcom_smd_unregister_edge(edge); 37 return ret; 38 } 39 40 static void rpm_proc_remove(struct platform_device *pdev) 41 { 42 struct qcom_smd_edge *edge = platform_get_drvdata(pdev); 43 44 if (edge) 45 qcom_smd_unregister_edge(edge); 46 } 47 48 static const struct of_device_id rpm_proc_of_match[] = { 49 { .compatible = "qcom,rpm-proc", }, 50 { /* sentinel */ } 51 }; 52 MODULE_DEVICE_TABLE(of, rpm_proc_of_match); 53 54 static struct platform_driver rpm_proc_driver = { 55 .probe = rpm_proc_probe, 56 .remove_new = rpm_proc_remove, 57 .driver = { 58 .name = "qcom-rpm-proc", 59 .of_match_table = rpm_proc_of_match, 60 }, 61 }; 62 63 static int __init rpm_proc_init(void) 64 { 65 return platform_driver_register(&rpm_proc_driver); 66 } 67 arch_initcall(rpm_proc_init); 68 69 static void __exit rpm_proc_exit(void) 70 { 71 platform_driver_unregister(&rpm_proc_driver); 72 } 73 module_exit(rpm_proc_exit); 74 75 MODULE_DESCRIPTION("Qualcomm RPM processor/subsystem driver"); 76 MODULE_AUTHOR("Stephan Gerhold <stephan@gerhold.net>"); 77 MODULE_LICENSE("GPL"); 78