Input: tm2-touchkey - add support for aries touchkey variant
[linux/fpc-iii.git] / drivers / remoteproc / qcom_common.c
blobacfc99f82fb808fbc3f83462c781eadb7a65bed0
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>
25 #include <linux/soc/qcom/mdt_loader.h>
27 #include "remoteproc_internal.h"
28 #include "qcom_common.h"
30 #define to_glink_subdev(d) container_of(d, struct qcom_rproc_glink, subdev)
31 #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
32 #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
34 static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
36 static int glink_subdev_probe(struct rproc_subdev *subdev)
38 struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
40 glink->edge = qcom_glink_smem_register(glink->dev, glink->node);
42 return PTR_ERR_OR_ZERO(glink->edge);
45 static void glink_subdev_remove(struct rproc_subdev *subdev, bool crashed)
47 struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
49 qcom_glink_smem_unregister(glink->edge);
50 glink->edge = NULL;
53 /**
54 * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc
55 * @rproc: rproc handle to parent the subdevice
56 * @glink: reference to a GLINK subdev context
58 void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
60 struct device *dev = &rproc->dev;
62 glink->node = of_get_child_by_name(dev->parent->of_node, "glink-edge");
63 if (!glink->node)
64 return;
66 glink->dev = dev;
67 rproc_add_subdev(rproc, &glink->subdev, glink_subdev_probe, glink_subdev_remove);
69 EXPORT_SYMBOL_GPL(qcom_add_glink_subdev);
71 /**
72 * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
73 * @rproc: rproc handle
74 * @glink: reference to a GLINK subdev context
76 void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
78 if (!glink->node)
79 return;
81 rproc_remove_subdev(rproc, &glink->subdev);
82 of_node_put(glink->node);
84 EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev);
86 /**
87 * qcom_register_dump_segments() - register segments for coredump
88 * @rproc: remoteproc handle
89 * @fw: firmware header
91 * Register all segments of the ELF in the remoteproc coredump segment list
93 * Return: 0 on success, negative errno on failure.
95 int qcom_register_dump_segments(struct rproc *rproc,
96 const struct firmware *fw)
98 const struct elf32_phdr *phdrs;
99 const struct elf32_phdr *phdr;
100 const struct elf32_hdr *ehdr;
101 int ret;
102 int i;
104 ehdr = (struct elf32_hdr *)fw->data;
105 phdrs = (struct elf32_phdr *)(ehdr + 1);
107 for (i = 0; i < ehdr->e_phnum; i++) {
108 phdr = &phdrs[i];
110 if (phdr->p_type != PT_LOAD)
111 continue;
113 if ((phdr->p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH)
114 continue;
116 if (!phdr->p_memsz)
117 continue;
119 ret = rproc_coredump_add_segment(rproc, phdr->p_paddr,
120 phdr->p_memsz);
121 if (ret)
122 return ret;
125 return 0;
127 EXPORT_SYMBOL_GPL(qcom_register_dump_segments);
129 static int smd_subdev_probe(struct rproc_subdev *subdev)
131 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
133 smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
135 return PTR_ERR_OR_ZERO(smd->edge);
138 static void smd_subdev_remove(struct rproc_subdev *subdev, bool crashed)
140 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
142 qcom_smd_unregister_edge(smd->edge);
143 smd->edge = NULL;
147 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
148 * @rproc: rproc handle to parent the subdevice
149 * @smd: reference to a Qualcomm subdev context
151 void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
153 struct device *dev = &rproc->dev;
155 smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
156 if (!smd->node)
157 return;
159 smd->dev = dev;
160 rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove);
162 EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
165 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
166 * @rproc: rproc handle
167 * @smd: the SMD subdevice to remove
169 void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
171 if (!smd->node)
172 return;
174 rproc_remove_subdev(rproc, &smd->subdev);
175 of_node_put(smd->node);
177 EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
180 * qcom_register_ssr_notifier() - register SSR notification handler
181 * @nb: notifier_block to notify for restart notifications
183 * Returns 0 on success, negative errno on failure.
185 * This register the @notify function as handler for restart notifications. As
186 * remote processors are stopped this function will be called, with the SSR
187 * name passed as a parameter.
189 int qcom_register_ssr_notifier(struct notifier_block *nb)
191 return blocking_notifier_chain_register(&ssr_notifiers, nb);
193 EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier);
196 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
197 * @nb: notifier_block to unregister
199 void qcom_unregister_ssr_notifier(struct notifier_block *nb)
201 blocking_notifier_chain_unregister(&ssr_notifiers, nb);
203 EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier);
205 static int ssr_notify_start(struct rproc_subdev *subdev)
207 return 0;
210 static void ssr_notify_stop(struct rproc_subdev *subdev, bool crashed)
212 struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
214 blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr->name);
218 * qcom_add_ssr_subdev() - register subdevice as restart notification source
219 * @rproc: rproc handle
220 * @ssr: SSR subdevice handle
221 * @ssr_name: identifier to use for notifications originating from @rproc
223 * As the @ssr is registered with the @rproc SSR events will be sent to all
224 * registered listeners in the system as the remoteproc is shut down.
226 void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr,
227 const char *ssr_name)
229 ssr->name = ssr_name;
231 rproc_add_subdev(rproc, &ssr->subdev, ssr_notify_start, ssr_notify_stop);
233 EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);
236 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
237 * @rproc: rproc handle
238 * @ssr: SSR subdevice handle
240 void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr)
242 rproc_remove_subdev(rproc, &ssr->subdev);
244 EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev);
246 MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
247 MODULE_LICENSE("GPL v2");