All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: em: Add Device Tree support
@ 2013-02-26 13:26 ` Magnus Damm
  0 siblings, 0 replies; 9+ messages in thread
From: Magnus Damm @ 2013-02-26 13:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: grant.likely, Magnus Damm, horms, linus.walleij, linux-sh

From: Magnus Damm <damm@opensource.se>

Update the Emma Mobile GPIO driver to add DT support.

The patch simply adds a two-cell xlate function and
updates the probe code to allow configuration via DT
using the "ngpios" property plus OF id in the same
style as gpio-mvebu.c. The code is also adjusted to
use postcore_initcall() to force early setup.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 Written on top of:
 [PATCH] gpio: em: Use irq_domain_add_simple() to fix runtime error

 drivers/gpio/gpio-em.c |   45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

--- 0010/drivers/gpio/gpio-em.c
+++ work/drivers/gpio/gpio-em.c	2013-02-26 22:11:58.000000000 +0900
@@ -231,10 +231,12 @@ static int em_gio_irq_domain_map(struct
 
 static struct irq_domain_ops em_gio_irq_domain_ops = {
 	.map	= em_gio_irq_domain_map,
+	.xlate	= irq_domain_xlate_twocell,
 };
 
 static int em_gio_probe(struct platform_device *pdev)
 {
+	struct gpio_em_config pdata_dt;
 	struct gpio_em_config *pdata = pdev->dev.platform_data;
 	struct em_gio_priv *p;
 	struct resource *io[2], *irq[2];
@@ -259,8 +261,8 @@ static int em_gio_probe(struct platform_
 	irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
 
-	if (!io[0] || !io[1] || !irq[0] || !irq[1] || !pdata) {
-		dev_err(&pdev->dev, "missing IRQ, IOMEM or configuration\n");
+	if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
+		dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
 		ret = -EINVAL;
 		goto err1;
 	}
@@ -279,6 +281,25 @@ static int em_gio_probe(struct platform_
 		goto err2;
 	}
 
+	if (!pdata) {
+		memset(&pdata_dt, 0, sizeof(pdata_dt));
+		pdata = &pdata_dt;
+
+		if (of_property_read_u32(pdev->dev.of_node, "ngpios",
+					 &pdata->number_of_pins)) {
+			dev_err(&pdev->dev, "Missing ngpios OF property\n");
+			ret = -EINVAL;
+			goto err3;
+		}
+
+		ret = of_alias_get_id(pdev->dev.of_node, "gpio");
+		if (ret < 0) {
+			dev_err(&pdev->dev, "Couldn't get OF id\n");
+			goto err3;
+		}
+		pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */
+	}
+
 	gpio_chip = &p->gpio_chip;
 	gpio_chip->direction_input = em_gio_direction_input;
 	gpio_chip->get = em_gio_get;
@@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
 	return 0;
 }
 
+static const struct of_device_id em_gio_dt_ids[] = {
+	{ .compatible = "renesas,em-gio", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
+
 static struct platform_driver em_gio_device_driver = {
 	.probe		= em_gio_probe,
 	.remove		= em_gio_remove,
 	.driver		= {
 		.name	= "em_gio",
+		.of_match_table = em_gio_dt_ids,
+		.owner		= THIS_MODULE,
 	}
 };
 
-module_platform_driver(em_gio_device_driver);
+static int __init em_gio_init(void)
+{
+	return platform_driver_register(&em_gio_device_driver);
+}
+postcore_initcall(em_gio_init);
+
+static void __exit em_gio_exit(void)
+{
+	platform_driver_unregister(&em_gio_device_driver);
+}
+module_exit(em_gio_exit);
 
 MODULE_AUTHOR("Magnus Damm");
 MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver");

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] gpio: em: Add Device Tree support
@ 2013-02-26 13:26 ` Magnus Damm
  0 siblings, 0 replies; 9+ messages in thread
From: Magnus Damm @ 2013-02-26 13:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: grant.likely, Magnus Damm, horms, linus.walleij, linux-sh

From: Magnus Damm <damm@opensource.se>

Update the Emma Mobile GPIO driver to add DT support.

The patch simply adds a two-cell xlate function and
updates the probe code to allow configuration via DT
using the "ngpios" property plus OF id in the same
style as gpio-mvebu.c. The code is also adjusted to
use postcore_initcall() to force early setup.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 Written on top of:
 [PATCH] gpio: em: Use irq_domain_add_simple() to fix runtime error

 drivers/gpio/gpio-em.c |   45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

--- 0010/drivers/gpio/gpio-em.c
+++ work/drivers/gpio/gpio-em.c	2013-02-26 22:11:58.000000000 +0900
@@ -231,10 +231,12 @@ static int em_gio_irq_domain_map(struct
 
 static struct irq_domain_ops em_gio_irq_domain_ops = {
 	.map	= em_gio_irq_domain_map,
+	.xlate	= irq_domain_xlate_twocell,
 };
 
 static int em_gio_probe(struct platform_device *pdev)
 {
+	struct gpio_em_config pdata_dt;
 	struct gpio_em_config *pdata = pdev->dev.platform_data;
 	struct em_gio_priv *p;
 	struct resource *io[2], *irq[2];
@@ -259,8 +261,8 @@ static int em_gio_probe(struct platform_
 	irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
 
-	if (!io[0] || !io[1] || !irq[0] || !irq[1] || !pdata) {
-		dev_err(&pdev->dev, "missing IRQ, IOMEM or configuration\n");
+	if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
+		dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
 		ret = -EINVAL;
 		goto err1;
 	}
@@ -279,6 +281,25 @@ static int em_gio_probe(struct platform_
 		goto err2;
 	}
 
+	if (!pdata) {
+		memset(&pdata_dt, 0, sizeof(pdata_dt));
+		pdata = &pdata_dt;
+
+		if (of_property_read_u32(pdev->dev.of_node, "ngpios",
+					 &pdata->number_of_pins)) {
+			dev_err(&pdev->dev, "Missing ngpios OF property\n");
+			ret = -EINVAL;
+			goto err3;
+		}
+
+		ret = of_alias_get_id(pdev->dev.of_node, "gpio");
+		if (ret < 0) {
+			dev_err(&pdev->dev, "Couldn't get OF id\n");
+			goto err3;
+		}
+		pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */
+	}
+
 	gpio_chip = &p->gpio_chip;
 	gpio_chip->direction_input = em_gio_direction_input;
 	gpio_chip->get = em_gio_get;
@@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
 	return 0;
 }
 
+static const struct of_device_id em_gio_dt_ids[] = {
+	{ .compatible = "renesas,em-gio", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
+
 static struct platform_driver em_gio_device_driver = {
 	.probe		= em_gio_probe,
 	.remove		= em_gio_remove,
 	.driver		= {
 		.name	= "em_gio",
+		.of_match_table = em_gio_dt_ids,
+		.owner		= THIS_MODULE,
 	}
 };
 
-module_platform_driver(em_gio_device_driver);
+static int __init em_gio_init(void)
+{
+	return platform_driver_register(&em_gio_device_driver);
+}
+postcore_initcall(em_gio_init);
+
+static void __exit em_gio_exit(void)
+{
+	platform_driver_unregister(&em_gio_device_driver);
+}
+module_exit(em_gio_exit);
 
 MODULE_AUTHOR("Magnus Damm");
 MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver");

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
  2013-02-26 13:26 ` Magnus Damm
@ 2013-02-26 22:41   ` Dmitry Torokhov
  -1 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2013-02-26 22:41 UTC (permalink / raw)
  To: Magnus Damm; +Cc: linux-kernel, grant.likely, horms, linus.walleij, linux-sh

Hi Magnus,

On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
> From: Magnus Damm <damm@opensource.se>
> 
> Update the Emma Mobile GPIO driver to add DT support.
> 

...

> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
>  	return 0;
>  }
>  

#ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
support is not enabled (or is entire ARM arch now enables device tree?).

> +static const struct of_device_id em_gio_dt_ids[] = {
> +	{ .compatible = "renesas,em-gio", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
> +
>  static struct platform_driver em_gio_device_driver = {
>  	.probe		= em_gio_probe,
>  	.remove		= em_gio_remove,
>  	.driver		= {
>  		.name	= "em_gio",
> +		.of_match_table = em_gio_dt_ids,
> +		.owner		= THIS_MODULE,
>  	}
>  };
>  

-- 
Dmitry

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
@ 2013-02-26 22:41   ` Dmitry Torokhov
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2013-02-26 22:41 UTC (permalink / raw)
  To: Magnus Damm; +Cc: linux-kernel, grant.likely, horms, linus.walleij, linux-sh

Hi Magnus,

On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
> From: Magnus Damm <damm@opensource.se>
> 
> Update the Emma Mobile GPIO driver to add DT support.
> 

...

> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
>  	return 0;
>  }
>  

#ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
support is not enabled (or is entire ARM arch now enables device tree?).

> +static const struct of_device_id em_gio_dt_ids[] = {
> +	{ .compatible = "renesas,em-gio", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
> +
>  static struct platform_driver em_gio_device_driver = {
>  	.probe		= em_gio_probe,
>  	.remove		= em_gio_remove,
>  	.driver		= {
>  		.name	= "em_gio",
> +		.of_match_table = em_gio_dt_ids,
> +		.owner		= THIS_MODULE,
>  	}
>  };
>  

-- 
Dmitry

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
  2013-02-26 22:41   ` Dmitry Torokhov
@ 2013-02-27 10:13     ` Magnus Damm
  -1 siblings, 0 replies; 9+ messages in thread
From: Magnus Damm @ 2013-02-27 10:13 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-kernel, grant.likely, horms, linus.walleij, linux-sh

Hi Dmitry,

Thanks for your feedback!

On Wed, Feb 27, 2013 at 7:41 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Hi Magnus,
>
> On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
>> From: Magnus Damm <damm@opensource.se>
>>
>> Update the Emma Mobile GPIO driver to add DT support.
>>
>
> ...
>
>> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
>>       return 0;
>>  }
>>
>
> #ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
> support is not enabled (or is entire ARM arch now enables device tree?).
>
>> +static const struct of_device_id em_gio_dt_ids[] = {
>> +     { .compatible = "renesas,em-gio", },
>> +     {},
>> +};
>> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
>> +

I suppose we could sprinkle a couple of #ifdefs across the code, but I
have to say that I'm not that fond of #ifdefs in general. So if it was
up to me only then I would aim at having exactly zero #ifdefs in my
drivers at the expense of slightly larger binaries in some cases.

Are you interested in hacking on EMEV2 in general? I assume you're
busy, but I could try to locate a developer board for you if you'd
like.

Cheers,

/ magnus

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
@ 2013-02-27 10:13     ` Magnus Damm
  0 siblings, 0 replies; 9+ messages in thread
From: Magnus Damm @ 2013-02-27 10:13 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-kernel, grant.likely, horms, linus.walleij, linux-sh

Hi Dmitry,

Thanks for your feedback!

On Wed, Feb 27, 2013 at 7:41 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Hi Magnus,
>
> On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
>> From: Magnus Damm <damm@opensource.se>
>>
>> Update the Emma Mobile GPIO driver to add DT support.
>>
>
> ...
>
>> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
>>       return 0;
>>  }
>>
>
> #ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
> support is not enabled (or is entire ARM arch now enables device tree?).
>
>> +static const struct of_device_id em_gio_dt_ids[] = {
>> +     { .compatible = "renesas,em-gio", },
>> +     {},
>> +};
>> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
>> +

I suppose we could sprinkle a couple of #ifdefs across the code, but I
have to say that I'm not that fond of #ifdefs in general. So if it was
up to me only then I would aim at having exactly zero #ifdefs in my
drivers at the expense of slightly larger binaries in some cases.

Are you interested in hacking on EMEV2 in general? I assume you're
busy, but I could try to locate a developer board for you if you'd
like.

Cheers,

/ magnus

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
  2013-02-27 10:13     ` Magnus Damm
@ 2013-02-28  5:11       ` Simon Horman
  -1 siblings, 0 replies; 9+ messages in thread
From: Simon Horman @ 2013-02-28  5:11 UTC (permalink / raw)
  To: Magnus Damm
  Cc: Dmitry Torokhov, linux-kernel, grant.likely, linus.walleij, linux-sh

On Wed, Feb 27, 2013 at 07:13:46PM +0900, Magnus Damm wrote:
> Hi Dmitry,
> 
> Thanks for your feedback!
> 
> On Wed, Feb 27, 2013 at 7:41 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> > Hi Magnus,
> >
> > On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
> >> From: Magnus Damm <damm@opensource.se>
> >>
> >> Update the Emma Mobile GPIO driver to add DT support.
> >>
> >
> > ...
> >
> >> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
> >>       return 0;
> >>  }
> >>
> >
> > #ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
> > support is not enabled (or is entire ARM arch now enables device tree?).
> >
> >> +static const struct of_device_id em_gio_dt_ids[] = {
> >> +     { .compatible = "renesas,em-gio", },
> >> +     {},
> >> +};
> >> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
> >> +
> 
> I suppose we could sprinkle a couple of #ifdefs across the code, but I
> have to say that I'm not that fond of #ifdefs in general. So if it was
> up to me only then I would aim at having exactly zero #ifdefs in my
> drivers at the expense of slightly larger binaries in some cases.

My take on this is as follows (if anyone cares):

* The driver in question is currently only useful in conjunction with
  the Emev2 SoC and the kzm9g board which uses that SoC. The current
  (and to date only) practice when booting that board and thus SoC
  with merged upstream code is to do so using DT.

* The inclusion of the code above does not appear to cause build-time
  breakage even if CONFIG_OF is not set.

So it seems to me that it is reasonable to leave the code as is
without being guarded by an #ifdef.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
@ 2013-02-28  5:11       ` Simon Horman
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Horman @ 2013-02-28  5:11 UTC (permalink / raw)
  To: Magnus Damm
  Cc: Dmitry Torokhov, linux-kernel, grant.likely, linus.walleij, linux-sh

On Wed, Feb 27, 2013 at 07:13:46PM +0900, Magnus Damm wrote:
> Hi Dmitry,
> 
> Thanks for your feedback!
> 
> On Wed, Feb 27, 2013 at 7:41 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> > Hi Magnus,
> >
> > On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
> >> From: Magnus Damm <damm@opensource.se>
> >>
> >> Update the Emma Mobile GPIO driver to add DT support.
> >>
> >
> > ...
> >
> >> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
> >>       return 0;
> >>  }
> >>
> >
> > #ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
> > support is not enabled (or is entire ARM arch now enables device tree?).
> >
> >> +static const struct of_device_id em_gio_dt_ids[] = {
> >> +     { .compatible = "renesas,em-gio", },
> >> +     {},
> >> +};
> >> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
> >> +
> 
> I suppose we could sprinkle a couple of #ifdefs across the code, but I
> have to say that I'm not that fond of #ifdefs in general. So if it was
> up to me only then I would aim at having exactly zero #ifdefs in my
> drivers at the expense of slightly larger binaries in some cases.

My take on this is as follows (if anyone cares):

* The driver in question is currently only useful in conjunction with
  the Emev2 SoC and the kzm9g board which uses that SoC. The current
  (and to date only) practice when booting that board and thus SoC
  with merged upstream code is to do so using DT.

* The inclusion of the code above does not appear to cause build-time
  breakage even if CONFIG_OF is not set.

So it seems to me that it is reasonable to leave the code as is
without being guarded by an #ifdef.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: em: Add Device Tree support
  2013-02-28  5:11       ` Simon Horman
  (?)
@ 2013-03-02 20:07       ` Grant Likely
  -1 siblings, 0 replies; 9+ messages in thread
From: Grant Likely @ 2013-03-02 20:07 UTC (permalink / raw)
  To: Simon Horman, Magnus Damm
  Cc: Dmitry Torokhov, linux-kernel, linus.walleij, linux-sh

On Thu, 28 Feb 2013 14:11:23 +0900, Simon Horman <horms@verge.net.au> wrote:
> On Wed, Feb 27, 2013 at 07:13:46PM +0900, Magnus Damm wrote:
> > Hi Dmitry,
> > 
> > Thanks for your feedback!
> > 
> > On Wed, Feb 27, 2013 at 7:41 AM, Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> wrote:
> > > Hi Magnus,
> > >
> > > On Tue, Feb 26, 2013 at 10:26:23PM +0900, Magnus Damm wrote:
> > >> From: Magnus Damm <damm@opensource.se>
> > >>
> > >> Update the Emma Mobile GPIO driver to add DT support.
> > >>
> > >
> > > ...
> > >
> > >> @@ -366,15 +387,33 @@ static int em_gio_remove(struct platform
> > >>       return 0;
> > >>  }
> > >>
> > >
> > > #ifdef CONFIG_OF here? No need to have extra aliases in modules if OF
> > > support is not enabled (or is entire ARM arch now enables device tree?).
> > >
> > >> +static const struct of_device_id em_gio_dt_ids[] = {
> > >> +     { .compatible = "renesas,em-gio", },
> > >> +     {},
> > >> +};
> > >> +MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
> > >> +
> > 
> > I suppose we could sprinkle a couple of #ifdefs across the code, but I
> > have to say that I'm not that fond of #ifdefs in general. So if it was
> > up to me only then I would aim at having exactly zero #ifdefs in my
> > drivers at the expense of slightly larger binaries in some cases.
> 
> My take on this is as follows (if anyone cares):
> 
> * The driver in question is currently only useful in conjunction with
>   the Emev2 SoC and the kzm9g board which uses that SoC. The current
>   (and to date only) practice when booting that board and thus SoC
>   with merged upstream code is to do so using DT.
> 
> * The inclusion of the code above does not appear to cause build-time
>   breakage even if CONFIG_OF is not set.
> 
> So it seems to me that it is reasonable to leave the code as is
> without being guarded by an #ifdef.

I completely agree.  Applied for v3.10

g.

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-03-02 20:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-26 13:26 [PATCH] gpio: em: Add Device Tree support Magnus Damm
2013-02-26 13:26 ` Magnus Damm
2013-02-26 22:41 ` Dmitry Torokhov
2013-02-26 22:41   ` Dmitry Torokhov
2013-02-27 10:13   ` Magnus Damm
2013-02-27 10:13     ` Magnus Damm
2013-02-28  5:11     ` Simon Horman
2013-02-28  5:11       ` Simon Horman
2013-03-02 20:07       ` Grant Likely

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.