Re: [PATCH 11/46] ARM: pxa: cmx270: use platform device for nand

2019-10-22 Thread Arnd Bergmann
On Sat, Oct 19, 2019 at 11:44 AM Miquel Raynal
 wrote:
>
> Hi Arnd,
>
> Arnd Bergmann  wrote on Fri, 18 Oct 2019 17:41:26 +0200:
>
> > The driver traditionally hardcodes the MMIO register address and
> > the GPIO numbers from data defined in platform header files.
> >
> > To make it indepdendent of that, use a memory resource for the
> > registers, and a gpio lookup table to replace the gpio numbers.
>
> Looks good to me besides the typo s/indepdendent/independent/.

Fixed now

> Acked-by: Miquel Raynal 

Thanks!

 Arnd


Re: [PATCH 11/46] ARM: pxa: cmx270: use platform device for nand

2019-10-19 Thread Miquel Raynal
Hi Arnd,

Arnd Bergmann  wrote on Fri, 18 Oct 2019 17:41:26 +0200:

> The driver traditionally hardcodes the MMIO register address and
> the GPIO numbers from data defined in platform header files.
> 
> To make it indepdendent of that, use a memory resource for the
> registers, and a gpio lookup table to replace the gpio numbers.

Looks good to me besides the typo s/indepdendent/independent/.

Acked-by: Miquel Raynal 

> 
> Cc: Miquel Raynal 
> Cc: Richard Weinberger 
> Cc: David Woodhouse 
> Cc: Brian Norris 
> Cc: Marek Vasut 
> Cc: Vignesh Raghavendra 
> Cc: linux-...@lists.infradead.org
> Signed-off-by: Arnd Bergmann 
> ---
>  arch/arm/mach-pxa/cm-x270.c| 25 +
>  drivers/mtd/nand/raw/cmx270_nand.c | 88 +++---
>  2 files changed, 56 insertions(+), 57 deletions(-)
> 
> diff --git a/arch/arm/mach-pxa/cm-x270.c b/arch/arm/mach-pxa/cm-x270.c
> index 9baad11314f2..6d80400d8887 100644
> --- a/arch/arm/mach-pxa/cm-x270.c
> +++ b/arch/arm/mach-pxa/cm-x270.c
> @@ -40,6 +40,10 @@
>  #define GPIO19_WLAN_STRAP(19)
>  #define GPIO102_WLAN_RST (102)
>  
> +/* NAND GPIOS */
> +#define GPIO_NAND_CS (11)
> +#define GPIO_NAND_RB (89)
> +
>  static unsigned long cmx270_pin_config[] = {
>   /* AC'97 */
>   GPIO28_AC97_BITCLK,
> @@ -403,6 +407,26 @@ static void __init cmx270_init_spi(void)
>  static inline void cmx270_init_spi(void) {}
>  #endif
>  
> +static struct gpiod_lookup_table cmx270_nand_gpio_table = {
> + .dev_id = "cmx270-nand",
> + .table = {
> + GPIO_LOOKUP("gpio-pxa", GPIO_NAND_CS, "cs", GPIO_ACTIVE_HIGH),
> + GPIO_LOOKUP("gpio-pxa", GPIO_NAND_RB, "rb", GPIO_ACTIVE_HIGH),
> + { },
> + },
> +};
> +
> +static struct resource cmx270_nand_resources[] __initdata = {
> + DEFINE_RES_MEM(PXA_CS1_PHYS, 12),
> +};
> +
> +static void __init cmx270_init_nand(void)
> +{
> + platform_device_register_simple("cmx270-nand", -1,
> + cmx270_nand_resources, 1);
> + gpiod_add_lookup_table(_nand_gpio_table);
> +}
> +
>  void __init cmx270_init(void)
>  {
>   pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
> @@ -416,4 +440,5 @@ void __init cmx270_init(void)
>   cmx270_init_ohci();
>   cmx270_init_2700G();
>   cmx270_init_spi();
> + cmx270_init_nand();
>  }
> diff --git a/drivers/mtd/nand/raw/cmx270_nand.c 
> b/drivers/mtd/nand/raw/cmx270_nand.c
> index 7af3d0bdcdb8..31cb20858c46 100644
> --- a/drivers/mtd/nand/raw/cmx270_nand.c
> +++ b/drivers/mtd/nand/raw/cmx270_nand.c
> @@ -15,18 +15,17 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
>  #include 
>  
> -#include 
> -
> -#define GPIO_NAND_CS (11)
> -#define GPIO_NAND_RB (89)
> +static struct gpio_desc *gpiod_nand_cs;
> +static struct gpio_desc *gpiod_nand_rb;
>  
>  /* MTD structure for CM-X270 board */
>  static struct mtd_info *cmx270_nand_mtd;
> @@ -70,14 +69,14 @@ static void cmx270_read_buf(struct nand_chip *this, 
> u_char *buf, int len)
>  
>  static inline void nand_cs_on(void)
>  {
> - gpio_set_value(GPIO_NAND_CS, 0);
> + gpiod_set_value(gpiod_nand_cs, 0);
>  }
>  
>  static void nand_cs_off(void)
>  {
>   dsb();
>  
> - gpio_set_value(GPIO_NAND_CS, 1);
> + gpiod_set_value(gpiod_nand_cs, 1);
>  }
>  
>  /*
> @@ -120,48 +119,41 @@ static int cmx270_device_ready(struct nand_chip *this)
>  {
>   dsb();
>  
> - return (gpio_get_value(GPIO_NAND_RB));
> + return (gpiod_get_value(gpiod_nand_rb));
>  }
>  
>  /*
>   * Main initialization routine
>   */
> -static int __init cmx270_init(void)
> +static int cmx270_probe(struct platform_device *pdev)
>  {
>   struct nand_chip *this;
> + struct device *dev = >dev;
>   int ret;
>  
> - if (!(machine_is_armcore() && cpu_is_pxa27x()))
> - return -ENODEV;
> -
> - ret = gpio_request(GPIO_NAND_CS, "NAND CS");
> + gpiod_nand_cs = devm_gpiod_get(dev, "cs", GPIOD_OUT_HIGH);
> + ret = PTR_ERR_OR_ZERO(gpiod_nand_cs);
>   if (ret) {
>   pr_warn("CM-X270: failed to request NAND CS gpio\n");
>   return ret;
>   }
>  
> - gpio_direction_output(GPIO_NAND_CS, 1);
> -
> - ret = gpio_request(GPIO_NAND_RB, "NAND R/B");
> + gpiod_nand_rb = devm_gpiod_get(dev, "rb", GPIOD_IN);
> + ret = PTR_ERR_OR_ZERO(gpiod_nand_rb);
>   if (ret) {
>   pr_warn("CM-X270: failed to request NAND R/B gpio\n");
> - goto err_gpio_request;
> + return ret;
>   }
>  
> - gpio_direction_input(GPIO_NAND_RB);
> -
>   /* Allocate memory for MTD device structure and private data */
> - this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
> - if (!this) {
> - ret = -ENOMEM;
> - goto err_kzalloc;
> - }
> + this = devm_kzalloc(dev, sizeof(struct nand_chip), GFP_KERNEL);
> + if (!this)
> +   

[PATCH 11/46] ARM: pxa: cmx270: use platform device for nand

2019-10-18 Thread Arnd Bergmann
The driver traditionally hardcodes the MMIO register address and
the GPIO numbers from data defined in platform header files.

To make it indepdendent of that, use a memory resource for the
registers, and a gpio lookup table to replace the gpio numbers.

Cc: Miquel Raynal 
Cc: Richard Weinberger 
Cc: David Woodhouse 
Cc: Brian Norris 
Cc: Marek Vasut 
Cc: Vignesh Raghavendra 
Cc: linux-...@lists.infradead.org
Signed-off-by: Arnd Bergmann 
---
 arch/arm/mach-pxa/cm-x270.c| 25 +
 drivers/mtd/nand/raw/cmx270_nand.c | 88 +++---
 2 files changed, 56 insertions(+), 57 deletions(-)

diff --git a/arch/arm/mach-pxa/cm-x270.c b/arch/arm/mach-pxa/cm-x270.c
index 9baad11314f2..6d80400d8887 100644
--- a/arch/arm/mach-pxa/cm-x270.c
+++ b/arch/arm/mach-pxa/cm-x270.c
@@ -40,6 +40,10 @@
 #define GPIO19_WLAN_STRAP  (19)
 #define GPIO102_WLAN_RST   (102)
 
+/* NAND GPIOS */
+#define GPIO_NAND_CS   (11)
+#define GPIO_NAND_RB   (89)
+
 static unsigned long cmx270_pin_config[] = {
/* AC'97 */
GPIO28_AC97_BITCLK,
@@ -403,6 +407,26 @@ static void __init cmx270_init_spi(void)
 static inline void cmx270_init_spi(void) {}
 #endif
 
+static struct gpiod_lookup_table cmx270_nand_gpio_table = {
+   .dev_id = "cmx270-nand",
+   .table = {
+   GPIO_LOOKUP("gpio-pxa", GPIO_NAND_CS, "cs", GPIO_ACTIVE_HIGH),
+   GPIO_LOOKUP("gpio-pxa", GPIO_NAND_RB, "rb", GPIO_ACTIVE_HIGH),
+   { },
+   },
+};
+
+static struct resource cmx270_nand_resources[] __initdata = {
+   DEFINE_RES_MEM(PXA_CS1_PHYS, 12),
+};
+
+static void __init cmx270_init_nand(void)
+{
+   platform_device_register_simple("cmx270-nand", -1,
+   cmx270_nand_resources, 1);
+   gpiod_add_lookup_table(_nand_gpio_table);
+}
+
 void __init cmx270_init(void)
 {
pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
@@ -416,4 +440,5 @@ void __init cmx270_init(void)
cmx270_init_ohci();
cmx270_init_2700G();
cmx270_init_spi();
+   cmx270_init_nand();
 }
diff --git a/drivers/mtd/nand/raw/cmx270_nand.c 
b/drivers/mtd/nand/raw/cmx270_nand.c
index 7af3d0bdcdb8..31cb20858c46 100644
--- a/drivers/mtd/nand/raw/cmx270_nand.c
+++ b/drivers/mtd/nand/raw/cmx270_nand.c
@@ -15,18 +15,17 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
 #include 
 
-#include 
-
-#define GPIO_NAND_CS   (11)
-#define GPIO_NAND_RB   (89)
+static struct gpio_desc *gpiod_nand_cs;
+static struct gpio_desc *gpiod_nand_rb;
 
 /* MTD structure for CM-X270 board */
 static struct mtd_info *cmx270_nand_mtd;
@@ -70,14 +69,14 @@ static void cmx270_read_buf(struct nand_chip *this, u_char 
*buf, int len)
 
 static inline void nand_cs_on(void)
 {
-   gpio_set_value(GPIO_NAND_CS, 0);
+   gpiod_set_value(gpiod_nand_cs, 0);
 }
 
 static void nand_cs_off(void)
 {
dsb();
 
-   gpio_set_value(GPIO_NAND_CS, 1);
+   gpiod_set_value(gpiod_nand_cs, 1);
 }
 
 /*
@@ -120,48 +119,41 @@ static int cmx270_device_ready(struct nand_chip *this)
 {
dsb();
 
-   return (gpio_get_value(GPIO_NAND_RB));
+   return (gpiod_get_value(gpiod_nand_rb));
 }
 
 /*
  * Main initialization routine
  */
-static int __init cmx270_init(void)
+static int cmx270_probe(struct platform_device *pdev)
 {
struct nand_chip *this;
+   struct device *dev = >dev;
int ret;
 
-   if (!(machine_is_armcore() && cpu_is_pxa27x()))
-   return -ENODEV;
-
-   ret = gpio_request(GPIO_NAND_CS, "NAND CS");
+   gpiod_nand_cs = devm_gpiod_get(dev, "cs", GPIOD_OUT_HIGH);
+   ret = PTR_ERR_OR_ZERO(gpiod_nand_cs);
if (ret) {
pr_warn("CM-X270: failed to request NAND CS gpio\n");
return ret;
}
 
-   gpio_direction_output(GPIO_NAND_CS, 1);
-
-   ret = gpio_request(GPIO_NAND_RB, "NAND R/B");
+   gpiod_nand_rb = devm_gpiod_get(dev, "rb", GPIOD_IN);
+   ret = PTR_ERR_OR_ZERO(gpiod_nand_rb);
if (ret) {
pr_warn("CM-X270: failed to request NAND R/B gpio\n");
-   goto err_gpio_request;
+   return ret;
}
 
-   gpio_direction_input(GPIO_NAND_RB);
-
/* Allocate memory for MTD device structure and private data */
-   this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
-   if (!this) {
-   ret = -ENOMEM;
-   goto err_kzalloc;
-   }
+   this = devm_kzalloc(dev, sizeof(struct nand_chip), GFP_KERNEL);
+   if (!this)
+   return -ENOMEM;
 
-   cmx270_nand_io = ioremap(PXA_CS1_PHYS, 12);
+   cmx270_nand_io = devm_platform_ioremap_resource(pdev, 0);
if (!cmx270_nand_io) {
pr_debug("Unable to ioremap NAND device\n");
-   ret = -EINVAL;
-   goto err_ioremap;
+   return -EINVAL;
}
 
cmx270_nand_mtd