Skip to contentSkip to conversation

drm/tegra: switch to using devm_gpiod_get_optional

PATCH In review Dmitry Torokhov 2 participants 3 messages Sep 15, 2019 – Sep 16, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/tegra: switch to using devm_gpiod_get_optional

We do not really need to use API that fetches GPIO data from an arbitrary device tree node, as we are dealing with device tree node assigned to the device structure. We can easily switch to devm_gpiod_get_optional() plus gpiod_set_consumer_name() and clean up the code.

Note this is part of efforts to get rid of [devm_]gpiod_get_from_of_node in drivers so that gpiolib can be cleaned up.

---
 drivers/gpu/drm/tegra/output.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/gpu/drm/tegra/output.c +7 -11
index bdcaa4c7168c..b4248125b844 100644
@@ -121,19 +121,15 @@ int tegra_output_probe(struct tegra_output *output)
 		of_node_put(ddc);
 	}
 
-	output->hpd_gpio = devm_gpiod_get_from_of_node(output->dev,
-						       output->of_node,
-						       "nvidia,hpd-gpio", 0,
-						       GPIOD_IN,
-						       "HDMI hotplug detect");
-	if (IS_ERR(output->hpd_gpio)) {
-		if (PTR_ERR(output->hpd_gpio) != -ENOENT)
-			return PTR_ERR(output->hpd_gpio);
-
-		output->hpd_gpio = NULL;
-	}
+	output->hpd_gpio = devm_gpiod_get_optional(output->dev,
+						   "nvidia,hpd", GPIOD_IN);
+	if (IS_ERR(output->hpd_gpio))
+		return PTR_ERR(output->hpd_gpio);
 
 	if (output->hpd_gpio) {
+		gpiod_set_consumer_name(output->hpd_gpio,
+					"HDMI hotplug detect");
+
 		err = gpiod_to_irq(output->hpd_gpio);
 		if (err < 0) {
 			dev_err(output->dev, "gpiod_to_irq(): %d\n", err);
Signature · 5 lines
2.23.0.237.gc6a4ce50a0-goog


-- 
Dmitry
#1 lore raw
Quoted 6 lines · Dmitry Torokhov

We do not really need to use API that fetches GPIO data from an arbitrary device tree node, as we are dealing with device tree node assigned to the device structure. We can easily switch to devm_gpiod_get_optional() plus gpiod_set_consumer_name() and clean up the code.

Quoted 7 lines

Note this is part of efforts to get rid of [devm_]gpiod_get_from_of_node in drivers so that gpiolib can be cleaned up.

---
 drivers/gpu/drm/tegra/output.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

We can't do that. There's a special case in rgb.c that sets output->of_node to something different than output->dev, so we actually need to pass the struct device_node * separately.

Thierry

Quoted 38 lines
drivers/gpu/drm/tegra/output.c +7 -11
index bdcaa4c7168c..b4248125b844 100644
@@ -121,19 +121,15 @@ int tegra_output_probe(struct tegra_output *output)
 		of_node_put(ddc);
 	}
 
-	output->hpd_gpio = devm_gpiod_get_from_of_node(output->dev,
-						       output->of_node,
-						       "nvidia,hpd-gpio", 0,
-						       GPIOD_IN,
-						       "HDMI hotplug detect");
-	if (IS_ERR(output->hpd_gpio)) {
-		if (PTR_ERR(output->hpd_gpio) != -ENOENT)
-			return PTR_ERR(output->hpd_gpio);
-
-		output->hpd_gpio = NULL;
-	}
+	output->hpd_gpio = devm_gpiod_get_optional(output->dev,
+						   "nvidia,hpd", GPIOD_IN);
+	if (IS_ERR(output->hpd_gpio))
+		return PTR_ERR(output->hpd_gpio);
 
 	if (output->hpd_gpio) {
+		gpiod_set_consumer_name(output->hpd_gpio,
+					"HDMI hotplug detect");
+
 		err = gpiod_to_irq(output->hpd_gpio);
 		if (err < 0) {
 			dev_err(output->dev, "gpiod_to_irq(): %d\n", err);
Signature · 5 lines
2.23.0.237.gc6a4ce50a0-goog


-- 
Dmitry
#2 lore raw
Quoted 10 lines · Thierry Reding
Quoted 9 lines · Dmitry Torokhov

We do not really need to use API that fetches GPIO data from an arbitrary device tree node, as we are dealing with device tree node assigned to the device structure. We can easily switch to devm_gpiod_get_optional() plus gpiod_set_consumer_name() and clean up the code.

Note this is part of efforts to get rid of [devm_]gpiod_get_from_of_node in drivers so that gpiolib can be cleaned up.

Quoted 8 lines
Quoted 4 lines
---
 drivers/gpu/drm/tegra/output.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

We can't do that. There's a special case in rgb.c that sets output->of_node to something different than output->dev, so we actually need to pass the struct device_node * separately.

Ugh, brainfart on my part. I totally read it is output->dev.of_node, similar to another driver I was looking at...

Please discard, there will be another patch changing devm_gpiod_get_from_of_node() to devm_fwnode_gpiod_get() once Linus merges this new GPIO method.

Thanks.

Signature · 1 line
Dmitry