drm/i915/gvt: Roundup fb->height into tile's height at calucation fb->size
[linux-2.6-microblaze.git] / drivers / remoteproc / qcom_sysmon.c
index e976a60..c231314 100644 (file)
@@ -6,8 +6,9 @@
 #include <linux/module.h>
 #include <linux/notifier.h>
 #include <linux/slab.h>
+#include <linux/interrupt.h>
 #include <linux/io.h>
-#include <linux/notifier.h>
+#include <linux/of_irq.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/remoteproc/qcom_rproc.h>
@@ -25,6 +26,7 @@ struct qcom_sysmon {
 
        const char *name;
 
+       int shutdown_irq;
        int ssctl_version;
        int ssctl_instance;
 
@@ -34,6 +36,8 @@ struct qcom_sysmon {
 
        struct rpmsg_endpoint *ept;
        struct completion comp;
+       struct completion ind_comp;
+       struct completion shutdown_comp;
        struct mutex lock;
 
        bool ssr_ack;
@@ -137,6 +141,7 @@ static int sysmon_callback(struct rpmsg_device *rpdev, void *data, int count,
 }
 
 #define SSCTL_SHUTDOWN_REQ             0x21
+#define SSCTL_SHUTDOWN_READY_IND       0x21
 #define SSCTL_SUBSYS_EVENT_REQ         0x23
 
 #define SSCTL_MAX_MSG_LEN              7
@@ -252,6 +257,29 @@ static struct qmi_elem_info ssctl_subsys_event_resp_ei[] = {
        {}
 };
 
+static struct qmi_elem_info ssctl_shutdown_ind_ei[] = {
+       {}
+};
+
+static void sysmon_ind_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
+                         struct qmi_txn *txn, const void *data)
+{
+       struct qcom_sysmon *sysmon = container_of(qmi, struct qcom_sysmon, qmi);
+
+       complete(&sysmon->ind_comp);
+}
+
+static struct qmi_msg_handler qmi_indication_handler[] = {
+       {
+               .type = QMI_INDICATION,
+               .msg_id = SSCTL_SHUTDOWN_READY_IND,
+               .ei = ssctl_shutdown_ind_ei,
+               .decoded_size = 0,
+               .fn = sysmon_ind_cb
+       },
+       {}
+};
+
 /**
  * ssctl_request_shutdown() - request shutdown via SSCTL QMI service
  * @sysmon:    sysmon context
@@ -262,6 +290,8 @@ static void ssctl_request_shutdown(struct qcom_sysmon *sysmon)
        struct qmi_txn txn;
        int ret;
 
+       reinit_completion(&sysmon->ind_comp);
+       reinit_completion(&sysmon->shutdown_comp);
        ret = qmi_txn_init(&sysmon->qmi, &txn, ssctl_shutdown_resp_ei, &resp);
        if (ret < 0) {
                dev_err(sysmon->dev, "failed to allocate QMI txn\n");
@@ -283,6 +313,17 @@ static void ssctl_request_shutdown(struct qcom_sysmon *sysmon)
                dev_err(sysmon->dev, "shutdown request failed\n");
        else
                dev_dbg(sysmon->dev, "shutdown request completed\n");
+
+       if (sysmon->shutdown_irq > 0) {
+               ret = wait_for_completion_timeout(&sysmon->shutdown_comp,
+                                                 10 * HZ);
+               if (!ret) {
+                       ret = try_wait_for_completion(&sysmon->ind_comp);
+                       if (!ret)
+                               dev_err(sysmon->dev,
+                                       "timeout waiting for shutdown ack\n");
+               }
+       }
 }
 
 /**
@@ -432,6 +473,15 @@ static int sysmon_notify(struct notifier_block *nb, unsigned long event,
        return NOTIFY_DONE;
 }
 
+static irqreturn_t sysmon_shutdown_interrupt(int irq, void *data)
+{
+       struct qcom_sysmon *sysmon = data;
+
+       complete(&sysmon->shutdown_comp);
+
+       return IRQ_HANDLED;
+}
+
 /**
  * qcom_add_sysmon_subdev() - create a sysmon subdev for the given remoteproc
  * @rproc:     rproc context to associate the subdev with
@@ -449,7 +499,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc,
 
        sysmon = kzalloc(sizeof(*sysmon), GFP_KERNEL);
        if (!sysmon)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
        sysmon->dev = rproc->dev.parent;
        sysmon->rproc = rproc;
@@ -458,13 +508,37 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc,
        sysmon->ssctl_instance = ssctl_instance;
 
        init_completion(&sysmon->comp);
+       init_completion(&sysmon->ind_comp);
+       init_completion(&sysmon->shutdown_comp);
        mutex_init(&sysmon->lock);
 
-       ret = qmi_handle_init(&sysmon->qmi, SSCTL_MAX_MSG_LEN, &ssctl_ops, NULL);
+       sysmon->shutdown_irq = of_irq_get_byname(sysmon->dev->of_node,
+                                                "shutdown-ack");
+       if (sysmon->shutdown_irq < 0) {
+               if (sysmon->shutdown_irq != -ENODATA) {
+                       dev_err(sysmon->dev,
+                               "failed to retrieve shutdown-ack IRQ\n");
+                       return ERR_PTR(sysmon->shutdown_irq);
+               }
+       } else {
+               ret = devm_request_threaded_irq(sysmon->dev,
+                                               sysmon->shutdown_irq,
+                                               NULL, sysmon_shutdown_interrupt,
+                                               IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+                                               "q6v5 shutdown-ack", sysmon);
+               if (ret) {
+                       dev_err(sysmon->dev,
+                               "failed to acquire shutdown-ack IRQ\n");
+                       return ERR_PTR(ret);
+               }
+       }
+
+       ret = qmi_handle_init(&sysmon->qmi, SSCTL_MAX_MSG_LEN, &ssctl_ops,
+                             qmi_indication_handler);
        if (ret < 0) {
                dev_err(sysmon->dev, "failed to initialize qmi handle\n");
                kfree(sysmon);
-               return NULL;
+               return ERR_PTR(ret);
        }
 
        qmi_add_lookup(&sysmon->qmi, 43, 0, 0);