Skip to contentSkip to conversation

mfd: rtsx: add card reader rtl8402

PATCH In review [email protected] 2 participants 6 messages Nov 1, 2013 – Nov 14, 2013 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: rtsx: add card reader rtl8402

From: Micky Ching <[email protected]>

Add card reader rtl8042, rtl8402 is much like rtl8411, so just add it to rtl8411.c

---
 drivers/mfd/rtl8411.c  |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/rtsx_pcr.c |    5 ++++
 drivers/mfd/rtsx_pcr.h |    1 +
 3 files changed, 68 insertions(+)
drivers/mfd/rtl8411.c +62 -0
index 5280135..9d37dd6 100644
@@ -498,3 +498,65 @@ void rtl8411b_init_params(struct rtsx_pcr *pcr)
 			rtl8411b_qfn64_ms_pull_ctl_disable_tbl;
 	}
 }
+
+static int rtl8402_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
+{
+	u8 mask, val;
+	int err;
+
+	mask = (BPP_REG_TUNED18 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_MASK;
+	if (voltage == OUTPUT_3V3) {
+		err = rtsx_pci_write_register(pcr,
+				SD30_DRIVE_SEL, 0x07, pcr->sd30_drive_sel_3v3);
+		if (err < 0)
+			return err;
+		val = (BPP_ASIC_3V3 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_3V3;
+	} else if (voltage == OUTPUT_1V8) {
+		err = rtsx_pci_write_register(pcr,
+				SD30_DRIVE_SEL, 0x07, pcr->sd30_drive_sel_1v8);
+		if (err < 0)
+			return err;
+		val = (BPP_ASIC_2V0 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_1V8;
+	} else {
+		return -EINVAL;
+	}
+
+	return rtsx_pci_write_register(pcr, LDO_CTL, mask, val);
+}
+
+static const struct pcr_ops rtl8402_pcr_ops = {
+	.fetch_vendor_settings = rtl8411_fetch_vendor_settings,
+	.extra_init_hw = rtl8411_extra_init_hw,
+	.optimize_phy = NULL,
+	.turn_on_led = rtl8411_turn_on_led,
+	.turn_off_led = rtl8411_turn_off_led,
+	.enable_auto_blink = rtl8411_enable_auto_blink,
+	.disable_auto_blink = rtl8411_disable_auto_blink,
+	.card_power_on = rtl8411_card_power_on,
+	.card_power_off = rtl8411_card_power_off,
+	.switch_output_voltage = rtl8402_switch_output_voltage,
+	.cd_deglitch = rtl8411_cd_deglitch,
+	.conv_clk_and_div_n = rtl8411_conv_clk_and_div_n,
+	.force_power_down = rtl8411_force_power_down,
+};
+
+void rtl8402_init_params(struct rtsx_pcr *pcr)
+{
+	pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104;
+	pcr->num_slots = 2;
+	pcr->ops = &rtl8402_pcr_ops;
+
+	pcr->flags = 0;
+	pcr->card_drive_sel = RTL8411_CARD_DRIVE_DEFAULT;
+	pcr->sd30_drive_sel_1v8 = DRIVER_TYPE_B;
+	pcr->sd30_drive_sel_3v3 = DRIVER_TYPE_D;
+	pcr->aspm_en = ASPM_L1_EN;
+	pcr->tx_initial_phase = SET_CLOCK_PHASE(23, 7, 14);
+	pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10);
+
+	pcr->ic_version = rtl8411_get_ic_version(pcr);
+	pcr->sd_pull_ctl_enable_tbl = rtl8411_sd_pull_ctl_enable_tbl;
+	pcr->sd_pull_ctl_disable_tbl = rtl8411_sd_pull_ctl_disable_tbl;
+	pcr->ms_pull_ctl_enable_tbl = rtl8411_ms_pull_ctl_enable_tbl;
+	pcr->ms_pull_ctl_disable_tbl = rtl8411_ms_pull_ctl_disable_tbl;
+}
drivers/mfd/rtsx_pcr.c +5 -0
index 11e20af..93fabc7 100644
@@ -56,6 +56,7 @@ static DEFINE_PCI_DEVICE_TABLE(rtsx_pci_ids) = {
 	{ PCI_DEVICE(0x10EC, 0x5289), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5227), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5249), PCI_CLASS_OTHERS << 16, 0xFF0000 },
+	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ 0, }
 };
@@ -1046,6 +1047,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
 		rts5229_init_params(pcr);
 		break;
 
+	case 0x5286:
+		rtl8402_init_params(pcr);
+		break;
+
 	case 0x5289:
 		rtl8411_init_params(pcr);
 		break;
drivers/mfd/rtsx_pcr.h +1 -0
index 947e79b..8cac8db 100644
@@ -29,6 +29,7 @@
 
 void rts5209_init_params(struct rtsx_pcr *pcr);
 void rts5229_init_params(struct rtsx_pcr *pcr);
+void rtl8402_init_params(struct rtsx_pcr *pcr);
 void rtl8411_init_params(struct rtsx_pcr *pcr);
 void rts5227_init_params(struct rtsx_pcr *pcr);
 void rts5249_init_params(struct rtsx_pcr *pcr);
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 11 lines · On Fri, 01 Nov 2013, [email protected] wrote:

From: Micky Ching <[email protected]>

Add card reader rtl8042, rtl8402 is much like rtl8411, so just add it to rtl8411.c

---
 drivers/mfd/rtl8411.c  |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/rtsx_pcr.c |    5 ++++
 drivers/mfd/rtsx_pcr.h |    1 +
 3 files changed, 68 insertions(+)

Sorry Micky, but I'm not accepting this.

This patch adds 62 lines of duplicated code, with only a few variations. Please find a way to generify the driver. Also I think we should consider doing the voltage stuff using the Regulator Framework.

Quoted 105 lines
drivers/mfd/rtl8411.c +62 -0
index 5280135..9d37dd6 100644
@@ -498,3 +498,65 @@ void rtl8411b_init_params(struct rtsx_pcr *pcr)
 			rtl8411b_qfn64_ms_pull_ctl_disable_tbl;
 	}
 }
+
+static int rtl8402_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
+{
+	u8 mask, val;
+	int err;
+
+	mask = (BPP_REG_TUNED18 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_MASK;
+	if (voltage == OUTPUT_3V3) {
+		err = rtsx_pci_write_register(pcr,
+				SD30_DRIVE_SEL, 0x07, pcr->sd30_drive_sel_3v3);
+		if (err < 0)
+			return err;
+		val = (BPP_ASIC_3V3 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_3V3;
+	} else if (voltage == OUTPUT_1V8) {
+		err = rtsx_pci_write_register(pcr,
+				SD30_DRIVE_SEL, 0x07, pcr->sd30_drive_sel_1v8);
+		if (err < 0)
+			return err;
+		val = (BPP_ASIC_2V0 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_1V8;
+	} else {
+		return -EINVAL;
+	}
+
+	return rtsx_pci_write_register(pcr, LDO_CTL, mask, val);
+}
+
+static const struct pcr_ops rtl8402_pcr_ops = {
+	.fetch_vendor_settings = rtl8411_fetch_vendor_settings,
+	.extra_init_hw = rtl8411_extra_init_hw,
+	.optimize_phy = NULL,
+	.turn_on_led = rtl8411_turn_on_led,
+	.turn_off_led = rtl8411_turn_off_led,
+	.enable_auto_blink = rtl8411_enable_auto_blink,
+	.disable_auto_blink = rtl8411_disable_auto_blink,
+	.card_power_on = rtl8411_card_power_on,
+	.card_power_off = rtl8411_card_power_off,
+	.switch_output_voltage = rtl8402_switch_output_voltage,
+	.cd_deglitch = rtl8411_cd_deglitch,
+	.conv_clk_and_div_n = rtl8411_conv_clk_and_div_n,
+	.force_power_down = rtl8411_force_power_down,
+};
+
+void rtl8402_init_params(struct rtsx_pcr *pcr)
+{
+	pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104;
+	pcr->num_slots = 2;
+	pcr->ops = &rtl8402_pcr_ops;
+
+	pcr->flags = 0;
+	pcr->card_drive_sel = RTL8411_CARD_DRIVE_DEFAULT;
+	pcr->sd30_drive_sel_1v8 = DRIVER_TYPE_B;
+	pcr->sd30_drive_sel_3v3 = DRIVER_TYPE_D;
+	pcr->aspm_en = ASPM_L1_EN;
+	pcr->tx_initial_phase = SET_CLOCK_PHASE(23, 7, 14);
+	pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10);
+
+	pcr->ic_version = rtl8411_get_ic_version(pcr);
+	pcr->sd_pull_ctl_enable_tbl = rtl8411_sd_pull_ctl_enable_tbl;
+	pcr->sd_pull_ctl_disable_tbl = rtl8411_sd_pull_ctl_disable_tbl;
+	pcr->ms_pull_ctl_enable_tbl = rtl8411_ms_pull_ctl_enable_tbl;
+	pcr->ms_pull_ctl_disable_tbl = rtl8411_ms_pull_ctl_disable_tbl;
+}
drivers/mfd/rtsx_pcr.c +5 -0
index 11e20af..93fabc7 100644
@@ -56,6 +56,7 @@ static DEFINE_PCI_DEVICE_TABLE(rtsx_pci_ids) = {
 	{ PCI_DEVICE(0x10EC, 0x5289), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5227), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5249), PCI_CLASS_OTHERS << 16, 0xFF0000 },
+	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ 0, }
 };
@@ -1046,6 +1047,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
 		rts5229_init_params(pcr);
 		break;
 
+	case 0x5286:
+		rtl8402_init_params(pcr);
+		break;
+
 	case 0x5289:
 		rtl8411_init_params(pcr);
 		break;
drivers/mfd/rtsx_pcr.h +1 -0
index 947e79b..8cac8db 100644
@@ -29,6 +29,7 @@
 
 void rts5209_init_params(struct rtsx_pcr *pcr);
 void rts5229_init_params(struct rtsx_pcr *pcr);
+void rtl8402_init_params(struct rtsx_pcr *pcr);
 void rtl8411_init_params(struct rtsx_pcr *pcr);
 void rts5227_init_params(struct rtsx_pcr *pcr);
 void rts5249_init_params(struct rtsx_pcr *pcr);
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author
#2 lore raw

Hi Lee

I'm trying to merge the common code into a single function rtl8411_init_params(), but different chips may use a different rtlxxx_pcr_ops even they have much the same. This is because the ops may be called frequently.

Yet I'm trying to use Regulator Framework, it will make a somewhat big change , and I will add it in a later time.

So, I wanna to send the merged patch first, is that ok?

Quoted 124 lines · Lee Jones
Quoted 11 lines · On Fri, 01 Nov 2013, [email protected] wrote:

From: Micky Ching <[email protected]>

Add card reader rtl8042, rtl8402 is much like rtl8411, so just add it to rtl8411.c

---
  drivers/mfd/rtl8411.c  |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
  drivers/mfd/rtsx_pcr.c |    5 ++++
  drivers/mfd/rtsx_pcr.h |    1 +
  3 files changed, 68 insertions(+)

Sorry Micky, but I'm not accepting this.

This patch adds 62 lines of duplicated code, with only a few variations. Please find a way to generify the driver. Also I think we should consider doing the voltage stuff using the Regulator Framework.

Quoted 105 lines
drivers/mfd/rtl8411.c +62 -0
index 5280135..9d37dd6 100644
@@ -498,3 +498,65 @@ void rtl8411b_init_params(struct rtsx_pcr *pcr)
  			rtl8411b_qfn64_ms_pull_ctl_disable_tbl;
  	}
  }
+
+static int rtl8402_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
+{
+	u8 mask, val;
+	int err;
+
+	mask = (BPP_REG_TUNED18 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_MASK;
+	if (voltage == OUTPUT_3V3) {
+		err = rtsx_pci_write_register(pcr,
+				SD30_DRIVE_SEL, 0x07, pcr->sd30_drive_sel_3v3);
+		if (err < 0)
+			return err;
+		val = (BPP_ASIC_3V3 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_3V3;
+	} else if (voltage == OUTPUT_1V8) {
+		err = rtsx_pci_write_register(pcr,
+				SD30_DRIVE_SEL, 0x07, pcr->sd30_drive_sel_1v8);
+		if (err < 0)
+			return err;
+		val = (BPP_ASIC_2V0 << BPP_TUNED18_SHIFT_8402) | BPP_PAD_1V8;
+	} else {
+		return -EINVAL;
+	}
+
+	return rtsx_pci_write_register(pcr, LDO_CTL, mask, val);
+}
+
+static const struct pcr_ops rtl8402_pcr_ops = {
+	.fetch_vendor_settings = rtl8411_fetch_vendor_settings,
+	.extra_init_hw = rtl8411_extra_init_hw,
+	.optimize_phy = NULL,
+	.turn_on_led = rtl8411_turn_on_led,
+	.turn_off_led = rtl8411_turn_off_led,
+	.enable_auto_blink = rtl8411_enable_auto_blink,
+	.disable_auto_blink = rtl8411_disable_auto_blink,
+	.card_power_on = rtl8411_card_power_on,
+	.card_power_off = rtl8411_card_power_off,
+	.switch_output_voltage = rtl8402_switch_output_voltage,
+	.cd_deglitch = rtl8411_cd_deglitch,
+	.conv_clk_and_div_n = rtl8411_conv_clk_and_div_n,
+	.force_power_down = rtl8411_force_power_down,
+};
+
+void rtl8402_init_params(struct rtsx_pcr *pcr)
+{
+	pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104;
+	pcr->num_slots = 2;
+	pcr->ops = &rtl8402_pcr_ops;
+
+	pcr->flags = 0;
+	pcr->card_drive_sel = RTL8411_CARD_DRIVE_DEFAULT;
+	pcr->sd30_drive_sel_1v8 = DRIVER_TYPE_B;
+	pcr->sd30_drive_sel_3v3 = DRIVER_TYPE_D;
+	pcr->aspm_en = ASPM_L1_EN;
+	pcr->tx_initial_phase = SET_CLOCK_PHASE(23, 7, 14);
+	pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10);
+
+	pcr->ic_version = rtl8411_get_ic_version(pcr);
+	pcr->sd_pull_ctl_enable_tbl = rtl8411_sd_pull_ctl_enable_tbl;
+	pcr->sd_pull_ctl_disable_tbl = rtl8411_sd_pull_ctl_disable_tbl;
+	pcr->ms_pull_ctl_enable_tbl = rtl8411_ms_pull_ctl_enable_tbl;
+	pcr->ms_pull_ctl_disable_tbl = rtl8411_ms_pull_ctl_disable_tbl;
+}
drivers/mfd/rtsx_pcr.c +5 -0
index 11e20af..93fabc7 100644
@@ -56,6 +56,7 @@ static DEFINE_PCI_DEVICE_TABLE(rtsx_pci_ids) = {
  	{ PCI_DEVICE(0x10EC, 0x5289), PCI_CLASS_OTHERS << 16, 0xFF0000 },
  	{ PCI_DEVICE(0x10EC, 0x5227), PCI_CLASS_OTHERS << 16, 0xFF0000 },
  	{ PCI_DEVICE(0x10EC, 0x5249), PCI_CLASS_OTHERS << 16, 0xFF0000 },
+	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
  	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
  	{ 0, }
  };
@@ -1046,6 +1047,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
  		rts5229_init_params(pcr);
  		break;
 
+	case 0x5286:
+		rtl8402_init_params(pcr);
+		break;
+
  	case 0x5289:
  		rtl8411_init_params(pcr);
  		break;
drivers/mfd/rtsx_pcr.h +1 -0
index 947e79b..8cac8db 100644
@@ -29,6 +29,7 @@
 
  void rts5209_init_params(struct rtsx_pcr *pcr);
  void rts5229_init_params(struct rtsx_pcr *pcr);
+void rtl8402_init_params(struct rtsx_pcr *pcr);
  void rtl8411_init_params(struct rtsx_pcr *pcr);
  void rts5227_init_params(struct rtsx_pcr *pcr);
  void rts5249_init_params(struct rtsx_pcr *pcr);
Signature · 2 lines
Best Regards
Micky.
#3 lore raw
Quoted 4 lines

I'm trying to merge the common code into a single function rtl8411_init_params(), but different chips may use a different rtlxxx_pcr_ops even they have much the same. This is because the ops may be called frequently.

So to save confusion I've sent a patch-set with you CC'ed.

If you can test the patchset on your h/w and add your Tested-by: tag I will add it to each of the patches.

With regards to the 'mfd: rtsx: Add rtl8402 card reader' patch, I believe you are the rightful author of that patch, so if you can send me your Signed-off-by: for that one, I will add that and make you the author.

Quoted 2 lines

Yet I'm trying to use Regulator Framework, it will make a somewhat big change , and I will add it in a later time.

Yes that's fine. Base any new patches on top of this patch-set.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog 
author
#4 lore raw
Quoted 10 lines

So to save confusion I've sent a patch-set with you CC'ed

If you can test the patchset on your h/w and add your Tested-by: tag I will add it to each of the patches.

With regards to the 'mfd: rtsx: Add rtl8402 card reader' patch, I believe you are the rightful author of that patch, so if you can send me your Signed-off-by: for that one, I will add that and make you the author.

Sorry, I haven't received the patch-set you send, can you please resend the patch to me?

Signature · 2 lines
Best Regards
Micky.
#5 lore raw
Quoted 5 lines · micky
Quoted 5 lines

So to save confusion I've sent a patch-set with you CC'ed

If you can test the patchset on your h/w and add your Tested-by: tag I will add it to each of the patches.

Quoted 7 lines
Quoted 5 lines

With regards to the 'mfd: rtsx: Add rtl8402 card reader' patch, I believe you are the rightful author of that patch, so if you can send me your Signed-off-by: for that one, I will add that and make you the author.

Sorry, I haven't received the patch-set you send, can you please resend the patch to me?

Ah, it looks like they were caught up in an internal-error.

I've resent the set.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog