Linux 4.16.11
[linux/fpc-iii.git] / drivers / remoteproc / qcom_common.c
blob00602499713f43e3b82d92852c4225ab748fe0ef
1 /*
2 * Qualcomm Peripheral Image Loader helpers
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.
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.
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.
18 #include <linux/firmware.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/notifier.h>
22 #include <linux/remoteproc.h>
23 #include <linux/rpmsg/qcom_glink.h>
24 #include <linux/rpmsg/qcom_smd.h>
26 #include "remoteproc_internal.h"
27 #include "qcom_common.h"
29 #define to_glink_subdev(d) container_of(d, struct qcom_rproc_glink, subdev)
30 #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
31 #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
33 static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
35 static int glink_subdev_probe(struct rproc_subdev *subdev)
37 struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
39 glink->edge = qcom_glink_smem_register(glink->dev, glink->node);
41 return PTR_ERR_OR_ZERO(glink->edge);
44 static void glink_subdev_remove(struct rproc_subdev *subdev)
46 struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
48 qcom_glink_smem_unregister(glink->edge);
49 glink->edge = NULL;
52 /**
53 * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc
54 * @rproc: rproc handle to parent the subdevice
55 * @glink: reference to a GLINK subdev context
57 void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
59 struct device *dev = &rproc->dev;
61 glink->node = of_get_child_by_name(dev->parent->of_node, "glink-edge");
62 if (!glink->node)
63 return;
65 glink->dev = dev;
66 rproc_add_subdev(rproc, &glink->subdev, glink_subdev_probe, glink_subdev_remove);
68 EXPORT_SYMBOL_GPL(qcom_add_glink_subdev);
70 /**
71 * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
72 * @rproc: rproc handle
73 * @glink: reference to a GLINK subdev context
75 void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
77 rproc_remove_subdev(rproc, &glink->subdev);
78 of_node_put(glink->node);
80 EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev);
82 static int smd_subdev_probe(struct rproc_subdev *subdev)
84 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
86 smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
88 return PTR_ERR_OR_ZERO(smd->edge);
91 static void smd_subdev_remove(struct rproc_subdev *subdev)
93 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
95 qcom_smd_unregister_edge(smd->edge);
96 smd->edge = NULL;
99 /**
100 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
101 * @rproc: rproc handle to parent the subdevice
102 * @smd: reference to a Qualcomm subdev context
104 void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
106 struct device *dev = &rproc->dev;
108 smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
109 if (!smd->node)
110 return;
112 smd->dev = dev;
113 rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove);
115 EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
118 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
119 * @rproc: rproc handle
120 * @smd: the SMD subdevice to remove
122 void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
124 rproc_remove_subdev(rproc, &smd->subdev);
125 of_node_put(smd->node);
127 EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
130 * qcom_register_ssr_notifier() - register SSR notification handler
131 * @nb: notifier_block to notify for restart notifications
133 * Returns 0 on success, negative errno on failure.
135 * This register the @notify function as handler for restart notifications. As
136 * remote processors are stopped this function will be called, with the SSR
137 * name passed as a parameter.
139 int qcom_register_ssr_notifier(struct notifier_block *nb)
141 return blocking_notifier_chain_register(&ssr_notifiers, nb);
143 EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier);
146 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
147 * @nb: notifier_block to unregister
149 void qcom_unregister_ssr_notifier(struct notifier_block *nb)
151 blocking_notifier_chain_unregister(&ssr_notifiers, nb);
153 EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier);
155 static int ssr_notify_start(struct rproc_subdev *subdev)
157 return 0;
160 static void ssr_notify_stop(struct rproc_subdev *subdev)
162 struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
164 blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr->name);
168 * qcom_add_ssr_subdev() - register subdevice as restart notification source
169 * @rproc: rproc handle
170 * @ssr: SSR subdevice handle
171 * @ssr_name: identifier to use for notifications originating from @rproc
173 * As the @ssr is registered with the @rproc SSR events will be sent to all
174 * registered listeners in the system as the remoteproc is shut down.
176 void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr,
177 const char *ssr_name)
179 ssr->name = ssr_name;
181 rproc_add_subdev(rproc, &ssr->subdev, ssr_notify_start, ssr_notify_stop);
183 EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);
186 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
187 * @rproc: rproc handle
188 * @ssr: SSR subdevice handle
190 void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr)
192 rproc_remove_subdev(rproc, &ssr->subdev);
194 EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev);
196 MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
197 MODULE_LICENSE("GPL v2");