tech-kern archive

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

rtsx(4) adding RTS525A



This is in a Dell XPS 15 9550.

it seems to work. it detects card inserted and ejected, I can mount
stuff, write stuff, remount, read the same contents again.
I don't see a LED light for it on my machine.

(Needs a pcidevs entry too.)

I don't really know what I'm doing, mostly adapted to have the same
code as RTSX_IS_RTS5227... etc.
In openbsd, that is handled with an 'else' case. they don't seem to
have the RT84xxx stuff we have. I can also do this with 'else' if
that's better.
Shuffled the flags definitions to maintain order.

Thoughts? OKs?
From 935f6a2f88b99fda00e499b3aa0c751c72f9814b Mon Sep 17 00:00:00 2001
From: coypu <coypu%sdf.org@localhost>
Date: Tue, 24 Apr 2018 19:54:27 +0300
Subject: [PATCH 1/1] add RTS525A support. From openbsd.

---
 sys/dev/ic/rtsx.c      | 26 ++++++++++++++++---
 sys/dev/ic/rtsxreg.h   |  8 ++++++
 sys/dev/ic/rtsxvar.h   | 10 ++++---
 sys/dev/pci/rtsx_pci.c | 59 +++++++++++++++++++++++-------------------
 4 files changed, 69 insertions(+), 34 deletions(-)

diff --git a/sys/dev/ic/rtsx.c b/sys/dev/ic/rtsx.c
index 380ff8c78..d10b04404 100644
--- a/sys/dev/ic/rtsx.c
+++ b/sys/dev/ic/rtsx.c
@@ -560,7 +560,9 @@ rtsx_bus_power_off(struct rtsx_softc *sc)
 	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_bus_power_off(struct rtsx_softc *sc)
 	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 @@ rtsx_bus_power_on(struct rtsx_softc *sc)
 {
 	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 @@ rtsx_bus_power_on(struct rtsx_softc *sc)
 	 * 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 --git a/sys/dev/ic/rtsxreg.h b/sys/dev/ic/rtsxreg.h
index 3f00da885..90489b09a 100644
--- a/sys/dev/ic/rtsxreg.h
+++ b/sys/dev/ic/rtsxreg.h
@@ -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 --git a/sys/dev/ic/rtsxvar.h b/sys/dev/ic/rtsxvar.h
index 13f0d5242..98ea4236f 100644
--- a/sys/dev/ic/rtsxvar.h
+++ b/sys/dev/ic/rtsxvar.h
@@ -57,10 +57,11 @@ struct rtsx_softc {
 #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 @@ struct rtsx_softc {
 #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 --git a/sys/dev/pci/rtsx_pci.c b/sys/dev/pci/rtsx_pci.c
index 98061091b..83cdef71e 100644
--- a/sys/dev/pci/rtsx_pci.c
+++ b/sys/dev/pci/rtsx_pci.c
@@ -36,7 +36,8 @@ __KERNEL_RCSID(0, "$NetBSD: rtsx_pci.c,v 1.6 2016/07/07 06:55:41 msaitoh Exp $")
 
 #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 @@ rtsx_pci_match(device_t parent, cfdata_t cf, void *aux)
 	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 @@ rtsx_pci_attach(device_t parent, device_t self, void *aux)
 	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 @@ rtsx_pci_attach(device_t parent, device_t self, void *aux)
 		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 @@ rtsx_pci_attach(device_t parent, device_t self, void *aux)
 	/* 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;
-- 
2.17.0



Home | Main Index | Thread Index | Old Index