forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c
....@@ -31,6 +31,7 @@
3131 #include <linux/clk.h>
3232 #include <linux/regulator/consumer.h>
3333 #include <linux/mali/mali_utgard.h>
34
+#include <linux/pm_runtime.h>
3435 #include <soc/rockchip/rockchip_opp_select.h>
3536
3637 #include "mali_kernel_common.h"
....@@ -177,11 +178,7 @@
177178
178179 static int mali_open(struct inode *inode, struct file *filp);
179180 static int mali_release(struct inode *inode, struct file *filp);
180
-#ifdef HAVE_UNLOCKED_IOCTL
181181 static long mali_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
182
-#else
183
-static int mali_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
184
-#endif
185182
186183 static int mali_probe(struct platform_device *pdev);
187184 static int mali_remove(struct platform_device *pdev);
....@@ -275,11 +272,7 @@
275272 .owner = THIS_MODULE,
276273 .open = mali_open,
277274 .release = mali_release,
278
-#ifdef HAVE_UNLOCKED_IOCTL
279275 .unlocked_ioctl = mali_ioctl,
280
-#else
281
- .ioctl = mali_ioctl,
282
-#endif
283276 .compat_ioctl = mali_ioctl,
284277 .mmap = mali_mmap
285278 };
....@@ -521,6 +514,7 @@
521514 int err;
522515 #ifdef CONFIG_MALI_DEVFREQ
523516 struct mali_device *mdev;
517
+ const char *name = "mali";
524518 #endif
525519
526520 MALI_DEBUG_PRINT(2, ("mali_probe(): Called for platform device %s\n", pdev->name));
....@@ -575,25 +569,38 @@
575569 mdev->regulator = NULL;
576570 /* Allow probe to continue without regulator */
577571 }
572
+ if (mdev->regulator) {
573
+ mdev->opp_table = dev_pm_opp_set_regulators(mdev->dev, &name, 1);
574
+ if (IS_ERR(mdev->opp_table)) {
575
+ mdev->opp_table = NULL;
576
+ MALI_DEBUG_PRINT(2, ("Continuing without opp regulator\n"));
577
+ }
578
+ }
578579 #endif /* LINUX_VERSION_CODE >= 3, 12, 0 */
580
+
581
+ mdev->num_clks = devm_clk_bulk_get_all(mdev->dev, &mdev->clks);
582
+ if (mdev->num_clks < 1) {
583
+ MALI_DEBUG_PRINT(2, ("Continuing without Mali clock control\n"));
584
+ mdev->num_clks = 0;
585
+ mdev->clock = NULL;
586
+ } else {
587
+ /* Get "clk_mali" in the device tree for gpu dvfs */
588
+ mdev->clock = clk_get(mdev->dev, "clk_mali");
589
+ if (IS_ERR_OR_NULL(mdev->clock)) {
590
+ MALI_DEBUG_PRINT(2, ("Continuing without Mali dvfs clock\n"));
591
+ /* Allow probe to continue without clock. */
592
+ mdev->clock = NULL;
593
+ }
594
+ }
595
+ err = clk_bulk_prepare_enable(mdev->num_clks, mdev->clks);
596
+ if (err) {
597
+ MALI_PRINT_ERROR(("Failed to prepare clock (%d)\n", err));
598
+ goto clock_prepare_failed;
599
+ }
579600
580601 err = rk_platform_init_opp_table(mdev->dev);
581602 if (err)
582603 MALI_DEBUG_PRINT(3, ("Failed to init_opp_table\n"));
583
-
584
- /* Need to name the gpu clock "clk_mali" in the device tree */
585
- mdev->clock = clk_get(mdev->dev, "clk_mali");
586
- if (IS_ERR_OR_NULL(mdev->clock)) {
587
- MALI_DEBUG_PRINT(2, ("Continuing without Mali clock control\n"));
588
- mdev->clock = NULL;
589
- /* Allow probe to continue without clock. */
590
- } else {
591
- err = clk_prepare(mdev->clock);
592
- if (err) {
593
- MALI_PRINT_ERROR(("Failed to prepare clock (%d)\n", err));
594
- goto clock_prepare_failed;
595
- }
596
- }
597604
598605 /* initilize pm metrics related */
599606 if (mali_pm_metrics_init(mdev) < 0) {
....@@ -605,6 +612,7 @@
605612 MALI_DEBUG_PRINT(2, ("mali devfreq init failed\n"));
606613 goto devfreq_init_failed;
607614 }
615
+ clk_bulk_disable(mdev->num_clks, mdev->clks);
608616 #endif
609617
610618
....@@ -640,8 +648,9 @@
640648 devfreq_init_failed:
641649 mali_pm_metrics_term(mdev);
642650 pm_metrics_init_failed:
643
- clk_unprepare(mdev->clock);
651
+ clk_bulk_disable_unprepare(mdev->num_clks, mdev->clks);
644652 clock_prepare_failed:
653
+ clk_bulk_put(mdev->num_clks, mdev->clks);
645654 clk_put(mdev->clock);
646655 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_OF) \
647656 && defined(CONFIG_PM_OPP)
....@@ -651,6 +660,7 @@
651660 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \
652661 && defined(CONFIG_REGULATOR)
653662 regulator_put(mdev->regulator);
663
+ dev_pm_opp_put_regulators(mdev->opp_table);
654664 #endif /* LINUX_VERSION_CODE >= 3, 12, 0 */
655665 mali_device_free(mdev);
656666 #endif
....@@ -680,10 +690,12 @@
680690 mali_pm_metrics_term(mdev);
681691
682692 if (mdev->clock) {
683
- clk_unprepare(mdev->clock);
684693 clk_put(mdev->clock);
685694 mdev->clock = NULL;
686695 }
696
+ clk_bulk_unprepare(mdev->num_clks, mdev->clks);
697
+ clk_bulk_put(mdev->num_clks, mdev->clks);
698
+
687699 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_OF) \
688700 && defined(CONFIG_PM_OPP)
689701 dev_pm_opp_of_remove_table(mdev->dev);
....@@ -692,6 +704,7 @@
692704 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \
693705 && defined(CONFIG_REGULATOR)
694706 regulator_put(mdev->regulator);
707
+ dev_pm_opp_put_regulators(mdev->opp_table);
695708 #endif /* LINUX_VERSION_CODE >= 3, 12, 0 */
696709 mali_device_free(mdev);
697710 #endif
....@@ -733,6 +746,7 @@
733746 return -ENODEV;
734747 #endif
735748
749
+ pm_runtime_force_suspend(dev);
736750 #if defined(CONFIG_MALI_DEVFREQ) && \
737751 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
738752 devfreq_suspend_device(mdev->devfreq);
....@@ -777,6 +791,7 @@
777791 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
778792 devfreq_resume_device(mdev->devfreq);
779793 #endif
794
+ pm_runtime_force_resume(dev);
780795
781796 return 0;
782797 }
....@@ -917,19 +932,10 @@
917932 }
918933 }
919934
920
-#ifdef HAVE_UNLOCKED_IOCTL
921935 static long mali_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
922
-#else
923
-static int mali_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
924
-#endif
925936 {
926937 int err;
927938 struct mali_session_data *session_data;
928
-
929
-#ifndef HAVE_UNLOCKED_IOCTL
930
- /* inode not used */
931
- (void)inode;
932
-#endif
933939
934940 MALI_DEBUG_PRINT(7, ("Ioctl received 0x%08X 0x%08lX\n", cmd, arg));
935941