RE: [PATCH v3] gpio: mpc8xxx: Add ACPI support

2021-03-21 Thread Ran Wang
Hi Andy,

On Friday, March 19, 2021 6:32 PM, Andy Shevchenko wrote:
> 
> On Fri, Mar 19, 2021 at 10:10 AM Ran Wang  wrote:
> >
> > Current implementation only supports DT, now add ACPI support.
> 
> Thanks for an update, my comments below.
> 
> ...
> 
> > +#include 
> 
> Missed
> property.h
> mod_devicetable.h.

Got it.
 
> ...
> 
> > -   mpc8xxx_gc->regs = of_iomap(np, 0);
> > +   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
> 
> > if (!mpc8xxx_gc->regs)
> 
> This is wrong now.

Yes, will correct this in next version

> > return -ENOMEM;
> 
> This too.

Got it.
 
> ...
> 
> > +   fwnode = dev_fwnode(>dev);
> > if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
> > of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
> > -   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
> > +   of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
> 
> > +   !(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))
> 
> Since you left acpi.h inclusion, you may switch this to
> 
> is_acpi_node(fwnode)
> 
> or drop fwnode and use
> 
> has_acpi_companion(>dev)

OK, will use is_acpi_node(fwnode) instead (since fwnode is referred in 
following irq_domain_create_linear()

Thanks for your patient educate :)

Regards,
Ran



Re: [PATCH v3] gpio: mpc8xxx: Add ACPI support

2021-03-19 Thread Andy Shevchenko
On Fri, Mar 19, 2021 at 10:10 AM Ran Wang  wrote:
>
> Current implementation only supports DT, now add ACPI support.

Thanks for an update, my comments below.

...

> +#include 

Missed
property.h
mod_devicetable.h.

...

> -   mpc8xxx_gc->regs = of_iomap(np, 0);
> +   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);

> if (!mpc8xxx_gc->regs)

This is wrong now.

> return -ENOMEM;

This too.

...

> +   fwnode = dev_fwnode(>dev);
> if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
> of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
> -   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
> +   of_device_is_compatible(np, "fsl,ls1088a-gpio") ||

> +   !(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))

Since you left acpi.h inclusion, you may switch this to

is_acpi_node(fwnode)

or drop fwnode and use

has_acpi_companion(>dev)

> gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);


-- 
With Best Regards,
Andy Shevchenko


[PATCH v3] gpio: mpc8xxx: Add ACPI support

2021-03-19 Thread Ran Wang
Current implementation only supports DT, now add ACPI support.

Signed-off-by: Ran Wang 
---
Change in v3:
 - Recover ls1028a and ls1088a compatilbe checking logic

Change in v2:
 - Initialize devtype with NULL to fix compile warning.
 - Replace of_device_get_match_data() and acpi_match_device with 
device_get_match_data().
 - Replace acpi_match_device() with simpler checking logic per Andy's 
suggestion.

 drivers/gpio/gpio-mpc8xxx.c | 32 
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 6dfca83bcd90..25ac7db847af 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -9,6 +9,7 @@
  * kind, whether express or implied.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -303,8 +304,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
struct gpio_chip*gc;
-   const struct mpc8xxx_gpio_devtype *devtype =
-   of_device_get_match_data(>dev);
+   const struct mpc8xxx_gpio_devtype *devtype = NULL;
+   struct fwnode_handle *fwnode;
int ret;
 
mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
@@ -315,14 +316,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
raw_spin_lock_init(_gc->lock);
 
-   mpc8xxx_gc->regs = of_iomap(np, 0);
+   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
if (!mpc8xxx_gc->regs)
return -ENOMEM;
 
gc = _gc->gc;
gc->parent = >dev;
 
-   if (of_property_read_bool(np, "little-endian")) {
+   if (device_property_read_bool(>dev, "little-endian")) {
ret = bgpio_init(gc, >dev, 4,
 mpc8xxx_gc->regs + GPIO_DAT,
 NULL, NULL,
@@ -345,6 +346,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
mpc8xxx_gc->direction_output = gc->direction_output;
 
+   devtype = device_get_match_data(>dev);
if (!devtype)
devtype = _gpio_devtype_default;
 
@@ -369,9 +371,11 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
 * the port value to the GPIO Data Register.
 */
+   fwnode = dev_fwnode(>dev);
if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
+   of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
+   !(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))
gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
 
ret = gpiochip_add_data(gc, mpc8xxx_gc);
@@ -381,12 +385,15 @@ static int mpc8xxx_probe(struct platform_device *pdev)
goto err;
}
 
-   mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
+   mpc8xxx_gc->irqn = platform_get_irq(pdev, 0);
if (!mpc8xxx_gc->irqn)
return 0;
 
-   mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
-   _gpio_irq_ops, mpc8xxx_gc);
+   mpc8xxx_gc->irq = irq_domain_create_linear(fwnode,
+  MPC8XXX_GPIO_PINS,
+  _gpio_irq_ops,
+  mpc8xxx_gc);
+
if (!mpc8xxx_gc->irq)
return 0;
 
@@ -425,12 +432,21 @@ static int mpc8xxx_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id gpio_acpi_ids[] = {
+   {"NXP0031",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids);
+#endif
+
 static struct platform_driver mpc8xxx_plat_driver = {
.probe  = mpc8xxx_probe,
.remove = mpc8xxx_remove,
.driver = {
.name = "gpio-mpc8xxx",
.of_match_table = mpc8xxx_gpio_ids,
+   .acpi_match_table = ACPI_PTR(gpio_acpi_ids),
},
 };
 
-- 
2.25.1