Skip to contentSkip to conversation

drm/etnaviv: add optional reset support

PATCH Superseded LECOINTRE Philippe 3 participants 3 messages Dec 6, 2024 – Dec 10, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 drm/etnaviv: add optional reset support

Add optional reset support which is mentioned in vivante,gc.yaml to allow the driver to work on SoCs whose reset signal is asserted by default

---
v3:
- Rework to match initial feedback

---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 37 +++++++++++++++++++++++++++
 drivers/gpu/drm/etnaviv/etnaviv_gpu.h |  1 +
 2 files changed, 38 insertions(+)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +37 -0
index 2d4c112ce033..1961ebac315a 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 #include <linux/thermal.h>
 
 #include "etnaviv_cmdbuf.h"
@@ -172,6 +173,25 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
 	return 0;
 }
 
+static int etnaviv_gpu_reset_deassert(struct etnaviv_gpu *gpu)
+{
+	int ret;
+
+	/* 32 core clock cycles (slowest clock) required before deassertion */
+	/* 1 microsecond might match all implementations without computation */
+	usleep_range(1, 2);
+
+	ret = reset_control_deassert(gpu->rst);
+	if (ret)
+		return ret;
+
+	/* 128 core clock cycles (slowest clock) required before any activity on AHB */
+	/* 1 microsecond might match all implementations without computation */
+	usleep_range(1, 2);
+
+	return 0;
+}
+
 static inline bool etnaviv_is_model_rev(struct etnaviv_gpu *gpu, u32 model, u32 revision)
 {
 	return gpu->identity.model == model &&
@@ -799,6 +819,12 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
 		goto pm_put;
 	}
 
+	ret = etnaviv_gpu_reset_deassert(gpu);
+	if (ret) {
+		dev_err(gpu->dev, "GPU reset deassert failed\n");
+		goto fail;
+	}
+
 	etnaviv_hw_identify(gpu);
 
 	if (gpu->identity.model == 0) {
@@ -1860,6 +1886,17 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
 	if (IS_ERR(gpu->mmio))
 		return PTR_ERR(gpu->mmio);
 
+
+	/* Get Reset: */
+	gpu->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(gpu->rst))
+		return dev_err_probe(dev, PTR_ERR(gpu->rst),
+				     "failed to get reset\n");
+
+	err = reset_control_assert(gpu->rst);
+	if (err)
+		return dev_err_probe(dev, err, "failed to assert reset\n");
+
 	/* Get Interrupt: */
 	gpu->irq = platform_get_irq(pdev, 0);
 	if (gpu->irq < 0)
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +1 -0
index 4d8a7d48ade3..0985ea548b82 100644
@@ -158,6 +158,7 @@ struct etnaviv_gpu {
 	struct clk *clk_reg;
 	struct clk *clk_core;
 	struct clk *clk_shader;
+	struct reset_control *rst;
 
 	unsigned int freq_scale;
 	unsigned int fe_waitcycles;
Signature · 1 line
2.19.1
maintainer
#1 lore raw

Hi Philippe,

Am Freitag, dem 06.12.2024 um 17:00 +0000 schrieb LECOINTRE Philippe:

Quoted 5 lines

Add optional reset support which is mentioned in vivante,gc.yaml to allow the driver to work on SoCs whose reset signal is asserted by default

Upstream usually doesn't put much weight on such internal reviews. No harm here, as the patch is simple enough and I do review it before applying. Just as a hint for the future: if you want maintainers to take such reviews into account for speeding up the adoption of a patch, do the review on the public mailing lists.

Quoted 21 lines

---
v3:
- Rework to match initial feedback

---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 37 +++++++++++++++++++++++++++
 drivers/gpu/drm/etnaviv/etnaviv_gpu.h |  1 +
 2 files changed, 38 insertions(+)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +1 -0
index 2d4c112ce033..1961ebac315a 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 #include <linux/thermal.h>
 
 #include "etnaviv_cmdbuf.h"

drivers/gpu/drm/etnaviv/etnaviv_gpu.c int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value) · line 181

Quoted 9 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +6 -0
@@ -172,6 +173,25 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
 	return 0;
 }
 
+static int etnaviv_gpu_reset_deassert(struct etnaviv_gpu *gpu)
+{
+	int ret;
+
+	/* 32 core clock cycles (slowest clock) required before deassertion */
+	/* 1 microsecond might match all implementations without computation */

I missed to mention this before, as I was focused on the technical
side: this is not the multiline comment style used in the kernel/etnaviv. Please use the same style as already found in this file.

Quoted 52 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +30 -0
+	usleep_range(1, 2);
+
+	ret = reset_control_deassert(gpu->rst);
+	if (ret)
+		return ret;
+
+	/* 128 core clock cycles (slowest clock) required before any activity on AHB */
+	/* 1 microsecond might match all implementations without computation */
+	usleep_range(1, 2);
+
+	return 0;
+}
+
 static inline bool etnaviv_is_model_rev(struct etnaviv_gpu *gpu, u32 model, u32 revision)
 {
 	return gpu->identity.model == model &&
@@ -799,6 +819,12 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
 		goto pm_put;
 	}
 
+	ret = etnaviv_gpu_reset_deassert(gpu);
+	if (ret) {
+		dev_err(gpu->dev, "GPU reset deassert failed\n");
+		goto fail;
+	}
+
 	etnaviv_hw_identify(gpu);
 
 	if (gpu->identity.model == 0) {
@@ -1860,6 +1886,17 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
 	if (IS_ERR(gpu->mmio))
 		return PTR_ERR(gpu->mmio);
 
+
+	/* Get Reset: */
+	gpu->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(gpu->rst))
+		return dev_err_probe(dev, PTR_ERR(gpu->rst),
+				     "failed to get reset\n");
+
+	err = reset_control_assert(gpu->rst);
+	if (err)
+		return dev_err_probe(dev, err, "failed to assert reset\n");
+
 	/* Get Interrupt: */
 	gpu->irq = platform_get_irq(pdev, 0);
 	if (gpu->irq < 0)
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +0 -0
index 4d8a7d48ade3..0985ea548b82 100644

drivers/gpu/drm/etnaviv/etnaviv_gpu.h struct etnaviv_gpu { · line 161

Quoted 4 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +1 -0
@@ -158,6 +158,7 @@ struct etnaviv_gpu {
 	struct clk *clk_reg;
 	struct clk *clk_core;
 	struct clk *clk_shader;
+	struct reset_control *rst;

This needs a forward declaration of struct reset_control in the header, to avoid build failures if headers are included in a different order. Please put them right next to the existing ones for regulator and clk.

Other than that, patch looks good to me.

Regards,
Lucas

Quoted 3 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +0 -0
 	unsigned int freq_scale;
 	unsigned int fe_waitcycles;
#2 lore raw

Hi Lucas,

Quoted 20 lines

-----Message d'origine-----
De : Lucas Stach <[email protected]>
Envoyé : lundi 9 décembre 2024 11:07
À : LECOINTRE Philippe <[email protected]>; Russell King <[email protected]>; Christian Gmeiner <[email protected]>
Cc : David Airlie <[email protected]>; Simona Vetter <[email protected]>; [email protected]; [email protected]; linux- [email protected]; LENAIN Simon <[email protected]>; BARBEAU Etienne <[email protected]>; LEJEUNE Sebastien <[email protected]>
Objet : Re: [PATCH v3] drm/etnaviv: add optional reset support

Hi Philippe,

Am Freitag, dem 06.12.2024 um 17:00 +0000 schrieb LECOINTRE Philippe:

Quoted 4 lines

Add optional reset support which is mentioned in vivante,gc.yaml to allow the driver to work on SoCs whose reset signal is asserted by default

Quoted 9 lines
Quoted 2 lines

Upstream usually doesn't put much weight on such internal reviews. No harm here, as the patch is simple enough and I do review it before applying. Just as a hint for the future: if you want maintainers to take such reviews into account for speeding up the adoption of a patch, do the review on the public mailing lists.

Do you think an "Acked-by:" is better for our internal review ? Regards,
Simon

Quoted 114 lines
Quoted 6 lines

---
v3:
- Rework to match initial feedback

---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 37

+++++++++++++++++++++++++++

drivers/gpu/drm/etnaviv/etnaviv_gpu.h |

drivers/gpu/drm/etnaviv/etnaviv_gpu.c int etnaviv_gpu_get_param(struct etnaviv_gpu

Quoted 17 lines

1 +

 2 files changed, 38 insertions(+)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +1 -0
index 2d4c112ce033..1961ebac315a 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 #include <linux/thermal.h>
 
 #include "etnaviv_cmdbuf.h"
@@ -172,6 +173,25 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu

*gpu, u32 param, u64 *value)

drivers/gpu/drm/etnaviv/etnaviv_gpu.c int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)

Quoted 8 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -0
 	return 0;
 }
 
+static int etnaviv_gpu_reset_deassert(struct etnaviv_gpu *gpu) {
+	int ret;
+
+	/* 32 core clock cycles (slowest clock) required before deassertion */
+	/* 1 microsecond might match all implementations without

computation

drivers/gpu/drm/etnaviv/etnaviv_gpu.c int etnaviv_gpu_get_param(struct etnaviv_gpu · line 181

Quoted 1 line
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +1 -0
+*/

I missed to mention this before, as I was focused on the technical
side: this is not the multiline comment style used in the kernel/etnaviv. Please use the same style as already found in this file.

drivers/gpu/drm/etnaviv/etnaviv_gpu.c int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)

Quoted 7 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +7 -0
+	usleep_range(1, 2);
+
+	ret = reset_control_deassert(gpu->rst);
+	if (ret)
+		return ret;
+
+	/* 128 core clock cycles (slowest clock) required before any activity

on AHB */

drivers/gpu/drm/etnaviv/etnaviv_gpu.c int etnaviv_gpu_get_param(struct etnaviv_gpu · line 189

Quoted 1 line
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +1 -0
+	/* 1 microsecond might match all implementations without

computation */

drivers/gpu/drm/etnaviv/etnaviv_gpu.c static int etnaviv_gpu_platform_probe(struct

Quoted 22 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -0
+	usleep_range(1, 2);
+
+	return 0;
+}
+
 static inline bool etnaviv_is_model_rev(struct etnaviv_gpu *gpu, u32
 model, u32 revision)  {
 	return gpu->identity.model == model && @@ -799,6 +819,12 @@ int

etnaviv_gpu_init(struct etnaviv_gpu *gpu)

drivers/gpu/drm/etnaviv/etnaviv_gpu.c +6 -0
 		goto pm_put;
 	}
 
+	ret = etnaviv_gpu_reset_deassert(gpu);
+	if (ret) {
+		dev_err(gpu->dev, "GPU reset deassert failed\n");
+		goto fail;
+	}
+
 	etnaviv_hw_identify(gpu);
 
 	if (gpu->identity.model == 0) {
@@ -1860,6 +1886,17 @@ static int etnaviv_gpu_platform_probe(struct

platform_device *pdev)

Quoted 24 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +11 -0
 	if (IS_ERR(gpu->mmio))
 		return PTR_ERR(gpu->mmio);
 
+
+	/* Get Reset: */
+	gpu->rst = devm_reset_control_get_optional_exclusive(&pdev-
 dev, NULL);
+	if (IS_ERR(gpu->rst))
+		return dev_err_probe(dev, PTR_ERR(gpu->rst),
+				     "failed to get reset\n");
+
+	err = reset_control_assert(gpu->rst);
+	if (err)
+		return dev_err_probe(dev, err, "failed to assert reset\n");
+
 	/* Get Interrupt: */
 	gpu->irq = platform_get_irq(pdev, 0);
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +0 -0
 	if (gpu->irq < 0)
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +0 -0
index 4d8a7d48ade3..0985ea548b82 100644

drivers/gpu/drm/etnaviv/etnaviv_gpu.h struct etnaviv_gpu { · line 161

Quoted 4 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +1 -0
@@ -158,6 +158,7 @@ struct etnaviv_gpu {
 	struct clk *clk_reg;
 	struct clk *clk_core;
 	struct clk *clk_shader;
+	struct reset_control *rst;

This needs a forward declaration of struct reset_control in the header, to avoid build failures if headers are included in a different order. Please put them right next to the existing ones for regulator and clk.

Other than that, patch looks good to me.

Regards,
Lucas

Quoted 3 lines
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +0 -0
 	unsigned int freq_scale;
 	unsigned int fe_waitcycles;