Merge v5.8-rc1 into drm-misc-fixes
[linux-2.6-microblaze.git] / drivers / remoteproc / qcom_q6v5_ipa_notify.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Qualcomm IPA notification subdev support
5  *
6  * Copyright (C) 2019 Linaro Ltd.
7  */
8
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/remoteproc.h>
12 #include <linux/remoteproc/qcom_q6v5_ipa_notify.h>
13
14 static void
15 ipa_notify_common(struct rproc_subdev *subdev, enum qcom_rproc_event event)
16 {
17         struct qcom_rproc_ipa_notify *ipa_notify;
18         qcom_ipa_notify_t notify;
19
20         ipa_notify = container_of(subdev, struct qcom_rproc_ipa_notify, subdev);
21         notify = ipa_notify->notify;
22         if (notify)
23                 notify(ipa_notify->data, event);
24 }
25
26 static int ipa_notify_prepare(struct rproc_subdev *subdev)
27 {
28         ipa_notify_common(subdev, MODEM_STARTING);
29
30         return 0;
31 }
32
33 static int ipa_notify_start(struct rproc_subdev *subdev)
34 {
35         ipa_notify_common(subdev, MODEM_RUNNING);
36
37         return 0;
38 }
39
40 static void ipa_notify_stop(struct rproc_subdev *subdev, bool crashed)
41
42 {
43         ipa_notify_common(subdev, crashed ? MODEM_CRASHED : MODEM_STOPPING);
44 }
45
46 static void ipa_notify_unprepare(struct rproc_subdev *subdev)
47 {
48         ipa_notify_common(subdev, MODEM_OFFLINE);
49 }
50
51 static void ipa_notify_removing(struct rproc_subdev *subdev)
52 {
53         ipa_notify_common(subdev, MODEM_REMOVING);
54 }
55
56 /* Register the IPA notification subdevice with the Q6V5 MSS remoteproc */
57 void qcom_add_ipa_notify_subdev(struct rproc *rproc,
58                 struct qcom_rproc_ipa_notify *ipa_notify)
59 {
60         ipa_notify->notify = NULL;
61         ipa_notify->data = NULL;
62         ipa_notify->subdev.prepare = ipa_notify_prepare;
63         ipa_notify->subdev.start = ipa_notify_start;
64         ipa_notify->subdev.stop = ipa_notify_stop;
65         ipa_notify->subdev.unprepare = ipa_notify_unprepare;
66
67         rproc_add_subdev(rproc, &ipa_notify->subdev);
68 }
69 EXPORT_SYMBOL_GPL(qcom_add_ipa_notify_subdev);
70
71 /* Remove the IPA notification subdevice */
72 void qcom_remove_ipa_notify_subdev(struct rproc *rproc,
73                 struct qcom_rproc_ipa_notify *ipa_notify)
74 {
75         struct rproc_subdev *subdev = &ipa_notify->subdev;
76
77         ipa_notify_removing(subdev);
78
79         rproc_remove_subdev(rproc, subdev);
80         ipa_notify->notify = NULL;      /* Make it obvious */
81 }
82 EXPORT_SYMBOL_GPL(qcom_remove_ipa_notify_subdev);
83
84 MODULE_LICENSE("GPL v2");
85 MODULE_DESCRIPTION("Qualcomm IPA notification remoteproc subdev");