Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/imx Move to common function.



details:   https://anonhg.NetBSD.org/src/rev/cdadde3752d2
branches:  trunk
changeset: 349107:cdadde3752d2
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Thu Nov 24 08:41:20 2016 +0000

description:
Move to common function.
sdhc_set_gpio_cd() -> imx6_set_gpio()

diffstat:

 sys/arch/arm/imx/imx6_board.c |  53 ++++++++++++++++++++++++++++++++-
 sys/arch/arm/imx/imx6_usdhc.c |  67 ++++++++----------------------------------
 sys/arch/arm/imx/imx6var.h    |   3 +-
 3 files changed, 67 insertions(+), 56 deletions(-)

diffs (234 lines):

diff -r e291e9ebedcf -r cdadde3752d2 sys/arch/arm/imx/imx6_board.c
--- a/sys/arch/arm/imx/imx6_board.c     Thu Nov 24 07:32:19 2016 +0000
+++ b/sys/arch/arm/imx/imx6_board.c     Thu Nov 24 08:41:20 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_board.c,v 1.6 2016/10/20 09:53:07 skrll Exp $     */
+/*     $NetBSD: imx6_board.c,v 1.7 2016/11/24 08:41:20 hkenken Exp $   */
 
 /*
  * Copyright (c) 2012  Genetec Corporation.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: imx6_board.c,v 1.6 2016/10/20 09:53:07 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: imx6_board.c,v 1.7 2016/11/24 08:41:20 hkenken Exp $");
 
 #include "opt_imx.h"
 #include "arml2cc.h"
@@ -36,6 +36,7 @@
 #include <sys/bus.h>
 #include <sys/cpu.h>
 #include <sys/device.h>
+#include <sys/gpio.h>
 
 #include <arm/locore.h>
 #include <arm/cortex/a9tmr_var.h>
@@ -47,6 +48,7 @@
 #include <arm/imx/imx6_mmdcreg.h>
 #include <arm/imx/imx6_ccmreg.h>
 #include <arm/imx/imxwdogreg.h>
+#include <arm/imx/imxgpiovar.h>
 
 bus_space_tag_t imx6_ioreg_bst = &armv7_generic_bs_tag;
 bus_space_handle_t imx6_ioreg_bsh;
@@ -230,3 +232,50 @@
        a9tmr_init_cpu_clock(ci);
 }
 #endif
+
+void
+imx6_set_gpio(device_t self, const char *name, int32_t *gpio,
+    int32_t *active, u_int dir)
+{
+       prop_dictionary_t dict;
+       const char *pin_data;
+       int grp, pin;
+
+       *gpio = -1;
+       *active = -1;
+
+       dict = device_properties(self);
+       if (!prop_dictionary_get_cstring_nocopy(dict, name, &pin_data))
+               return;
+
+       /*
+        * "!1,6" -> gpio = GPIO_NO(1,6),  active = GPIO_PIN_LOW
+        * "3,31" -> gpio = GPIO_NO(3,31), active = GPIO_PIN_HIGH
+        * "!"    -> always not detected
+        * none   -> always detected
+        */
+       if (*pin_data == '!') {
+               *active = GPIO_PIN_LOW;
+               pin_data++;
+       } else
+               *active = GPIO_PIN_HIGH;
+
+       if (*pin_data == '\0')
+               return;
+
+       for (grp = 0; (*pin_data >= '0') && (*pin_data <= '9'); pin_data++)
+               grp = grp * 10 + *pin_data - '0';
+
+       KASSERT(*pin_data == ',');
+       pin_data++;
+
+       for (pin = 0; (*pin_data >= '0') && (*pin_data <= '9'); pin_data++)
+               pin = pin * 10 + *pin_data - '0';
+
+       KASSERT(*pin_data == '\0');
+
+       *gpio = GPIO_NO(grp, pin);
+#if NIMXGPIO > 0
+       gpio_set_direction(*gpio, dir);
+#endif
+}
diff -r e291e9ebedcf -r cdadde3752d2 sys/arch/arm/imx/imx6_usdhc.c
--- a/sys/arch/arm/imx/imx6_usdhc.c     Thu Nov 24 07:32:19 2016 +0000
+++ b/sys/arch/arm/imx/imx6_usdhc.c     Thu Nov 24 08:41:20 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_usdhc.c,v 1.2 2015/12/31 11:53:18 ryo Exp $ */
+/*     $NetBSD: imx6_usdhc.c,v 1.3 2016/11/24 08:41:20 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2012  Genetec Corporation.  All rights reserved.
@@ -30,7 +30,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_usdhc.c,v 1.2 2015/12/31 11:53:18 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_usdhc.c,v 1.3 2016/11/24 08:41:20 hkenken Exp $");
 
 #include "imxgpio.h"
 
@@ -39,6 +39,7 @@
 #include <sys/systm.h>
 #include <sys/bus.h>
 #include <sys/pmf.h>
+#include <sys/gpio.h>
 
 #include <machine/intr.h>
 
@@ -58,7 +59,7 @@
        /* we have only one slot */
        struct sdhc_host *sc_hosts[1];
        int32_t sc_gpio_cd;
-       int32_t sc_gpio_cd_low_active;
+       int32_t sc_gpio_cd_active;
        void *sc_ih;
 };
 
@@ -95,60 +96,16 @@
 #if NIMXGPIO > 0
        if (sc->sc_gpio_cd >= 0) {
                detect = gpio_data_read(sc->sc_gpio_cd);
+               if (sc->sc_gpio_cd_active == GPIO_PIN_LOW)
+                       detect = !detect;
        } else
 #endif
                detect = 1;
-       if (sc->sc_gpio_cd_low_active)
-               detect = detect ? 0 : 1;
 
        return detect;
 }
 
 static void
-sdhc_set_gpio_cd(struct sdhc_axi_softc *sc, const char *name)
-{
-       prop_dictionary_t dict;
-       const char *pin_data;
-       int grp, pin;
-
-       dict = device_properties(sc->sc_sdhc.sc_dev);
-       if (!prop_dictionary_get_cstring_nocopy(dict, name, &pin_data))
-               return;
-
-       /*
-        * "!1,6" -> gpio_cd = GPIO_NO(1,6),  gpio_cd_low_active = 1
-        * "3,31" -> gpio_cd = GPIO_NO(3,31), gpio_cd_low_active = 0
-        * "!"    -> always not detected
-        * none   -> always detected
-        */
-       if (*pin_data == '!') {
-               sc->sc_gpio_cd_low_active = 1;
-               pin_data++;
-       } else
-               sc->sc_gpio_cd_low_active = 0;
-
-       sc->sc_gpio_cd = -1;
-       if (*pin_data == '\0')
-               return;
-
-       for (grp = 0; (*pin_data >= '0') && (*pin_data <= '9'); pin_data++)
-               grp = grp * 10 + *pin_data - '0';
-
-       KASSERT(*pin_data == ',');
-       pin_data++;
-
-       for (pin = 0; (*pin_data >= '0') && (*pin_data <= '9'); pin_data++)
-               pin = pin * 10 + *pin_data - '0';
-
-       KASSERT(*pin_data == '\0');
-
-       sc->sc_gpio_cd = GPIO_NO(grp, pin);
-#if NIMXGPIO > 0
-       gpio_set_direction(sc->sc_gpio_cd, GPIO_DIR_IN);
-#endif
-}
-
-static void
 sdhc_attach(device_t parent, device_t self, void *aux)
 {
        struct sdhc_axi_softc *sc = device_private(self);
@@ -174,25 +131,29 @@
                v = imx6_ccm_read(CCM_CCGR6);
                imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC1_CLK_ENABLE(3));
                perclk = imx6_get_clock(IMX6CLK_USDHC1);
-               sdhc_set_gpio_cd(sc, "usdhc1-cd-gpio");
+               imx6_set_gpio(self, "usdhc1-cd-gpio", &sc->sc_gpio_cd,
+                   &sc->sc_gpio_cd_active, GPIO_DIR_IN);
                break;
        case IMX6_AIPS2_BASE + AIPS2_USDHC2_BASE:
                v = imx6_ccm_read(CCM_CCGR6);
                imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC2_CLK_ENABLE(3));
                perclk = imx6_get_clock(IMX6CLK_USDHC2);
-               sdhc_set_gpio_cd(sc, "usdhc2-cd-gpio");
+               imx6_set_gpio(self, "usdhc2-cd-gpio", &sc->sc_gpio_cd,
+                   &sc->sc_gpio_cd_active, GPIO_DIR_IN);
                break;
        case IMX6_AIPS2_BASE + AIPS2_USDHC3_BASE:
                v = imx6_ccm_read(CCM_CCGR6);
                imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC3_CLK_ENABLE(3));
                perclk = imx6_get_clock(IMX6CLK_USDHC3);
-               sdhc_set_gpio_cd(sc, "usdhc3-cd-gpio");
+               imx6_set_gpio(self, "usdhc3-cd-gpio", &sc->sc_gpio_cd,
+                   &sc->sc_gpio_cd_active, GPIO_DIR_IN);
                break;
        case IMX6_AIPS2_BASE + AIPS2_USDHC4_BASE:
                v = imx6_ccm_read(CCM_CCGR6);
                imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC4_CLK_ENABLE(3));
                perclk = imx6_get_clock(IMX6CLK_USDHC4);
-               sdhc_set_gpio_cd(sc, "usdhc4-cd-gpio");
+               imx6_set_gpio(self, "usdhc4-cd-gpio", &sc->sc_gpio_cd,
+                   &sc->sc_gpio_cd_active, GPIO_DIR_IN);
                break;
        }
 
diff -r e291e9ebedcf -r cdadde3752d2 sys/arch/arm/imx/imx6var.h
--- a/sys/arch/arm/imx/imx6var.h        Thu Nov 24 07:32:19 2016 +0000
+++ b/sys/arch/arm/imx/imx6var.h        Thu Nov 24 08:41:20 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6var.h,v 1.4 2015/12/31 12:14:01 ryo Exp $  */
+/*     $NetBSD: imx6var.h,v 1.5 2016/11/24 08:41:20 hkenken Exp $      */
 
 /*
  * Copyright (c) 2014 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -68,6 +68,7 @@
 void imx6_reset(void) __dead;
 void imx6_device_register(device_t, void *);
 void imx6_cpu_hatch(struct cpu_info *);
+void imx6_set_gpio(device_t, const char *, int32_t *, int32_t *, u_int);
 uint32_t imx6_chip_id(void);
 #define CHIPID_MINOR_MASK              0x000000ff
 #define CHIPID_MAJOR_MASK              0x00ffff00



Home | Main Index | Thread Index | Old Index