]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/gpu/drm/vc4/vc4_v3d.c
drm/vc4: Add helpers for pm get/put.
[linux.git] / drivers / gpu / drm / vc4 / vc4_v3d.c
index e1e728e95562a061e2cdddca34127fd8241bcf75..b2b974f20e232e0596eee53ba52e4466a12dc446 100644 (file)
@@ -138,6 +138,39 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
 }
 #endif /* CONFIG_DEBUG_FS */
 
+/**
+ * Wraps pm_runtime_get_sync() in a refcount, so that we can reliably
+ * get the pm_runtime refcount to 0 in vc4_reset().
+ */
+int
+vc4_v3d_pm_get(struct vc4_dev *vc4)
+{
+       mutex_lock(&vc4->power_lock);
+       if (vc4->power_refcount++ == 0) {
+               int ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
+
+               if (ret < 0) {
+                       vc4->power_refcount--;
+                       mutex_unlock(&vc4->power_lock);
+                       return ret;
+               }
+       }
+       mutex_unlock(&vc4->power_lock);
+
+       return 0;
+}
+
+void
+vc4_v3d_pm_put(struct vc4_dev *vc4)
+{
+       mutex_lock(&vc4->power_lock);
+       if (--vc4->power_refcount == 0) {
+               pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
+               pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
+       }
+       mutex_unlock(&vc4->power_lock);
+}
+
 static void vc4_v3d_init_hw(struct drm_device *dev)
 {
        struct vc4_dev *vc4 = to_vc4_dev(dev);