All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support
@ 2016-05-31 20:44 Hamish Martin
  2016-06-10  0:34 ` Simon Glass
  0 siblings, 1 reply; 9+ messages in thread
From: Hamish Martin @ 2016-05-31 20:44 UTC (permalink / raw)
  To: u-boot

Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
  struct mpc85xx_gpio_plat gpio_blocks[] = {
         {
                 .addr = 0x130000,
                 .ngpios = 32,
         },
         {
                 .addr = 0x131000,
                 .ngpios = 32,
         },
  };

  U_BOOT_DEVICES(my_platform_gpios) = {
         { "gpio_mpc85xx", &gpio_blocks[0] },
         { "gpio_mpc85xx", &gpio_blocks[1] },
  };

This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.

Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
---
 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
 drivers/gpio/mpc85xx_gpio.c                  | 37 ++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
index 41b6677bba38..76faa22c8b43 100644
--- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
+++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
@@ -18,4 +18,10 @@
 #include <asm/mpc85xx_gpio.h>
 #endif
 
+struct mpc85xx_gpio_plat {
+	ulong addr;
+	unsigned long size;
+	uint ngpios;
+};
+
 #endif
diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
index 04773e2b31c3..3754a8215c36 100644
--- a/drivers/gpio/mpc85xx_gpio.c
+++ b/drivers/gpio/mpc85xx_gpio.c
@@ -163,23 +163,41 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
 	return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
-	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
 	fdt_addr_t addr;
 	fdt_size_t size;
 
 	addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
 						  "reg", 0, &size);
 
-	data->addr = addr;
-	data->base = map_sysmem(CONFIG_SYS_IMMR + addr, size);
+	plat->addr = addr;
+	plat->size = size;
+	plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+						  "ngpios", 32);
 
-	if (!data->base)
+	return 0;
+}
+#endif
+
+static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
+{
+	struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
+	unsigned long size = plat->size;
+
+	if (size == 0)
+		size = 0x100;
+
+	priv->addr = plat->addr;
+	priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
+
+	if (!priv->base)
 		return -ENOMEM;
 
-	data->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-					  "ngpios", 32);
-	data->dat_shadow = 0;
+	priv->gpio_count = plat->ngpios;
+	priv->dat_shadow = 0;
 
 	return 0;
 }
@@ -190,6 +208,8 @@ static int mpc85xx_gpio_probe(struct udevice *dev)
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
 	char name[32], *str;
 
+	mpc85xx_gpio_platdata_to_priv(dev);
+
 	snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
 	str = strdup(name);
 
@@ -221,8 +241,11 @@ U_BOOT_DRIVER(gpio_mpc85xx) = {
 	.name	= "gpio_mpc85xx",
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_mpc85xx_ops,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 	.ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct mpc85xx_gpio_plat),
 	.of_match = mpc85xx_gpio_ids,
+#endif
 	.probe	= mpc85xx_gpio_probe,
 	.priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
 };
-- 
2.8.3

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

* [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support
  2016-05-31 20:44 [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support Hamish Martin
@ 2016-06-10  0:34 ` Simon Glass
  2016-06-13 22:17   ` [U-Boot] [PATCH v2] " Hamish Martin
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Glass @ 2016-06-10  0:34 UTC (permalink / raw)
  To: u-boot

Hi,

On 31 May 2016 at 14:44, Hamish Martin
<hamish.martin@alliedtelesis.co.nz> wrote:
> Define a platform data structure for the MPC85XX GPIO driver to allow
> use of the driver without device tree. Users should define the GPIO
> blocks for their platform like this:
>   struct mpc85xx_gpio_plat gpio_blocks[] = {
>          {
>                  .addr = 0x130000,
>                  .ngpios = 32,
>          },
>          {
>                  .addr = 0x131000,
>                  .ngpios = 32,
>          },
>   };
>
>   U_BOOT_DEVICES(my_platform_gpios) = {
>          { "gpio_mpc85xx", &gpio_blocks[0] },
>          { "gpio_mpc85xx", &gpio_blocks[1] },
>   };
>
> This is intended to build upon the recent submission of the base
> MPC85XX driver from Mario Six. We need to use that new driver
> without dts support and this patch gives us that flexibility.
> This has been tested on a Freescale T2080 CPU, although only the first
> GPIO block.
>
> Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
> Reviewed-by: Mario Six <mario.six@gdsys.cc>
> Tested-by: Mario Six <mario.six@gdsys.cc>
> ---
>  arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
>  drivers/gpio/mpc85xx_gpio.c                  | 37 ++++++++++++++++++++++------
>  2 files changed, 36 insertions(+), 7 deletions(-)

Is this a v2/v3 patch? If so, can you please resend it with the version number?

Regards,
Simon

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

* [U-Boot] [PATCH v2] dm: gpio: MPC85XX GPIO platform data support
  2016-06-10  0:34 ` Simon Glass
@ 2016-06-13 22:17   ` Hamish Martin
  2016-06-17  3:50     ` Simon Glass
  0 siblings, 1 reply; 9+ messages in thread
From: Hamish Martin @ 2016-06-13 22:17 UTC (permalink / raw)
  To: u-boot

Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
  struct mpc85xx_gpio_plat gpio_blocks[] = {
         {
                 .addr = 0x130000,
                 .ngpios = 32,
         },
         {
                 .addr = 0x131000,
                 .ngpios = 32,
         },
  };

  U_BOOT_DEVICES(my_platform_gpios) = {
         { "gpio_mpc85xx", &gpio_blocks[0] },
         { "gpio_mpc85xx", &gpio_blocks[1] },
  };

This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.

Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
---
Changes for v2:
  - Fix compile errors noted by Mario Six
  - Added Mario's review and test tags

---
 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
 drivers/gpio/mpc85xx_gpio.c                  | 37 ++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
index 41b6677bba38..76faa22c8b43 100644
--- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
+++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
@@ -18,4 +18,10 @@
 #include <asm/mpc85xx_gpio.h>
 #endif
 
+struct mpc85xx_gpio_plat {
+	ulong addr;
+	unsigned long size;
+	uint ngpios;
+};
+
 #endif
diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
index 04773e2b31c3..3754a8215c36 100644
--- a/drivers/gpio/mpc85xx_gpio.c
+++ b/drivers/gpio/mpc85xx_gpio.c
@@ -163,23 +163,41 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
 	return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
-	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
 	fdt_addr_t addr;
 	fdt_size_t size;
 
 	addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
 						  "reg", 0, &size);
 
-	data->addr = addr;
-	data->base = map_sysmem(CONFIG_SYS_IMMR + addr, size);
+	plat->addr = addr;
+	plat->size = size;
+	plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+						  "ngpios", 32);
 
-	if (!data->base)
+	return 0;
+}
+#endif
+
+static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
+{
+	struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
+	unsigned long size = plat->size;
+
+	if (size == 0)
+		size = 0x100;
+
+	priv->addr = plat->addr;
+	priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
+
+	if (!priv->base)
 		return -ENOMEM;
 
-	data->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-					  "ngpios", 32);
-	data->dat_shadow = 0;
+	priv->gpio_count = plat->ngpios;
+	priv->dat_shadow = 0;
 
 	return 0;
 }
@@ -190,6 +208,8 @@ static int mpc85xx_gpio_probe(struct udevice *dev)
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
 	char name[32], *str;
 
+	mpc85xx_gpio_platdata_to_priv(dev);
+
 	snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
 	str = strdup(name);
 
@@ -221,8 +241,11 @@ U_BOOT_DRIVER(gpio_mpc85xx) = {
 	.name	= "gpio_mpc85xx",
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_mpc85xx_ops,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 	.ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct mpc85xx_gpio_plat),
 	.of_match = mpc85xx_gpio_ids,
+#endif
 	.probe	= mpc85xx_gpio_probe,
 	.priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
 };
-- 
2.8.3

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

* [U-Boot] [PATCH v2] dm: gpio: MPC85XX GPIO platform data support
  2016-06-13 22:17   ` [U-Boot] [PATCH v2] " Hamish Martin
@ 2016-06-17  3:50     ` Simon Glass
  2016-07-03 23:25       ` Simon Glass
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Glass @ 2016-06-17  3:50 UTC (permalink / raw)
  To: u-boot

On 13 June 2016 at 16:17, Hamish Martin
<hamish.martin@alliedtelesis.co.nz> wrote:
> Define a platform data structure for the MPC85XX GPIO driver to allow
> use of the driver without device tree. Users should define the GPIO
> blocks for their platform like this:
>   struct mpc85xx_gpio_plat gpio_blocks[] = {
>          {
>                  .addr = 0x130000,
>                  .ngpios = 32,
>          },
>          {
>                  .addr = 0x131000,
>                  .ngpios = 32,
>          },
>   };
>
>   U_BOOT_DEVICES(my_platform_gpios) = {
>          { "gpio_mpc85xx", &gpio_blocks[0] },
>          { "gpio_mpc85xx", &gpio_blocks[1] },
>   };
>
> This is intended to build upon the recent submission of the base
> MPC85XX driver from Mario Six. We need to use that new driver
> without dts support and this patch gives us that flexibility.
> This has been tested on a Freescale T2080 CPU, although only the first
> GPIO block.
>
> Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
> Reviewed-by: Mario Six <mario.six@gdsys.cc>
> Tested-by: Mario Six <mario.six@gdsys.cc>
> ---
> Changes for v2:
>   - Fix compile errors noted by Mario Six
>   - Added Mario's review and test tags
>
>
> ---
>  arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
>  drivers/gpio/mpc85xx_gpio.c                  | 37 ++++++++++++++++++++++------
>  2 files changed, 36 insertions(+), 7 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH v2] dm: gpio: MPC85XX GPIO platform data support
  2016-06-17  3:50     ` Simon Glass
@ 2016-07-03 23:25       ` Simon Glass
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Glass @ 2016-07-03 23:25 UTC (permalink / raw)
  To: u-boot

On 16 June 2016 at 21:50, Simon Glass <sjg@chromium.org> wrote:
> On 13 June 2016 at 16:17, Hamish Martin
> <hamish.martin@alliedtelesis.co.nz> wrote:
>> Define a platform data structure for the MPC85XX GPIO driver to allow
>> use of the driver without device tree. Users should define the GPIO
>> blocks for their platform like this:
>>   struct mpc85xx_gpio_plat gpio_blocks[] = {
>>          {
>>                  .addr = 0x130000,
>>                  .ngpios = 32,
>>          },
>>          {
>>                  .addr = 0x131000,
>>                  .ngpios = 32,
>>          },
>>   };
>>
>>   U_BOOT_DEVICES(my_platform_gpios) = {
>>          { "gpio_mpc85xx", &gpio_blocks[0] },
>>          { "gpio_mpc85xx", &gpio_blocks[1] },
>>   };
>>
>> This is intended to build upon the recent submission of the base
>> MPC85XX driver from Mario Six. We need to use that new driver
>> without dts support and this patch gives us that flexibility.
>> This has been tested on a Freescale T2080 CPU, although only the first
>> GPIO block.
>>
>> Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
>> Reviewed-by: Mario Six <mario.six@gdsys.cc>
>> Tested-by: Mario Six <mario.six@gdsys.cc>
>> ---
>> Changes for v2:
>>   - Fix compile errors noted by Mario Six
>>   - Added Mario's review and test tags
>>
>>
>> ---
>>  arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
>>  drivers/gpio/mpc85xx_gpio.c                  | 37 ++++++++++++++++++++++------
>>  2 files changed, 36 insertions(+), 7 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm/next, thanks!

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

* [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support
  2016-05-30 21:00 [U-Boot] [PATCH] " Hamish Martin
@ 2016-05-31  5:58 ` Mario Six
  0 siblings, 0 replies; 9+ messages in thread
From: Mario Six @ 2016-05-31  5:58 UTC (permalink / raw)
  To: u-boot

Hi Hamish,

On Mon, May 30, 2016 at 11:00 PM, Hamish Martin
<hamish.martin@alliedtelesis.co.nz> wrote:
> Define a platform data structure for the MPC85XX GPIO driver to allow
> use of the driver without device tree. Users should define the GPIO
> blocks for their platform like this:
>   struct mpc85xx_gpio_plat gpio_blocks[] = {
>          {
>                  .addr = 0x130000,
>                  .ngpios = 32,
>          },
>          {
>                  .addr = 0x131000,
>                  .ngpios = 32,
>          },
>   };
>
>   U_BOOT_DEVICES(my_platform_gpios) = {
>          { "gpio_mpc85xx", &gpio_blocks[0] },
>          { "gpio_mpc85xx", &gpio_blocks[1] },
>   };
>
> This is intended to build upon the recent submission of the base
> MPC85XX driver from Mario Six. We need to use that new driver
> without dts support and this patch gives us that flexibility.
> This has been tested on a Freescale T2080 CPU, although only the first
> GPIO block.
>
> Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
> Reviewed-by: Mario Six <mario.six@gdsys.cc>
> Tested-by: Mario Six <mario.six@gdsys.cc>
> ---
>  arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
>  drivers/gpio/mpc85xx_gpio.c                  | 36 ++++++++++++++++++++++------
>  2 files changed, 35 insertions(+), 7 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
> index 41b6677bba38..76faa22c8b43 100644
> --- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
> +++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
> @@ -18,4 +18,10 @@
>  #include <asm/mpc85xx_gpio.h>
>  #endif
>
> +struct mpc85xx_gpio_plat {
> +       ulong addr;
> +       unsigned long size;
> +       uint ngpios;
> +};
> +
>  #endif
> diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
> index 04773e2b31c3..c4563bee4d84 100644
> --- a/drivers/gpio/mpc85xx_gpio.c
> +++ b/drivers/gpio/mpc85xx_gpio.c
> @@ -163,23 +163,41 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
>         return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
>  }
>
> +#if CONFIG_IS_ENABLED(OF_CONTROL)
>  static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
> -       struct mpc85xx_gpio_data *data = dev_get_priv(dev);
> +       struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev)
>         fdt_addr_t addr;
>         fdt_size_t size;
>
>         addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
>                                                   "reg", 0, &size);
>
> -       data->addr = addr;
> -       data->base = map_sysmem(CONFIG_SYS_IMMR + addr, size);
> +       plat->addr = addr;
> +       plat->size = size;
> +       plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> +                                                 "ngpios", 32);
>
> -       if (!data->base)
> +       return 0;
> +}
> +#endif
> +
> +static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
> +{
> +       struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
> +       struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
> +       unsigned long size = plat->size;
> +
> +       if (size == 0)
> +               size = 0x100;
> +
> +       priv->addr = plat->addr;
> +       priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
> +
> +       if (!priv->base)
>                 return -ENOMEM;
>
> -       data->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> -                                         "ngpios", 32);
> -       data->dat_shadow = 0;
> +       priv->gpio_count = plat->ngpios;
> +       priv->dat_shadow = 0;
>
>         return 0;
>  }
> @@ -190,6 +208,8 @@ static int mpc85xx_gpio_probe(struct udevice *dev)
>         struct mpc85xx_gpio_data *data = dev_get_priv(dev);
>         char name[32], *str;
>
> +       mpc85xx_gpio_platdata_to_priv(dev);
> +
>         snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
>         str = strdup(name);
>
> @@ -221,8 +241,10 @@ U_BOOT_DRIVER(gpio_mpc85xx) = {
>         .name   = "gpio_mpc85xx",
>         .id     = UCLASS_GPIO,
>         .ops    = &gpio_mpc85xx_ops,
> +#if CONFIG_IS_ENABLED(OF_CONTROL)
>         .ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
>         .of_match = mpc85xx_gpio_ids,
> +#endif
>         .probe  = mpc85xx_gpio_probe,
>         .priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
>  };
> --
> 2.8.3
>

There were two little corrections in my last reply (missing semicolon + missing
.platdata_auto_alloc_size); if you could add those, that would be great.

Best regards,
Mario

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

* [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support
@ 2016-05-30 21:00 Hamish Martin
  2016-05-31  5:58 ` Mario Six
  0 siblings, 1 reply; 9+ messages in thread
From: Hamish Martin @ 2016-05-30 21:00 UTC (permalink / raw)
  To: u-boot

Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
  struct mpc85xx_gpio_plat gpio_blocks[] = {
         {
                 .addr = 0x130000,
                 .ngpios = 32,
         },
         {
                 .addr = 0x131000,
                 .ngpios = 32,
         },
  };

  U_BOOT_DEVICES(my_platform_gpios) = {
         { "gpio_mpc85xx", &gpio_blocks[0] },
         { "gpio_mpc85xx", &gpio_blocks[1] },
  };

This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.

Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
---
 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
 drivers/gpio/mpc85xx_gpio.c                  | 36 ++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
index 41b6677bba38..76faa22c8b43 100644
--- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
+++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
@@ -18,4 +18,10 @@
 #include <asm/mpc85xx_gpio.h>
 #endif
 
+struct mpc85xx_gpio_plat {
+	ulong addr;
+	unsigned long size;
+	uint ngpios;
+};
+
 #endif
diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
index 04773e2b31c3..c4563bee4d84 100644
--- a/drivers/gpio/mpc85xx_gpio.c
+++ b/drivers/gpio/mpc85xx_gpio.c
@@ -163,23 +163,41 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
 	return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
-	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev)
 	fdt_addr_t addr;
 	fdt_size_t size;
 
 	addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
 						  "reg", 0, &size);
 
-	data->addr = addr;
-	data->base = map_sysmem(CONFIG_SYS_IMMR + addr, size);
+	plat->addr = addr;
+	plat->size = size;
+	plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+						  "ngpios", 32);
 
-	if (!data->base)
+	return 0;
+}
+#endif
+
+static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
+{
+	struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
+	unsigned long size = plat->size;
+
+	if (size == 0)
+		size = 0x100;
+
+	priv->addr = plat->addr;
+	priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
+
+	if (!priv->base)
 		return -ENOMEM;
 
-	data->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-					  "ngpios", 32);
-	data->dat_shadow = 0;
+	priv->gpio_count = plat->ngpios;
+	priv->dat_shadow = 0;
 
 	return 0;
 }
@@ -190,6 +208,8 @@ static int mpc85xx_gpio_probe(struct udevice *dev)
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
 	char name[32], *str;
 
+	mpc85xx_gpio_platdata_to_priv(dev);
+
 	snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
 	str = strdup(name);
 
@@ -221,8 +241,10 @@ U_BOOT_DRIVER(gpio_mpc85xx) = {
 	.name	= "gpio_mpc85xx",
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_mpc85xx_ops,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 	.ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
 	.of_match = mpc85xx_gpio_ids,
+#endif
 	.probe	= mpc85xx_gpio_probe,
 	.priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
 };
-- 
2.8.3

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

* [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support
  2016-05-30  0:57 Hamish Martin
@ 2016-05-30  8:01 ` Mario Six
  0 siblings, 0 replies; 9+ messages in thread
From: Mario Six @ 2016-05-30  8:01 UTC (permalink / raw)
  To: u-boot

Hi Hamish,

On Mon, May 30, 2016 at 2:57 AM, Hamish Martin
<hamish.martin@alliedtelesis.co.nz> wrote:
> Define a platform data structure for the MPC85XX GPIO driver to allow
> use of the driver without device tree. Users should define the GPIO
> blocks for their platform like this:
>   struct mpc85xx_gpio_plat gpio_blocks[] = {
>          {
>                  .addr = 0x130000,
>                  .ngpios = 32,
>          },
>          {
>                  .addr = 0x131000,
>                  .ngpios = 32,
>          },
>   };
>
>   U_BOOT_DEVICES(my_platform_gpios) = {
>          { "gpio_mpc85xx", &gpio_blocks[0] },
>          { "gpio_mpc85xx", &gpio_blocks[1] },
>   };
>
> This is intended to build upon the recent submission of the base
> MPC85XX driver from Mario Six. We need to use that new driver
> without dts support and this patch gives us that flexibility.
> This has been tested on a Freescale T2080 CPU, although only the first
> GPIO block.
>
> Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
> ---
>  arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
>  drivers/gpio/mpc85xx_gpio.c                  | 36 ++++++++++++++++++++++------
>  2 files changed, 35 insertions(+), 7 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
> index 41b6677bba38..76faa22c8b43 100644
> --- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
> +++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
> @@ -18,4 +18,10 @@
>  #include <asm/mpc85xx_gpio.h>
>  #endif
>
> +struct mpc85xx_gpio_plat {
> +       ulong addr;
> +       unsigned long size;
> +       uint ngpios;
> +};
> +
>  #endif
> diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
> index 04773e2b31c3..c4563bee4d84 100644
> --- a/drivers/gpio/mpc85xx_gpio.c
> +++ b/drivers/gpio/mpc85xx_gpio.c
> @@ -163,23 +163,41 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
>         return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
>  }
>
> +#if CONFIG_IS_ENABLED(OF_CONTROL)
>  static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
> -       struct mpc85xx_gpio_data *data = dev_get_priv(dev);
> +       struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev)

Missing semicolon :-)

>         fdt_addr_t addr;
>         fdt_size_t size;
>
>         addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
>                                                   "reg", 0, &size);
>
> -       data->addr = addr;
> -       data->base = map_sysmem(CONFIG_SYS_IMMR + addr, size);
> +       plat->addr = addr;
> +       plat->size = size;
> +       plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> +                                                 "ngpios", 32);
>
> -       if (!data->base)
> +       return 0;
> +}
> +#endif
> +
> +static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
> +{
> +       struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
> +       struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
> +       unsigned long size = plat->size;
> +
> +       if (size == 0)
> +               size = 0x100;
> +
> +       priv->addr = plat->addr;
> +       priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
> +
> +       if (!priv->base)
>                 return -ENOMEM;
>
> -       data->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
> -                                         "ngpios", 32);
> -       data->dat_shadow = 0;
> +       priv->gpio_count = plat->ngpios;
> +       priv->dat_shadow = 0;
>
>         return 0;
>  }
> @@ -190,6 +208,8 @@ static int mpc85xx_gpio_probe(struct udevice *dev)
>         struct mpc85xx_gpio_data *data = dev_get_priv(dev);
>         char name[32], *str;
>
> +       mpc85xx_gpio_platdata_to_priv(dev);
> +
>         snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
>         str = strdup(name);
>
> @@ -221,8 +241,10 @@ U_BOOT_DRIVER(gpio_mpc85xx) = {
>         .name   = "gpio_mpc85xx",
>         .id     = UCLASS_GPIO,
>         .ops    = &gpio_mpc85xx_ops,
> +#if CONFIG_IS_ENABLED(OF_CONTROL)
>         .ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
>         .of_match = mpc85xx_gpio_ids,

boards using device tree need a

.platdata_auto_alloc_size = sizeof(struct mpc85xx_gpio_plat),

here, otherwise the data structure is not allocated properly.

> +#endif
>         .probe  = mpc85xx_gpio_probe,
>         .priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
>  };
> --
> 2.8.3
>

Aside from that:

Reviewed-By: Mario Six <mario.six@gdsys.cc>
Tested-By: Mario Six <mario.six@gdsys.cc> (on P1022)

Best regards,
Mario

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

* [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support
@ 2016-05-30  0:57 Hamish Martin
  2016-05-30  8:01 ` Mario Six
  0 siblings, 1 reply; 9+ messages in thread
From: Hamish Martin @ 2016-05-30  0:57 UTC (permalink / raw)
  To: u-boot

Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
  struct mpc85xx_gpio_plat gpio_blocks[] = {
         {
                 .addr = 0x130000,
                 .ngpios = 32,
         },
         {
                 .addr = 0x131000,
                 .ngpios = 32,
         },
  };

  U_BOOT_DEVICES(my_platform_gpios) = {
         { "gpio_mpc85xx", &gpio_blocks[0] },
         { "gpio_mpc85xx", &gpio_blocks[1] },
  };

This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.

Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
---
 arch/powerpc/include/asm/arch-mpc85xx/gpio.h |  6 +++++
 drivers/gpio/mpc85xx_gpio.c                  | 36 ++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
index 41b6677bba38..76faa22c8b43 100644
--- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
+++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h
@@ -18,4 +18,10 @@
 #include <asm/mpc85xx_gpio.h>
 #endif
 
+struct mpc85xx_gpio_plat {
+	ulong addr;
+	unsigned long size;
+	uint ngpios;
+};
+
 #endif
diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c
index 04773e2b31c3..c4563bee4d84 100644
--- a/drivers/gpio/mpc85xx_gpio.c
+++ b/drivers/gpio/mpc85xx_gpio.c
@@ -163,23 +163,41 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
 	return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
-	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev)
 	fdt_addr_t addr;
 	fdt_size_t size;
 
 	addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
 						  "reg", 0, &size);
 
-	data->addr = addr;
-	data->base = map_sysmem(CONFIG_SYS_IMMR + addr, size);
+	plat->addr = addr;
+	plat->size = size;
+	plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+						  "ngpios", 32);
 
-	if (!data->base)
+	return 0;
+}
+#endif
+
+static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
+{
+	struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
+	struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
+	unsigned long size = plat->size;
+
+	if (size == 0)
+		size = 0x100;
+
+	priv->addr = plat->addr;
+	priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
+
+	if (!priv->base)
 		return -ENOMEM;
 
-	data->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-					  "ngpios", 32);
-	data->dat_shadow = 0;
+	priv->gpio_count = plat->ngpios;
+	priv->dat_shadow = 0;
 
 	return 0;
 }
@@ -190,6 +208,8 @@ static int mpc85xx_gpio_probe(struct udevice *dev)
 	struct mpc85xx_gpio_data *data = dev_get_priv(dev);
 	char name[32], *str;
 
+	mpc85xx_gpio_platdata_to_priv(dev);
+
 	snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
 	str = strdup(name);
 
@@ -221,8 +241,10 @@ U_BOOT_DRIVER(gpio_mpc85xx) = {
 	.name	= "gpio_mpc85xx",
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_mpc85xx_ops,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 	.ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
 	.of_match = mpc85xx_gpio_ids,
+#endif
 	.probe	= mpc85xx_gpio_probe,
 	.priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
 };
-- 
2.8.3

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

end of thread, other threads:[~2016-07-03 23:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-31 20:44 [U-Boot] [PATCH] dm: gpio: MPC85XX GPIO platform data support Hamish Martin
2016-06-10  0:34 ` Simon Glass
2016-06-13 22:17   ` [U-Boot] [PATCH v2] " Hamish Martin
2016-06-17  3:50     ` Simon Glass
2016-07-03 23:25       ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2016-05-30 21:00 [U-Boot] [PATCH] " Hamish Martin
2016-05-31  5:58 ` Mario Six
2016-05-30  0:57 Hamish Martin
2016-05-30  8:01 ` Mario Six

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.