summaryrefslogtreecommitdiff
path: root/drivers/spi/spi-pl022.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-pl022.c')
-rw-r--r--drivers/spi/spi-pl022.c94
1 files changed, 69 insertions, 25 deletions
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index f37ad2271ad..c3e5c4df660 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -29,7 +29,7 @@
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/spi/spi.h>
-#include <linux/workqueue.h>
+#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/err.h>
@@ -41,6 +41,7 @@
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/pm_runtime.h>
+#include <linux/sched.h>
/*
* This macro is used to define some register default values.
@@ -330,12 +331,13 @@ struct vendor_data {
* @clk: outgoing clock "SPICLK" for the SPI bus
* @master: SPI framework hookup
* @master_info: controller-specific data from machine setup
- * @workqueue: a workqueue on which any spi_message request is queued
- * @pump_messages: work struct for scheduling work to the workqueue
+ * @kworker: thread struct for message pump
+ * @kworker_task: pointer to task for message pump kworker thread
+ * @pump_messages: work struct for scheduling work to the message pump
* @queue_lock: spinlock to syncronise access to message queue
* @queue: message queue
- * @busy: workqueue is busy
- * @running: workqueue is running
+ * @busy: message pump is busy
+ * @running: message pump is running
* @pump_transfers: Tasklet used in Interrupt Transfer mode
* @cur_msg: Pointer to current spi_message being processed
* @cur_transfer: Pointer to current spi_transfer
@@ -365,9 +367,10 @@ struct pl022 {
struct clk *clk;
struct spi_master *master;
struct pl022_ssp_controller *master_info;
- /* Driver message queue */
- struct workqueue_struct *workqueue;
- struct work_struct pump_messages;
+ /* Driver message pump */
+ struct kthread_worker kworker;
+ struct task_struct *kworker_task;
+ struct kthread_work pump_messages;
spinlock_t queue_lock;
struct list_head queue;
bool busy;
@@ -504,12 +507,19 @@ static void giveback(struct pl022 *pl022)
pl022->cur_msg = NULL;
pl022->cur_transfer = NULL;
pl022->cur_chip = NULL;
- queue_work(pl022->workqueue, &pl022->pump_messages);
+ queue_kthread_work(&pl022->kworker, &pl022->pump_messages);
spin_unlock_irqrestore(&pl022->queue_lock, flags);
msg->state = NULL;
if (msg->complete)
msg->complete(msg->context);
+
+ /* disable the SPI/SSP operation */
+ writew((readw(SSP_CR1(pl022->virtbase)) &
+ (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase));
+
+ /* This message is completed, so let's turn off the clocks & power */
+ pm_runtime_put(&pl022->adev->dev);
}
/**
@@ -914,6 +924,12 @@ static int configure_dma(struct pl022 *pl022)
struct dma_async_tx_descriptor *rxdesc;
struct dma_async_tx_descriptor *txdesc;
+ /* DMA burstsize should be same as the FIFO trigger level */
+ rx_conf.src_maxburst = pl022->rx_lev_trig ? 1 <<
+ (pl022->rx_lev_trig + 1) : pl022->rx_lev_trig;
+ tx_conf.dst_maxburst = pl022->tx_lev_trig ? 1 <<
+ (pl022->tx_lev_trig + 1) : pl022->tx_lev_trig;
+
/* Check that the channels are available */
if (!rxchan || !txchan)
return -ENODEV;
@@ -1494,8 +1510,8 @@ out:
}
/**
- * pump_messages - Workqueue function which processes spi message queue
- * @data: pointer to private data of SSP driver
+ * pump_messages - kthread work function which processes spi message queue
+ * @work: pointer to kthread work struct contained in the pl022 private struct
*
* This function checks if there is any spi message in the queue that
* needs processing and delegate control to appropriate function
@@ -1503,7 +1519,7 @@ out:
* based on the kind of the transfer
*
*/
-static void pump_messages(struct work_struct *work)
+static void pump_messages(struct kthread_work *work)
{
struct pl022 *pl022 =
container_of(work, struct pl022, pump_messages);
@@ -1556,7 +1572,7 @@ static void pump_messages(struct work_struct *work)
if (!was_busy)
/*
* We enable the core voltage and clocks here, then the clocks
- * and core will be disabled when this workqueue is run again
+ * and core will be disabled when this thread is run again
* and there is no more work to be done.
*/
pm_runtime_get_sync(&pl022->adev->dev);
@@ -1572,6 +1588,8 @@ static void pump_messages(struct work_struct *work)
static int __init init_queue(struct pl022 *pl022)
{
+ struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
+
INIT_LIST_HEAD(&pl022->queue);
spin_lock_init(&pl022->queue_lock);
@@ -1581,11 +1599,29 @@ static int __init init_queue(struct pl022 *pl022)
tasklet_init(&pl022->pump_transfers, pump_transfers,
(unsigned long)pl022);
- INIT_WORK(&pl022->pump_messages, pump_messages);
- pl022->workqueue = create_singlethread_workqueue(
+ init_kthread_worker(&pl022->kworker);
+ pl022->kworker_task = kthread_run(kthread_worker_fn,
+ &pl022->kworker,
dev_name(pl022->master->dev.parent));
- if (pl022->workqueue == NULL)
- return -EBUSY;
+ if (IS_ERR(pl022->kworker_task)) {
+ dev_err(&pl022->adev->dev,
+ "failed to create message pump task\n");
+ return -ENOMEM;
+ }
+ init_kthread_work(&pl022->pump_messages, pump_messages);
+
+ /*
+ * Board config will indicate if this controller should run the
+ * message pump with high (realtime) priority to reduce the transfer
+ * latency on the bus by minimising the delay between a transfer
+ * request and the scheduling of the message pump thread. Without this
+ * setting the message pump thread will remain at default priority.
+ */
+ if (pl022->master_info->rt) {
+ dev_info(&pl022->adev->dev,
+ "will run message pump with realtime priority\n");
+ sched_setscheduler(pl022->kworker_task, SCHED_FIFO, &param);
+ }
return 0;
}
@@ -1608,7 +1644,7 @@ static int start_queue(struct pl022 *pl022)
pl022->next_msg_cs_active = false;
spin_unlock_irqrestore(&pl022->queue_lock, flags);
- queue_work(pl022->workqueue, &pl022->pump_messages);
+ queue_kthread_work(&pl022->kworker, &pl022->pump_messages);
return 0;
}
@@ -1646,16 +1682,20 @@ static int destroy_queue(struct pl022 *pl022)
int status;
status = stop_queue(pl022);
- /* we are unloading the module or failing to load (only two calls
+
+ /*
+ * We are unloading the module or failing to load (only two calls
* to this routine), and neither call can handle a return value.
- * However, destroy_workqueue calls flush_workqueue, and that will
- * block until all work is done. If the reason that stop_queue
- * timed out is that the work will never finish, then it does no
- * good to call destroy_workqueue, so return anyway. */
+ * However, flush_kthread_worker will block until all work is done.
+ * If the reason that stop_queue timed out is that the work will never
+ * finish, then it does no good to call flush/stop thread, so
+ * return anyway.
+ */
if (status != 0)
return status;
- destroy_workqueue(pl022->workqueue);
+ flush_kthread_worker(&pl022->kworker);
+ kthread_stop(pl022->kworker_task);
return 0;
}
@@ -1802,7 +1842,7 @@ static int pl022_transfer(struct spi_device *spi, struct spi_message *msg)
list_add_tail(&msg->queue, &pl022->queue);
if (pl022->running && !pl022->busy)
- queue_work(pl022->workqueue, &pl022->pump_messages);
+ queue_kthread_work(&pl022->kworker, &pl022->pump_messages);
spin_unlock_irqrestore(&pl022->queue_lock, flags);
return 0;
@@ -2195,6 +2235,9 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
printk(KERN_INFO "pl022: mapped registers from 0x%08x to %p\n",
adev->res.start, pl022->virtbase);
+ pm_runtime_enable(dev);
+ pm_runtime_resume(dev);
+
pl022->clk = clk_get(&adev->dev, NULL);
if (IS_ERR(pl022->clk)) {
status = PTR_ERR(pl022->clk);
@@ -2318,6 +2361,7 @@ pl022_remove(struct amba_device *adev)
clk_disable(pl022->clk);
clk_unprepare(pl022->clk);
clk_put(pl022->clk);
+ pm_runtime_disable(&adev->dev);
iounmap(pl022->virtbase);
amba_release_regions(adev);
tasklet_disable(&pl022->pump_transfers);