mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, sameo@linux.intel.com,
	micky_ching@realsil.com.cn
Cc: linus.walleij@linaro.org, Lee Jones <lee.jones@linaro.org>
Subject: [PATCH 2/4] mfd: rtsx: Generify the switch voltage routine
Date: Thu, 14 Nov 2013 09:29:13 +0000	[thread overview]
Message-ID: <1384421355-4434-3-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1384421355-4434-1-git-send-email-lee.jones@linaro.org>

Other, upcoming devices will want to change the shift value when using
the switch voltage call-back routine. In this patch we will ensure that
unnecessary code duplication shall not occur.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/mfd/rtl8411.c        | 12 ++++++++----
 drivers/mfd/rtsx_pcr.c       |  3 ++-
 include/linux/mfd/rtsx_pci.h |  3 ++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/rtl8411.c b/drivers/mfd/rtl8411.c
index 92e9bf6..9bba4e2 100644
--- a/drivers/mfd/rtl8411.c
+++ b/drivers/mfd/rtl8411.c
@@ -191,24 +191,25 @@ static int rtl8411_card_power_off(struct rtsx_pcr *pcr, int card)
 			BPP_LDO_POWB, BPP_LDO_SUSPEND);
 }
 
-static int rtl8411_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
+static int rtl84xx_switch_output_voltage(struct rtsx_pcr *pcr,
+					 u8 voltage, int shift)
 {
 	u8 mask, val;
 	int err;
 
-	mask = (BPP_REG_TUNED18 << BPP_TUNED18_SHIFT_8411) | BPP_PAD_MASK;
+	mask = (BPP_REG_TUNED18 << shift) | 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_8411) | BPP_PAD_3V3;
+		val = (BPP_ASIC_3V3 << shift) | 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_1V8 << BPP_TUNED18_SHIFT_8411) | BPP_PAD_1V8;
+		val = (BPP_ASIC_1V8 << shift) | BPP_PAD_1V8;
 	} else {
 		return -EINVAL;
 	}
@@ -426,6 +427,7 @@ static struct pcr_ops rtl84xx_pcr_generic_ops = {
 	.card_power_on = rtl8411_card_power_on,
 	.card_power_off = rtl8411_card_power_off,
 	.switch_output_voltage = rtl84xx_switch_output_voltage,
+	.voltage_reg_shift = 0,        /* Dynamic */
 	.cd_deglitch = rtl8411_cd_deglitch,
 	.conv_clk_and_div_n = rtl8411_conv_clk_and_div_n,
 	.force_power_down = rtl8411_force_power_down,
@@ -455,6 +457,7 @@ void rtl8411_init_params(struct rtsx_pcr *pcr)
 	/* Device Ops variation. */
 	pcr->ops->fetch_vendor_settings = rtl8411_fetch_vendor_settings;
 	pcr->ops->extra_init_hw = rtl8411_extra_init_hw;
+	pcr->ops->voltage_reg_shift = BPP_TUNED18_SHIFT_8411;
 
 	pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10);
 
@@ -469,6 +472,7 @@ void rtl8411b_init_params(struct rtsx_pcr *pcr)
 	/* Device Ops variation. */
 	pcr->ops->fetch_vendor_settings = rtl8411b_fetch_vendor_settings;
 	pcr->ops->extra_init_hw = rtl8411b_extra_init_hw;
+	pcr->ops->voltage_reg_shift = BPP_TUNED18_SHIFT_8411;
 
 	pcr->tx_initial_phase = SET_CLOCK_PHASE(23, 7, 14);
 	pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10);
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index e6ae772..f41ee8f 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -734,7 +734,8 @@ EXPORT_SYMBOL_GPL(rtsx_pci_card_exclusive_check);
 int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
 {
 	if (pcr->ops->switch_output_voltage)
-		return pcr->ops->switch_output_voltage(pcr, voltage);
+		return pcr->ops->switch_output_voltage(pcr, voltage,
+					pcr->ops->voltage_reg_shift);
 
 	return 0;
 }
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index f5f3ffc..5afc448 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -774,11 +774,12 @@ struct pcr_ops {
 	int		(*card_power_on)(struct rtsx_pcr *pcr, int card);
 	int		(*card_power_off)(struct rtsx_pcr *pcr, int card);
 	int		(*switch_output_voltage)(struct rtsx_pcr *pcr,
-						u8 voltage);
+						 u8 voltage, int shift);
 	unsigned int	(*cd_deglitch)(struct rtsx_pcr *pcr);
 	int		(*conv_clk_and_div_n)(int clk, int dir);
 	void		(*fetch_vendor_settings)(struct rtsx_pcr *pcr);
 	void		(*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state);
+	int		voltage_reg_shift;
 };
 
 enum PDEV_STAT  {PDEV_STAT_IDLE, PDEV_STAT_RUN};
-- 
1.8.1.2


  parent reply	other threads:[~2013-11-14  9:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14  9:29 [PATCH 0/4] mfd: rtsx: Decrease driver size and add new device Lee Jones
2013-11-14  9:29 ` [PATCH 1/4] mfd: rtsx: Generify call-back operations in order to reduce code duplication Lee Jones
2013-11-15  3:43   ` [PATCH 1/4] mfd: rtsx: Generify call-back operations in orderto " micky
2013-11-14  9:29 ` Lee Jones [this message]
2013-11-15  2:59   ` [PATCH 2/4] mfd: rtsx: Generify the switch voltage routine micky
2013-11-15 15:37     ` Lee Jones
2013-11-14  9:29 ` [PATCH 3/4] mfd: rtsx: Add rtl8402 card reader Lee Jones
2013-11-14  9:29 ` [PATCH 4/4] mfd: rtsx: Prevent 'used uninitialised' warnings Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384421355-4434-3-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=micky_ching@realsil.com.cn \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®