Skip to content

Commit ab4e8f8

Browse files
wwang-rsSamuel Ortiz
authored andcommitted
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: Wei WANG <wei_wang@realsil.com.cn> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent ef85e73 commit ab4e8f8

6 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎drivers/mfd/rtl8411.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ static unsigned int rtl8411_cd_deglitch(struct rtsx_pcr *pcr)
178178
return card_exist;
179179
}
180180

181+
static int rtl8411_conv_clk_and_div_n(int input, int dir)
182+
{
183+
int output;
184+
185+
if (dir == CLK_TO_DIV_N)
186+
output = input * 4 / 5 - 2;
187+
else
188+
output = (input + 2) * 5 / 4;
189+
190+
return output;
191+
}
192+
181193
static const struct pcr_ops rtl8411_pcr_ops = {
182194
.extra_init_hw = rtl8411_extra_init_hw,
183195
.optimize_phy = NULL,
@@ -189,6 +201,7 @@ static const struct pcr_ops rtl8411_pcr_ops = {
189201
.card_power_off = rtl8411_card_power_off,
190202
.switch_output_voltage = rtl8411_switch_output_voltage,
191203
.cd_deglitch = rtl8411_cd_deglitch,
204+
.conv_clk_and_div_n = rtl8411_conv_clk_and_div_n,
192205
};
193206

194207
/* SD Pull Control Enable:

‎drivers/mfd/rts5209.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static const struct pcr_ops rts5209_pcr_ops = {
174174
.card_power_off = rts5209_card_power_off,
175175
.switch_output_voltage = rts5209_switch_output_voltage,
176176
.cd_deglitch = NULL,
177+
.conv_clk_and_div_n = NULL,
177178
};
178179

179180
/* SD Pull Control Enable:

‎drivers/mfd/rts5229.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static const struct pcr_ops rts5229_pcr_ops = {
144144
.card_power_off = rts5229_card_power_off,
145145
.switch_output_voltage = rts5229_switch_output_voltage,
146146
.cd_deglitch = NULL,
147+
.conv_clk_and_div_n = NULL,
147148
};
148149

149150
/* SD Pull Control Enable:

‎drivers/mfd/rtsx_pcr.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,10 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
630630
if (clk == pcr->cur_clock)
631631
return 0;
632632

633-
N = (u8)(clk - 2);
633+
if (pcr->ops->conv_clk_and_div_n)
634+
N = (u8)pcr->ops->conv_clk_and_div_n(clk, CLK_TO_DIV_N);
635+
else
636+
N = (u8)(clk - 2);
634637
if ((clk <= 2) || (N > max_N))
635638
return -EINVAL;
636639

@@ -641,7 +644,14 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
641644
/* Make sure that the SSC clock div_n is equal or greater than min_N */
642645
div = CLK_DIV_1;
643646
while ((N < min_N) && (div < max_div)) {
644-
N = (N + 2) * 2 - 2;
647+
if (pcr->ops->conv_clk_and_div_n) {
648+
int dbl_clk = pcr->ops->conv_clk_and_div_n(N,
649+
DIV_N_TO_CLK) * 2;
650+
N = (u8)pcr->ops->conv_clk_and_div_n(dbl_clk,
651+
CLK_TO_DIV_N);
652+
} else {
653+
N = (N + 2) * 2 - 2;
654+
}
645655
div++;
646656
}
647657
dev_dbg(&(pcr->pci->dev), "N = %d, div = %d\n", N, div);

‎include/linux/mfd/rtsx_common.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#define RTSX_SD_CARD 0
3939
#define RTSX_MS_CARD 1
4040

41+
#define CLK_TO_DIV_N 0
42+
#define DIV_N_TO_CLK 1
43+
4144
struct platform_device;
4245

4346
struct rtsx_slot {

‎include/linux/mfd/rtsx_pci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ struct pcr_ops {
704704
int (*switch_output_voltage)(struct rtsx_pcr *pcr,
705705
u8 voltage);
706706
unsigned int (*cd_deglitch)(struct rtsx_pcr *pcr);
707+
int (*conv_clk_and_div_n)(int clk, int dir);
707708
};
708709

709710
enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN};

0 commit comments

Comments
 (0)