hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/video/rockchip/mpp/mpp_vdpu2.c
....@@ -20,6 +20,8 @@
2020 #include <linux/uaccess.h>
2121 #include <linux/regmap.h>
2222 #include <linux/proc_fs.h>
23
+#include <linux/mfd/syscon.h>
24
+#include <linux/rockchip/cpu.h>
2325 #include <soc/rockchip/pm_domains.h>
2426
2527 #include "mpp_debug.h"
....@@ -69,6 +71,9 @@
6971 #define VDPU2_DEC_CLOCK_GATE_EN BIT(4)
7072 #define VDPU2_DEC_START BIT(0)
7173
74
+#define VDPU2_REG_SOFT_RESET 0x0e8
75
+#define VDPU2_REG_SOFT_RESET_INDEX (58)
76
+
7277 #define VDPU2_REG_DIR_MV_BASE 0x0f8
7378 #define VDPU2_REG_DIR_MV_BASE_INDEX (62)
7479
....@@ -108,6 +113,7 @@
108113 #endif
109114 struct reset_control *rst_a;
110115 struct reset_control *rst_h;
116
+ struct regmap *grf;
111117 };
112118
113119 static struct mpp_hw_info vdpu_v2_hw_info = {
....@@ -340,6 +346,7 @@
340346 u32 i;
341347 u32 reg_en;
342348 struct vdpu_task *task = to_vdpu_task(mpp_task);
349
+ u32 timing_en = mpp->srv->timing_en;
343350
344351 mpp_debug_enter();
345352
....@@ -354,12 +361,21 @@
354361
355362 mpp_write_req(mpp, task->reg, s, e, reg_en);
356363 }
364
+
365
+ /* flush tlb before starting hardware */
366
+ mpp_iommu_flush_tlb(mpp->iommu_info);
367
+
357368 /* init current task */
358369 mpp->cur_task = mpp_task;
370
+
371
+ mpp_task_run_begin(mpp_task, timing_en, MPP_WORK_TIMEOUT_DELAY);
372
+
359373 /* Flush the registers */
360374 wmb();
361375 mpp_write(mpp, VDPU2_REG_DEC_EN,
362376 task->reg[reg_en] | VDPU2_DEC_START);
377
+
378
+ mpp_task_run_end(mpp_task, timing_en);
363379
364380 mpp_debug_leave();
365381
....@@ -456,6 +472,10 @@
456472 dec->procfs = NULL;
457473 return -EIO;
458474 }
475
+
476
+ /* for common mpp_dev options */
477
+ mpp_procfs_create_common(dec->procfs, mpp);
478
+
459479 mpp_procfs_create_u32("aclk", 0644,
460480 dec->procfs, &dec->aclk_info.debug_rate_hz);
461481 mpp_procfs_create_u32("session_buffers", 0644,
....@@ -596,21 +616,38 @@
596616 return IRQ_HANDLED;
597617 }
598618
619
+static int vdpu_soft_reset(struct mpp_dev *mpp)
620
+{
621
+ u32 val;
622
+
623
+ mpp_write(mpp, VDPU2_REG_SOFT_RESET, 1);
624
+ udelay(2);
625
+ val = mpp_read(mpp, VDPU2_REG_SOFT_RESET);
626
+
627
+ return val;
628
+}
629
+
599630 static int vdpu_reset(struct mpp_dev *mpp)
600631 {
601632 struct vdpu_dev *dec = to_vdpu_dev(mpp);
633
+ u32 ret = 0;
602634
603635 mpp_write(mpp, VDPU2_REG_DEC_EN, 0);
604636 mpp_write(mpp, VDPU2_REG_DEC_INT, 0);
605
- if (dec->rst_a && dec->rst_h) {
637
+
638
+ /* soft reset first */
639
+ ret = vdpu_soft_reset(mpp);
640
+ if (ret && dec->rst_a && dec->rst_h) {
606641 /* Don't skip this or iommu won't work after reset */
607
- rockchip_pmu_idle_request(mpp->dev, true);
642
+ mpp_debug(DEBUG_RESET, "reset in\n");
643
+ mpp_pmu_idle_request(mpp, true);
608644 mpp_safe_reset(dec->rst_a);
609645 mpp_safe_reset(dec->rst_h);
610646 udelay(5);
611647 mpp_safe_unreset(dec->rst_a);
612648 mpp_safe_unreset(dec->rst_h);
613
- rockchip_pmu_idle_request(mpp->dev, false);
649
+ mpp_pmu_idle_request(mpp, false);
650
+ mpp_debug(DEBUG_RESET, "reset out\n");
614651 }
615652
616653 return 0;
....@@ -758,12 +795,53 @@
758795 dev_err(dev, "wait total running time out\n");
759796 }
760797
798
+static int vdpu_runtime_suspend(struct device *dev)
799
+{
800
+ struct mpp_dev *mpp = dev_get_drvdata(dev);
801
+ struct mpp_grf_info *info = mpp->grf_info;
802
+ struct mpp_taskqueue *queue = mpp->queue;
803
+
804
+ if (cpu_is_rk3528() && info && info->mem_offset) {
805
+ mutex_lock(&queue->ref_lock);
806
+ if (!atomic_dec_if_positive(&queue->runtime_cnt)) {
807
+ regmap_write(info->grf, info->mem_offset,
808
+ info->val_mem_off);
809
+ }
810
+ mutex_unlock(&queue->ref_lock);
811
+ }
812
+
813
+ return 0;
814
+}
815
+
816
+static int vdpu_runtime_resume(struct device *dev)
817
+{
818
+ struct mpp_dev *mpp = dev_get_drvdata(dev);
819
+ struct mpp_grf_info *info = mpp->grf_info;
820
+ struct mpp_taskqueue *queue = mpp->queue;
821
+
822
+ if (cpu_is_rk3528() && info && info->mem_offset) {
823
+ mutex_lock(&queue->ref_lock);
824
+ regmap_write(info->grf, info->mem_offset,
825
+ info->val_mem_on);
826
+ atomic_inc(&queue->runtime_cnt);
827
+ mutex_unlock(&queue->ref_lock);
828
+ }
829
+
830
+ return 0;
831
+}
832
+
833
+static const struct dev_pm_ops vdpu_pm_ops = {
834
+ .runtime_suspend = vdpu_runtime_suspend,
835
+ .runtime_resume = vdpu_runtime_resume,
836
+};
837
+
761838 struct platform_driver rockchip_vdpu2_driver = {
762839 .probe = vdpu_probe,
763840 .remove = vdpu_remove,
764841 .shutdown = vdpu_shutdown,
765842 .driver = {
766843 .name = VDPU2_DRIVER_NAME,
844
+ .pm = &vdpu_pm_ops,
767845 .of_match_table = of_match_ptr(mpp_vdpu2_dt_match),
768846 },
769847 };