Skip to contentSkip to conversation

gpio: tegra186: Add ACPI support

PATCH Superseded Akhil R 6 participants 19 messages Jun 17, 2021 – Aug 5, 2021

Subsystems (2)
lore
Share & tools
lore

Akhil R

author
#0 lore raw

PATCH 1/1 gpio: tegra186: Add ACPI support

From: Akhil Rajeev <[email protected]>

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---

 drivers/gpio/gpio-tegra186.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)
drivers/gpio/gpio-tegra186.c +28 -7
index 1bd9e44..c8051be 100644
@@ -5,6 +5,7 @@
  * Author: Thierry Reding <[email protected]>
  */
 
+#include <linux/acpi.h>
 #include <linux/gpio/driver.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
@@ -620,13 +621,18 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
+	if (has_acpi_companion(&pdev->dev)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+	} else {
+		gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
+		gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
+	}
 
-	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
 	if (IS_ERR(gpio->secure))
 		return PTR_ERR(gpio->secure);
 
-	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
 	if (IS_ERR(gpio->base))
 		return PTR_ERR(gpio->base);
 
@@ -690,11 +696,15 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
-	gpio->gpio.of_node = pdev->dev.of_node;
-	gpio->gpio.of_gpio_n_cells = 2;
-	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	if (!has_acpi_companion(&pdev->dev)) {
+		gpio->gpio.of_node = pdev->dev.of_node;
+		gpio->gpio.of_gpio_n_cells = 2;
+		gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+		gpio->intc.name = pdev->dev.of_node->name;
+	} else {
+		gpio->intc.name = gpio->soc->name;
+	}
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +928,21 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+#endif
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = ACPI_PTR(tegra186_gpio_acpi_match),
 	},
 	.probe = tegra186_gpio_probe,
 	.remove = tegra186_gpio_remove,
Signature · 1 line
2.7.4
#1 lore raw

Hi Akhil,

thanks for your patch!

Quoted 6 lines · Akhil R

From: Akhil Rajeev <[email protected]>

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

Please include ACPI GPIO maintainer Andy Shevchenko on subsequent posts, he is looking after ACPI handling in the GPIO subsystem and always provide excellent reviews. (Added on To:)

It looks OK to my untrained eye, but I don't know ACPI details and expected behaviours as well as Andy.

Yours,
Linus Walleij

#2 lore raw
In reply to Akhil R
Quoted 5 lines · Akhil R

From: Akhil Rajeev <[email protected]>

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

...

Quoted 1 line

+#include <linux/acpi.h>

It probably should be property.h, see below.

...

drivers/gpio/gpio-tegra186.c static int tegra186_gpio_probe(struct platform_device *pdev) · line 631

Quoted 7 lines
drivers/gpio/gpio-tegra186.c +7 -0
+       if (has_acpi_companion(&pdev->dev)) {
+               gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+               gpio->base = devm_platform_ioremap_resource(pdev, 1);
+       } else {
+               gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
+               gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
+       }

General comment here.
Can't we rather try named resources first and fallback to indexed ones? (Or other way around)

In this case you don't need to check for ACPI at all.

...

Quoted 1 line

+ .acpi_match_table = ACPI_PTR(tegra186_gpio_acpi_match),

You can drop ACPI_PTR() along with ugly ifdeffery.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

PATCH v2 1/1 gpio: tegra186: Add ACPI support

From: Akhil Rajeev <[email protected]>

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
v2 changes:
* fallback to find resource by index if name is not found to support ACPI.
* removed #ifdef and ACPI_PTR.
* Apparently, acpi.h is required to support changes @@ -690,11 +697,15

 drivers/gpio/gpio-tegra186.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)
drivers/gpio/gpio-tegra186.c +30 -10
index 1bd9e44..fa1295a 100644
@@ -5,6 +5,7 @@
  * Author: Thierry Reding <[email protected]>
  */
 
+#include <linux/acpi.h>
 #include <linux/gpio/driver.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
@@ -620,15 +621,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
-
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+
+	if (IS_ERR(gpio->secure) || IS_ERR(gpio->base)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+
+		if (IS_ERR(gpio->secure))
+			return PTR_ERR(gpio->secure);
+
+		if (IS_ERR(gpio->base))
+			return PTR_ERR(gpio->base);
+	}
 
 	err = platform_irq_count(pdev);
 	if (err < 0)
@@ -690,11 +697,15 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
-	gpio->gpio.of_node = pdev->dev.of_node;
-	gpio->gpio.of_gpio_n_cells = 2;
-	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	if (!has_acpi_companion(&pdev->dev)) {
+		gpio->gpio.of_node = pdev->dev.of_node;
+		gpio->gpio.of_gpio_n_cells = 2;
+		gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+		gpio->intc.name = pdev->dev.of_node->name;
+	} else {
+		gpio->intc.name = gpio->soc->name;
+	}
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +929,19 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = tegra186_gpio_acpi_match,
 	},
 	.probe = tegra186_gpio_probe,
 	.remove = tegra186_gpio_remove,
Signature · 1 line
2.7.4
#4 lore raw

On Fri, Jun 18, 2021 at 4:39 PM Akhil R <[email protected]> wrote:

Thanks for update, my comments below.

Quoted 1 line

From: Akhil Rajeev <[email protected]>

You need to fix your Git configuration so you won't have this header inside the commit message.

Quoted 2 lines

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

...

Quoted 1 line

+#include <linux/acpi.h>

property.h ? (see below)

...

Quoted 11 lines
drivers/gpio/gpio-tegra186.c +1 -6
-       gpio->soc = of_device_get_match_data(&pdev->dev);
+       gpio->soc = device_get_match_data(&pdev->dev);
 
        gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-       if (IS_ERR(gpio->secure))
-               return PTR_ERR(gpio->secure);
-
        gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-       if (IS_ERR(gpio->base))
-               return PTR_ERR(gpio->base);
 

drivers/gpio/gpio-tegra186.c static int tegra186_gpio_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/gpio/gpio-tegra186.c +10 -0
+       if (IS_ERR(gpio->secure) || IS_ERR(gpio->base)) {
+               gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+               gpio->base = devm_platform_ioremap_resource(pdev, 1);
+
+               if (IS_ERR(gpio->secure))
+                       return PTR_ERR(gpio->secure);
+
+               if (IS_ERR(gpio->base))
+                       return PTR_ERR(gpio->base);
+       }

What about doing like

      gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
      if (IS_ERR(gpio->secure))
              gpio->secure = devm_platform_ioremap_resource(pdev, 0);
      if (IS_ERR(gpio->secure))
              return PTR_ERR(gpio->secure);

and similar for gpio->base?

...

Quoted 4 lines
drivers/gpio/gpio-tegra186.c +0 -3
-       gpio->gpio.of_node = pdev->dev.of_node;
-       gpio->gpio.of_gpio_n_cells = 2;
-       gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
 

drivers/gpio/gpio-tegra186.c static int tegra186_gpio_probe(struct platform_device *pdev) · line 708

Quoted 10 lines
drivers/gpio/gpio-tegra186.c +8 -1
-       gpio->intc.name = pdev->dev.of_node->name;
 
+       if (!has_acpi_companion(&pdev->dev)) {
+               gpio->gpio.of_node = pdev->dev.of_node;
+               gpio->gpio.of_gpio_n_cells = 2;
+               gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+               gpio->intc.name = pdev->dev.of_node->name;
+       } else {
+               gpio->intc.name = gpio->soc->name;
+       }

Wouldn't the following be enough?

- gpio->intc.name = pdev->dev.of_node->name;
+ gpio->intc.name = devm_kasprintf(&pdev->dev, "%pfw",
dev_fwnode(&pdev->dev));
+ if (!gpio->intc.name)
+ return -ENOMEM;

Note, all above are questions and you know better which direction to take. In either way, please test and look at the result.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#5 lore raw

Thanks Andy for the suggestions. Few thoughts I have below.

Quoted 9 lines

What about doing like

     gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
     if (IS_ERR(gpio->secure))
             gpio->secure = devm_platform_ioremap_resource(pdev, 0);
     if (IS_ERR(gpio->secure))
             return PTR_ERR(gpio->secure);

and similar for gpio->base?

Wouldn't this cause a redundant check if it had already succeeded in getting the resource by name? Also, could it happen that if the device tree is incorrect, then one of the resource is fetched by name and other by the index, which I guess, would mess things up. Just my random thoughts, not sure if it is valid enough.

Review

Quoted 7 lines

Wouldn't the following be enough?

(quoted diff) +1 -1
-       gpio->intc.name = pdev->dev.of_node->name;
+       gpio->intc.name = devm_kasprintf(&pdev->dev, "%pfw",

dev_fwnode(&pdev->dev));

(quoted diff) +2 -0
+       if (!gpio->intc.name)
+

How about this way? I feel it would be right to add the OF functions conditionally.

+ if (pdev->dev.of_node) {

+       gpio->gpio.of_node = pdev->dev.of_node;
+       gpio->gpio.of_gpio_n_cells = 2;
+       gpio->gpio.of_xlate = tegra186_gpio_of_xlate;

+ }

+ gpio->intc.name = gpio->soc->name;

--
Best Regards,
Akhil

author
#6 lore raw

Hi Andy,

Please let me know if you have any inputs regarding the changes.

--
Best Regards,
Akhil

#7 lore raw
In reply to Akhil R
Quoted 18 lines · Akhil R
Quoted 9 lines

What about doing like

     gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
     if (IS_ERR(gpio->secure))
             gpio->secure = devm_platform_ioremap_resource(pdev, 0);
     if (IS_ERR(gpio->secure))
             return PTR_ERR(gpio->secure);

and similar for gpio->base?

Wouldn't this cause a redundant check if it had already succeeded in getting the resource by name? Also, could it happen that if the device tree is incorrect, then one of the resource is fetched by name and other by the index, which I guess, would mess things up. Just my random thoughts, not sure if it is valid enough.

Quoted 2 lines

Wouldn't the following be enough?

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +1 -1
-       gpio->intc.name = pdev->dev.of_node->name;
+       gpio->intc.name = devm_kasprintf(&pdev->dev, "%pfw",

dev_fwnode(&pdev->dev));

(quoted diff) +2 -0
+       if (!gpio->intc.name)
+

How about this way? I feel it would be right to add the OF functions conditionally.

Looks okay, although I have a question here.

Quoted 1 line

+ if (pdev->dev.of_node) {

Do we really need this check at all? If the OF-node is NULL then it doesn't matter if other fields are filled or not, correct?

What you need is #ifdef CONFIG_OF_GPIO (IIRC the name correctly).

Quoted 6 lines
drivers/gpio/gpio-tegra186.c +5 -0
+       gpio->gpio.of_node = pdev->dev.of_node;
+       gpio->gpio.of_gpio_n_cells = 2;
+       gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+   }
 
+   gpio->intc.name = gpio->soc->name;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#8 lore raw
Quoted 26 lines
Quoted 18 lines
Quoted 1 line

What about doing like

     gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
Quoted 6 lines
     if (IS_ERR(gpio->secure))
             gpio->secure = devm_platform_ioremap_resource(pdev, 0);
     if (IS_ERR(gpio->secure))
             return PTR_ERR(gpio->secure);

and similar for gpio->base?

Wouldn't this cause a redundant check if it had already succeeded in getting the resource by name? Also, could it happen that if the device tree is incorrect, then one of the resource is fetched by name and other by the index, which I guess, would mess things up. Just my random thoughts, not sure if it is valid enough.

Quoted 2 lines

Wouldn't the following be enough?

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +1 -1
-       gpio->intc.name = pdev->dev.of_node->name;
+       gpio->intc.name = devm_kasprintf(&pdev->dev, "%pfw",

dev_fwnode(&pdev->dev));

(quoted diff) +2 -0
+       if (!gpio->intc.name)
+

How about this way? I feel it would be right to add the OF functions conditionally.

Quoted 15 lines

Looks okay, although I have a question here.

+ if (pdev->dev.of_node) {

Do we really need this check at all? If the OF-node is NULL then it doesn't matter if other fields are filled or not, correct?

What you need is #ifdef CONFIG_OF_GPIO (IIRC the name correctly).

Quoted 6 lines
drivers/gpio/gpio-tegra186.c +5 -0
+       gpio->gpio.of_node = pdev->dev.of_node;
+       gpio->gpio.of_gpio_n_cells = 2;
+       gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+   }
 
+   gpio->intc.name = gpio->soc->name;

Okay. It makes sense. Thanks Andy. I would make the changes and send out an updated patch.

--
Best Regards,
Akhil

author
#9 lore raw

PATCH v3 1/1 gpio: tegra186: Add ACPI support

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

Change-Id Id8e892f989e4ccc935b87aa0d84b10a3d1efd8f9
---
 drivers/gpio/gpio-tegra186.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/gpio/gpio-tegra186.c +25 -7
index 1bd9e44..3b553c2 100644
@@ -620,15 +620,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
-
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+
+	if (IS_ERR(gpio->secure) || IS_ERR(gpio->base)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+
+		if (IS_ERR(gpio->secure))
+			return PTR_ERR(gpio->secure);
+
+		if (IS_ERR(gpio->base))
+			return PTR_ERR(gpio->base);
+	}
 
 	err = platform_irq_count(pdev);
 	if (err < 0)
@@ -690,11 +696,13 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
+#if defined(CONFIG_OF_GPIO)
 	gpio->gpio.of_node = pdev->dev.of_node;
 	gpio->gpio.of_gpio_n_cells = 2;
 	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+#endif /* CONFIG_OF_GPIO */
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	gpio->intc.name = dev_name(&pdev->dev);
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +926,20 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = tegra186_gpio_acpi_match,
 	},
 	.probe = tegra186_gpio_probe,
 	.remove = tegra186_gpio_remove,
Signature · 1 line
2.7.4
Reviewed-by on v3 1/1
#10 lore raw
Quoted 3 lines · Akhil R

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

Thanks for an update, my comments below.
After addressing, feel free to add

Quoted 1 line

Change-Id: Id8e892f989e4ccc935b87aa0d84b10a3d1efd8f9

This is not for upstream.

Quoted 1 line

...

drivers/gpio/gpio-tegra186.c static const struct of_device_id tegra186_gpio_of_match[] = { · line 934

Quoted 7 lines
drivers/gpio/gpio-tegra186.c +6 -0
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+       { .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+       { .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+       { .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+       { .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
 
+       {},

Comma is not needed for terminator lines.

Quoted 2 lines
drivers/gpio/gpio-tegra186.c +2 -0
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#11 lore raw

PATCH v4 1/1 gpio: tegra186: Add ACPI support

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
 drivers/gpio/gpio-tegra186.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/gpio/gpio-tegra186.c +25 -7
index 1bd9e44..e0ba8cd 100644
@@ -620,15 +620,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
-
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+
+	if (IS_ERR(gpio->secure) || IS_ERR(gpio->base)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+
+		if (IS_ERR(gpio->secure))
+			return PTR_ERR(gpio->secure);
+
+		if (IS_ERR(gpio->base))
+			return PTR_ERR(gpio->base);
+	}
 
 	err = platform_irq_count(pdev);
 	if (err < 0)
@@ -690,11 +696,13 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
+#if defined(CONFIG_OF_GPIO)
 	gpio->gpio.of_node = pdev->dev.of_node;
 	gpio->gpio.of_gpio_n_cells = 2;
 	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+#endif /* CONFIG_OF_GPIO */
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	gpio->intc.name = dev_name(&pdev->dev);
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +926,20 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = tegra186_gpio_acpi_match,
 	},
 	.probe = tegra186_gpio_probe,
 	.remove = tegra186_gpio_remove,
Signature · 1 line
2.7.4
maintainer
#12 lore raw
Quoted 19 lines · Akhil R

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
 drivers/gpio/gpio-tegra186.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/gpio/gpio-tegra186.c +1 -1
index 1bd9e44..e0ba8cd 100644
@@ -620,15 +620,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);

drivers/gpio/gpio-tegra186.c static int tegra186_gpio_probe(struct platform_device *pdev) · line 628

Quoted 10 lines
drivers/gpio/gpio-tegra186.c +2 -5
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
-
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+
+	if (IS_ERR(gpio->secure) || IS_ERR(gpio->base)) {

The OR here seems a bit odd, my preference would be how Andy suggested initially ...

    gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
    if (IS_ERR(gpio->secure)) {
        gpio->secure = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(gpio->secure))
            return PTR_ERR(gpio->secure)
    }

Cheers
Jon

Signature · 1 line
nvpublic
author
#13 lore raw

PATCH v5 1/1 gpio: tegra186: Add ACPI support

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
v5 changes:
* Updated ioremap_resource check as per Jon's comments.

 drivers/gpio/gpio-tegra186.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/gpio/gpio-tegra186.c +24 -6
index 1bd9e44..8a64dcb 100644
@@ -620,15 +620,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
+	if (IS_ERR(gpio->secure)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(gpio->secure))
+			return PTR_ERR(gpio->secure);
+	}
 
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+	if (IS_ERR(gpio->base)) {
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+		if (IS_ERR(gpio->base))
+			return PTR_ERR(gpio->base);
+	}
 
 	err = platform_irq_count(pdev);
 	if (err < 0)
@@ -690,11 +696,13 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
+#if defined(CONFIG_OF_GPIO)
 	gpio->gpio.of_node = pdev->dev.of_node;
 	gpio->gpio.of_gpio_n_cells = 2;
 	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+#endif /* CONFIG_OF_GPIO */
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	gpio->intc.name = dev_name(&pdev->dev);
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +926,20 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = tegra186_gpio_acpi_match,
 	},
 	.probe = tegra186_gpio_probe,
 	.remove = tegra186_gpio_remove,
Signature · 1 line
2.7.4
maintainer Reviewed-by on v5 1/1
#14 lore raw
Quoted 70 lines · Akhil R

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
v5 changes:
* Updated ioremap_resource check as per Jon's comments.

 drivers/gpio/gpio-tegra186.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/gpio/gpio-tegra186.c +21 -6
index 1bd9e44..8a64dcb 100644
@@ -620,15 +620,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
+	if (IS_ERR(gpio->secure)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(gpio->secure))
+			return PTR_ERR(gpio->secure);
+	}
 
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+	if (IS_ERR(gpio->base)) {
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+		if (IS_ERR(gpio->base))
+			return PTR_ERR(gpio->base);
+	}
 
 	err = platform_irq_count(pdev);
 	if (err < 0)
@@ -690,11 +696,13 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
+#if defined(CONFIG_OF_GPIO)
 	gpio->gpio.of_node = pdev->dev.of_node;
 	gpio->gpio.of_gpio_n_cells = 2;
 	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+#endif /* CONFIG_OF_GPIO */
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	gpio->intc.name = dev_name(&pdev->dev);
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +926,20 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+	{}
+};

drivers/gpio/gpio-tegra186.c static const struct of_device_id tegra186_gpio_of_match[] = { · line 945

Quoted 10 lines
drivers/gpio/gpio-tegra186.c +3 -0
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = tegra186_gpio_acpi_match,
 	},
 	.probe = tegra186_gpio_probe,
 	.remove = tegra186_gpio_remove,

Looks good to me.

Cheers
Jon

Signature · 1 line
nvpublic
#15 lore raw
In reply to Akhil R
Quoted 81 lines · Akhil R

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
v5 changes:
* Updated ioremap_resource check as per Jon's comments.

 drivers/gpio/gpio-tegra186.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/gpio/gpio-tegra186.c +24 -7
index 1bd9e44..8a64dcb 100644
@@ -620,15 +620,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
        if (!gpio)
                return -ENOMEM;
 
-       gpio->soc = of_device_get_match_data(&pdev->dev);
+       gpio->soc = device_get_match_data(&pdev->dev);
 
        gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-       if (IS_ERR(gpio->secure))
-               return PTR_ERR(gpio->secure);
+       if (IS_ERR(gpio->secure)) {
+               gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+               if (IS_ERR(gpio->secure))
+                       return PTR_ERR(gpio->secure);
+       }
 
        gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-       if (IS_ERR(gpio->base))
-               return PTR_ERR(gpio->base);
+       if (IS_ERR(gpio->base)) {
+               gpio->base = devm_platform_ioremap_resource(pdev, 1);
+               if (IS_ERR(gpio->base))
+                       return PTR_ERR(gpio->base);
+       }
 
        err = platform_irq_count(pdev);
        if (err < 0)
@@ -690,11 +696,13 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
        gpio->gpio.names = (const char * const *)names;
 
+#if defined(CONFIG_OF_GPIO)
        gpio->gpio.of_node = pdev->dev.of_node;
        gpio->gpio.of_gpio_n_cells = 2;
        gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+#endif /* CONFIG_OF_GPIO */
 
-       gpio->intc.name = pdev->dev.of_node->name;
+       gpio->intc.name = dev_name(&pdev->dev);
        gpio->intc.irq_ack = tegra186_irq_ack;
        gpio->intc.irq_mask = tegra186_irq_mask;
        gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -918,10 +926,20 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+       { .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+       { .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+       { .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+       { .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+       {}
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
        .driver = {
                .name = "tegra186-gpio",
                .of_match_table = tegra186_gpio_of_match,
+               .acpi_match_table = tegra186_gpio_acpi_match,
        },
        .probe = tegra186_gpio_probe,
        .remove = tegra186_gpio_remove,
--
Quoted 2 lines

2.7.4

Can you rebase it on top of v5.14-rc1 and resend?

Bart

author
#16 lore raw

PATCH v6 1/1 gpio: tegra186: Add ACPI support

Add ACPI module ID to probe the driver from the ACPI based bootloader firmware.

---
v6 changes:
* Rebased on top of v5.14-rc1

 drivers/gpio/gpio-tegra186.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/gpio/gpio-tegra186.c +24 -6
index d38980b..046b7c8 100644
@@ -610,15 +610,21 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	gpio->soc = of_device_get_match_data(&pdev->dev);
+	gpio->soc = device_get_match_data(&pdev->dev);
 
 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
-	if (IS_ERR(gpio->secure))
-		return PTR_ERR(gpio->secure);
+	if (IS_ERR(gpio->secure)) {
+		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(gpio->secure))
+			return PTR_ERR(gpio->secure);
+	}
 
 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
-	if (IS_ERR(gpio->base))
-		return PTR_ERR(gpio->base);
+	if (IS_ERR(gpio->base)) {
+		gpio->base = devm_platform_ioremap_resource(pdev, 1);
+		if (IS_ERR(gpio->base))
+			return PTR_ERR(gpio->base);
+	}
 
 	err = platform_irq_count(pdev);
 	if (err < 0)
@@ -680,11 +686,13 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
 
 	gpio->gpio.names = (const char * const *)names;
 
+#if defined(CONFIG_OF_GPIO)
 	gpio->gpio.of_node = pdev->dev.of_node;
 	gpio->gpio.of_gpio_n_cells = 2;
 	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
+#endif /* CONFIG_OF_GPIO */
 
-	gpio->intc.name = pdev->dev.of_node->name;
+	gpio->intc.name = dev_name(&pdev->dev);
 	gpio->intc.irq_ack = tegra186_irq_ack;
 	gpio->intc.irq_mask = tegra186_irq_mask;
 	gpio->intc.irq_unmask = tegra186_irq_unmask;
@@ -896,10 +904,20 @@ static const struct of_device_id tegra186_gpio_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
 
+static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
+	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
+	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
+	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
+	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+
 static struct platform_driver tegra186_gpio_driver = {
 	.driver = {
 		.name = "tegra186-gpio",
 		.of_match_table = tegra186_gpio_of_match,
+		.acpi_match_table = tegra186_gpio_acpi_match,
 	},
 	.probe = tegra186_gpio_probe,
 };
Signature · 1 line
2.7.4
#18 lore raw
In reply to Akhil R
Thank you for the patch! Yet something to improve:

Hi Akhil,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on gpio/for-next]
[also build test ERROR on v5.13-rc6 next-20210618]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Akhil-R/gpio-tegra186-Add-ACPI-support/20210617-180601
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next
config: x86_64-randconfig-s022-20210618 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/b8c186168bab74f0c9b85d7231fb09f562e10242
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Akhil-R/gpio-tegra186-Add-ACPI-support/20210617-180601
        git checkout b8c186168bab74f0c9b85d7231fb09f562e10242
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

drivers/gpio/gpio-tegra186: struct acpi_device_id is 32 bytes. The last of 4 is:
0x4e 0x56 0x44 0x41 0x30 0x34 0x30 0x38 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

>> FATAL: modpost: drivers/gpio/gpio-tegra186: struct acpi_device_id is not terminated with a NULL entry!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org