Module Name: src
Committed By: hkenken
Date: Thu Nov 24 08:41:20 UTC 2016
Modified Files:
src/sys/arch/arm/imx: imx6_board.c imx6_usdhc.c imx6var.h
Log Message:
Move to common function.
sdhc_set_gpio_cd() -> imx6_set_gpio()
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/imx/imx6_board.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/imx/imx6_usdhc.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/imx/imx6var.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/imx/imx6_board.c
diff -u src/sys/arch/arm/imx/imx6_board.c:1.6 src/sys/arch/arm/imx/imx6_board.c:1.7
--- src/sys/arch/arm/imx/imx6_board.c:1.6 Thu Oct 20 09:53:07 2016
+++ src/sys/arch/arm/imx/imx6_board.c Thu Nov 24 08:41:20 2016
@@ -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 @@ __KERNEL_RCSID(1, "$NetBSD: imx6_board.c
#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 @@ __KERNEL_RCSID(1, "$NetBSD: imx6_board.c
#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 @@ imx6_cpu_hatch(struct cpu_info *ci)
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
+}
Index: src/sys/arch/arm/imx/imx6_usdhc.c
diff -u src/sys/arch/arm/imx/imx6_usdhc.c:1.2 src/sys/arch/arm/imx/imx6_usdhc.c:1.3
--- src/sys/arch/arm/imx/imx6_usdhc.c:1.2 Thu Dec 31 11:53:18 2015
+++ src/sys/arch/arm/imx/imx6_usdhc.c Thu Nov 24 08:41:20 2016
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: imx6_usdhc.c
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/pmf.h>
+#include <sys/gpio.h>
#include <machine/intr.h>
@@ -58,7 +59,7 @@ struct sdhc_axi_softc {
/* 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 @@ imx6_sdhc_card_detect(struct sdhc_softc
#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 @@ sdhc_attach(device_t parent, device_t se
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;
}
Index: src/sys/arch/arm/imx/imx6var.h
diff -u src/sys/arch/arm/imx/imx6var.h:1.4 src/sys/arch/arm/imx/imx6var.h:1.5
--- src/sys/arch/arm/imx/imx6var.h:1.4 Thu Dec 31 12:14:01 2015
+++ src/sys/arch/arm/imx/imx6var.h Thu Nov 24 08:41:20 2016
@@ -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 <[email protected]>
@@ -68,6 +68,7 @@ uint32_t imx6_armrootclk(void);
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