1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Genesys Logic, Inc.
5 * Authors: Ben Chuang <ben.chuang@genesyslogic.com.tw>
7 * Version: v0.9.0 (2019-08-08)
10 #include <linux/bitfield.h>
11 #include <linux/bits.h>
12 #include <linux/pci.h>
13 #include <linux/mmc/mmc.h>
14 #include <linux/delay.h>
16 #include "sdhci-pci.h"
19 /* Genesys Logic extra registers */
20 #define SDHCI_GLI_9750_WT 0x800
21 #define SDHCI_GLI_9750_WT_EN BIT(0)
22 #define GLI_9750_WT_EN_ON 0x1
23 #define GLI_9750_WT_EN_OFF 0x0
25 #define SDHCI_GLI_9750_DRIVING 0x860
26 #define SDHCI_GLI_9750_DRIVING_1 GENMASK(11, 0)
27 #define SDHCI_GLI_9750_DRIVING_2 GENMASK(27, 26)
28 #define GLI_9750_DRIVING_1_VALUE 0xFFF
29 #define GLI_9750_DRIVING_2_VALUE 0x3
30 #define SDHCI_GLI_9750_SEL_1 BIT(29)
31 #define SDHCI_GLI_9750_SEL_2 BIT(31)
32 #define SDHCI_GLI_9750_ALL_RST (BIT(24)|BIT(25)|BIT(28)|BIT(30))
34 #define SDHCI_GLI_9750_PLL 0x864
35 #define SDHCI_GLI_9750_PLL_LDIV GENMASK(9, 0)
36 #define SDHCI_GLI_9750_PLL_PDIV GENMASK(14, 12)
37 #define SDHCI_GLI_9750_PLL_DIR BIT(15)
38 #define SDHCI_GLI_9750_PLL_TX2_INV BIT(23)
39 #define SDHCI_GLI_9750_PLL_TX2_DLY GENMASK(22, 20)
40 #define GLI_9750_PLL_TX2_INV_VALUE 0x1
41 #define GLI_9750_PLL_TX2_DLY_VALUE 0x0
42 #define SDHCI_GLI_9750_PLLSSC_STEP GENMASK(28, 24)
43 #define SDHCI_GLI_9750_PLLSSC_EN BIT(31)
45 #define SDHCI_GLI_9750_PLLSSC 0x86C
46 #define SDHCI_GLI_9750_PLLSSC_PPM GENMASK(31, 16)
48 #define SDHCI_GLI_9750_SW_CTRL 0x874
49 #define SDHCI_GLI_9750_SW_CTRL_4 GENMASK(7, 6)
50 #define GLI_9750_SW_CTRL_4_VALUE 0x3
52 #define SDHCI_GLI_9750_MISC 0x878
53 #define SDHCI_GLI_9750_MISC_TX1_INV BIT(2)
54 #define SDHCI_GLI_9750_MISC_RX_INV BIT(3)
55 #define SDHCI_GLI_9750_MISC_TX1_DLY GENMASK(6, 4)
56 #define GLI_9750_MISC_TX1_INV_VALUE 0x0
57 #define GLI_9750_MISC_RX_INV_ON 0x1
58 #define GLI_9750_MISC_RX_INV_OFF 0x0
59 #define GLI_9750_MISC_RX_INV_VALUE GLI_9750_MISC_RX_INV_OFF
60 #define GLI_9750_MISC_TX1_DLY_VALUE 0x5
62 #define SDHCI_GLI_9750_TUNING_CONTROL 0x540
63 #define SDHCI_GLI_9750_TUNING_CONTROL_EN BIT(4)
64 #define GLI_9750_TUNING_CONTROL_EN_ON 0x1
65 #define GLI_9750_TUNING_CONTROL_EN_OFF 0x0
66 #define SDHCI_GLI_9750_TUNING_CONTROL_GLITCH_1 BIT(16)
67 #define SDHCI_GLI_9750_TUNING_CONTROL_GLITCH_2 GENMASK(20, 19)
68 #define GLI_9750_TUNING_CONTROL_GLITCH_1_VALUE 0x1
69 #define GLI_9750_TUNING_CONTROL_GLITCH_2_VALUE 0x2
71 #define SDHCI_GLI_9750_TUNING_PARAMETERS 0x544
72 #define SDHCI_GLI_9750_TUNING_PARAMETERS_RX_DLY GENMASK(2, 0)
73 #define GLI_9750_TUNING_PARAMETERS_RX_DLY_VALUE 0x1
75 #define SDHCI_GLI_9763E_CTRL_HS400 0x7
77 #define SDHCI_GLI_9763E_HS400_ES_REG 0x52C
78 #define SDHCI_GLI_9763E_HS400_ES_BIT BIT(8)
80 #define PCIE_GLI_9763E_VHS 0x884
81 #define GLI_9763E_VHS_REV GENMASK(19, 16)
82 #define GLI_9763E_VHS_REV_R 0x0
83 #define GLI_9763E_VHS_REV_M 0x1
84 #define GLI_9763E_VHS_REV_W 0x2
85 #define PCIE_GLI_9763E_MB 0x888
86 #define GLI_9763E_MB_CMDQ_OFF BIT(19)
87 #define PCIE_GLI_9763E_SCR 0x8E0
88 #define GLI_9763E_SCR_AXI_REQ BIT(9)
90 #define PCIE_GLI_9763E_MMC_CTRL 0x960
91 #define GLI_9763E_HS400_SLOW BIT(3)
93 #define SDHCI_GLI_9763E_CQE_BASE_ADDR 0x200
94 #define GLI_9763E_CQE_TRNS_MODE (SDHCI_TRNS_MULTI | \
95 SDHCI_TRNS_BLK_CNT_EN | \
98 #define PCI_GLI_9755_WT 0x800
99 #define PCI_GLI_9755_WT_EN BIT(0)
100 #define GLI_9755_WT_EN_ON 0x1
101 #define GLI_9755_WT_EN_OFF 0x0
103 #define PCI_GLI_9755_PECONF 0x44
104 #define PCI_GLI_9755_LFCLK GENMASK(14, 12)
105 #define PCI_GLI_9755_DMACLK BIT(29)
107 #define PCI_GLI_9755_PLL 0x64
108 #define PCI_GLI_9755_PLL_LDIV GENMASK(9, 0)
109 #define PCI_GLI_9755_PLL_PDIV GENMASK(14, 12)
110 #define PCI_GLI_9755_PLL_DIR BIT(15)
111 #define PCI_GLI_9755_PLLSSC_STEP GENMASK(28, 24)
112 #define PCI_GLI_9755_PLLSSC_EN BIT(31)
114 #define PCI_GLI_9755_PLLSSC 0x68
115 #define PCI_GLI_9755_PLLSSC_PPM GENMASK(15, 0)
117 #define GLI_MAX_TUNING_LOOP 40
119 /* Genesys Logic chipset */
120 static inline void gl9750_wt_on(struct sdhci_host
*host
)
125 wt_value
= sdhci_readl(host
, SDHCI_GLI_9750_WT
);
126 wt_enable
= FIELD_GET(SDHCI_GLI_9750_WT_EN
, wt_value
);
128 if (wt_enable
== GLI_9750_WT_EN_ON
)
131 wt_value
&= ~SDHCI_GLI_9750_WT_EN
;
132 wt_value
|= FIELD_PREP(SDHCI_GLI_9750_WT_EN
, GLI_9750_WT_EN_ON
);
134 sdhci_writel(host
, wt_value
, SDHCI_GLI_9750_WT
);
137 static inline void gl9750_wt_off(struct sdhci_host
*host
)
142 wt_value
= sdhci_readl(host
, SDHCI_GLI_9750_WT
);
143 wt_enable
= FIELD_GET(SDHCI_GLI_9750_WT_EN
, wt_value
);
145 if (wt_enable
== GLI_9750_WT_EN_OFF
)
148 wt_value
&= ~SDHCI_GLI_9750_WT_EN
;
149 wt_value
|= FIELD_PREP(SDHCI_GLI_9750_WT_EN
, GLI_9750_WT_EN_OFF
);
151 sdhci_writel(host
, wt_value
, SDHCI_GLI_9750_WT
);
154 static void gli_set_9750(struct sdhci_host
*host
)
166 driving_value
= sdhci_readl(host
, SDHCI_GLI_9750_DRIVING
);
167 pll_value
= sdhci_readl(host
, SDHCI_GLI_9750_PLL
);
168 sw_ctrl_value
= sdhci_readl(host
, SDHCI_GLI_9750_SW_CTRL
);
169 misc_value
= sdhci_readl(host
, SDHCI_GLI_9750_MISC
);
170 parameter_value
= sdhci_readl(host
, SDHCI_GLI_9750_TUNING_PARAMETERS
);
171 control_value
= sdhci_readl(host
, SDHCI_GLI_9750_TUNING_CONTROL
);
173 driving_value
&= ~(SDHCI_GLI_9750_DRIVING_1
);
174 driving_value
&= ~(SDHCI_GLI_9750_DRIVING_2
);
175 driving_value
|= FIELD_PREP(SDHCI_GLI_9750_DRIVING_1
,
176 GLI_9750_DRIVING_1_VALUE
);
177 driving_value
|= FIELD_PREP(SDHCI_GLI_9750_DRIVING_2
,
178 GLI_9750_DRIVING_2_VALUE
);
179 driving_value
&= ~(SDHCI_GLI_9750_SEL_1
|SDHCI_GLI_9750_SEL_2
|SDHCI_GLI_9750_ALL_RST
);
180 driving_value
|= SDHCI_GLI_9750_SEL_2
;
181 sdhci_writel(host
, driving_value
, SDHCI_GLI_9750_DRIVING
);
183 sw_ctrl_value
&= ~SDHCI_GLI_9750_SW_CTRL_4
;
184 sw_ctrl_value
|= FIELD_PREP(SDHCI_GLI_9750_SW_CTRL_4
,
185 GLI_9750_SW_CTRL_4_VALUE
);
186 sdhci_writel(host
, sw_ctrl_value
, SDHCI_GLI_9750_SW_CTRL
);
188 /* reset the tuning flow after reinit and before starting tuning */
189 pll_value
&= ~SDHCI_GLI_9750_PLL_TX2_INV
;
190 pll_value
&= ~SDHCI_GLI_9750_PLL_TX2_DLY
;
191 pll_value
|= FIELD_PREP(SDHCI_GLI_9750_PLL_TX2_INV
,
192 GLI_9750_PLL_TX2_INV_VALUE
);
193 pll_value
|= FIELD_PREP(SDHCI_GLI_9750_PLL_TX2_DLY
,
194 GLI_9750_PLL_TX2_DLY_VALUE
);
196 misc_value
&= ~SDHCI_GLI_9750_MISC_TX1_INV
;
197 misc_value
&= ~SDHCI_GLI_9750_MISC_RX_INV
;
198 misc_value
&= ~SDHCI_GLI_9750_MISC_TX1_DLY
;
199 misc_value
|= FIELD_PREP(SDHCI_GLI_9750_MISC_TX1_INV
,
200 GLI_9750_MISC_TX1_INV_VALUE
);
201 misc_value
|= FIELD_PREP(SDHCI_GLI_9750_MISC_RX_INV
,
202 GLI_9750_MISC_RX_INV_VALUE
);
203 misc_value
|= FIELD_PREP(SDHCI_GLI_9750_MISC_TX1_DLY
,
204 GLI_9750_MISC_TX1_DLY_VALUE
);
206 parameter_value
&= ~SDHCI_GLI_9750_TUNING_PARAMETERS_RX_DLY
;
207 parameter_value
|= FIELD_PREP(SDHCI_GLI_9750_TUNING_PARAMETERS_RX_DLY
,
208 GLI_9750_TUNING_PARAMETERS_RX_DLY_VALUE
);
210 control_value
&= ~SDHCI_GLI_9750_TUNING_CONTROL_GLITCH_1
;
211 control_value
&= ~SDHCI_GLI_9750_TUNING_CONTROL_GLITCH_2
;
212 control_value
|= FIELD_PREP(SDHCI_GLI_9750_TUNING_CONTROL_GLITCH_1
,
213 GLI_9750_TUNING_CONTROL_GLITCH_1_VALUE
);
214 control_value
|= FIELD_PREP(SDHCI_GLI_9750_TUNING_CONTROL_GLITCH_2
,
215 GLI_9750_TUNING_CONTROL_GLITCH_2_VALUE
);
217 sdhci_writel(host
, pll_value
, SDHCI_GLI_9750_PLL
);
218 sdhci_writel(host
, misc_value
, SDHCI_GLI_9750_MISC
);
220 /* disable tuned clk */
221 ctrl2
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
222 ctrl2
&= ~SDHCI_CTRL_TUNED_CLK
;
223 sdhci_writew(host
, ctrl2
, SDHCI_HOST_CONTROL2
);
225 /* enable tuning parameters control */
226 control_value
&= ~SDHCI_GLI_9750_TUNING_CONTROL_EN
;
227 control_value
|= FIELD_PREP(SDHCI_GLI_9750_TUNING_CONTROL_EN
,
228 GLI_9750_TUNING_CONTROL_EN_ON
);
229 sdhci_writel(host
, control_value
, SDHCI_GLI_9750_TUNING_CONTROL
);
231 /* write tuning parameters */
232 sdhci_writel(host
, parameter_value
, SDHCI_GLI_9750_TUNING_PARAMETERS
);
234 /* disable tuning parameters control */
235 control_value
&= ~SDHCI_GLI_9750_TUNING_CONTROL_EN
;
236 control_value
|= FIELD_PREP(SDHCI_GLI_9750_TUNING_CONTROL_EN
,
237 GLI_9750_TUNING_CONTROL_EN_OFF
);
238 sdhci_writel(host
, control_value
, SDHCI_GLI_9750_TUNING_CONTROL
);
240 /* clear tuned clk */
241 ctrl2
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
242 ctrl2
&= ~SDHCI_CTRL_TUNED_CLK
;
243 sdhci_writew(host
, ctrl2
, SDHCI_HOST_CONTROL2
);
248 static void gli_set_9750_rx_inv(struct sdhci_host
*host
, bool b
)
254 misc_value
= sdhci_readl(host
, SDHCI_GLI_9750_MISC
);
255 misc_value
&= ~SDHCI_GLI_9750_MISC_RX_INV
;
257 misc_value
|= FIELD_PREP(SDHCI_GLI_9750_MISC_RX_INV
,
258 GLI_9750_MISC_RX_INV_ON
);
260 misc_value
|= FIELD_PREP(SDHCI_GLI_9750_MISC_RX_INV
,
261 GLI_9750_MISC_RX_INV_OFF
);
263 sdhci_writel(host
, misc_value
, SDHCI_GLI_9750_MISC
);
268 static int __sdhci_execute_tuning_9750(struct sdhci_host
*host
, u32 opcode
)
273 for (rx_inv
= 0; rx_inv
< 2; rx_inv
++) {
274 gli_set_9750_rx_inv(host
, !!rx_inv
);
275 sdhci_start_tuning(host
);
277 for (i
= 0; i
< GLI_MAX_TUNING_LOOP
; i
++) {
280 sdhci_send_tuning(host
, opcode
);
282 if (!host
->tuning_done
) {
283 sdhci_abort_tuning(host
, opcode
);
287 ctrl
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
288 if (!(ctrl
& SDHCI_CTRL_EXEC_TUNING
)) {
289 if (ctrl
& SDHCI_CTRL_TUNED_CLK
)
290 return 0; /* Success! */
295 if (!host
->tuning_done
) {
296 pr_info("%s: Tuning timeout, falling back to fixed sampling clock\n",
297 mmc_hostname(host
->mmc
));
301 pr_info("%s: Tuning failed, falling back to fixed sampling clock\n",
302 mmc_hostname(host
->mmc
));
303 sdhci_reset_tuning(host
);
308 static int gl9750_execute_tuning(struct sdhci_host
*host
, u32 opcode
)
310 host
->mmc
->retune_period
= 0;
311 if (host
->tuning_mode
== SDHCI_TUNING_MODE_1
)
312 host
->mmc
->retune_period
= host
->tuning_count
;
315 host
->tuning_err
= __sdhci_execute_tuning_9750(host
, opcode
);
316 sdhci_end_tuning(host
);
321 static void gl9750_disable_ssc_pll(struct sdhci_host
*host
)
326 pll
= sdhci_readl(host
, SDHCI_GLI_9750_PLL
);
327 pll
&= ~(SDHCI_GLI_9750_PLL_DIR
| SDHCI_GLI_9750_PLLSSC_EN
);
328 sdhci_writel(host
, pll
, SDHCI_GLI_9750_PLL
);
332 static void gl9750_set_pll(struct sdhci_host
*host
, u8 dir
, u16 ldiv
, u8 pdiv
)
337 pll
= sdhci_readl(host
, SDHCI_GLI_9750_PLL
);
338 pll
&= ~(SDHCI_GLI_9750_PLL_LDIV
|
339 SDHCI_GLI_9750_PLL_PDIV
|
340 SDHCI_GLI_9750_PLL_DIR
);
341 pll
|= FIELD_PREP(SDHCI_GLI_9750_PLL_LDIV
, ldiv
) |
342 FIELD_PREP(SDHCI_GLI_9750_PLL_PDIV
, pdiv
) |
343 FIELD_PREP(SDHCI_GLI_9750_PLL_DIR
, dir
);
344 sdhci_writel(host
, pll
, SDHCI_GLI_9750_PLL
);
347 /* wait for pll stable */
351 static void gl9750_set_ssc(struct sdhci_host
*host
, u8 enable
, u8 step
, u16 ppm
)
357 pll
= sdhci_readl(host
, SDHCI_GLI_9750_PLL
);
358 ssc
= sdhci_readl(host
, SDHCI_GLI_9750_PLLSSC
);
359 pll
&= ~(SDHCI_GLI_9750_PLLSSC_STEP
|
360 SDHCI_GLI_9750_PLLSSC_EN
);
361 ssc
&= ~SDHCI_GLI_9750_PLLSSC_PPM
;
362 pll
|= FIELD_PREP(SDHCI_GLI_9750_PLLSSC_STEP
, step
) |
363 FIELD_PREP(SDHCI_GLI_9750_PLLSSC_EN
, enable
);
364 ssc
|= FIELD_PREP(SDHCI_GLI_9750_PLLSSC_PPM
, ppm
);
365 sdhci_writel(host
, ssc
, SDHCI_GLI_9750_PLLSSC
);
366 sdhci_writel(host
, pll
, SDHCI_GLI_9750_PLL
);
370 static void gl9750_set_ssc_pll_205mhz(struct sdhci_host
*host
)
372 /* set pll to 205MHz and enable ssc */
373 gl9750_set_ssc(host
, 0x1, 0x1F, 0xFFE7);
374 gl9750_set_pll(host
, 0x1, 0x246, 0x0);
377 static void sdhci_gl9750_set_clock(struct sdhci_host
*host
, unsigned int clock
)
379 struct mmc_ios
*ios
= &host
->mmc
->ios
;
382 host
->mmc
->actual_clock
= 0;
384 gl9750_disable_ssc_pll(host
);
385 sdhci_writew(host
, 0, SDHCI_CLOCK_CONTROL
);
390 clk
= sdhci_calc_clk(host
, clock
, &host
->mmc
->actual_clock
);
391 if (clock
== 200000000 && ios
->timing
== MMC_TIMING_UHS_SDR104
) {
392 host
->mmc
->actual_clock
= 205000000;
393 gl9750_set_ssc_pll_205mhz(host
);
396 sdhci_enable_clk(host
, clk
);
399 static void gli_pcie_enable_msi(struct sdhci_pci_slot
*slot
)
403 ret
= pci_alloc_irq_vectors(slot
->chip
->pdev
, 1, 1,
404 PCI_IRQ_MSI
| PCI_IRQ_MSIX
);
406 pr_warn("%s: enable PCI MSI failed, error=%d\n",
407 mmc_hostname(slot
->host
->mmc
), ret
);
411 slot
->host
->irq
= pci_irq_vector(slot
->chip
->pdev
, 0);
414 static inline void gl9755_wt_on(struct pci_dev
*pdev
)
419 pci_read_config_dword(pdev
, PCI_GLI_9755_WT
, &wt_value
);
420 wt_enable
= FIELD_GET(PCI_GLI_9755_WT_EN
, wt_value
);
422 if (wt_enable
== GLI_9755_WT_EN_ON
)
425 wt_value
&= ~PCI_GLI_9755_WT_EN
;
426 wt_value
|= FIELD_PREP(PCI_GLI_9755_WT_EN
, GLI_9755_WT_EN_ON
);
428 pci_write_config_dword(pdev
, PCI_GLI_9755_WT
, wt_value
);
431 static inline void gl9755_wt_off(struct pci_dev
*pdev
)
436 pci_read_config_dword(pdev
, PCI_GLI_9755_WT
, &wt_value
);
437 wt_enable
= FIELD_GET(PCI_GLI_9755_WT_EN
, wt_value
);
439 if (wt_enable
== GLI_9755_WT_EN_OFF
)
442 wt_value
&= ~PCI_GLI_9755_WT_EN
;
443 wt_value
|= FIELD_PREP(PCI_GLI_9755_WT_EN
, GLI_9755_WT_EN_OFF
);
445 pci_write_config_dword(pdev
, PCI_GLI_9755_WT
, wt_value
);
448 static void gl9755_disable_ssc_pll(struct pci_dev
*pdev
)
453 pci_read_config_dword(pdev
, PCI_GLI_9755_PLL
, &pll
);
454 pll
&= ~(PCI_GLI_9755_PLL_DIR
| PCI_GLI_9755_PLLSSC_EN
);
455 pci_write_config_dword(pdev
, PCI_GLI_9755_PLL
, pll
);
459 static void gl9755_set_pll(struct pci_dev
*pdev
, u8 dir
, u16 ldiv
, u8 pdiv
)
464 pci_read_config_dword(pdev
, PCI_GLI_9755_PLL
, &pll
);
465 pll
&= ~(PCI_GLI_9755_PLL_LDIV
|
466 PCI_GLI_9755_PLL_PDIV
|
467 PCI_GLI_9755_PLL_DIR
);
468 pll
|= FIELD_PREP(PCI_GLI_9755_PLL_LDIV
, ldiv
) |
469 FIELD_PREP(PCI_GLI_9755_PLL_PDIV
, pdiv
) |
470 FIELD_PREP(PCI_GLI_9755_PLL_DIR
, dir
);
471 pci_write_config_dword(pdev
, PCI_GLI_9755_PLL
, pll
);
474 /* wait for pll stable */
478 static void gl9755_set_ssc(struct pci_dev
*pdev
, u8 enable
, u8 step
, u16 ppm
)
484 pci_read_config_dword(pdev
, PCI_GLI_9755_PLL
, &pll
);
485 pci_read_config_dword(pdev
, PCI_GLI_9755_PLLSSC
, &ssc
);
486 pll
&= ~(PCI_GLI_9755_PLLSSC_STEP
|
487 PCI_GLI_9755_PLLSSC_EN
);
488 ssc
&= ~PCI_GLI_9755_PLLSSC_PPM
;
489 pll
|= FIELD_PREP(PCI_GLI_9755_PLLSSC_STEP
, step
) |
490 FIELD_PREP(PCI_GLI_9755_PLLSSC_EN
, enable
);
491 ssc
|= FIELD_PREP(PCI_GLI_9755_PLLSSC_PPM
, ppm
);
492 pci_write_config_dword(pdev
, PCI_GLI_9755_PLLSSC
, ssc
);
493 pci_write_config_dword(pdev
, PCI_GLI_9755_PLL
, pll
);
497 static void gl9755_set_ssc_pll_205mhz(struct pci_dev
*pdev
)
499 /* set pll to 205MHz and enable ssc */
500 gl9755_set_ssc(pdev
, 0x1, 0x1F, 0xFFE7);
501 gl9755_set_pll(pdev
, 0x1, 0x246, 0x0);
504 static void sdhci_gl9755_set_clock(struct sdhci_host
*host
, unsigned int clock
)
506 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
507 struct mmc_ios
*ios
= &host
->mmc
->ios
;
508 struct pci_dev
*pdev
;
511 pdev
= slot
->chip
->pdev
;
512 host
->mmc
->actual_clock
= 0;
514 gl9755_disable_ssc_pll(pdev
);
515 sdhci_writew(host
, 0, SDHCI_CLOCK_CONTROL
);
520 clk
= sdhci_calc_clk(host
, clock
, &host
->mmc
->actual_clock
);
521 if (clock
== 200000000 && ios
->timing
== MMC_TIMING_UHS_SDR104
) {
522 host
->mmc
->actual_clock
= 205000000;
523 gl9755_set_ssc_pll_205mhz(pdev
);
526 sdhci_enable_clk(host
, clk
);
529 static void gl9755_hw_setting(struct sdhci_pci_slot
*slot
)
531 struct pci_dev
*pdev
= slot
->chip
->pdev
;
536 pci_read_config_dword(pdev
, PCI_GLI_9755_PECONF
, &value
);
537 value
&= ~PCI_GLI_9755_LFCLK
;
538 value
&= ~PCI_GLI_9755_DMACLK
;
539 pci_write_config_dword(pdev
, PCI_GLI_9755_PECONF
, value
);
544 static int gli_probe_slot_gl9750(struct sdhci_pci_slot
*slot
)
546 struct sdhci_host
*host
= slot
->host
;
548 gli_pcie_enable_msi(slot
);
549 slot
->host
->mmc
->caps2
|= MMC_CAP2_NO_SDIO
;
550 sdhci_enable_v4_mode(host
);
555 static int gli_probe_slot_gl9755(struct sdhci_pci_slot
*slot
)
557 struct sdhci_host
*host
= slot
->host
;
559 gl9755_hw_setting(slot
);
560 gli_pcie_enable_msi(slot
);
561 slot
->host
->mmc
->caps2
|= MMC_CAP2_NO_SDIO
;
562 sdhci_enable_v4_mode(host
);
567 static void sdhci_gli_voltage_switch(struct sdhci_host
*host
)
570 * According to Section 3.6.1 signal voltage switch procedure in
571 * SD Host Controller Simplified Spec. 4.20, steps 6~8 are as
573 * (6) Set 1.8V Signal Enable in the Host Control 2 register.
574 * (7) Wait 5ms. 1.8V voltage regulator shall be stable within this
576 * (8) If 1.8V Signal Enable is cleared by Host Controller, go to
579 * Wait 5ms after set 1.8V signal enable in Host Control 2 register
580 * to ensure 1.8V signal enable bit is set by GL9750/GL9755.
582 usleep_range(5000, 5500);
585 static void sdhci_gl9750_reset(struct sdhci_host
*host
, u8 mask
)
587 sdhci_reset(host
, mask
);
591 static u32
sdhci_gl9750_readl(struct sdhci_host
*host
, int reg
)
595 value
= readl(host
->ioaddr
+ reg
);
596 if (unlikely(reg
== SDHCI_MAX_CURRENT
&& !(value
& 0xff)))
602 #ifdef CONFIG_PM_SLEEP
603 static int sdhci_pci_gli_resume(struct sdhci_pci_chip
*chip
)
605 struct sdhci_pci_slot
*slot
= chip
->slots
[0];
607 pci_free_irq_vectors(slot
->chip
->pdev
);
608 gli_pcie_enable_msi(slot
);
610 return sdhci_pci_resume_host(chip
);
613 static int sdhci_cqhci_gli_resume(struct sdhci_pci_chip
*chip
)
615 struct sdhci_pci_slot
*slot
= chip
->slots
[0];
618 ret
= sdhci_pci_gli_resume(chip
);
622 return cqhci_resume(slot
->host
->mmc
);
625 static int sdhci_cqhci_gli_suspend(struct sdhci_pci_chip
*chip
)
627 struct sdhci_pci_slot
*slot
= chip
->slots
[0];
630 ret
= cqhci_suspend(slot
->host
->mmc
);
634 return sdhci_suspend_host(slot
->host
);
638 static void gl9763e_hs400_enhanced_strobe(struct mmc_host
*mmc
,
641 struct sdhci_host
*host
= mmc_priv(mmc
);
644 val
= sdhci_readl(host
, SDHCI_GLI_9763E_HS400_ES_REG
);
645 if (ios
->enhanced_strobe
)
646 val
|= SDHCI_GLI_9763E_HS400_ES_BIT
;
648 val
&= ~SDHCI_GLI_9763E_HS400_ES_BIT
;
650 sdhci_writel(host
, val
, SDHCI_GLI_9763E_HS400_ES_REG
);
653 static void sdhci_set_gl9763e_signaling(struct sdhci_host
*host
,
658 ctrl_2
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
659 ctrl_2
&= ~SDHCI_CTRL_UHS_MASK
;
660 if (timing
== MMC_TIMING_MMC_HS200
)
661 ctrl_2
|= SDHCI_CTRL_UHS_SDR104
;
662 else if (timing
== MMC_TIMING_MMC_HS
)
663 ctrl_2
|= SDHCI_CTRL_UHS_SDR25
;
664 else if (timing
== MMC_TIMING_MMC_DDR52
)
665 ctrl_2
|= SDHCI_CTRL_UHS_DDR50
;
666 else if (timing
== MMC_TIMING_MMC_HS400
)
667 ctrl_2
|= SDHCI_GLI_9763E_CTRL_HS400
;
669 sdhci_writew(host
, ctrl_2
, SDHCI_HOST_CONTROL2
);
672 static void sdhci_gl9763e_dumpregs(struct mmc_host
*mmc
)
674 sdhci_dumpregs(mmc_priv(mmc
));
677 static void sdhci_gl9763e_cqe_pre_enable(struct mmc_host
*mmc
)
679 struct cqhci_host
*cq_host
= mmc
->cqe_private
;
682 value
= cqhci_readl(cq_host
, CQHCI_CFG
);
683 value
|= CQHCI_ENABLE
;
684 cqhci_writel(cq_host
, value
, CQHCI_CFG
);
687 static void sdhci_gl9763e_cqe_enable(struct mmc_host
*mmc
)
689 struct sdhci_host
*host
= mmc_priv(mmc
);
691 sdhci_writew(host
, GLI_9763E_CQE_TRNS_MODE
, SDHCI_TRANSFER_MODE
);
692 sdhci_cqe_enable(mmc
);
695 static u32
sdhci_gl9763e_cqhci_irq(struct sdhci_host
*host
, u32 intmask
)
700 if (!sdhci_cqe_irq(host
, intmask
, &cmd_error
, &data_error
))
703 cqhci_irq(host
->mmc
, intmask
, cmd_error
, data_error
);
708 static void sdhci_gl9763e_cqe_post_disable(struct mmc_host
*mmc
)
710 struct sdhci_host
*host
= mmc_priv(mmc
);
711 struct cqhci_host
*cq_host
= mmc
->cqe_private
;
714 value
= cqhci_readl(cq_host
, CQHCI_CFG
);
715 value
&= ~CQHCI_ENABLE
;
716 cqhci_writel(cq_host
, value
, CQHCI_CFG
);
717 sdhci_writew(host
, 0x0, SDHCI_TRANSFER_MODE
);
720 static const struct cqhci_host_ops sdhci_gl9763e_cqhci_ops
= {
721 .enable
= sdhci_gl9763e_cqe_enable
,
722 .disable
= sdhci_cqe_disable
,
723 .dumpregs
= sdhci_gl9763e_dumpregs
,
724 .pre_enable
= sdhci_gl9763e_cqe_pre_enable
,
725 .post_disable
= sdhci_gl9763e_cqe_post_disable
,
728 static int gl9763e_add_host(struct sdhci_pci_slot
*slot
)
730 struct device
*dev
= &slot
->chip
->pdev
->dev
;
731 struct sdhci_host
*host
= slot
->host
;
732 struct cqhci_host
*cq_host
;
736 ret
= sdhci_setup_host(host
);
740 cq_host
= devm_kzalloc(dev
, sizeof(*cq_host
), GFP_KERNEL
);
746 cq_host
->mmio
= host
->ioaddr
+ SDHCI_GLI_9763E_CQE_BASE_ADDR
;
747 cq_host
->ops
= &sdhci_gl9763e_cqhci_ops
;
749 dma64
= host
->flags
& SDHCI_USE_64_BIT_DMA
;
751 cq_host
->caps
|= CQHCI_TASK_DESC_SZ_128
;
753 ret
= cqhci_init(cq_host
, host
->mmc
, dma64
);
757 ret
= __sdhci_add_host(host
);
764 sdhci_cleanup_host(host
);
768 static void sdhci_gl9763e_reset(struct sdhci_host
*host
, u8 mask
)
770 if ((host
->mmc
->caps2
& MMC_CAP2_CQE
) && (mask
& SDHCI_RESET_ALL
) &&
771 host
->mmc
->cqe_private
)
772 cqhci_deactivate(host
->mmc
);
773 sdhci_reset(host
, mask
);
776 static void gli_set_gl9763e(struct sdhci_pci_slot
*slot
)
778 struct pci_dev
*pdev
= slot
->chip
->pdev
;
781 pci_read_config_dword(pdev
, PCIE_GLI_9763E_VHS
, &value
);
782 value
&= ~GLI_9763E_VHS_REV
;
783 value
|= FIELD_PREP(GLI_9763E_VHS_REV
, GLI_9763E_VHS_REV_W
);
784 pci_write_config_dword(pdev
, PCIE_GLI_9763E_VHS
, value
);
786 pci_read_config_dword(pdev
, PCIE_GLI_9763E_SCR
, &value
);
787 value
|= GLI_9763E_SCR_AXI_REQ
;
788 pci_write_config_dword(pdev
, PCIE_GLI_9763E_SCR
, value
);
790 pci_read_config_dword(pdev
, PCIE_GLI_9763E_MMC_CTRL
, &value
);
791 value
&= ~GLI_9763E_HS400_SLOW
;
792 pci_write_config_dword(pdev
, PCIE_GLI_9763E_MMC_CTRL
, value
);
794 pci_read_config_dword(pdev
, PCIE_GLI_9763E_VHS
, &value
);
795 value
&= ~GLI_9763E_VHS_REV
;
796 value
|= FIELD_PREP(GLI_9763E_VHS_REV
, GLI_9763E_VHS_REV_R
);
797 pci_write_config_dword(pdev
, PCIE_GLI_9763E_VHS
, value
);
800 static int gli_probe_slot_gl9763e(struct sdhci_pci_slot
*slot
)
802 struct pci_dev
*pdev
= slot
->chip
->pdev
;
803 struct sdhci_host
*host
= slot
->host
;
806 host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
|
808 MMC_CAP_NONREMOVABLE
;
809 host
->mmc
->caps2
|= MMC_CAP2_HS200_1_8V_SDR
|
810 MMC_CAP2_HS400_1_8V
|
815 pci_read_config_dword(pdev
, PCIE_GLI_9763E_MB
, &value
);
816 if (!(value
& GLI_9763E_MB_CMDQ_OFF
))
817 host
->mmc
->caps2
|= MMC_CAP2_CQE
| MMC_CAP2_CQE_DCMD
;
819 gli_pcie_enable_msi(slot
);
820 host
->mmc_host_ops
.hs400_enhanced_strobe
=
821 gl9763e_hs400_enhanced_strobe
;
822 gli_set_gl9763e(slot
);
823 sdhci_enable_v4_mode(host
);
828 static const struct sdhci_ops sdhci_gl9755_ops
= {
829 .set_clock
= sdhci_gl9755_set_clock
,
830 .enable_dma
= sdhci_pci_enable_dma
,
831 .set_bus_width
= sdhci_set_bus_width
,
832 .reset
= sdhci_reset
,
833 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
834 .voltage_switch
= sdhci_gli_voltage_switch
,
837 const struct sdhci_pci_fixes sdhci_gl9755
= {
838 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
839 .quirks2
= SDHCI_QUIRK2_BROKEN_DDR50
,
840 .probe_slot
= gli_probe_slot_gl9755
,
841 .ops
= &sdhci_gl9755_ops
,
842 #ifdef CONFIG_PM_SLEEP
843 .resume
= sdhci_pci_gli_resume
,
847 static const struct sdhci_ops sdhci_gl9750_ops
= {
848 .read_l
= sdhci_gl9750_readl
,
849 .set_clock
= sdhci_gl9750_set_clock
,
850 .enable_dma
= sdhci_pci_enable_dma
,
851 .set_bus_width
= sdhci_set_bus_width
,
852 .reset
= sdhci_gl9750_reset
,
853 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
854 .voltage_switch
= sdhci_gli_voltage_switch
,
855 .platform_execute_tuning
= gl9750_execute_tuning
,
858 const struct sdhci_pci_fixes sdhci_gl9750
= {
859 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
860 .quirks2
= SDHCI_QUIRK2_BROKEN_DDR50
,
861 .probe_slot
= gli_probe_slot_gl9750
,
862 .ops
= &sdhci_gl9750_ops
,
863 #ifdef CONFIG_PM_SLEEP
864 .resume
= sdhci_pci_gli_resume
,
868 static const struct sdhci_ops sdhci_gl9763e_ops
= {
869 .set_clock
= sdhci_set_clock
,
870 .enable_dma
= sdhci_pci_enable_dma
,
871 .set_bus_width
= sdhci_set_bus_width
,
872 .reset
= sdhci_gl9763e_reset
,
873 .set_uhs_signaling
= sdhci_set_gl9763e_signaling
,
874 .voltage_switch
= sdhci_gli_voltage_switch
,
875 .irq
= sdhci_gl9763e_cqhci_irq
,
878 const struct sdhci_pci_fixes sdhci_gl9763e
= {
879 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
880 .probe_slot
= gli_probe_slot_gl9763e
,
881 .ops
= &sdhci_gl9763e_ops
,
882 #ifdef CONFIG_PM_SLEEP
883 .resume
= sdhci_cqhci_gli_resume
,
884 .suspend
= sdhci_cqhci_gli_suspend
,
886 .add_host
= gl9763e_add_host
,