From cc3ec45f39be1956698c9bc41b0c100e6320ece1 Mon Sep 17 00:00:00 2001
From: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
Date: Tue, 11 Aug 2020 11:27:34 -0700
Subject: [PATCH 1/2] lima: Add ZynqMP specific changes for Lima

This patch does following Xilinx specific modifications:
    1) Add zynqmp specific clock support for GP, PP0 and PP1.
    2) Update the device tree to use proper interrupt names.
    3) Do not initialize the regulators for zynqmp devices.

Signed-off-by: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
---
 arch/arm64/boot/dts/xilinx/zynqmp.dtsi |  2 +-
 drivers/gpu/drm/lima/lima_device.c     | 58 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/lima/lima_device.h     |  6 ++++
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/xilinx/zynqmp.dtsi b/arch/arm64/boot/dts/xilinx/zynqmp.dtsi
index b0b306e..97e7762 100644
--- a/arch/arm64/boot/dts/xilinx/zynqmp.dtsi
+++ b/arch/arm64/boot/dts/xilinx/zynqmp.dtsi
@@ -462,7 +462,7 @@
 			reg = <0x0 0xfd4b0000 0x0 0x10000>;
 			interrupt-parent = <&gic>;
 			interrupts = <0 132 4>, <0 132 4>, <0 132 4>, <0 132 4>, <0 132 4>, <0 132 4>;
-			interrupt-names = "IRQGP", "IRQGPMMU", "IRQPP0", "IRQPPMMU0", "IRQPP1", "IRQPPMMU1";
+			interrupt-names = "gp", "gpmmu", "pp0", "ppmmu0", "pp1", "ppmmu1";
 			clock-names = "gpu", "gpu_pp0", "gpu_pp1";
 			power-domains = <&zynqmp_firmware PD_GPU>;
 		};
diff --git a/drivers/gpu/drm/lima/lima_device.c b/drivers/gpu/drm/lima/lima_device.c
index d86b8d8..cecb210 100644
--- a/drivers/gpu/drm/lima/lima_device.c
+++ b/drivers/gpu/drm/lima/lima_device.c
@@ -79,6 +79,50 @@ const char *lima_ip_name(struct lima_ip *ip)
 
 static int lima_clk_init(struct lima_device *dev)
 {
+#if defined(CONFIG_ARCH_ZYNQMP)
+	int err = 0;
+
+	dev->clk_gpu_gp = devm_clk_get(dev->dev, "gpu");
+	if (IS_ERR(dev->clk_gpu_gp))
+		return PTR_ERR(dev->clk_gpu_gp);
+
+	dev->clk_gpu_pp0 = devm_clk_get(dev->dev, "gpu_pp0");
+	if (IS_ERR(dev->clk_gpu_pp0))
+		return PTR_ERR(dev->clk_gpu_pp0);
+
+	dev->clk_gpu_pp1 = devm_clk_get(dev->dev, "gpu_pp1");
+	if (IS_ERR(dev->clk_gpu_pp1))
+		return PTR_ERR(dev->clk_gpu_pp1);
+
+	err = clk_prepare_enable(dev->clk_gpu_gp);
+	if (err) {
+		dev_err(dev->dev, "Could not enable clock for GP %d\n", err);
+		goto error_out0;
+	}
+
+	err = clk_prepare_enable(dev->clk_gpu_pp0);
+	if (err) {
+		dev_err(dev->dev, "Could not enable clock for PP0 %d\n", err);
+		goto error_out1;
+	}
+
+	err = clk_prepare_enable(dev->clk_gpu_pp1);
+	if (err) {
+		dev_err(dev->dev, "Could not enable clock for PP1 %d\n", err);
+		goto error_out2;
+	}
+
+	return 0;
+
+error_out2:
+	clk_disable_unprepare(dev->clk_gpu_pp1);
+error_out1:
+	clk_disable_unprepare(dev->clk_gpu_pp0);
+error_out0:
+	clk_disable_unprepare(dev->clk_gpu_gp);
+
+	return err;
+#else
 	int err;
 
 	dev->clk_bus = devm_clk_get(dev->dev, "bus");
@@ -128,14 +172,21 @@ static int lima_clk_init(struct lima_device *dev)
 error_out0:
 	clk_disable_unprepare(dev->clk_bus);
 	return err;
+#endif
 }
 
 static void lima_clk_fini(struct lima_device *dev)
 {
+#if defined(CONFIG_ARCH_ZYNQMP)
+	clk_disable_unprepare(dev->clk_gpu_pp1);
+	clk_disable_unprepare(dev->clk_gpu_pp0);
+	clk_disable_unprepare(dev->clk_gpu_gp);
+#else
 	if (dev->reset != NULL)
 		reset_control_assert(dev->reset);
 	clk_disable_unprepare(dev->clk_gpu);
 	clk_disable_unprepare(dev->clk_bus);
+#endif
 }
 
 static int lima_regulator_init(struct lima_device *dev)
@@ -298,9 +349,12 @@ int lima_device_init(struct lima_device *ldev)
 	if (err)
 		return err;
 
+#if defined(CONFIG_ARCH_ZYNQMP)
+#else
 	err = lima_regulator_init(ldev);
 	if (err)
 		goto err_out0;
+#endif
 
 	ldev->empty_vm = lima_vm_create(ldev);
 	if (!ldev->empty_vm) {
@@ -343,8 +397,12 @@ int lima_device_init(struct lima_device *ldev)
 	if (err)
 		goto err_out5;
 
+#if defined(CONFIG_ARCH_ZYNQMP)
+	dev_info(ldev->dev, "mod rate = %lu", clk_get_rate(ldev->clk_gpu_gp));
+#else
 	dev_info(ldev->dev, "bus rate = %lu\n", clk_get_rate(ldev->clk_bus));
 	dev_info(ldev->dev, "mod rate = %lu", clk_get_rate(ldev->clk_gpu));
+#endif
 
 	return 0;
 
diff --git a/drivers/gpu/drm/lima/lima_device.h b/drivers/gpu/drm/lima/lima_device.h
index 31158d8..fad2b15 100644
--- a/drivers/gpu/drm/lima/lima_device.h
+++ b/drivers/gpu/drm/lima/lima_device.h
@@ -80,8 +80,14 @@ struct lima_device {
 	int num_pp;
 
 	void __iomem *iomem;
+#if defined(CONFIG_ARCH_ZYNQMP)
+	struct clk *clk_gpu_gp;
+	struct clk *clk_gpu_pp0;
+	struct clk *clk_gpu_pp1;
+#else
 	struct clk *clk_bus;
 	struct clk *clk_gpu;
+#endif
 	struct reset_control *reset;
 	struct regulator *regulator;
 
-- 
2.7.4

