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 a driver for Amlogic "SDIO" MMC con...



details:   https://anonhg.NetBSD.org/src/rev/19bd0e434545
branches:  trunk
changeset: 337551:19bd0e434545
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Apr 19 18:54:52 2015 +0000

description:
Add a driver for Amlogic "SDIO" MMC controller.

diffstat:

 sys/arch/arm/amlogic/amlogic_board.c   |  123 +++++++-
 sys/arch/arm/amlogic/amlogic_crureg.h  |   21 +-
 sys/arch/arm/amlogic/amlogic_io.c      |    8 +-
 sys/arch/arm/amlogic/amlogic_sdio.c    |  499 +++++++++++++++++++++++++++++++++
 sys/arch/arm/amlogic/amlogic_sdioreg.h |  116 +++++++
 sys/arch/arm/amlogic/amlogic_var.h     |   13 +-
 sys/arch/arm/amlogic/files.amlogic     |    7 +-
 7 files changed, 779 insertions(+), 8 deletions(-)

diffs (truncated from 921 to 300 lines):

diff -r 07b04ad9003b -r 19bd0e434545 sys/arch/arm/amlogic/amlogic_board.c
--- a/sys/arch/arm/amlogic/amlogic_board.c      Sun Apr 19 18:53:33 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_board.c      Sun Apr 19 18:54:52 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_board.c,v 1.11 2015/04/03 14:02:06 jmcneill Exp $ */
+/* $NetBSD: amlogic_board.c,v 1.12 2015/04/19 18:54:52 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.11 2015/04/03 14:02:06 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.12 2015/04/19 18:54:52 jmcneill Exp $");
 
 #define        _ARM32_BUS_DMA_PRIVATE
 #include <sys/param.h>
@@ -109,6 +109,31 @@
 }
 
 uint32_t
+amlogic_get_rate_clk81(void)
+{
+       uint32_t cc, rate;
+
+       rate = amlogic_get_rate_fixed();
+       cc = CBUS_READ(HHI_MPEG_CLK_CNTL_REG);
+       
+       switch (__SHIFTOUT(cc, HHI_MPEG_CLK_CNTL_DIV_SRC)) {
+       case 7:
+               rate /= 5;
+               break;
+       case 6:
+               rate /= 3;
+               break;
+       case 5:
+               rate /= 4;
+               break;
+       default:
+               panic("CLK81: unknown rate, HHI_MPEG_CLK_CNTL_REG = %#x", cc);
+       }
+
+       return rate / (__SHIFTOUT(cc, HHI_MPEG_CLK_CNTL_DIV_N) + 1);
+}
+
+uint32_t
 amlogic_get_rate_fixed(void)
 {
        uint32_t cntl;
@@ -216,6 +241,11 @@
                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);
+
+               /* XXX ODROID-C1 */
+               CBUS_SET_CLEAR(PREG_PAD_GPIO5_EN_N_REG, 0x20000000, 0);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO5_OUT_REG, 0, 0x80000000);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO5_EN_N_REG, 0, 0x80000000);
                break;
        case AMLOGIC_SDHC_PORT_C:
                /* BOOT -> SDHC pin mux settings */
@@ -224,6 +254,93 @@
                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);
+
+               /* XXX ODROID-C1 */
+               CBUS_SET_CLEAR(PAD_PULL_UP_3_REG, 0, 0x000000ff);
+               break;
+       default:
+               return EINVAL;
+       }
+
+       return 0;
+}
+
+void
+amlogic_sdhc_reset_port(int port)
+{
+       switch (port) {
+       case AMLOGIC_SDHC_PORT_C:
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0, 0x01000000);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO3_EN_N_REG, 0, 0x00000200);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO3_OUT_REG, 0x00000200, 0);
+               delay(1000);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO3_OUT_REG, 0, 0x00000200);
+               delay(2000);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO3_OUT_REG, 0x00000200, 0);
+               delay(1000);
+               break;
+       }
+}
+
+bool
+amlogic_sdhc_is_removable(int port)
+{
+       switch (port) {
+       case AMLOGIC_SDHC_PORT_B:
+               return true;
+       default:
+               return false;
+       }
+}
+
+bool
+amlogic_sdhc_is_card_present(int port)
+{
+       switch (port) {
+       case AMLOGIC_SDHC_PORT_B:
+               /* GPIO CARD_6 */
+               return !(CBUS_READ(PREG_PAD_GPIO0_IN_REG) & __BIT(28));
+       default:
+               return true;
+       }
+}
+
+void
+amlogic_sdio_init(void)
+{
+       /* enable SDIO clk */
+       CBUS_WRITE(EE_CLK_GATING0_REG,
+           CBUS_READ(EE_CLK_GATING0_REG) | EE_CLK_GATING0_SDIO);
+
+       /* reset */
+       CBUS_SET_CLEAR(RESET6_REG, RESET6_SDIO, 0);
+}
+
+int
+amlogic_sdio_select_port(int port)
+{
+       switch (port) {
+       case AMLOGIC_SDIO_PORT_B:
+               /* CARD -> SDIO pin mux settings */
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_6_REG, 0, 0x3f000000);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_8_REG, 0, 0x0000063f);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0, 0x000000f0);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0x0000fc00, 0);
+
+               /* XXX ODROID-C1 */
+               CBUS_SET_CLEAR(PREG_PAD_GPIO5_EN_N_REG, 0x20000000, 0);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO5_OUT_REG, 0, 0x80000000);
+               CBUS_SET_CLEAR(PREG_PAD_GPIO5_EN_N_REG, 0, 0x80000000);
+               break;
+       case AMLOGIC_SDIO_PORT_C:
+               /* BOOT -> SDIO pin mux settings */
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_2_REG, 0, 0x06c2fc00);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_8_REG, 0, 0x0000003f);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_4_REG, 0, 0x6c000000);
+               CBUS_SET_CLEAR(PERIPHS_PIN_MUX_6_REG, 0xfc000000, 0);
+
+               /* XXX ODROID-C1 */
+               CBUS_SET_CLEAR(PAD_PULL_UP_3_REG, 0, 0x000000ff);
                break;
        default:
                return EINVAL;
@@ -292,7 +409,7 @@
        }
 
        if (port == 0) {
-               CBUS_WRITE(RESET1_REG, RESET1_USB);
+               CBUS_SET_CLEAR(RESET1_REG, RESET1_USB, 0);
        }
 
        amlogic_usbphy_clkgate_enable(port);
diff -r 07b04ad9003b -r 19bd0e434545 sys/arch/arm/amlogic/amlogic_crureg.h
--- a/sys/arch/arm/amlogic/amlogic_crureg.h     Sun Apr 19 18:53:33 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_crureg.h     Sun Apr 19 18:54:52 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_crureg.h,v 1.8 2015/04/03 14:02:06 jmcneill Exp $ */
+/* $NetBSD: amlogic_crureg.h,v 1.9 2015/04/19 18:54:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -54,6 +54,10 @@
 #define HHI_SYS_CPU_CLK_CNTL1_SDIV     __BITS(29,20)
 #define HHI_SYS_CPU_CLK_CNTL1_PERIPH_CLK_MUX __BITS(8,6)
 
+#define HHI_MPEG_CLK_CNTL_REG          CBUS_REG(0x105d)
+#define HHI_MPEG_CLK_CNTL_DIV_SRC      __BITS(14,12)
+#define HHI_MPEG_CLK_CNTL_DIV_N                __BITS(5,0)
+
 #define HHI_SYS_CPU_CLK_CNTL0_REG      CBUS_REG(0x1067)
 #define HHI_SYS_CPU_CLK_CNTL0_CLKSEL   __BIT(7)
 #define HHI_SYS_CPU_CLK_CNTL0_SOUTSEL  __BITS(3,2)
@@ -72,10 +76,25 @@
 #define RESET1_REG                     CBUS_REG(0x1102)
 #define RESET1_USB                     __BIT(2)
 
+#define RESET6_REG                     CBUS_REG(0x1107)
+#define RESET6_SDIO                    __BIT(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 PREG_PAD_GPIO0_OUT_REG         CBUS_REG(0x200d)
+#define PREG_PAD_GPIO0_IN_REG          CBUS_REG(0x200e)
+
+#define PREG_PAD_GPIO3_EN_N_REG                CBUS_REG(0x2015)
+#define PREG_PAD_GPIO3_OUT_REG         CBUS_REG(0x2016)
+#define PREG_PAD_GPIO3_IN_REG          CBUS_REG(0x2017)
+#define PREG_PAD_GPIO3_PUPD_EN_REG     CBUS_REG(0x204a)
+#define PREG_PAD_GPIO3_PUPD_REG                CBUS_REG(0x203c)
+
+#define PREG_PAD_GPIO5_EN_N_REG                CBUS_REG(0x201b)
+#define PREG_PAD_GPIO5_OUT_REG         CBUS_REG(0x201c)
+#define PREG_PAD_GPIO5_IN_REG          CBUS_REG(0x201d)
 
 #define PERIPHS_PIN_MUX_0_REG          CBUS_REG(0x202c)
 #define PERIPHS_PIN_MUX_1_REG          CBUS_REG(0x202d)
diff -r 07b04ad9003b -r 19bd0e434545 sys/arch/arm/amlogic/amlogic_io.c
--- a/sys/arch/arm/amlogic/amlogic_io.c Sun Apr 19 18:53:33 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_io.c Sun Apr 19 18:54:52 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_io.c,v 1.9 2015/03/29 22:49:44 jmcneill Exp $ */
+/* $NetBSD: amlogic_io.c,v 1.10 2015/04/19 18:54:52 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.9 2015/03/29 22:49:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.10 2015/04/19 18:54:52 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -73,6 +73,10 @@
     AMLOGIC_USB1_OFFSET, AMLOGIC_USB_SIZE, 1, AMLOGIC_INTR_USB1 },
   { "awge",
     AMLOGIC_GMAC_OFFSET, AMLOGIC_GMAC_SIZE, NOPORT, AMLOGIC_INTR_GMAC },
+  { "amlogicsdio",
+    AMLOGIC_SDIO_OFFSET, AMLOGIC_SDIO_SIZE, 1, AMLOGIC_INTR_SDIO },
+  { "amlogicsdio",
+    AMLOGIC_SDIO_OFFSET, AMLOGIC_SDIO_SIZE, 2, AMLOGIC_INTR_SDIO },
   { "amlogicsdhc",
     AMLOGIC_SDHC_OFFSET, AMLOGIC_SDHC_SIZE, 1, AMLOGIC_INTR_SDHC },
   { "amlogicsdhc",
diff -r 07b04ad9003b -r 19bd0e434545 sys/arch/arm/amlogic/amlogic_sdio.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_sdio.c       Sun Apr 19 18:54:52 2015 +0000
@@ -0,0 +1,499 @@
+/* $NetBSD: amlogic_sdio.c,v 1.1 2015/04/19 18:54:52 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_sdio.c,v 1.1 2015/04/19 18:54:52 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_sdioreg.h>
+#include <arm/amlogic/amlogic_var.h>
+
+static int     amlogic_sdio_match(device_t, cfdata_t, void *);
+static void    amlogic_sdio_attach(device_t, device_t, void *);
+static void    amlogic_sdio_attach_i(device_t);
+
+static int     amlogic_sdio_intr(void *);
+
+struct amlogic_sdio_softc {
+       device_t                sc_dev;



Home | Main Index | Thread Index | Old Index