diff mbox series

[RFC,4/4] platform/x86: i2c-multi-instantiate: Add IRQ_RESOURCE_GPIO_OPTIONAL IRQ type

Message ID 20201105080014.45410-5-hdegoede@redhat.com
State New
Headers show
Series [RFC,1/4] i2c: core: Allow i2c_board_info to specify that the core should not try to find an IRQ | expand

Commit Message

Hans de Goede Nov. 5, 2020, 8 a.m. UTC
Most I2C-drivers treat IRQs as optional and in some cases ACPI
devices managed by i2c-multi-instantiate.c may have a GpioInt resource
specified on some systems, while it is not there on others.

Add a new IRQ_RESOURCE_GPIO_OPTIONAL IRQ type, which still tries to get
a GpioInt IRQ, but does not consider it a fatal error when this fails.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/i2c-multi-instantiate.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Andy Shevchenko Nov. 5, 2020, 10:36 a.m. UTC | #1
On Thu, Nov 5, 2020 at 10:00 AM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Most I2C-drivers treat IRQs as optional and in some cases ACPI
> devices managed by i2c-multi-instantiate.c may have a GpioInt resource
> specified on some systems, while it is not there on others.

GpioInt()

> Add a new IRQ_RESOURCE_GPIO_OPTIONAL IRQ type, which still tries to get
> a GpioInt IRQ, but does not consider it a fatal error when this fails.

GpioInt()

...

> -#define IRQ_RESOURCE_TYPE      GENMASK(1, 0)
> -#define IRQ_RESOURCE_NONE      0
> -#define IRQ_RESOURCE_GPIO      1
> -#define IRQ_RESOURCE_APIC      2
> +#define IRQ_RESOURCE_TYPE              GENMASK(1, 0)
> +#define IRQ_RESOURCE_NONE              0
> +#define IRQ_RESOURCE_GPIO              1
> +#define IRQ_RESOURCE_GPIO_OPTIONAL     2
> +#define IRQ_RESOURCE_APIC              3

I think flag is cleaner:

#define IRQ_RESOURCE_OPTIONAL     BIT(2)

...

>                 case IRQ_RESOURCE_GPIO:
>                         ret = acpi_dev_gpio_irq_get(adev, inst_data[i].irq_idx);
> -                       if (ret < 0) {
> +                       if (ret < 0 && (!irq_optional || ret != -ENOENT)) {

ret < 0 && !((inst_data[i].flags & IRQ_RESOURCE_OPTIONAL) && ret == -ENOENT)

>                                 dev_err(dev, "Error requesting irq at index %d: %d\n",
>                                         inst_data[i].irq_idx, ret);
>                                 goto error;
diff mbox series

Patch

diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c
index cbccfcbed44c..55c6d6e8d576 100644
--- a/drivers/platform/x86/i2c-multi-instantiate.c
+++ b/drivers/platform/x86/i2c-multi-instantiate.c
@@ -15,10 +15,11 @@ 
 #include <linux/platform_device.h>
 #include <linux/types.h>
 
-#define IRQ_RESOURCE_TYPE	GENMASK(1, 0)
-#define IRQ_RESOURCE_NONE	0
-#define IRQ_RESOURCE_GPIO	1
-#define IRQ_RESOURCE_APIC	2
+#define IRQ_RESOURCE_TYPE		GENMASK(1, 0)
+#define IRQ_RESOURCE_NONE		0
+#define IRQ_RESOURCE_GPIO		1
+#define IRQ_RESOURCE_GPIO_OPTIONAL	2
+#define IRQ_RESOURCE_APIC		3
 
 struct i2c_inst_data {
 	const char *type;
@@ -64,6 +65,7 @@  static int i2c_multi_inst_probe(struct platform_device *pdev)
 	struct i2c_board_info board_info = {};
 	struct device *dev = &pdev->dev;
 	struct acpi_device *adev;
+	bool irq_optional;
 	char name[32];
 	int i, ret;
 
@@ -94,10 +96,14 @@  static int i2c_multi_inst_probe(struct platform_device *pdev)
 			 inst_data[i].type, i);
 		board_info.dev_name = name;
 		board_info.fwnode = dev->fwnode;
+		irq_optional = false;
 		switch (inst_data[i].flags & IRQ_RESOURCE_TYPE) {
+		case IRQ_RESOURCE_GPIO_OPTIONAL:
+			irq_optional = true;
+			fallthrough;
 		case IRQ_RESOURCE_GPIO:
 			ret = acpi_dev_gpio_irq_get(adev, inst_data[i].irq_idx);
-			if (ret < 0) {
+			if (ret < 0 && (!irq_optional || ret != -ENOENT)) {
 				dev_err(dev, "Error requesting irq at index %d: %d\n",
 					inst_data[i].irq_idx, ret);
 				goto error;