Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
[sfrench/cifs-2.6.git] / sound / soc / intel / common / sst-ipc.c
index 45a85190a081a9e554839f16bc86f6e9100f1855..62f3a8e0ec87696389d46c7824297b5e36fce188 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/sched.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
-#include <linux/kthread.h>
 #include <sound/asound.h>
 
 #include "sst-dsp.h"
@@ -109,10 +108,9 @@ static int ipc_tx_message(struct sst_generic_ipc *ipc, u64 header,
                ipc->ops.tx_data_copy(msg, tx_data, tx_bytes);
 
        list_add_tail(&msg->list, &ipc->tx_list);
+       schedule_work(&ipc->kwork);
        spin_unlock_irqrestore(&ipc->dsp->spinlock, flags);
 
-       kthread_queue_work(&ipc->kworker, &ipc->kwork);
-
        if (wait)
                return tx_wait_done(ipc, msg, rx_data);
        else
@@ -156,35 +154,32 @@ free_mem:
        return -ENOMEM;
 }
 
-static void ipc_tx_msgs(struct kthread_work *work)
+static void ipc_tx_msgs(struct work_struct *work)
 {
        struct sst_generic_ipc *ipc =
                container_of(work, struct sst_generic_ipc, kwork);
        struct ipc_message *msg;
-       unsigned long flags;
 
-       spin_lock_irqsave(&ipc->dsp->spinlock, flags);
-
-       if (list_empty(&ipc->tx_list) || ipc->pending) {
-               spin_unlock_irqrestore(&ipc->dsp->spinlock, flags);
-               return;
-       }
+       spin_lock_irq(&ipc->dsp->spinlock);
 
-       /* if the DSP is busy, we will TX messages after IRQ.
-        * also postpone if we are in the middle of procesing completion irq*/
-       if (ipc->ops.is_dsp_busy && ipc->ops.is_dsp_busy(ipc->dsp)) {
-               dev_dbg(ipc->dev, "ipc_tx_msgs dsp busy\n");
-               spin_unlock_irqrestore(&ipc->dsp->spinlock, flags);
-               return;
-       }
+       while (!list_empty(&ipc->tx_list) && !ipc->pending) {
+               /* if the DSP is busy, we will TX messages after IRQ.
+                * also postpone if we are in the middle of processing
+                * completion irq
+                */
+               if (ipc->ops.is_dsp_busy && ipc->ops.is_dsp_busy(ipc->dsp)) {
+                       dev_dbg(ipc->dev, "ipc_tx_msgs dsp busy\n");
+                       break;
+               }
 
-       msg = list_first_entry(&ipc->tx_list, struct ipc_message, list);
-       list_move(&msg->list, &ipc->rx_list);
+               msg = list_first_entry(&ipc->tx_list, struct ipc_message, list);
+               list_move(&msg->list, &ipc->rx_list);
 
-       if (ipc->ops.tx_msg != NULL)
-               ipc->ops.tx_msg(ipc, msg);
+               if (ipc->ops.tx_msg != NULL)
+                       ipc->ops.tx_msg(ipc, msg);
+       }
 
-       spin_unlock_irqrestore(&ipc->dsp->spinlock, flags);
+       spin_unlock_irq(&ipc->dsp->spinlock);
 }
 
 int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc, u64 header,
@@ -220,6 +215,14 @@ int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc, u64 header,
 }
 EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nowait);
 
+int sst_ipc_tx_message_nopm(struct sst_generic_ipc *ipc, u64 header,
+       void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes)
+{
+       return ipc_tx_message(ipc, header, tx_data, tx_bytes,
+               rx_data, rx_bytes, 1);
+}
+EXPORT_SYMBOL_GPL(sst_ipc_tx_message_nopm);
+
 struct ipc_message *sst_ipc_reply_find_msg(struct sst_generic_ipc *ipc,
        u64 header)
 {
@@ -297,19 +300,7 @@ int sst_ipc_init(struct sst_generic_ipc *ipc)
        if (ret < 0)
                return -ENOMEM;
 
-       /* start the IPC message thread */
-       kthread_init_worker(&ipc->kworker);
-       ipc->tx_thread = kthread_run(kthread_worker_fn,
-                                       &ipc->kworker, "%s",
-                                       dev_name(ipc->dev));
-       if (IS_ERR(ipc->tx_thread)) {
-               dev_err(ipc->dev, "error: failed to create message TX task\n");
-               ret = PTR_ERR(ipc->tx_thread);
-               kfree(ipc->msg);
-               return ret;
-       }
-
-       kthread_init_work(&ipc->kwork, ipc_tx_msgs);
+       INIT_WORK(&ipc->kwork, ipc_tx_msgs);
        return 0;
 }
 EXPORT_SYMBOL_GPL(sst_ipc_init);
@@ -318,8 +309,7 @@ void sst_ipc_fini(struct sst_generic_ipc *ipc)
 {
        int i;
 
-       if (ipc->tx_thread)
-               kthread_stop(ipc->tx_thread);
+       cancel_work_sync(&ipc->kwork);
 
        if (ipc->msg) {
                for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) {