bus: mhi: core: Use helper API to trigger a non-blocking host resume
authorBhaumik Bhatt <bbhatt@codeaurora.org>
Tue, 29 Sep 2020 17:52:03 +0000 (23:22 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 Oct 2020 09:33:46 +0000 (11:33 +0200)
Autonomous low power mode support requires the MHI host to resume from
multiple places and post a wakeup source to exit system suspend. This
needs to be done in a non-blocking manner. Introduce a helper API to
trigger the host resume for data transfers and other non-blocking use
cases while supporting implementation of autonomous low power modes.

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Bhaumik Bhatt <bbhatt@codeaurora.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20200929175218.8178-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/bus/mhi/core/internal.h
drivers/bus/mhi/core/main.c
drivers/bus/mhi/core/pm.c

index bcfa7b6558ef2cdbdeba66af8f99ae9e0cb739ed..1bbd6e99d38d6f4ad39d52f6c8307d5923e22aca 100644 (file)
@@ -599,6 +599,13 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl);
 int mhi_send_cmd(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
                 enum mhi_cmd_type cmd);
 
+static inline void mhi_trigger_resume(struct mhi_controller *mhi_cntrl)
+{
+       pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0);
+       mhi_cntrl->runtime_get(mhi_cntrl);
+       mhi_cntrl->runtime_put(mhi_cntrl);
+}
+
 /* Register access methods */
 void mhi_db_brstmode(struct mhi_controller *mhi_cntrl, struct db_cfg *db_cfg,
                     void __iomem *db_addr, dma_addr_t db_val);
index 1f622ce6be8be97f19879848a6d4aad7e03895e9..79be18ec2ebfd0830c67b9f79efb1cc418041a5e 100644 (file)
@@ -909,8 +909,7 @@ void mhi_ctrl_ev_task(unsigned long data)
                 * process it since we are probably in a suspended state,
                 * so trigger a resume.
                 */
-               mhi_cntrl->runtime_get(mhi_cntrl);
-               mhi_cntrl->runtime_put(mhi_cntrl);
+               mhi_trigger_resume(mhi_cntrl);
 
                return;
        }
@@ -971,10 +970,8 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
        }
 
        /* we're in M3 or transitioning to M3 */
-       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-               mhi_cntrl->runtime_get(mhi_cntrl);
-               mhi_cntrl->runtime_put(mhi_cntrl);
-       }
+       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+               mhi_trigger_resume(mhi_cntrl);
 
        /* Toggle wake to exit out of M2 */
        mhi_cntrl->wake_toggle(mhi_cntrl);
@@ -1032,10 +1029,8 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
        }
 
        /* we're in M3 or transitioning to M3 */
-       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-               mhi_cntrl->runtime_get(mhi_cntrl);
-               mhi_cntrl->runtime_put(mhi_cntrl);
-       }
+       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+               mhi_trigger_resume(mhi_cntrl);
 
        /* Toggle wake to exit out of M2 */
        mhi_cntrl->wake_toggle(mhi_cntrl);
@@ -1147,10 +1142,8 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
        read_lock_irqsave(&mhi_cntrl->pm_lock, flags);
 
        /* we're in M3 or transitioning to M3 */
-       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-               mhi_cntrl->runtime_get(mhi_cntrl);
-               mhi_cntrl->runtime_put(mhi_cntrl);
-       }
+       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+               mhi_trigger_resume(mhi_cntrl);
 
        /* Toggle wake to exit out of M2 */
        mhi_cntrl->wake_toggle(mhi_cntrl);
index 661d704c8093d8465432dc72b48c5f34e7d05ee6..b227d415e937a8fcf960f87b16ccc15543283db5 100644 (file)
@@ -824,11 +824,8 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl)
        /* Wake up the device */
        read_lock_bh(&mhi_cntrl->pm_lock);
        mhi_cntrl->wake_get(mhi_cntrl, true);
-       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-               pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0);
-               mhi_cntrl->runtime_get(mhi_cntrl);
-               mhi_cntrl->runtime_put(mhi_cntrl);
-       }
+       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+               mhi_trigger_resume(mhi_cntrl);
        read_unlock_bh(&mhi_cntrl->pm_lock);
 
        ret = wait_event_timeout(mhi_cntrl->state_event,
@@ -1139,10 +1136,8 @@ void mhi_device_put(struct mhi_device *mhi_dev)
 
        mhi_dev->dev_wake--;
        read_lock_bh(&mhi_cntrl->pm_lock);
-       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
-               mhi_cntrl->runtime_get(mhi_cntrl);
-               mhi_cntrl->runtime_put(mhi_cntrl);
-       }
+       if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state))
+               mhi_trigger_resume(mhi_cntrl);
 
        mhi_cntrl->wake_put(mhi_cntrl, false);
        read_unlock_bh(&mhi_cntrl->pm_lock);