Source-Changes-HG archive

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

[src/trunk]: src/sys/dev rtsx(4): Add support for RT525A, from o...



details:   https://anonhg.NetBSD.org/src/rev/e863109c4a58
branches:  trunk
changeset: 318455:e863109c4a58
user:      maya <maya%NetBSD.org@localhost>
date:      Tue Apr 24 18:34:30 2018 +0000
description:
rtsx(4): Add support for RT525A, from openbsd.

ok rkujawa

diffstat:

 sys/dev/ic/rtsx.c      |  30 +++++++++++++++++++----
 sys/dev/ic/rtsxreg.h   |  10 +++++++-
 sys/dev/ic/rtsxvar.h   |  12 +++++---
 sys/dev/pci/rtsx_pci.c |  63 +++++++++++++++++++++++++++----------------------
 4 files changed, 75 insertions(+), 40 deletions(-)

diffs (252 lines):

diff -r fc0ba25a7eb9 -r e863109c4a58 sys/dev/ic/rtsx.c
--- a/sys/dev/ic/rtsx.c Tue Apr 24 18:31:48 2018 +0000
+++ b/sys/dev/ic/rtsx.c Tue Apr 24 18:34:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsx.c,v 1.2 2014/10/29 14:24:09 nonaka Exp $  */
+/*     $NetBSD: rtsx.c,v 1.3 2018/04/24 18:34:30 maya Exp $    */
 /*     $OpenBSD: rtsx.c,v 1.10 2014/08/19 17:55:03 phessler Exp $      */
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsx.c,v 1.2 2014/10/29 14:24:09 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsx.c,v 1.3 2018/04/24 18:34:30 maya Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -560,7 +560,9 @@
        disable3 = RTSX_PULL_CTL_DISABLE3;
        if (RTSX_IS_RTS5209(sc))
                RTSX_SET(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_OFF);
-       else if (RTSX_IS_RTS5227(sc) || RTSX_IS_RTS5229(sc)) {
+       else if (RTSX_IS_RTS5227(sc)
+               || RTSX_IS_RTS5229(sc)
+               || RTSX_IS_RTS525A(sc)) {
                RTSX_CLR(sc, RTSX_PWR_GATE_CTRL, RTSX_LDO3318_VCC1 |
                    RTSX_LDO3318_VCC2);
                if (RTSX_IS_RTS5229_TYPE_C(sc))
@@ -578,7 +580,10 @@
        RTSX_CLR(sc, RTSX_CARD_PWR_CTL, RTSX_PMOS_STRG_800mA);
 
        /* Disable pull control. */
-       if (RTSX_IS_RTS5209(sc) || RTSX_IS_RTS5227(sc) || RTSX_IS_RTS5229(sc)) {
+       if (RTSX_IS_RTS5209(sc)
+           || RTSX_IS_RTS5227(sc)
+           || RTSX_IS_RTS5229(sc)
+           || RTSX_IS_RTS525A(sc)) {
                RTSX_WRITE(sc, RTSX_CARD_PULL_CTL1, RTSX_PULL_CTL_DISABLE12);
                RTSX_WRITE(sc, RTSX_CARD_PULL_CTL2, RTSX_PULL_CTL_DISABLE12);
                RTSX_WRITE(sc, RTSX_CARD_PULL_CTL3, disable3);
@@ -612,13 +617,23 @@
 {
        uint8_t enable3;
 
+       if (RTSX_IS_RTS525A(sc)) {
+               int err = rtsx_write(sc, RTSX_LDO_VCC_CFG1, RTSX_LDO_VCC_TUNE_MASK,
+                   RTSX_LDO_VCC_3V3);
+               if (err)
+                       return err;
+       }
+
        /* Select SD card. */
        RTSX_WRITE(sc, RTSX_CARD_SELECT, RTSX_SD_MOD_SEL);
        RTSX_WRITE(sc, RTSX_CARD_SHARE_MODE, RTSX_CARD_SHARE_48_SD);
        RTSX_SET(sc, RTSX_CARD_CLK_EN, RTSX_SD_CLK_EN);
 
        /* Enable pull control. */
-       if (RTSX_IS_RTS5209(sc) || RTSX_IS_RTS5227(sc) || RTSX_IS_RTS5229(sc)) {
+       if (RTSX_IS_RTS5209(sc)
+           || RTSX_IS_RTS5227(sc)
+           || RTSX_IS_RTS5229(sc)
+           || RTSX_IS_RTS525A(sc)) {
                RTSX_WRITE(sc, RTSX_CARD_PULL_CTL1, RTSX_PULL_CTL_ENABLE12);
                RTSX_WRITE(sc, RTSX_CARD_PULL_CTL2, RTSX_PULL_CTL_ENABLE12);
                if (RTSX_IS_RTS5229_TYPE_C(sc))
@@ -653,7 +668,10 @@
         * delay in between.
         */
 
-       if (RTSX_IS_RTS5209(sc) || RTSX_IS_RTS5227(sc) || RTSX_IS_RTS5229(sc)) {
+       if (RTSX_IS_RTS5209(sc)
+           || RTSX_IS_RTS5227(sc)
+           || RTSX_IS_RTS5229(sc)
+           || RTSX_IS_RTS525A(sc)) {
                /* Partial power. */
                RTSX_SET(sc, RTSX_CARD_PWR_CTL, RTSX_SD_PARTIAL_PWR_ON);
                if (RTSX_IS_RTS5209(sc))
diff -r fc0ba25a7eb9 -r e863109c4a58 sys/dev/ic/rtsxreg.h
--- a/sys/dev/ic/rtsxreg.h      Tue Apr 24 18:31:48 2018 +0000
+++ b/sys/dev/ic/rtsxreg.h      Tue Apr 24 18:34:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsxreg.h,v 1.2 2014/10/29 14:24:09 nonaka Exp $       */
+/*     $NetBSD: rtsxreg.h,v 1.3 2018/04/24 18:34:30 maya Exp $ */
 /*     $OpenBSD: rtsxreg.h,v 1.3 2013/11/26 20:33:16 deraadt Exp $     */
 
 /*
@@ -544,6 +544,14 @@
 
 #define        RTSX_DUMMY_REG          0xFE90
 
+#define        RTSX_LDO_VCC_CFG1       0xFF73
+#define        RTSX_LDO_VCC_REF_TUNE_MASK      0x30
+#define        RTSX_LDO_VCC_REF_1V2            0x20
+#define        RTSX_LDO_VCC_TUNE_MASK          0x07
+#define        RTSX_LDO_VCC_1V8                0x04
+#define        RTSX_LDO_VCC_3V3                0x07
+#define        RTSX_LDO_VCC_LMT_EN             0x08
+
 #define        RTSX_SG_INT             0x04
 #define        RTSX_SG_END             0x02
 #define        RTSX_SG_VALID           0x01
diff -r fc0ba25a7eb9 -r e863109c4a58 sys/dev/ic/rtsxvar.h
--- a/sys/dev/ic/rtsxvar.h      Tue Apr 24 18:31:48 2018 +0000
+++ b/sys/dev/ic/rtsxvar.h      Tue Apr 24 18:34:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsxvar.h,v 1.2 2014/10/29 14:24:09 nonaka Exp $       */
+/*     $NetBSD: rtsxvar.h,v 1.3 2018/04/24 18:34:30 maya Exp $ */
 /*     $OpenBSD: rtsxvar.h,v 1.3 2014/08/19 17:55:03 phessler Exp $    */
 
 /*
@@ -57,10 +57,11 @@
 #define        RTSX_F_5227             __BIT(3)
 #define        RTSX_F_5229             __BIT(4)
 #define        RTSX_F_5229_TYPE_C      __BIT(5)
-#define        RTSX_F_8402             __BIT(6)
-#define        RTSX_F_8411             __BIT(7)
-#define        RTSX_F_8411B            __BIT(8)
-#define        RTSX_F_8411B_QFN48      __BIT(9)
+#define        RTSX_F_525A             __BIT(6)
+#define        RTSX_F_8402             __BIT(7)
+#define        RTSX_F_8411             __BIT(8)
+#define        RTSX_F_8411B            __BIT(9)
+#define        RTSX_F_8411B_QFN48      __BIT(10)
 };
 
 #define        RTSX_IS_RTS5209(sc)     (((sc)->sc_flags & RTSX_F_5209) == RTSX_F_5209)
@@ -69,6 +70,7 @@
 #define        RTSX_IS_RTS5229_TYPE_C(sc)                                      \
        (((sc)->sc_flags & (RTSX_F_5229|RTSX_F_5229_TYPE_C)) ==         \
                           (RTSX_F_5229|RTSX_F_5229_TYPE_C))
+#define        RTSX_IS_RTS525A(sc)     (((sc)->sc_flags & RTSX_F_525A) == RTSX_F_525A)
 #define        RTSX_IS_RTL8402(sc)     (((sc)->sc_flags & RTSX_F_8402) == RTSX_F_8402)
 #define        RTSX_IS_RTL8411(sc)     (((sc)->sc_flags & RTSX_F_8411) == RTSX_F_8411)
 #define        RTSX_IS_RTL8411B(sc)                                            \
diff -r fc0ba25a7eb9 -r e863109c4a58 sys/dev/pci/rtsx_pci.c
--- a/sys/dev/pci/rtsx_pci.c    Tue Apr 24 18:31:48 2018 +0000
+++ b/sys/dev/pci/rtsx_pci.c    Tue Apr 24 18:34:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsx_pci.c,v 1.6 2016/07/07 06:55:41 msaitoh Exp $     */
+/*     $NetBSD: rtsx_pci.c,v 1.7 2018/04/24 18:34:30 maya Exp $        */
 /*     $OpenBSD: rtsx_pci.c,v 1.7 2014/08/19 17:55:03 phessler Exp $   */
 
 
@@ -20,7 +20,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsx_pci.c,v 1.6 2016/07/07 06:55:41 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsx_pci.c,v 1.7 2018/04/24 18:34:30 maya Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -36,7 +36,8 @@
 
 #include <dev/sdmmc/sdmmcvar.h>
 
-#define RTSX_PCI_BAR   0x10
+#define RTSX_PCI_BAR           0x10
+#define RTSX_PCI_BAR_525A      0x14
 
 struct rtsx_pci_softc {
        struct rtsx_softc sc;
@@ -78,6 +79,7 @@
        case PCI_PRODUCT_REALTEK_RTS5209:
        case PCI_PRODUCT_REALTEK_RTS5227:
        case PCI_PRODUCT_REALTEK_RTS5229:
+       case PCI_PRODUCT_REALTEK_RTS525A:
        case PCI_PRODUCT_REALTEK_RTL8402:
        case PCI_PRODUCT_REALTEK_RTL8411:
        case PCI_PRODUCT_REALTEK_RTL8411B:
@@ -100,11 +102,40 @@
        bus_space_handle_t ioh;
        bus_size_t size;
        uint32_t flags;
+       int bar = RTSX_PCI_BAR;
        char intrbuf[PCI_INTRSTR_LEN];
 
        sc->sc.sc_dev = self;
        sc->sc_pc = pc;
 
+       switch (PCI_PRODUCT(pa->pa_id)) {
+       case PCI_PRODUCT_REALTEK_RTS5209:
+               flags = RTSX_F_5209;
+               break;
+       case PCI_PRODUCT_REALTEK_RTS5227:
+               flags = RTSX_F_5227;
+               break;
+       case PCI_PRODUCT_REALTEK_RTS5229:
+               flags = RTSX_F_5229;
+               break;
+       case PCI_PRODUCT_REALTEK_RTS525A:
+               flags = RTSX_F_525A;
+               bar = RTSX_PCI_BAR_525A;
+               break;
+       case PCI_PRODUCT_REALTEK_RTL8402:
+               flags = RTSX_F_8402;
+               break;
+       case PCI_PRODUCT_REALTEK_RTL8411:
+               flags = RTSX_F_8411;
+               break;
+       case PCI_PRODUCT_REALTEK_RTL8411B:
+               flags = RTSX_F_8411B;
+               break;
+       default:
+               flags = 0;
+               break;
+       }
+
        pci_aprint_devinfo(pa, NULL);
 
        if ((pci_conf_read(pc, tag, RTSX_CFG_PCI) & RTSX_CFG_ASIC) != 0) {
@@ -112,7 +143,7 @@
                return;
        }
 
-       if (pci_mapreg_map(pa, RTSX_PCI_BAR, PCI_MAPREG_TYPE_MEM, 0,
+       if (pci_mapreg_map(pa, bar, PCI_MAPREG_TYPE_MEM, 0,
            &iot, &ioh, NULL, &size)) {
                aprint_error_dev(self, "couldn't map registers\n");
                return;
@@ -139,30 +170,6 @@
        /* Power up the device */
        pci_set_powerstate(pc, tag, PCI_PMCSR_STATE_D0);
 
-       switch (PCI_PRODUCT(pa->pa_id)) {
-       case PCI_PRODUCT_REALTEK_RTS5209:
-               flags = RTSX_F_5209;
-               break;
-       case PCI_PRODUCT_REALTEK_RTS5227:
-               flags = RTSX_F_5227;
-               break;
-       case PCI_PRODUCT_REALTEK_RTS5229:
-               flags = RTSX_F_5229;
-               break;
-       case PCI_PRODUCT_REALTEK_RTL8402:
-               flags = RTSX_F_8402;
-               break;
-       case PCI_PRODUCT_REALTEK_RTL8411:
-               flags = RTSX_F_8411;
-               break;
-       case PCI_PRODUCT_REALTEK_RTL8411B:
-               flags = RTSX_F_8411B;
-               break;
-       default:
-               flags = 0;
-               break;
-       }
-
        if (rtsx_attach(&sc->sc, iot, ioh, size, pa->pa_dmat, flags) != 0) {
                aprint_error_dev(self, "couldn't initialize chip\n");
                return;



Home | Main Index | Thread Index | Old Index