Skip to contentSkip to conversation

Add modules to support realtek PCIE card reader

PATCH Superseded [email protected] 2 participants 8 messages Sep 10, 2012

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add modules to support realtek PCIE card reader

From: Wei WANG <[email protected]>

Support for Realtek PCI-Express driver-based card readers including rts5209 and rts5229.

v2:
1. Using platform device to replace realtek slot bus

v3:
1. Fix a bug that DMA out of SW-IOMMU space in Lenovo Thinkpad x121e
2. Tested by Borislav Petkov <[email protected]>

v4:
1. Fulfill power management callbacks

v5:
1. Support Memstick card

Wei WANG (3):
drivers/mfd: Add realtek pcie card reader driver drivers/mmc: Add realtek pcie sdmmc host driver drivers/memstick: Add realtek pcie memstick host driver

 drivers/memstick/host/Kconfig       |   10 +
 drivers/memstick/host/Makefile      |    1 +
 drivers/memstick/host/rtsx_pci_ms.c |  637 ++++++++++++++++
 drivers/mfd/Kconfig                 |    9 +
 drivers/mfd/Makefile                |    4 +
 drivers/mfd/rts5209.c               |  223 ++++++
 drivers/mfd/rts5229.c               |  215 ++++++
 drivers/mfd/rtsx_pcr.c              | 1359 ++++++++++++++++++++++++++++++++++
 drivers/mfd/rtsx_pcr.h              |   31 +
 drivers/mmc/host/Kconfig            |    7 +
 drivers/mmc/host/Makefile           |    2 +
 drivers/mmc/host/rtsx_pci_sdmmc.c   | 1372 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/rtsx_common.h     |   47 ++
 include/linux/mfd/rtsx_pci.h        |  765 +++++++++++++++++++
 14 files changed, 4682 insertions(+)
 create mode 100644 drivers/memstick/host/rtsx_pci_ms.c
 create mode 100644 drivers/mfd/rts5209.c
 create mode 100644 drivers/mfd/rts5229.c
 create mode 100644 drivers/mfd/rtsx_pcr.c
 create mode 100644 drivers/mfd/rtsx_pcr.h
 create mode 100644 drivers/mmc/host/rtsx_pci_sdmmc.c
 create mode 100644 include/linux/mfd/rtsx_common.h
 create mode 100644 include/linux/mfd/rtsx_pci.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 1/3 drivers/mfd: Add realtek pcie card reader driver

From: Wei WANG <[email protected]>

Realtek PCI-E card reader driver adapts requests from upper-level sdmmc/memstick layer to the real physical card reader.

---
 drivers/mfd/Kconfig             |    9 +
 drivers/mfd/Makefile            |    4 +
 drivers/mfd/rts5209.c           |  223 +++++++
 drivers/mfd/rts5229.c           |  215 +++++++
 drivers/mfd/rtsx_pcr.c          | 1359 +++++++++++++++++++++++++++++++++++++++
 drivers/mfd/rtsx_pcr.h          |   31 +
 include/linux/mfd/rtsx_common.h |   47 ++
 include/linux/mfd/rtsx_pci.h    |  765 ++++++++++++++++++++++
 8 files changed, 2653 insertions(+)
 create mode 100644 drivers/mfd/rts5209.c
 create mode 100644 drivers/mfd/rts5229.c
 create mode 100644 drivers/mfd/rtsx_pcr.c
 create mode 100644 drivers/mfd/rtsx_pcr.h
 create mode 100644 include/linux/mfd/rtsx_common.h
 create mode 100644 include/linux/mfd/rtsx_pci.h
drivers/mfd/Kconfig +9 -0
index d1facef..4c07a34 100644
@@ -63,6 +63,15 @@ config MFD_SM501_GPIO
 	 lines on the SM501. The platform data is used to supply the
 	 base number for the first GPIO line to register.
 
+config MFD_RTSX_PCI
+	tristate "Support for Realtek PCI-E driver-based card reader"
+	depends on PCI
+	help
+	  This supports for Realtek PCI-Express driver-based card reader including
+	  rts5209, rts5229, etc. Realtek driver-based card reader supports access
+	  to many types of memory cards, such as Memory Stick, Memory Stick Pro,
+	  Secure Digital and MultiMediaCard.
+
 config MFD_ASIC3
 	bool "Support for Compaq ASIC3"
 	depends on GENERIC_HARDIRQS && GPIOLIB && ARM
drivers/mfd/Makefile +4 -0
index 79dd22d..e8cdc7b 100644
@@ -9,6 +9,9 @@ obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
 obj-$(CONFIG_MFD_ASIC3)		+= asic3.o tmio_core.o
 
+rtsx_pci-objs			:= rtsx_pcr.o rts5209.o rts5229.o
+obj-$(CONFIG_MFD_RTSX_PCI)	+= rtsx_pci.o
+
 obj-$(CONFIG_HTC_EGPIO)		+= htc-egpio.o
 obj-$(CONFIG_HTC_PASIC3)	+= htc-pasic3.o
 obj-$(CONFIG_HTC_I2CPLD)	+= htc-i2cpld.o
@@ -132,3 +135,4 @@ obj-$(CONFIG_MFD_RC5T583)	+= rc5t583.o rc5t583-irq.o
 obj-$(CONFIG_MFD_SEC_CORE)	+= sec-core.o sec-irq.o
 obj-$(CONFIG_MFD_ANATOP)	+= anatop-mfd.o
 obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
+obj-$(CONFIG_MFD_RTSX_PCI)	+= rtsx_pci.o
drivers/mfd/rts5209.c new file +223 -0

223 lines not on this page · raw message

drivers/mfd/rts5229.c new file +215 -0

215 lines not on this page · raw message

drivers/mfd/rtsx_pcr.c new file +1359 -0

1,359 lines not on this page · raw message

drivers/mfd/rtsx_pcr.h new file +31 -0
new file mode 100644
index 0000000..0a56b39
@@ -0,0 +1,31 @@
+/* Driver for Realtek PCI-Express card reader
+ *
+ * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *   Wei WANG <[email protected]>
+ *   No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
+ */
+
+#ifndef __RTSX_PCR_H
+#define __RTSX_PCR_H
+
+#include <linux/mfd/rtsx_pci.h>
+
+void rts5209_init_params(struct rtsx_pcr *pcr);
+void rts5229_init_params(struct rtsx_pcr *pcr);
+
+#endif
include/linux/mfd/rtsx_common.h new file +47 -0

47 lines not on this page · raw message

include/linux/mfd/rtsx_pci.h new file +765 -0

765 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v5 1/3] drivers/mfd: Add realtek pcie card reader driver

I just had a couple few style comments is all, nothing that couldn't be fixed in a later patch.

drivers/mfd/rts5209.c line 54

Quoted 4 lines · On Mon, Sep 10, 2012 at 04:03:29PM +0800, [email protected] wrote:
drivers/mfd/rts5209.c new file +4 -0
+static int rts5209_extra_init_hw(struct rtsx_pcr *pcr)
+{
+	return 0;
+}

It would be nicer if the caller checked whether this pointer was NULL and only called it if it needed to.

drivers/mfd/rts5209.c line 65

Quoted 11 lines
drivers/mfd/rts5209.c new file +11 -0
+
+static int rts5209_optimize_phy(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xB966);
+	if (err < 0)
+		return err;
+
+	return 0;
+}

static int rts5209_optimize_phy(struct rtsx_pcr *pcr)

{
	return rtsx_pci_write_phy_register(pcr, 0x00, 0xB966);
}

drivers/mfd/rts5209.c line 76

Quoted 11 lines
drivers/mfd/rts5209.c new file +11 -0
+
+static int rts5209_turn_on_led(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, 0xFD58, 0x01, 0x00);
+	if (err < 0)
+		return err;
+
+	return 0;
+}

Same.

drivers/mfd/rts5209.c line 88

Quoted 12 lines
drivers/mfd/rts5209.c new file +12 -0
+
+static int rts5209_turn_off_led(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, 0xFD58, 0x01, 0x01);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+

Same.

drivers/mfd/rts5209.c line 99

Quoted 11 lines
drivers/mfd/rts5209.c new file +11 -0
+static int rts5209_enable_auto_blink(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, CARD_AUTO_BLINK, 0xFF, 0x0D);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+

Same.

drivers/mfd/rts5209.c line 110

Quoted 11 lines
drivers/mfd/rts5209.c new file +11 -0
+static int rts5209_disable_auto_blink(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, CARD_AUTO_BLINK, 0x08, 0x00);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+

Same.

[snip ]

Quoted 7 lines
drivers/mfd/rts5229.c new file +7 -0
+static int rts5229_extra_init_hw(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	rtsx_pci_init_cmd(pcr);
+
+	/* Switch LDO3318 source from DV33 to card_3v3 */

drivers/mfd/rts5229.c line 52

Quoted 10 lines
drivers/mfd/rts5229.c new file +10 -0
+	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, 0xFE78, 0x03, 0x00);
+	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, 0xFE78, 0x03, 0x01);
+	/* LED shine disabled, set initial shine cycle period */
+	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, 0xFC1E, 0x0F, 0x02);
+
+	err = rtsx_pci_send_cmd(pcr, 100);
+	if (err < 0)
+		return err;
+
+	return 0;
	return rtsx_pci_send_cmd(pcr, 100);

drivers/mfd/rts5229.c line 65

Quoted 13 lines
drivers/mfd/rts5229.c new file +13 -0
+}
+
+static int rts5229_optimize_phy(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	/* Optimize RX sensitivity */
+	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42);
+	if (err < 0)
+		return err;
+
+	return 0;
+}

Same.

drivers/mfd/rts5229.c line 77

Quoted 12 lines
drivers/mfd/rts5229.c new file +12 -0
+
+static int rts5229_turn_on_led(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, 0xFC1F, 0x02, 0x02);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+

Same.

drivers/mfd/rts5229.c line 87

Quoted 10 lines
drivers/mfd/rts5229.c new file +10 -0
+static int rts5229_turn_off_led(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, 0xFC1F, 0x02, 0x00);
+	if (err < 0)
+		return err;
+
+	return 0;
+}

Same.

drivers/mfd/rts5229.c line 98

Quoted 11 lines
drivers/mfd/rts5229.c new file +11 -0
+
+static int rts5229_enable_auto_blink(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, 0xFC1E, 0x08, 0x08);
+	if (err < 0)
+		return err;
+
+	return 0;
+}

Same.

drivers/mfd/rts5229.c line 109

Quoted 11 lines
drivers/mfd/rts5229.c new file +11 -0
+
+static int rts5229_disable_auto_blink(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, 0xFC1E, 0x08, 0x00);
+	if (err < 0)
+		return err;
+
+	return 0;
+}

Same.

[ snip ].

drivers/mfd/rtsx_pcr.c line 48

Quoted 5 lines
drivers/mfd/rtsx_pcr.c new file +5 -0
+static DEFINE_PCI_DEVICE_TABLE(rtsx_pci_ids) = {
+	{ 0x10EC, 0x5209, PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_OTHERS << 16, 0xFF0000 },
+	{ 0x10EC, 0x5229, PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_OTHERS << 16, 0xFF0000 },

If you want to fit it all on one line you could do:

	{ PCI_DEVICE(0x10EC, 0x5229), PCI_CLASS_OTHERS << 16, 0xFF0000 },

It's weird that this is the only driver in the kernel which uses the PCI_CLASS_OTHERS macro like this.

[ snip ]

drivers/mfd/rtsx_pcr.c line 103

Quoted 11 lines
drivers/mfd/rtsx_pcr.c new file +11 -0
+int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data)
+{
+	u32 val = 2 << 30;
+	int i;
+
+	val |= (u32)(addr & 0x3FFF) << 16;
+	rtsx_pci_writel(pcr, RTSX_HAIMR, val);
+
+	for (i = 0; i < MAX_RW_REG_CNT; i++) {
+		val = rtsx_pci_readl(pcr, RTSX_HAIMR);
+		if ((val & (1 << 31)) == 0)

When we set this we do "2 << 30" but when we test it we do "1 << 31". It would be nice to be consistent.

drivers/mfd/rtsx_pcr.c line 154

Quoted 4 lines
drivers/mfd/rtsx_pcr.c new file +4 -0
+int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
+{
+	int err, i, finished = 0;
+	u16 data = 0;
            ^^^^^^^^

Not needed.

Quoted 2 lines
drivers/mfd/rtsx_pcr.c new file +2 -0
+	u8 *ptr, tmp;
+

[ snip ]

drivers/mfd/rtsx_pcr.c line 399

Quoted 13 lines
drivers/mfd/rtsx_pcr.c new file +13 -0
+	spin_lock_irqsave(&pcr->lock, flags);
+
+	if (pcr->trans_result == TRANS_RESULT_FAIL) {
+		err = -EINVAL;
+		spin_unlock_irqrestore(&pcr->lock, flags);
+		goto out;
+	} else if (pcr->trans_result == TRANS_NO_DEVICE) {
+		err = -ENODEV;
+		spin_unlock_irqrestore(&pcr->lock, flags);
+		goto out;
+	}
+
+	spin_unlock_irqrestore(&pcr->lock, flags);

Could be written like:

	if (pcr->trans_result == TRANS_RESULT_FAIL)
		err = -EINVAL;
	else if (pcr->trans_result == TRANS_NO_DEVICE)
		err = -ENODEV;

	spin_unlock_irqrestore(&pcr->lock, flags);
Quoted 6 lines
drivers/mfd/rtsx_pcr.c new file +6 -0
+
+out:
+	spin_lock_irqsave(&pcr->lock, flags);
+	pcr->done = NULL;
+	spin_unlock_irqrestore(&pcr->lock, flags);
+

[snip]

drivers/mfd/rtsx_pcr.c line 1079

Quoted 2 lines
drivers/mfd/rtsx_pcr.c new file +2 -0
+	pcr->slots = kzalloc(sizeof(struct rtsx_slot) * pcr->num_slots,
+			GFP_KERNEL);

You could use kcalloc() here.

regards,
dan carpenter

#3 lore raw

PATCH v5 2/3 drivers/mmc: Add realtek pcie sdmmc host driver

In reply to [email protected]

From: Wei WANG <[email protected]>

Realtek PCI-E SD/MMC card host driver is used to access SD/MMC card, with the help of Realtek PCI-E card reader MFD driver.

---
 drivers/mmc/host/Kconfig          |    7 +
 drivers/mmc/host/Makefile         |    2 +
 drivers/mmc/host/rtsx_pci_sdmmc.c | 1372 +++++++++++++++++++++++++++++++++++++
 3 files changed, 1381 insertions(+)
 create mode 100644 drivers/mmc/host/rtsx_pci_sdmmc.c
drivers/mmc/host/Kconfig +7 -0
index aa131b3..d6f0c01 100644
@@ -612,3 +612,10 @@ config MMC_USHC
 
 	  Note: These controllers only support SDIO cards and do not
 	  support MMC or SD memory cards.
+
+config MMC_REALTEK_PCI
+	tristate "Realtek PCI-E SD/MMC Card Interface Driver"
+	depends on MFD_RTSX_PCI
+	help
+	  Say Y here to include driver code to support SD/MMC card interface
+	  of Realtek PCI-E driver-based card reader
drivers/mmc/host/Makefile +2 -0
index 8922b06..4679ba3 100644
@@ -45,6 +45,8 @@ obj-$(CONFIG_MMC_JZ4740)	+= jz4740_mmc.o
 obj-$(CONFIG_MMC_VUB300)	+= vub300.o
 obj-$(CONFIG_MMC_USHC)		+= ushc.o
 
+obj-$(CONFIG_MMC_REALTEK_PCI)	+= rtsx_pci_sdmmc.o
+
 obj-$(CONFIG_MMC_SDHCI_PLTFM)		+= sdhci-pltfm.o
 obj-$(CONFIG_MMC_SDHCI_CNS3XXX)		+= sdhci-cns3xxx.o
 obj-$(CONFIG_MMC_SDHCI_ESDHC_IMX)	+= sdhci-esdhc-imx.o
drivers/mmc/host/rtsx_pci_sdmmc.c new file +1372 -0

1,372 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v5 3/3 drivers/memstick: Add realtek pcie memstick host driver

In reply to [email protected]

From: Wei WANG <[email protected]>

Realtek PCI-E Memstick card host driver is used to access Memstick card, with the help of Realtek PCI-E card reader MFD driver.

---
 drivers/memstick/host/Kconfig       |   10 +
 drivers/memstick/host/Makefile      |    1 +
 drivers/memstick/host/rtsx_pci_ms.c |  637 +++++++++++++++++++++++++++++++++++
 3 files changed, 648 insertions(+)
 create mode 100644 drivers/memstick/host/rtsx_pci_ms.c
drivers/memstick/host/Kconfig +10 -0
index cc0997a..d539638 100644
@@ -42,3 +42,13 @@ config MEMSTICK_R592
 
 	  To compile this driver as a module, choose M here: the module will
 	  be called r592.
+
+config MEMSTICK_REALTEK_PCI
+	tristate "Realtek PCI-E Memstick Card Interface Driver"
+	depends on MFD_RTSX_PCI
+	help
+	  Say Y here to include driver code to support Memstick card interface
+	  of Realtek PCI-E driver-based card reader
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called rtsx_pci_ms.
drivers/memstick/host/Makefile +1 -0
index 31ba8d3..af3459d 100644
@@ -5,3 +5,4 @@
 obj-$(CONFIG_MEMSTICK_TIFM_MS)		+= tifm_ms.o
 obj-$(CONFIG_MEMSTICK_JMICRON_38X)	+= jmb38x_ms.o
 obj-$(CONFIG_MEMSTICK_R592)		+= r592.o
+obj-$(CONFIG_MEMSTICK_REALTEK_PCI)	+= rtsx_pci_ms.o
drivers/memstick/host/rtsx_pci_ms.c new file +637 -0

637 lines not on this page · raw message

Signature · 1 line
1.7.9.5