dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / soc / qcom / glink_ssr.c
blob19c7399eddb5ad80a3bb6282d71cbdf2af82464a
1 /*
2 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
3 * Copyright (c) 2017, Linaro Ltd.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/completion.h>
16 #include <linux/module.h>
17 #include <linux/notifier.h>
18 #include <linux/rpmsg.h>
19 #include <linux/remoteproc/qcom_rproc.h>
21 /**
22 * struct do_cleanup_msg - The data structure for an SSR do_cleanup message
23 * version: The G-Link SSR protocol version
24 * command: The G-Link SSR command - do_cleanup
25 * seq_num: Sequence number
26 * name_len: Length of the name of the subsystem being restarted
27 * name: G-Link edge name of the subsystem being restarted
29 struct do_cleanup_msg {
30 __le32 version;
31 __le32 command;
32 __le32 seq_num;
33 __le32 name_len;
34 char name[32];
37 /**
38 * struct cleanup_done_msg - The data structure for an SSR cleanup_done message
39 * version: The G-Link SSR protocol version
40 * response: The G-Link SSR response to a do_cleanup command, cleanup_done
41 * seq_num: Sequence number
43 struct cleanup_done_msg {
44 __le32 version;
45 __le32 response;
46 __le32 seq_num;
49 /**
50 * G-Link SSR protocol commands
52 #define GLINK_SSR_DO_CLEANUP 0
53 #define GLINK_SSR_CLEANUP_DONE 1
55 struct glink_ssr {
56 struct device *dev;
57 struct rpmsg_endpoint *ept;
59 struct notifier_block nb;
61 u32 seq_num;
62 struct completion completion;
65 static int qcom_glink_ssr_callback(struct rpmsg_device *rpdev,
66 void *data, int len, void *priv, u32 addr)
68 struct cleanup_done_msg *msg = data;
69 struct glink_ssr *ssr = dev_get_drvdata(&rpdev->dev);
71 if (len < sizeof(*msg)) {
72 dev_err(ssr->dev, "message too short\n");
73 return -EINVAL;
76 if (le32_to_cpu(msg->version) != 0)
77 return -EINVAL;
79 if (le32_to_cpu(msg->response) != GLINK_SSR_CLEANUP_DONE)
80 return 0;
82 if (le32_to_cpu(msg->seq_num) != ssr->seq_num) {
83 dev_err(ssr->dev, "invalid sequence number of response\n");
84 return -EINVAL;
87 complete(&ssr->completion);
89 return 0;
92 static int qcom_glink_ssr_notify(struct notifier_block *nb, unsigned long event,
93 void *data)
95 struct glink_ssr *ssr = container_of(nb, struct glink_ssr, nb);
96 struct do_cleanup_msg msg;
97 char *ssr_name = data;
98 int ret;
100 ssr->seq_num++;
101 reinit_completion(&ssr->completion);
103 memset(&msg, 0, sizeof(msg));
104 msg.command = cpu_to_le32(GLINK_SSR_DO_CLEANUP);
105 msg.seq_num = cpu_to_le32(ssr->seq_num);
106 msg.name_len = cpu_to_le32(strlen(ssr_name));
107 strlcpy(msg.name, ssr_name, sizeof(msg.name));
109 ret = rpmsg_send(ssr->ept, &msg, sizeof(msg));
110 if (ret < 0)
111 dev_err(ssr->dev, "failed to send cleanup message\n");
113 ret = wait_for_completion_timeout(&ssr->completion, HZ);
114 if (!ret)
115 dev_err(ssr->dev, "timeout waiting for cleanup done message\n");
117 return NOTIFY_DONE;
120 static int qcom_glink_ssr_probe(struct rpmsg_device *rpdev)
122 struct glink_ssr *ssr;
124 ssr = devm_kzalloc(&rpdev->dev, sizeof(*ssr), GFP_KERNEL);
125 if (!ssr)
126 return -ENOMEM;
128 init_completion(&ssr->completion);
130 ssr->dev = &rpdev->dev;
131 ssr->ept = rpdev->ept;
132 ssr->nb.notifier_call = qcom_glink_ssr_notify;
134 dev_set_drvdata(&rpdev->dev, ssr);
136 return qcom_register_ssr_notifier(&ssr->nb);
139 static void qcom_glink_ssr_remove(struct rpmsg_device *rpdev)
141 struct glink_ssr *ssr = dev_get_drvdata(&rpdev->dev);
143 qcom_unregister_ssr_notifier(&ssr->nb);
146 static const struct rpmsg_device_id qcom_glink_ssr_match[] = {
147 { "glink_ssr" },
151 static struct rpmsg_driver qcom_glink_ssr_driver = {
152 .probe = qcom_glink_ssr_probe,
153 .remove = qcom_glink_ssr_remove,
154 .callback = qcom_glink_ssr_callback,
155 .id_table = qcom_glink_ssr_match,
156 .drv = {
157 .name = "qcom_glink_ssr",
160 module_rpmsg_driver(qcom_glink_ssr_driver);
162 MODULE_ALIAS("rpmsg:glink_ssr");
163 MODULE_DESCRIPTION("Qualcomm GLINK SSR notifier");
164 MODULE_LICENSE("GPL v2");