hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/video/rockchip/mpp/mpp_vdpp.c
....@@ -18,6 +18,8 @@
1818 #include <linux/uaccess.h>
1919 #include <linux/regmap.h>
2020 #include <linux/proc_fs.h>
21
+#include <linux/mfd/syscon.h>
22
+#include <linux/rockchip/cpu.h>
2123 #include <soc/rockchip/pm_domains.h>
2224
2325 #include "mpp_debug.h"
....@@ -27,6 +29,8 @@
2729 #define VDPP_DRIVER_NAME "mpp_vdpp"
2830
2931 #define VDPP_SESSION_MAX_BUFFERS 15
32
+#define VDPP_REG_WORK_MODE 0x0008
33
+#define VDPP_REG_VDPP_MODE BIT(1)
3034
3135 #define to_vdpp_info(info) \
3236 container_of(info, struct vdpp_hw_info, hw)
....@@ -87,6 +91,7 @@
8791 struct reset_control *rst_s;
8892 /* for zme */
8993 void __iomem *zme_base;
94
+ struct regmap *grf;
9095 };
9196
9297 static struct vdpp_hw_info vdpp_v1_hw_info = {
....@@ -332,6 +337,9 @@
332337 }
333338 }
334339
340
+ /* flush tlb before starting hardware */
341
+ mpp_iommu_flush_tlb(mpp->iommu_info);
342
+
335343 /* init current task */
336344 mpp->cur_task = mpp_task;
337345 /* Flush the register before the start the device */
....@@ -474,6 +482,8 @@
474482 int ret;
475483 struct vdpp_dev *vdpp = to_vdpp_dev(mpp);
476484
485
+ mpp->grf_info = &mpp->srv->grf_infos[MPP_DRIVER_VDPP];
486
+
477487 /* Get clock info from dtsi */
478488 ret = mpp_get_clk_info(mpp, &vdpp->aclk_info, "aclk");
479489 if (ret)
....@@ -546,12 +556,18 @@
546556 {
547557 struct vdpp_dev *vdpp = to_vdpp_dev(mpp);
548558 struct vdpp_hw_info *hw_info = vdpp->hw_info;
559
+ u32 work_mode = mpp_read(mpp, VDPP_REG_WORK_MODE);
549560
561
+ if (!(work_mode & VDPP_REG_VDPP_MODE))
562
+ return IRQ_NONE;
550563 mpp->irq_status = mpp_read(mpp, hw_info->int_sta_base);
551564 if (!(mpp->irq_status & hw_info->int_mask))
552565 return IRQ_NONE;
553566 mpp_write(mpp, hw_info->int_en_base, 0);
554567 mpp_write(mpp, hw_info->int_clr_base, mpp->irq_status);
568
+
569
+ /* ensure hardware is being off status */
570
+ mpp_write(mpp, hw_info->start_base, 0);
555571
556572 return IRQ_WAKE_THREAD;
557573 }
....@@ -590,7 +606,7 @@
590606 mpp_debug(DEBUG_RESET, "reset in\n");
591607
592608 /* Don't skip this or iommu won't work after reset */
593
- rockchip_pmu_idle_request(mpp->dev, true);
609
+ mpp_pmu_idle_request(mpp, true);
594610 mpp_safe_reset(vdpp->rst_a);
595611 mpp_safe_reset(vdpp->rst_h);
596612 mpp_safe_reset(vdpp->rst_s);
....@@ -598,7 +614,7 @@
598614 mpp_safe_unreset(vdpp->rst_a);
599615 mpp_safe_unreset(vdpp->rst_h);
600616 mpp_safe_unreset(vdpp->rst_s);
601
- rockchip_pmu_idle_request(mpp->dev, false);
617
+ mpp_pmu_idle_request(mpp, false);
602618
603619 mpp_debug(DEBUG_RESET, "reset out\n");
604620 }
....@@ -617,14 +633,18 @@
617633 mpp_write(mpp, hw_info->cfg_base, hw_info->bit_rst_en);
618634 ret = readl_relaxed_poll_timeout(mpp->reg_base + hw_info->rst_sta_base,
619635 rst_status,
620
- !(rst_status & hw_info->bit_rst_done),
621
- 0, 2);
636
+ rst_status & hw_info->bit_rst_done,
637
+ 0, 5);
622638 if (ret) {
623639 mpp_err("soft reset timeout, use cru reset\n");
624640 return _vdpp_reset(mpp, vdpp);
625641 }
626642
627643 mpp_write(mpp, hw_info->rst_sta_base, 0);
644
+
645
+ /* ensure hardware is being off status */
646
+ mpp_write(mpp, hw_info->start_base, 0);
647
+
628648
629649 return 0;
630650 }
....@@ -710,6 +730,7 @@
710730 dev_err(dev, "register interrupter runtime failed\n");
711731 return -EINVAL;
712732 }
733
+
713734 mpp->session_max_buffers = VDPP_SESSION_MAX_BUFFERS;
714735 vdpp->hw_info = to_vdpp_info(mpp->var->hw_info);
715736 vdpp_procfs_init(mpp);
....@@ -751,12 +772,53 @@
751772 dev_err(dev, "wait total running time out\n");
752773 }
753774
775
+static int vdpp_runtime_suspend(struct device *dev)
776
+{
777
+ struct mpp_dev *mpp = dev_get_drvdata(dev);
778
+ struct mpp_grf_info *info = mpp->grf_info;
779
+ struct mpp_taskqueue *queue = mpp->queue;
780
+
781
+ if (cpu_is_rk3528() && info && info->mem_offset) {
782
+ mutex_lock(&queue->ref_lock);
783
+ if (!atomic_dec_if_positive(&queue->runtime_cnt)) {
784
+ regmap_write(info->grf, info->mem_offset,
785
+ info->val_mem_off);
786
+ }
787
+ mutex_unlock(&queue->ref_lock);
788
+ }
789
+
790
+ return 0;
791
+}
792
+
793
+static int vdpp_runtime_resume(struct device *dev)
794
+{
795
+ struct mpp_dev *mpp = dev_get_drvdata(dev);
796
+ struct mpp_grf_info *info = mpp->grf_info;
797
+ struct mpp_taskqueue *queue = mpp->queue;
798
+
799
+ if (cpu_is_rk3528() && info && info->mem_offset) {
800
+ mutex_lock(&queue->ref_lock);
801
+ regmap_write(info->grf, info->mem_offset,
802
+ info->val_mem_on);
803
+ atomic_inc(&queue->runtime_cnt);
804
+ mutex_unlock(&queue->ref_lock);
805
+ }
806
+
807
+ return 0;
808
+}
809
+
810
+static const struct dev_pm_ops vdpp_pm_ops = {
811
+ .runtime_suspend = vdpp_runtime_suspend,
812
+ .runtime_resume = vdpp_runtime_resume,
813
+};
814
+
754815 struct platform_driver rockchip_vdpp_driver = {
755816 .probe = vdpp_probe,
756817 .remove = vdpp_remove,
757818 .shutdown = vdpp_shutdown,
758819 .driver = {
759820 .name = VDPP_DRIVER_NAME,
821
+ .pm = &vdpp_pm_ops,
760822 .of_match_table = of_match_ptr(mpp_vdpp_dt_match),
761823 },
762824 };