Thread (15 messages) 15 messages, 2 authors, 2021-04-01

[PATCH v3 6/9] media: hantro: add fallback handling for single irq/clk

flat view
STALE2018d REVIEWED: 3 (3M)

From: Emil Velikov <hidden>
Date: 2021-03-31 17:36:22
Also in: linux-media, linux-rockchip
Subsystem: media input infrastructure (v4l/dvb), staging subsystem, the rest · Maintainers: Mauro Carvalho Chehab, Greg Kroah-Hartman, Linus Torvalds

Revision v3 of 2 in this series; 1 review trailer.

Revisions (2)
  1. v3 current
  2. v4 [diff vs current]
From: Emil Velikov <redacted>

Currently the driver expects that each irq/clk will have a name
specified.

A valid point was raised by the DT maintainers - when there is a single
interrupt line or clock - the names are not needed.

This is handled:
 - clk - implicitly - ultimately we'll call of_clk_get_hw(..., 0, NULL
   which will get the first clock from the pmc
 - irq - explicitly - platform_get_irq(..., 0)

To gracefully handle potential bugs, add respective WARN_ON() if we're
having more than one irq/clk, yet lacking the respective names.

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Suggested-by: Ezequiel Garcia <redacted>
Signed-off-by: Emil Velikov <redacted>
---
v3
 - New patch
---
 drivers/staging/media/hantro/hantro_drv.c | 24 +++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index e5f200e64993..d1294eb9cd07 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -752,8 +752,16 @@ static int hantro_probe(struct platform_device *pdev)
 	if (!vpu->clocks)
 		return -ENOMEM;
 
-	for (i = 0; i < vpu->variant->num_clocks; i++)
+	for (i = 0; i < vpu->variant->num_clocks; i++) {
 		vpu->clocks[i].id = vpu->variant->clk_names[i];
+
+		/*
+		 * Warn and refuse to load if the driver has multiple clocks,
+		 * yet they are lacking the respective names.
+		 */
+		if (WARN_ON(!vpu->variant->clk_names[i] && i))
+			return -ENXIO;
+	}
 	ret = devm_clk_bulk_get(&pdev->dev, vpu->variant->num_clocks,
 				vpu->clocks);
 	if (ret)
@@ -791,7 +799,19 @@ static int hantro_probe(struct platform_device *pdev)
 		if (!vpu->variant->irqs[i].handler)
 			continue;
 
-		irq = platform_get_irq_byname(vpu->pdev, irq_name);
+		/*
+		 * If the driver has a single IRQ, chances are there will be no
+		 * actual name in the DT bindings.
+		 */
+		if (!irq_name) {
+			if (WARN_ON(i))
+				return -ENXIO;
+
+			irq_name = "default";
+			irq = platform_get_irq(vpu->pdev, 0);
+		} else {
+			irq = platform_get_irq_byname(vpu->pdev, irq_name);
+		}
 		if (irq <= 0)
 			return -ENXIO;
 
-- 
2.31.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help