Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/amlogic Add Amlogic SD/MMC driver.



details:   https://anonhg.NetBSD.org/src/rev/34b718ca1e52
branches:  trunk
changeset: 806776:34b718ca1e52
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Mar 08 12:44:55 2015 +0000

description:
Add Amlogic SD/MMC driver.

diffstat:

 sys/arch/arm/amlogic/amlogic_board.c   |   58 +-
 sys/arch/arm/amlogic/amlogic_crureg.h  |   20 +-
 sys/arch/arm/amlogic/amlogic_io.c      |   10 +-
 sys/arch/arm/amlogic/amlogic_reg.h     |    3 +-
 sys/arch/arm/amlogic/amlogic_sdhc.c    |  585 +++++++++++++++++++++++++++++++++
 sys/arch/arm/amlogic/amlogic_sdhcreg.h |  150 ++++++++
 sys/arch/arm/amlogic/amlogic_var.h     |    8 +-
 7 files changed, 796 insertions(+), 38 deletions(-)

diffs (truncated from 952 to 300 lines):

diff -r 00afd7f9ebca -r 34b718ca1e52 sys/arch/arm/amlogic/amlogic_board.c
--- a/sys/arch/arm/amlogic/amlogic_board.c      Sun Mar 08 11:22:05 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_board.c      Sun Mar 08 12:44:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_board.c,v 1.8 2015/03/07 21:32:47 jmcneill Exp $ */
+/* $NetBSD: amlogic_board.c,v 1.9 2015/03/08 12:44:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_amlogic.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.8 2015/03/07 21:32:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.9 2015/03/08 12:44:55 jmcneill Exp $");
 
 #define        _ARM32_BUS_DMA_PRIVATE
 #include <sys/param.h>
@@ -191,47 +191,47 @@
 void
 amlogic_rng_init(void)
 {
-       printf("%s: GATING0 = %#x, GATING3 = %#x\n", __func__,
-           CBUS_READ(EE_CLK_GATING0_REG), CBUS_READ(EE_CLK_GATING3_REG));
-
        CBUS_WRITE(EE_CLK_GATING0_REG,
            CBUS_READ(EE_CLK_GATING0_REG) | EE_CLK_GATING0_RNG);
        CBUS_WRITE(EE_CLK_GATING3_REG,
            CBUS_READ(EE_CLK_GATING3_REG) | EE_CLK_GATING3_RNG);
-
-       printf("%s: GATING0 = %#x, GATING3 = %#x\n", __func__,
-           CBUS_READ(EE_CLK_GATING0_REG), CBUS_READ(EE_CLK_GATING3_REG));
 }
 
 void
 amlogic_sdhc_init(void)
 {
-       /* CARD -> SDHC pin mux settings */
-       CBUS_SET_CLEAR(PERIPHS_PIN_MUX_5_REG, 0, 0x00007c00);
-       CBUS_SET_CLEAR(PERIPHS_PIN_MUX_4_REG, 0, 0x7c000000);
-       CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0, 0x0000fc00);
-       CBUS_SET_CLEAR(PERIPHS_PIN_MUX_8_REG, 0, 0x00000600);
-       CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0x000000f0, 0);
-
-       const uint32_t pupd_mask = __BITS(25,20);       /* CARD_0-CARD_5 */
-       CBUS_SET_CLEAR(CBUS_REG(0x203c), pupd_mask, 0); /* PU/PD */
-       CBUS_SET_CLEAR(CBUS_REG(0x204a), pupd_mask, 0); /* PU/PD-EN */
-
-       const uint32_t io_mask = __BITS(27,22);         /* CARD_0-CARD_5 */
-       CBUS_SET_CLEAR(CBUS_REG(0x200c), io_mask, 0);   /* OEN */
-
-       /* XXX ODROID-C1 specific */
-       const uint32_t pwr_mask = __BIT(31);            /* CARD_8 */
-       CBUS_SET_CLEAR(CBUS_REG(0x201c), 0, pwr_mask);  /* O */
-       CBUS_SET_CLEAR(CBUS_REG(0x201b), 0, pwr_mask);  /* OEN */
-       const uint32_t cd_mask = __BIT(29);
-       CBUS_SET_CLEAR(CBUS_REG(0x201b), cd_mask, 0);   /* OEN */
-
        /* enable SDHC clk */
        CBUS_WRITE(EE_CLK_GATING0_REG,
            CBUS_READ(EE_CLK_GATING0_REG) | EE_CLK_GATING0_SDHC);
 }
 
+int
+amlogic_sdhc_select_port(int port)
+{
+       switch (port) {
+       case AMLOGIC_SDHC_PORT_B:
+               /* CARD -> SDHC pin mux settings */
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_5_REG, 0, 0x00007c00);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_4_REG, 0, 0x7c000000);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0, 0x0000fc00);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_8_REG, 0, 0x00000600);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0x000000f0, 0);
+               break;
+       case AMLOGIC_SDHC_PORT_C:
+               /* BOOT -> SDHC pin mux settings */
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0, 0x04c000f0);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_5_REG, 0, 0x00007c00);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_6_REG, 0, 0xff000000);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_4_REG, 0x70000000, 0);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_7_REG, 0x000c0000, 0);
+               break;
+       default:
+               return EINVAL;
+       }
+
+       return 0;
+}
+
 static void
 amlogic_usbphy_clkgate_enable(int port)
 {
diff -r 00afd7f9ebca -r 34b718ca1e52 sys/arch/arm/amlogic/amlogic_crureg.h
--- a/sys/arch/arm/amlogic/amlogic_crureg.h     Sun Mar 08 11:22:05 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_crureg.h     Sun Mar 08 12:44:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_crureg.h,v 1.6 2015/03/07 21:32:47 jmcneill Exp $ */
+/* $NetBSD: amlogic_crureg.h,v 1.7 2015/03/08 12:44:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -75,6 +75,8 @@
 #define PREG_CTLREG0_ADDR_REG          CBUS_REG(0x2000)
 #define PREG_CTLREG0_ADDR_CLKRATE      __BITS(9,4)
 
+#define PREG_PAD_GPIO0_EN_N_REG                CBUS_REG(0x200c)
+
 #define PERIPHS_PIN_MUX_0_REG          CBUS_REG(0x202c)
 #define PERIPHS_PIN_MUX_1_REG          CBUS_REG(0x202d)
 #define PERIPHS_PIN_MUX_2_REG          CBUS_REG(0x202e)
@@ -86,9 +88,25 @@
 #define PERIPHS_PIN_MUX_8_REG          CBUS_REG(0x2034)
 #define PERIPHS_PIN_MUX_9_REG          CBUS_REG(0x2035)
 
+#define PAD_PULL_UP_6_REG              CBUS_REG(0x2039)
+#define PAD_PULL_UP_0_REG              CBUS_REG(0x203a)
+#define PAD_PULL_UP_1_REG              CBUS_REG(0x203b)
+#define PAD_PULL_UP_2_REG              CBUS_REG(0x203c)
+#define PAD_PULL_UP_3_REG              CBUS_REG(0x203d)
+#define PAD_PULL_UP_4_REG              CBUS_REG(0x203e)
+#define PAD_PULL_UP_5_REG              CBUS_REG(0x203f)
+
 #define RAND64_ADDR0_REG               CBUS_REG(0x2040)
 #define RAND64_ADDR1_REG               CBUS_REG(0x2041)
 
+#define PAD_PULL_UP_EN_0_REG           CBUS_REG(0x2048)
+#define PAD_PULL_UP_EN_1_REG           CBUS_REG(0x2049)
+#define PAD_PULL_UP_EN_2_REG           CBUS_REG(0x204a)
+#define PAD_PULL_UP_EN_3_REG           CBUS_REG(0x204b)
+#define PAD_PULL_UP_EN_4_REG           CBUS_REG(0x204c)
+#define PAD_PULL_UP_EN_5_REG           CBUS_REG(0x204d)
+#define PAD_PULL_UP_EN_6_REG           CBUS_REG(0x204e)
+
 #define PREI_USB_PHY_A_CFG_REG         CBUS_REG(0x2200)
 #define PREI_USB_PHY_A_CTRL_REG                CBUS_REG(0x2201)
 #define PREI_USB_PHY_A_ADP_BC_REG      CBUS_REG(0x2203)
diff -r 00afd7f9ebca -r 34b718ca1e52 sys/arch/arm/amlogic/amlogic_io.c
--- a/sys/arch/arm/amlogic/amlogic_io.c Sun Mar 08 11:22:05 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_io.c Sun Mar 08 12:44:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_io.c,v 1.5 2015/03/07 21:34:25 jmcneill Exp $ */
+/* $NetBSD: amlogic_io.c,v 1.6 2015/03/08 12:44:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_amlogic.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.5 2015/03/07 21:34:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.6 2015/03/08 12:44:55 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -75,10 +75,10 @@
     AMLOGIC_USB1_OFFSET, AMLOGIC_USB_SIZE, 1, AMLOGIC_INTR_USB1 },
   { "awge",
     AMLOGIC_GMAC_OFFSET, AMLOGIC_GMAC_SIZE, NOPORT, AMLOGIC_INTR_GMAC },
-#if notyet
   { "amlogicsdhc",
-    AMLOGIC_SDHC_OFFSET, AMLOGIC_SDHC_SIZE, 0, AMLOGIC_INTR_SDHC },
-#endif
+    AMLOGIC_SDHC_OFFSET, AMLOGIC_SDHC_SIZE, 1, AMLOGIC_INTR_SDHC },
+  { "amlogicsdhc",
+    AMLOGIC_SDHC_OFFSET, AMLOGIC_SDHC_SIZE, 2, AMLOGIC_INTR_SDHC },
 };
 
 int
diff -r 00afd7f9ebca -r 34b718ca1e52 sys/arch/arm/amlogic/amlogic_reg.h
--- a/sys/arch/arm/amlogic/amlogic_reg.h        Sun Mar 08 11:22:05 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_reg.h        Sun Mar 08 12:44:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_reg.h,v 1.7 2015/03/07 21:32:47 jmcneill Exp $ */
+/* $NetBSD: amlogic_reg.h,v 1.8 2015/03/08 12:44:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -55,6 +55,7 @@
 
 #define AMLOGIC_AOBUS_OFFSET   0x08100000
 
+#define AMLOGIC_AO_RTI_PIN_MUX_OFFSET 0x08100014
 #define AMLOGIC_GPIOAO_OFFSET  0x08100024
 
 #define AMLOGIC_UART0AO_OFFSET 0x081004c0
diff -r 00afd7f9ebca -r 34b718ca1e52 sys/arch/arm/amlogic/amlogic_sdhc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_sdhc.c       Sun Mar 08 12:44:55 2015 +0000
@@ -0,0 +1,585 @@
+/* $NetBSD: amlogic_sdhc.c,v 1.1 2015/03/08 12:44:55 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "locators.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: amlogic_sdhc.c,v 1.1 2015/03/08 12:44:55 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <dev/sdmmc/sdmmcvar.h>
+#include <dev/sdmmc/sdmmcchip.h>
+#include <dev/sdmmc/sdmmc_ioreg.h>
+
+#include <arm/amlogic/amlogic_reg.h>
+#include <arm/amlogic/amlogic_sdhcreg.h>
+#include <arm/amlogic/amlogic_var.h>
+
+static int     amlogic_sdhc_match(device_t, cfdata_t, void *);
+static void    amlogic_sdhc_attach(device_t, device_t, void *);
+static void    amlogic_sdhc_attach_i(device_t);
+
+static int     amlogic_sdhc_intr(void *);
+
+struct amlogic_sdhc_softc {
+       device_t                sc_dev;
+       bus_space_tag_t         sc_bst;
+       bus_space_handle_t      sc_bsh;
+       bus_dma_tag_t           sc_dmat;
+       void                    *sc_ih;
+
+       device_t                sc_sdmmc_dev;
+       kmutex_t                sc_intr_lock;
+       kcondvar_t              sc_intr_cv;
+
+       uint32_t                sc_intr_ista;
+};
+
+CFATTACH_DECL_NEW(amlogic_sdhc, sizeof(struct amlogic_sdhc_softc),
+       amlogic_sdhc_match, amlogic_sdhc_attach, NULL, NULL);
+
+static int     amlogic_sdhc_host_reset(sdmmc_chipset_handle_t);
+static uint32_t        amlogic_sdhc_host_ocr(sdmmc_chipset_handle_t);
+static int     amlogic_sdhc_host_maxblklen(sdmmc_chipset_handle_t);
+static int     amlogic_sdhc_card_detect(sdmmc_chipset_handle_t);
+static int     amlogic_sdhc_write_protect(sdmmc_chipset_handle_t);
+static int     amlogic_sdhc_bus_power(sdmmc_chipset_handle_t, uint32_t);
+static int     amlogic_sdhc_bus_clock(sdmmc_chipset_handle_t, int);
+static int     amlogic_sdhc_bus_width(sdmmc_chipset_handle_t, int);
+static int     amlogic_sdhc_bus_rod(sdmmc_chipset_handle_t, int);
+static void    amlogic_sdhc_exec_command(sdmmc_chipset_handle_t,
+                                    struct sdmmc_command *);
+static void    amlogic_sdhc_card_enable_intr(sdmmc_chipset_handle_t, int);
+static void    amlogic_sdhc_card_intr_ack(sdmmc_chipset_handle_t);
+
+static int     amlogic_sdhc_set_clock(struct amlogic_sdhc_softc *, u_int);
+static int     amlogic_sdhc_wait_idle(struct amlogic_sdhc_softc *);
+static int     amlogic_sdhc_wait_ista(struct amlogic_sdhc_softc *, uint32_t, int);
+
+static struct sdmmc_chip_functions amlogic_sdhc_chip_functions = {
+       .host_reset = amlogic_sdhc_host_reset,
+       .host_ocr = amlogic_sdhc_host_ocr,
+       .host_maxblklen = amlogic_sdhc_host_maxblklen,
+       .card_detect = amlogic_sdhc_card_detect,
+       .write_protect = amlogic_sdhc_write_protect,
+       .bus_power = amlogic_sdhc_bus_power,
+       .bus_clock = amlogic_sdhc_bus_clock,
+       .bus_width = amlogic_sdhc_bus_width,
+       .bus_rod = amlogic_sdhc_bus_rod,
+       .exec_command = amlogic_sdhc_exec_command,
+       .card_enable_intr = amlogic_sdhc_card_enable_intr,
+       .card_intr_ack = amlogic_sdhc_card_intr_ack,
+};
+
+#define SDHC_WRITE(sc, reg, val) \
+       bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
+#define SDHC_READ(sc, reg) \
+       bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
+
+static int



Home | Main Index | Thread Index | Old Index