Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab4e8f8b authored by Wei WANG's avatar Wei WANG Committed by Samuel Ortiz
Browse files

mfd: rtsx: Add clock divider hook



Add callback function conv_clk_and_div_n to convert between SSC clock
and its divider N.
For rtl8411, the formula to calculate SSC clock divider N is different
with the other card reader models.

Signed-off-by: default avatarWei WANG <wei_wang@realsil.com.cn>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent ef85e736
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -178,6 +178,18 @@ static unsigned int rtl8411_cd_deglitch(struct rtsx_pcr *pcr)
	return card_exist;
	return card_exist;
}
}


static int rtl8411_conv_clk_and_div_n(int input, int dir)
{
	int output;

	if (dir == CLK_TO_DIV_N)
		output = input * 4 / 5 - 2;
	else
		output = (input + 2) * 5 / 4;

	return output;
}

static const struct pcr_ops rtl8411_pcr_ops = {
static const struct pcr_ops rtl8411_pcr_ops = {
	.extra_init_hw = rtl8411_extra_init_hw,
	.extra_init_hw = rtl8411_extra_init_hw,
	.optimize_phy = NULL,
	.optimize_phy = NULL,
@@ -189,6 +201,7 @@ static const struct pcr_ops rtl8411_pcr_ops = {
	.card_power_off = rtl8411_card_power_off,
	.card_power_off = rtl8411_card_power_off,
	.switch_output_voltage = rtl8411_switch_output_voltage,
	.switch_output_voltage = rtl8411_switch_output_voltage,
	.cd_deglitch = rtl8411_cd_deglitch,
	.cd_deglitch = rtl8411_cd_deglitch,
	.conv_clk_and_div_n = rtl8411_conv_clk_and_div_n,
};
};


/* SD Pull Control Enable:
/* SD Pull Control Enable:
+1 −0
Original line number Original line Diff line number Diff line
@@ -174,6 +174,7 @@ static const struct pcr_ops rts5209_pcr_ops = {
	.card_power_off = rts5209_card_power_off,
	.card_power_off = rts5209_card_power_off,
	.switch_output_voltage = rts5209_switch_output_voltage,
	.switch_output_voltage = rts5209_switch_output_voltage,
	.cd_deglitch = NULL,
	.cd_deglitch = NULL,
	.conv_clk_and_div_n = NULL,
};
};


/* SD Pull Control Enable:
/* SD Pull Control Enable:
+1 −0
Original line number Original line Diff line number Diff line
@@ -144,6 +144,7 @@ static const struct pcr_ops rts5229_pcr_ops = {
	.card_power_off = rts5229_card_power_off,
	.card_power_off = rts5229_card_power_off,
	.switch_output_voltage = rts5229_switch_output_voltage,
	.switch_output_voltage = rts5229_switch_output_voltage,
	.cd_deglitch = NULL,
	.cd_deglitch = NULL,
	.conv_clk_and_div_n = NULL,
};
};


/* SD Pull Control Enable:
/* SD Pull Control Enable:
+12 −2
Original line number Original line Diff line number Diff line
@@ -630,6 +630,9 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
	if (clk == pcr->cur_clock)
	if (clk == pcr->cur_clock)
		return 0;
		return 0;


	if (pcr->ops->conv_clk_and_div_n)
		N = (u8)pcr->ops->conv_clk_and_div_n(clk, CLK_TO_DIV_N);
	else
		N = (u8)(clk - 2);
		N = (u8)(clk - 2);
	if ((clk <= 2) || (N > max_N))
	if ((clk <= 2) || (N > max_N))
		return -EINVAL;
		return -EINVAL;
@@ -641,7 +644,14 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
	/* Make sure that the SSC clock div_n is equal or greater than min_N */
	/* Make sure that the SSC clock div_n is equal or greater than min_N */
	div = CLK_DIV_1;
	div = CLK_DIV_1;
	while ((N < min_N) && (div < max_div)) {
	while ((N < min_N) && (div < max_div)) {
		if (pcr->ops->conv_clk_and_div_n) {
			int dbl_clk = pcr->ops->conv_clk_and_div_n(N,
					DIV_N_TO_CLK) * 2;
			N = (u8)pcr->ops->conv_clk_and_div_n(dbl_clk,
					CLK_TO_DIV_N);
		} else {
			N = (N + 2) * 2 - 2;
			N = (N + 2) * 2 - 2;
		}
		div++;
		div++;
	}
	}
	dev_dbg(&(pcr->pci->dev), "N = %d, div = %d\n", N, div);
	dev_dbg(&(pcr->pci->dev), "N = %d, div = %d\n", N, div);
+3 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,9 @@
#define RTSX_SD_CARD			0
#define RTSX_SD_CARD			0
#define RTSX_MS_CARD			1
#define RTSX_MS_CARD			1


#define CLK_TO_DIV_N			0
#define DIV_N_TO_CLK			1

struct platform_device;
struct platform_device;


struct rtsx_slot {
struct rtsx_slot {
Loading