hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
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"
....@@ -521,6 +522,7 @@
521522 int err;
522523 #ifdef CONFIG_MALI_DEVFREQ
523524 struct mali_device *mdev;
525
+ const char *name = "mali";
524526 #endif
525527
526528 MALI_DEBUG_PRINT(2, ("mali_probe(): Called for platform device %s\n", pdev->name));
....@@ -575,25 +577,38 @@
575577 mdev->regulator = NULL;
576578 /* Allow probe to continue without regulator */
577579 }
580
+ if (mdev->regulator) {
581
+ mdev->opp_table = dev_pm_opp_set_regulators(mdev->dev, &name, 1);
582
+ if (IS_ERR(mdev->opp_table)) {
583
+ mdev->opp_table = NULL;
584
+ MALI_DEBUG_PRINT(2, ("Continuing without opp regulator\n"));
585
+ }
586
+ }
578587 #endif /* LINUX_VERSION_CODE >= 3, 12, 0 */
588
+
589
+ mdev->num_clks = devm_clk_bulk_get_all(mdev->dev, &mdev->clks);
590
+ if (mdev->num_clks < 1) {
591
+ MALI_DEBUG_PRINT(2, ("Continuing without Mali clock control\n"));
592
+ mdev->num_clks = 0;
593
+ mdev->clock = NULL;
594
+ } else {
595
+ /* Get "clk_mali" in the device tree for gpu dvfs */
596
+ mdev->clock = clk_get(mdev->dev, "clk_mali");
597
+ if (IS_ERR_OR_NULL(mdev->clock)) {
598
+ MALI_DEBUG_PRINT(2, ("Continuing without Mali dvfs clock\n"));
599
+ /* Allow probe to continue without clock. */
600
+ mdev->clock = NULL;
601
+ }
602
+ }
603
+ err = clk_bulk_prepare_enable(mdev->num_clks, mdev->clks);
604
+ if (err) {
605
+ MALI_PRINT_ERROR(("Failed to prepare clock (%d)\n", err));
606
+ goto clock_prepare_failed;
607
+ }
579608
580609 err = rk_platform_init_opp_table(mdev->dev);
581610 if (err)
582611 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
- }
597612
598613 /* initilize pm metrics related */
599614 if (mali_pm_metrics_init(mdev) < 0) {
....@@ -605,6 +620,7 @@
605620 MALI_DEBUG_PRINT(2, ("mali devfreq init failed\n"));
606621 goto devfreq_init_failed;
607622 }
623
+ clk_bulk_disable(mdev->num_clks, mdev->clks);
608624 #endif
609625
610626
....@@ -640,8 +656,9 @@
640656 devfreq_init_failed:
641657 mali_pm_metrics_term(mdev);
642658 pm_metrics_init_failed:
643
- clk_unprepare(mdev->clock);
659
+ clk_bulk_disable_unprepare(mdev->num_clks, mdev->clks);
644660 clock_prepare_failed:
661
+ clk_bulk_put(mdev->num_clks, mdev->clks);
645662 clk_put(mdev->clock);
646663 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_OF) \
647664 && defined(CONFIG_PM_OPP)
....@@ -651,6 +668,7 @@
651668 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \
652669 && defined(CONFIG_REGULATOR)
653670 regulator_put(mdev->regulator);
671
+ dev_pm_opp_put_regulators(mdev->opp_table);
654672 #endif /* LINUX_VERSION_CODE >= 3, 12, 0 */
655673 mali_device_free(mdev);
656674 #endif
....@@ -680,10 +698,12 @@
680698 mali_pm_metrics_term(mdev);
681699
682700 if (mdev->clock) {
683
- clk_unprepare(mdev->clock);
684701 clk_put(mdev->clock);
685702 mdev->clock = NULL;
686703 }
704
+ clk_bulk_unprepare(mdev->num_clks, mdev->clks);
705
+ clk_bulk_put(mdev->num_clks, mdev->clks);
706
+
687707 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_OF) \
688708 && defined(CONFIG_PM_OPP)
689709 dev_pm_opp_of_remove_table(mdev->dev);
....@@ -692,6 +712,7 @@
692712 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \
693713 && defined(CONFIG_REGULATOR)
694714 regulator_put(mdev->regulator);
715
+ dev_pm_opp_put_regulators(mdev->opp_table);
695716 #endif /* LINUX_VERSION_CODE >= 3, 12, 0 */
696717 mali_device_free(mdev);
697718 #endif
....@@ -733,6 +754,7 @@
733754 return -ENODEV;
734755 #endif
735756
757
+ pm_runtime_force_suspend(dev);
736758 #if defined(CONFIG_MALI_DEVFREQ) && \
737759 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
738760 devfreq_suspend_device(mdev->devfreq);
....@@ -777,6 +799,7 @@
777799 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
778800 devfreq_resume_device(mdev->devfreq);
779801 #endif
802
+ pm_runtime_force_resume(dev);
780803
781804 return 0;
782805 }