1 /* 2 * Qualcomm Peripheral Image Loader helpers 3 * 4 * Copyright (C) 2016 Linaro Ltd 5 * Copyright (C) 2015 Sony Mobile Communications Inc 6 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * version 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 */ 17 18 #include <linux/firmware.h> 19 #include <linux/kernel.h> 20 #include <linux/module.h> 21 #include <linux/remoteproc.h> 22 #include <linux/rpmsg/qcom_smd.h> 23 24 #include "remoteproc_internal.h" 25 #include "qcom_common.h" 26 27 #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev) 28 29 /** 30 * qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc 31 * @rproc: remoteproc handle 32 * @fw: firmware header 33 * @tablesz: outgoing size of the table 34 * 35 * Returns a dummy table. 36 */ 37 struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc, 38 const struct firmware *fw, 39 int *tablesz) 40 { 41 static struct resource_table table = { .ver = 1, }; 42 43 *tablesz = sizeof(table); 44 return &table; 45 } 46 EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table); 47 48 static int smd_subdev_probe(struct rproc_subdev *subdev) 49 { 50 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev); 51 52 smd->edge = qcom_smd_register_edge(smd->dev, smd->node); 53 54 return IS_ERR(smd->edge) ? PTR_ERR(smd->edge) : 0; 55 } 56 57 static void smd_subdev_remove(struct rproc_subdev *subdev) 58 { 59 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev); 60 61 qcom_smd_unregister_edge(smd->edge); 62 smd->edge = NULL; 63 } 64 65 /** 66 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc 67 * @rproc: rproc handle to parent the subdevice 68 * @smd: reference to a Qualcomm subdev context 69 */ 70 void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd) 71 { 72 struct device *dev = &rproc->dev; 73 74 smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge"); 75 if (!smd->node) 76 return; 77 78 smd->dev = dev; 79 rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove); 80 } 81 EXPORT_SYMBOL_GPL(qcom_add_smd_subdev); 82 83 /** 84 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc 85 * @rproc: rproc handle 86 * @smd: the SMD subdevice to remove 87 */ 88 void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd) 89 { 90 rproc_remove_subdev(rproc, &smd->subdev); 91 of_node_put(smd->node); 92 } 93 EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev); 94 95 MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver"); 96 MODULE_LICENSE("GPL v2"); 97