Re: [RFC PATCH 03/10] i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

2020-02-22 Thread Heiko Schocher

Hello Stefan,

Am 20.02.2020 um 18:49 schrieb Stefan B.:

Hello Heiko,

see below my feedback, please give me further advise where indicated.

Unfortunately there have been some Bugs in the i2c-driver and I learned that this driver has not 
been used at all ("i2c-gpio" has been used instead). So I have done several Bugfixes and 
improvements appart from your proposals.



Regards
Stefan


Am 04.02.20 um 07:58 schrieb Heiko Schocher:

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in
   "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

Signed-off-by: Stefan Bosch 
---

  drivers/gpio/Kconfig   |   9 +
  drivers/gpio/Makefile  |   1 +
  drivers/gpio/nx_gpio.c | 252 +++
  drivers/i2c/Kconfig    |   9 +
  drivers/i2c/Makefile   |   1 +
  drivers/i2c/nx_i2c.c   | 537 +
  drivers/mmc/Kconfig    |   6 +
  drivers/mmc/Makefile   |   1 +
  drivers/mmc/nexell_dw_mmc_dm.c | 350 +++
  drivers/pwm/Makefile   |   1 +
  drivers/pwm/pwm-nexell.c   | 252 +++
  drivers/pwm/pwm-nexell.h   |  54 +


Could you please split this patch into 4 parts (i2c, gpio, mmc and
pwm) ?

Thanks!


Ok, I will split this patch.


Thanks!


  12 files changed, 1473 insertions(+)
  create mode 100644 drivers/gpio/nx_gpio.c
  create mode 100644 drivers/i2c/nx_i2c.c
  create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
  create mode 100644 drivers/pwm/pwm-nexell.c
  create mode 100644 drivers/pwm/pwm-nexell.h


[...]

diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 449046b..e3340de 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)    += pm8916_gpio.o
  obj-$(CONFIG_MT7621_GPIO)    += mt7621_gpio.o
  obj-$(CONFIG_MSCC_SGPIO)    += mscc_sgpio.o
  obj-$(CONFIG_SIFIVE_GPIO)    += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)    += nx_gpio.o


Please keep lists sorted.


The list is not sorted (at least in no alphabetical order), but I can e.g. move "... += nx_gpio.o" 
one line up?


Find for me.


diff --git a/drivers/gpio/nx_gpio.c b/drivers/gpio/nx_gpio.c
new file mode 100644
index 000..86472f6
--- /dev/null
+++ b/drivers/gpio/nx_gpio.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+    u32    data;    /* Data register */
+    u32    outputenb;    /* Output Enable register */
+    u32    detmode[2];    /* Detect Mode Register */
+    u32    intenb;    /* Interrupt Enable Register */
+    u32    det;    /* Event Detect Register */
+    u32    pad;    /* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+    u32    pwrgate;    /* Power Gating Register */
+    u32    reserved0[28];    /* Reserved0 */
+    u32    outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+    u32    outputenb;    /* Alive GPIO Output Enable Register */
+    u32    outputenb_read; /* Alive GPIO Output Read Register */
+    u32    reserved1[3];    /* Reserved1 */
+    u32    pad_reset;    /* Alive GPIO Output Reset Register */
+    u32    data;    /* Alive GPIO Output Register */
+    u32    pad_read;    /* Alive GPIO Pad Read Register */
+    u32    reserved2[33];    /* Reserved2 */
+    u32    pad;    /* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+    void *regs;
+    int gpio_count;
+    const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    const char *bank_name = plat->bank_name;
+
+    if (!strcmp(bank_name, "gpio_alv"))
+    return 1;
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    setbits_le32(>outputenb_reset, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, unsigned int 
pin,
+  int val)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    if (val)
+    setbits_le32(>data, 1 << pin);
+    else
+    setbits_le32(>pad_reset, 1 << pin);
+
+    setbits_le32(>outputenb, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+    unsigned int mask = 1UL << pin;
+    unsigned int value;
+
+    value = 

Re: [RFC PATCH 03/10] i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

2020-02-20 Thread Stefan B.

Hello Heiko,

see below my feedback, please give me further advise where indicated.

Unfortunately there have been some Bugs in the i2c-driver and I learned 
that this driver has not been used at all ("i2c-gpio" has been used 
instead). So I have done several Bugfixes and improvements appart from 
your proposals.



Regards
Stefan


Am 04.02.20 um 07:58 schrieb Heiko Schocher:

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in
   "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

Signed-off-by: Stefan Bosch 
---

  drivers/gpio/Kconfig   |   9 +
  drivers/gpio/Makefile  |   1 +
  drivers/gpio/nx_gpio.c | 252 +++
  drivers/i2c/Kconfig    |   9 +
  drivers/i2c/Makefile   |   1 +
  drivers/i2c/nx_i2c.c   | 537 
+

  drivers/mmc/Kconfig    |   6 +
  drivers/mmc/Makefile   |   1 +
  drivers/mmc/nexell_dw_mmc_dm.c | 350 +++
  drivers/pwm/Makefile   |   1 +
  drivers/pwm/pwm-nexell.c   | 252 +++
  drivers/pwm/pwm-nexell.h   |  54 +


Could you please split this patch into 4 parts (i2c, gpio, mmc and
pwm) ?

Thanks!


Ok, I will split this patch.


  12 files changed, 1473 insertions(+)
  create mode 100644 drivers/gpio/nx_gpio.c
  create mode 100644 drivers/i2c/nx_i2c.c
  create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
  create mode 100644 drivers/pwm/pwm-nexell.c
  create mode 100644 drivers/pwm/pwm-nexell.h


[...]

diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 449046b..e3340de 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)    += pm8916_gpio.o
  obj-$(CONFIG_MT7621_GPIO)    += mt7621_gpio.o
  obj-$(CONFIG_MSCC_SGPIO)    += mscc_sgpio.o
  obj-$(CONFIG_SIFIVE_GPIO)    += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)    += nx_gpio.o


Please keep lists sorted.


The list is not sorted (at least in no alphabetical order), but I can 
e.g. move "... += nx_gpio.o" one line up?





diff --git a/drivers/gpio/nx_gpio.c b/drivers/gpio/nx_gpio.c
new file mode 100644
index 000..86472f6
--- /dev/null
+++ b/drivers/gpio/nx_gpio.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+    u32    data;    /* Data register */
+    u32    outputenb;    /* Output Enable register */
+    u32    detmode[2];    /* Detect Mode Register */
+    u32    intenb;    /* Interrupt Enable Register */
+    u32    det;    /* Event Detect Register */
+    u32    pad;    /* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+    u32    pwrgate;    /* Power Gating Register */
+    u32    reserved0[28];    /* Reserved0 */
+    u32    outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+    u32    outputenb;    /* Alive GPIO Output Enable Register */
+    u32    outputenb_read; /* Alive GPIO Output Read Register */
+    u32    reserved1[3];    /* Reserved1 */
+    u32    pad_reset;    /* Alive GPIO Output Reset Register */
+    u32    data;    /* Alive GPIO Output Register */
+    u32    pad_read;    /* Alive GPIO Pad Read Register */
+    u32    reserved2[33];    /* Reserved2 */
+    u32    pad;    /* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+    void *regs;
+    int gpio_count;
+    const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    const char *bank_name = plat->bank_name;
+
+    if (!strcmp(bank_name, "gpio_alv"))
+    return 1;
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, 
unsigned int pin)

+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    setbits_le32(>outputenb_reset, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, 
unsigned int pin,

+  int val)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    if (val)
+    setbits_le32(>data, 1 << pin);
+    else
+    setbits_le32(>pad_reset, 1 << pin);
+
+    setbits_le32(>outputenb, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int 
pin)

+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+    unsigned int mask = 1UL << pin;
+    unsigned int value;
+
+    value = (readl(>pad_read) & mask) >> pin;
+
+    return value;
+}
+
+static int 

Re: [RFC PATCH 03/10] i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

2020-02-04 Thread Stefan B.

Hello Heiko,

thanks a lot for your annotations and suggestions. I will have a look at 
them and give you feedback ASAP.



Regards
Stefan


Am 04.02.20 um 07:58 schrieb Heiko Schocher:

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in
   "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

Signed-off-by: Stefan Bosch 
---

  drivers/gpio/Kconfig   |   9 +
  drivers/gpio/Makefile  |   1 +
  drivers/gpio/nx_gpio.c | 252 +++
  drivers/i2c/Kconfig    |   9 +
  drivers/i2c/Makefile   |   1 +
  drivers/i2c/nx_i2c.c   | 537 
+

  drivers/mmc/Kconfig    |   6 +
  drivers/mmc/Makefile   |   1 +
  drivers/mmc/nexell_dw_mmc_dm.c | 350 +++
  drivers/pwm/Makefile   |   1 +
  drivers/pwm/pwm-nexell.c   | 252 +++
  drivers/pwm/pwm-nexell.h   |  54 +


Could you please split this patch into 4 parts (i2c, gpio, mmc and
pwm) ?

Thanks!


  12 files changed, 1473 insertions(+)
  create mode 100644 drivers/gpio/nx_gpio.c
  create mode 100644 drivers/i2c/nx_i2c.c
  create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
  create mode 100644 drivers/pwm/pwm-nexell.c
  create mode 100644 drivers/pwm/pwm-nexell.h


[...]

diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 449046b..e3340de 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)    += pm8916_gpio.o
  obj-$(CONFIG_MT7621_GPIO)    += mt7621_gpio.o
  obj-$(CONFIG_MSCC_SGPIO)    += mscc_sgpio.o
  obj-$(CONFIG_SIFIVE_GPIO)    += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)    += nx_gpio.o


Please keep lists sorted.


diff --git a/drivers/gpio/nx_gpio.c b/drivers/gpio/nx_gpio.c
new file mode 100644
index 000..86472f6
--- /dev/null
+++ b/drivers/gpio/nx_gpio.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+    u32    data;    /* Data register */
+    u32    outputenb;    /* Output Enable register */
+    u32    detmode[2];    /* Detect Mode Register */
+    u32    intenb;    /* Interrupt Enable Register */
+    u32    det;    /* Event Detect Register */
+    u32    pad;    /* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+    u32    pwrgate;    /* Power Gating Register */
+    u32    reserved0[28];    /* Reserved0 */
+    u32    outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+    u32    outputenb;    /* Alive GPIO Output Enable Register */
+    u32    outputenb_read; /* Alive GPIO Output Read Register */
+    u32    reserved1[3];    /* Reserved1 */
+    u32    pad_reset;    /* Alive GPIO Output Reset Register */
+    u32    data;    /* Alive GPIO Output Register */
+    u32    pad_read;    /* Alive GPIO Pad Read Register */
+    u32    reserved2[33];    /* Reserved2 */
+    u32    pad;    /* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+    void *regs;
+    int gpio_count;
+    const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    const char *bank_name = plat->bank_name;
+
+    if (!strcmp(bank_name, "gpio_alv"))
+    return 1;
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, 
unsigned int pin)

+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    setbits_le32(>outputenb_reset, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, 
unsigned int pin,

+  int val)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    if (val)
+    setbits_le32(>data, 1 << pin);
+    else
+    setbits_le32(>pad_reset, 1 << pin);
+
+    setbits_le32(>outputenb, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int 
pin)

+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+    unsigned int mask = 1UL << pin;
+    unsigned int value;
+
+    value = (readl(>pad_read) & mask) >> pin;
+
+    return value;
+}
+
+static int nx_alive_gpio_set_value(struct udevice *dev, unsigned int 
pin,

+   int val)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    if (val)
+    setbits_le32(>data, 1 << pin);
+    else
+    clrbits_le32(>pad_reset, 1 << pin);
+
+    return 0;

Re: [RFC PATCH 03/10] i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

2020-02-03 Thread Heiko Schocher

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in
   "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

Signed-off-by: Stefan Bosch 
---

  drivers/gpio/Kconfig   |   9 +
  drivers/gpio/Makefile  |   1 +
  drivers/gpio/nx_gpio.c | 252 +++
  drivers/i2c/Kconfig|   9 +
  drivers/i2c/Makefile   |   1 +
  drivers/i2c/nx_i2c.c   | 537 +
  drivers/mmc/Kconfig|   6 +
  drivers/mmc/Makefile   |   1 +
  drivers/mmc/nexell_dw_mmc_dm.c | 350 +++
  drivers/pwm/Makefile   |   1 +
  drivers/pwm/pwm-nexell.c   | 252 +++
  drivers/pwm/pwm-nexell.h   |  54 +


Could you please split this patch into 4 parts (i2c, gpio, mmc and
pwm) ?

Thanks!


  12 files changed, 1473 insertions(+)
  create mode 100644 drivers/gpio/nx_gpio.c
  create mode 100644 drivers/i2c/nx_i2c.c
  create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
  create mode 100644 drivers/pwm/pwm-nexell.c
  create mode 100644 drivers/pwm/pwm-nexell.h


[...]

diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 449046b..e3340de 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO) += pm8916_gpio.o
  obj-$(CONFIG_MT7621_GPIO) += mt7621_gpio.o
  obj-$(CONFIG_MSCC_SGPIO)  += mscc_sgpio.o
  obj-$(CONFIG_SIFIVE_GPIO) += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)  += nx_gpio.o


Please keep lists sorted.


diff --git a/drivers/gpio/nx_gpio.c b/drivers/gpio/nx_gpio.c
new file mode 100644
index 000..86472f6
--- /dev/null
+++ b/drivers/gpio/nx_gpio.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+   u32 data;   /* Data register */
+   u32 outputenb;  /* Output Enable register */
+   u32 detmode[2]; /* Detect Mode Register */
+   u32 intenb; /* Interrupt Enable Register */
+   u32 det;/* Event Detect Register */
+   u32 pad;/* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+   u32 pwrgate;/* Power Gating Register */
+   u32 reserved0[28];  /* Reserved0 */
+   u32 outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+   u32 outputenb;  /* Alive GPIO Output Enable Register */
+   u32 outputenb_read; /* Alive GPIO Output Read Register */
+   u32 reserved1[3];   /* Reserved1 */
+   u32 pad_reset;  /* Alive GPIO Output Reset Register */
+   u32 data;   /* Alive GPIO Output Register */
+   u32 pad_read;   /* Alive GPIO Pad Read Register */
+   u32 reserved2[33];  /* Reserved2 */
+   u32 pad;/* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+   void *regs;
+   int gpio_count;
+   const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   const char *bank_name = plat->bank_name;
+
+   if (!strcmp(bank_name, "gpio_alv"))
+   return 1;
+
+   return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+
+   setbits_le32(>outputenb_reset, 1 << pin);
+
+   return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, unsigned int 
pin,
+ int val)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+
+   if (val)
+   setbits_le32(>data, 1 << pin);
+   else
+   setbits_le32(>pad_reset, 1 << pin);
+
+   setbits_le32(>outputenb, 1 << pin);
+
+   return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+   unsigned int mask = 1UL << pin;
+   unsigned int value;
+
+   value = (readl(>pad_read) & mask) >> pin;
+
+   return value;
+}
+
+static int nx_alive_gpio_set_value(struct udevice *dev, unsigned int pin,
+  int val)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+
+   if (val)
+   setbits_le32(>data, 1 << pin);
+   else
+

[RFC PATCH 03/10] i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

2020-02-03 Thread Stefan Bosch
Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in
  "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

Signed-off-by: Stefan Bosch 
---

 drivers/gpio/Kconfig   |   9 +
 drivers/gpio/Makefile  |   1 +
 drivers/gpio/nx_gpio.c | 252 +++
 drivers/i2c/Kconfig|   9 +
 drivers/i2c/Makefile   |   1 +
 drivers/i2c/nx_i2c.c   | 537 +
 drivers/mmc/Kconfig|   6 +
 drivers/mmc/Makefile   |   1 +
 drivers/mmc/nexell_dw_mmc_dm.c | 350 +++
 drivers/pwm/Makefile   |   1 +
 drivers/pwm/pwm-nexell.c   | 252 +++
 drivers/pwm/pwm-nexell.h   |  54 +
 12 files changed, 1473 insertions(+)
 create mode 100644 drivers/gpio/nx_gpio.c
 create mode 100644 drivers/i2c/nx_i2c.c
 create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
 create mode 100644 drivers/pwm/pwm-nexell.c
 create mode 100644 drivers/pwm/pwm-nexell.h

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 1de6f52..febda89 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -421,4 +421,13 @@ config MT7621_GPIO
help
  Say yes here to support MediaTek MT7621 compatible GPIOs.
 
+config NX_GPIO
+   bool "Nexell GPIO driver"
+   depends on DM_GPIO
+   help
+ Support GPIO access on Nexell SoCs. The GPIOs are arranged into
+ a number of banks (different for each SoC type) each with 32 GPIOs.
+ The GPIOs for a device are defined in the device tree with one node
+ for each bank.
+
 endmenu
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 449046b..e3340de 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO) += pm8916_gpio.o
 obj-$(CONFIG_MT7621_GPIO)  += mt7621_gpio.o
 obj-$(CONFIG_MSCC_SGPIO)   += mscc_sgpio.o
 obj-$(CONFIG_SIFIVE_GPIO)  += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)  += nx_gpio.o
diff --git a/drivers/gpio/nx_gpio.c b/drivers/gpio/nx_gpio.c
new file mode 100644
index 000..86472f6
--- /dev/null
+++ b/drivers/gpio/nx_gpio.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+   u32 data;   /* Data register */
+   u32 outputenb;  /* Output Enable register */
+   u32 detmode[2]; /* Detect Mode Register */
+   u32 intenb; /* Interrupt Enable Register */
+   u32 det;/* Event Detect Register */
+   u32 pad;/* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+   u32 pwrgate;/* Power Gating Register */
+   u32 reserved0[28];  /* Reserved0 */
+   u32 outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+   u32 outputenb;  /* Alive GPIO Output Enable Register */
+   u32 outputenb_read; /* Alive GPIO Output Read Register */
+   u32 reserved1[3];   /* Reserved1 */
+   u32 pad_reset;  /* Alive GPIO Output Reset Register */
+   u32 data;   /* Alive GPIO Output Register */
+   u32 pad_read;   /* Alive GPIO Pad Read Register */
+   u32 reserved2[33];  /* Reserved2 */
+   u32 pad;/* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+   void *regs;
+   int gpio_count;
+   const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   const char *bank_name = plat->bank_name;
+
+   if (!strcmp(bank_name, "gpio_alv"))
+   return 1;
+
+   return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+
+   setbits_le32(>outputenb_reset, 1 << pin);
+
+   return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, unsigned int 
pin,
+ int val)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+
+   if (val)
+   setbits_le32(>data, 1 << pin);
+   else
+   setbits_le32(>pad_reset, 1 << pin);
+
+   setbits_le32(>outputenb, 1 << pin);
+
+   return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+   struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+   struct nx_alive_gpio_regs *const regs = plat->regs;
+   unsigned int mask = 1UL << pin;
+   unsigned int value;
+
+