gpio: merrifield: Add support of ACPI enabled platforms
PATCH 1/1 gpio: merrifield: Add support of ACPI enabled platforms
The driver needs the pin control device name for ACPI.
We are looking through ACPI namespace and return first found device based on ACPI HID for Intel Merrifield FLIS.
--- drivers/gpio/gpio-merrifield.c | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/gpio/gpio-merrifield.c +42 -1
@@ -9,6 +9,7 @@* published by the Free Software Foundation. */ +#include <linux/acpi.h> #include <linux/bitops.h> #include <linux/gpio/driver.h> #include <linux/init.h>
@@ -380,9 +381,48 @@ static void mrfld_irq_init_hw(struct mrfld_gpio *priv) } } +#ifdef CONFIG_ACPI +static const struct acpi_device_id mrfld_pinctrl_acpi_ids[] = { + {"INTC1002" }, + {} +}; + +static acpi_status +mrfld_acpi_find_pinctrl (acpi_handle handle,u32 lvl,void *context,void **rv) +{ +const char **name = context; +struct acpi_device *adev; + +if (acpi_bus_get_device (handle, &adev)) +return AE_OK ; + +if (acpi_match_device_ids (adev, mrfld_pinctrl_acpi_ids)) +return AE_OK ; + + *name =dev_name (&adev->dev); +return AE_CTRL_TERMINATE ; +} + +static const char *mrfld_acpi_get_pinctrl_dev_name (const char *fallback) +{ +const char *pinctrl_dev_name = fallback; + +acpi_walk_namespace (ACPI_TYPE_DEVICE ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , mrfld_acpi_find_pinctrl,NULL , + &pinctrl_dev_name,NULL ); +return pinctrl_dev_name; +} +#else +static inline const char *mrfld_acpi_get_pinctrl_dev_name (const char *fallback) +{ +return fallback; +} +#endif +static int mrfld_gpio_probe (struct pci_dev *pdev,const struct pci_device_id *id) {const struct mrfld_gpio_pinrange *range; +const char *pinctrl_dev_name;struct mrfld_gpio *priv;u32 gpio_base, irq_base;void __iomem *base;
@@ -439,10 +479,11 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *idreturn retval; } + pinctrl_dev_name =mrfld_acpi_get_pinctrl_dev_name ("pinctrl-merrifield" );for (i =0 ; i <ARRAY_SIZE (mrfld_gpio_ranges); i++) { range = &mrfld_gpio_ranges[i]; retval =gpiochip_add_pin_range (&priv->chip, -"pinctrl-merrifield" , + pinctrl_dev_name, range->gpio_base, range->pin_base, range->npins);
Signature · 1 line
2.15.1
Quoted 48 lines · Andy Shevchenko
The driver needs the pin control device name for ACPI.
We are looking through ACPI namespace and return first found device based on ACPI HID for Intel Merrifield FLIS.
Cc Mika Westerberg <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpio/gpio-merrifield.c | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)drivers/gpio/gpio-merrifield.c +22
-0@@ -9,6 +9,7 @@* published by the Free Software Foundation. */ +#include <linux/acpi.h> #include <linux/bitops.h> #include <linux/gpio/driver.h> #include <linux/init.h> @@ -380,9 +381,48 @@ static void mrfld_irq_init_hw(struct mrfld_gpio *priv) } } +#ifdef CONFIG_ACPI +static const struct acpi_device_id mrfld_pinctrl_acpi_ids[] = { + {"INTC1002" }, + {} +}; + +static acpi_status +mrfld_acpi_find_pinctrl (acpi_handle handle,u32 lvl,void *context,void **rv) +{ +const char **name = context; +struct acpi_device *adev; + +if (acpi_bus_get_device (handle, &adev)) +return AE_OK ; + +if (acpi_match_device_ids (adev, mrfld_pinctrl_acpi_ids)) +return AE_OK ; + + *name =dev_name (&adev->dev); +return AE_CTRL_TERMINATE ; +}
drivers/gpio/gpio-merrifield.c static void mrfld_irq_init_hw(struct mrfld_gpio *priv) · line 414
Quoted 10 lines
drivers/gpio/gpio-merrifield.c +10
-0+ +static const char *mrfld_acpi_get_pinctrl_dev_name (const char *fallback) +{ +const char *pinctrl_dev_name = fallback; + +acpi_walk_namespace (ACPI_TYPE_DEVICE ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , mrfld_acpi_find_pinctrl,NULL , + &pinctrl_dev_name,NULL ); +return pinctrl_dev_name; +}
I wonder if there is a better way to "connect" these things without need to walk ACPI namespace in GPIO drivers? How does DT handle handle separated GPIO and pinctrl drivers? Maybe there is a binding that we could reuse in ACPI side.
Quoted 10 lines · Mika Westerberg
Quoted 9 lines · Andy Shevchenko
The driver needs the pin control device name for ACPI.
We are looking through ACPI namespace and return first found device based on ACPI HID for Intel Merrifield FLIS.
drivers/gpio/gpio-merrifield.c +4
-0+static const struct acpi_device_id mrfld_pinctrl_acpi_ids[] = { + {"INTC1002" }, + {} +};
...
Quoted 7 lines
Quoted 7 lines
+static const char *mrfld_acpi_get_pinctrl_dev_name(const char *fallback)
drivers/gpio/gpio-merrifield.c +5
-0+{ +const char *pinctrl_dev_name = fallback; + + acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX,
Quoted 8 lines
drivers/gpio/gpio-merrifield.c static void mrfld_irq_init_hw(struct mrfld_gpio *priv) · line 414
Quoted 4 lines
mrfld_acpi_find_pinctrl, NULL,drivers/gpio/gpio-merrifield.c +3
-0+ &pinctrl_dev_name, NULL); +return pinctrl_dev_name; +}I wonder if there is a better way to "connect" these things without need
to walk ACPI namespace in GPIO drivers?
I would lovely use that if there is any.
Quoted 3 lines
How does DT handle handle
separated GPIO and pinctrl drivers? Maybe there is a binding that we could reuse in ACPI side.
Do they need it?
The problem here is in GPIO <-> pin mapping which requires instance name of the device to be supplied.
AFAIU (perhaps missed something) in DT pinctrl device directly has this mapping in the DTS, so, no need to call gpiochip_add_pin_range().
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 30 lines · Andy Shevchenko
Quoted 10 lines · Mika Westerberg
Quoted 9 lines · Andy Shevchenko
The driver needs the pin control device name for ACPI.
We are looking through ACPI namespace and return first found device
based on ACPI HID for Intel Merrifield FLIS.drivers/gpio/gpio-merrifield.c +4
-0+static const struct acpi_device_id mrfld_pinctrl_acpi_ids[] = { + {"INTC1002" }, + {} +};...
Quoted 7 lines
Quoted 7 lines
+static const char *mrfld_acpi_get_pinctrl_dev_name(const char *fallback)
drivers/gpio/gpio-merrifield.c +5
-0+{ +const char *pinctrl_dev_name = fallback; + + acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX,Quoted 8 lines
drivers/gpio/gpio-merrifield.c static void mrfld_irq_init_hw(struct mrfld_gpio *priv) · line 414
Quoted 4 lines
mrfld_acpi_find_pinctrl, NULL,drivers/gpio/gpio-merrifield.c +3
-0+ &pinctrl_dev_name, NULL); +return pinctrl_dev_name; +}I wonder if there is a better way to "connect" these things without need
to walk ACPI namespace in GPIO drivers?
Quoted 1 line
I would lovely use that if there is any.
It appears there is another user of this, i.e. ASoC Intel, which needs same.
Moreover, we can avoid scan entire ACPI namespace and narrow to scan only registered ACPI devices on ACPI bus in Linux (see acpi_dev_present() for example).
I'm about to send patch (series) v2 utilizing that.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy