Skip to content

Commit

Permalink
spi: Move ctlr->cur_msg_prepared to struct spi_message
Browse files Browse the repository at this point in the history
This enables the possibility to transfer a message that is not at the
current tip of the async message queue.
This is in preparation of the next patch(es) which enable spi_sync messages
to skip the queue altogether.

Signed-off-by: David Jander <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
yope authored and broonie committed Jun 27, 2022
1 parent 40308f9 commit 1714582
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
spi_finalize_current_message(ctlr);
goto out;
}
ctlr->cur_msg_prepared = true;
msg->prepared = true;
}

ret = spi_map_msg(ctlr, msg);
Expand Down Expand Up @@ -1926,17 +1926,18 @@ void spi_finalize_current_message(struct spi_controller *ctlr)
*/
spi_res_release(ctlr, mesg);

if (ctlr->cur_msg_prepared && ctlr->unprepare_message) {
if (mesg->prepared && ctlr->unprepare_message) {
ret = ctlr->unprepare_message(ctlr, mesg);
if (ret) {
dev_err(&ctlr->dev, "failed to unprepare message: %d\n",
ret);
}
}

mesg->prepared = false;

spin_lock_irqsave(&ctlr->queue_lock, flags);
ctlr->cur_msg = NULL;
ctlr->cur_msg_prepared = false;
ctlr->fallback = false;
kthread_queue_work(ctlr->kworker, &ctlr->pump_messages);
spin_unlock_irqrestore(&ctlr->queue_lock, flags);
Expand Down
7 changes: 4 additions & 3 deletions include/linux/spi/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,6 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch
* @queue: message queue
* @idling: the device is entering idle state
* @cur_msg: the currently in-flight message
* @cur_msg_prepared: spi_prepare_message was called for the currently
* in-flight message
* @cur_msg_mapped: message has been mapped for DMA
* @last_cs: the last chip_select that is recorded by set_cs, -1 on non chip
* selected
Expand Down Expand Up @@ -621,7 +619,6 @@ struct spi_controller {
bool running;
bool rt;
bool auto_runtime_pm;
bool cur_msg_prepared;
bool cur_msg_mapped;
char last_cs;
bool last_cs_mode_high;
Expand Down Expand Up @@ -988,6 +985,7 @@ struct spi_transfer {
* @queue: for use by whichever driver currently owns the message
* @state: for use by whichever driver currently owns the message
* @resources: for resource management when the spi message is processed
* @prepared: spi_prepare_message was called for the this message
*
* A @spi_message is used to execute an atomic sequence of data transfers,
* each represented by a struct spi_transfer. The sequence is "atomic"
Expand Down Expand Up @@ -1037,6 +1035,9 @@ struct spi_message {

/* list of spi_res reources when the spi message is processed */
struct list_head resources;

/* spi_prepare_message was called for this message */
bool prepared;
};

static inline void spi_message_init_no_memset(struct spi_message *m)
Expand Down

0 comments on commit 1714582

Please sign in to comment.