Instead of directly invoking ti_sci_handle->dev_ops.get_device /
put_device (that is direct firmware logic), it is better to abstract it
through linux/pm_runtime.h's pm_runtime_put/get_sync which will call
the vendor's specific firmware logic automatically. The rationale here
being better code quality and reduced scope for refactoring in case of
any changes to the ti_sci protocol.

Signed-off-by: Siddharth Karanam <[email protected]>
---
 drivers/remoteproc/ti_sci_dev.h | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/remoteproc/ti_sci_dev.h b/drivers/remoteproc/ti_sci_dev.h
index 897998a97d7f..ec17af3ebf5e 100644
--- a/drivers/remoteproc/ti_sci_dev.h
+++ b/drivers/remoteproc/ti_sci_dev.h
@@ -59,23 +59,30 @@ static inline int ti_sci_dev_is_on(struct ti_sci_dev *tsd, 
bool *r_state,
        return ret;
 }
 
+/* Request power on to rproc through the TI-SCI PM domain */
 static inline int ti_sci_dev_get_device(struct ti_sci_dev *tsd)
 {
-       int ret;
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(tsd->dev);
+       if (ret < 0) {
+               dev_err(tsd->dev, "pm_runtime_get_sync failed, ret = %d\n", 
ret);
+               pm_runtime_put_noidle(tsd->dev);
+       }
 
-       ret = tsd->ops->get_device(tsd->sci, tsd->dev_id);
-       if (ret)
-               dev_err(tsd->dev, "ti-sci device get failed: %d\n", ret);
        return ret;
 }
 
+/* Request power off to a rproc through the TI-SCI PM domain */
 static inline int ti_sci_dev_put_device(struct ti_sci_dev *tsd)
 {
-       int ret;
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(tsd->dev);
+
+       if (ret < 0)
+               dev_err(tsd->dev, "pm_runtime_put_sync failed, ret = %d\n", 
ret);
 
-       ret = tsd->ops->put_device(tsd->sci, tsd->dev_id);
-       if (ret)
-               dev_err(tsd->dev, "ti-sci device put failed: %d\n", ret);
        return ret;
 }
 
-- 
2.55.0


Reply via email to