1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 BayHub Technology Ltd.
5 * Authors: Peter Guo <peter.guo@bayhubtech.com>
6 * Adam Lee <adam.lee@canonical.com>
7 * Ernest Zhang <ernest.zhang@bayhubtech.com>
10 #include <linux/pci.h>
11 #include <linux/mmc/host.h>
12 #include <linux/mmc/mmc.h>
13 #include <linux/delay.h>
14 #include <linux/iopoll.h>
17 #include "sdhci-pci.h"
20 * O2Micro device registers
23 #define O2_SD_MISC_REG5 0x64
24 #define O2_SD_LD0_CTRL 0x68
25 #define O2_SD_DEV_CTRL 0x88
26 #define O2_SD_LOCK_WP 0xD3
27 #define O2_SD_TEST_REG 0xD4
28 #define O2_SD_FUNC_REG0 0xDC
29 #define O2_SD_MULTI_VCC3V 0xEE
30 #define O2_SD_CLKREQ 0xEC
31 #define O2_SD_CAPS 0xE0
32 #define O2_SD_ADMA1 0xE2
33 #define O2_SD_ADMA2 0xE7
34 #define O2_SD_INF_MOD 0xF1
35 #define O2_SD_MISC_CTRL4 0xFC
36 #define O2_SD_TUNING_CTRL 0x300
37 #define O2_SD_PLL_SETTING 0x304
38 #define O2_SD_MISC_SETTING 0x308
39 #define O2_SD_CLK_SETTING 0x328
40 #define O2_SD_CAP_REG2 0x330
41 #define O2_SD_CAP_REG0 0x334
42 #define O2_SD_UHS1_CAP_SETTING 0x33C
43 #define O2_SD_DELAY_CTRL 0x350
44 #define O2_SD_UHS2_L1_CTRL 0x35C
45 #define O2_SD_FUNC_REG3 0x3E0
46 #define O2_SD_FUNC_REG4 0x3E4
47 #define O2_SD_LED_ENABLE BIT(6)
48 #define O2_SD_FREG0_LEDOFF BIT(13)
49 #define O2_SD_FREG4_ENABLE_CLK_SET BIT(22)
51 #define O2_SD_VENDOR_SETTING 0x110
52 #define O2_SD_VENDOR_SETTING2 0x1C8
53 #define O2_SD_HW_TUNING_DISABLE BIT(4)
55 #define O2_PLL_DLL_WDT_CONTROL1 0x1CC
56 #define O2_PLL_FORCE_ACTIVE BIT(18)
57 #define O2_PLL_LOCK_STATUS BIT(14)
58 #define O2_PLL_SOFT_RESET BIT(12)
59 #define O2_DLL_LOCK_STATUS BIT(11)
61 #define O2_SD_DETECT_SETTING 0x324
63 static const u32 dmdn_table
[] = {0x2B1C0000,
64 0x2C1A0000, 0x371B0000, 0x35100000};
65 #define DMDN_SZ ARRAY_SIZE(dmdn_table)
71 static void sdhci_o2_wait_card_detect_stable(struct sdhci_host
*host
)
77 timeout
= ktime_add_ms(ktime_get(), 50);
79 bool timedout
= ktime_after(ktime_get(), timeout
);
81 scratch32
= sdhci_readl(host
, SDHCI_PRESENT_STATE
);
82 if ((scratch32
& SDHCI_CARD_PRESENT
) >> SDHCI_CARD_PRES_SHIFT
83 == (scratch32
& SDHCI_CD_LVL
) >> SDHCI_CD_LVL_SHIFT
)
87 pr_err("%s: Card Detect debounce never finished.\n",
88 mmc_hostname(host
->mmc
));
96 static void sdhci_o2_enable_internal_clock(struct sdhci_host
*host
)
102 /* PLL software reset */
103 scratch32
= sdhci_readl(host
, O2_PLL_DLL_WDT_CONTROL1
);
104 scratch32
|= O2_PLL_SOFT_RESET
;
105 sdhci_writel(host
, scratch32
, O2_PLL_DLL_WDT_CONTROL1
);
107 scratch32
&= ~(O2_PLL_SOFT_RESET
);
108 sdhci_writel(host
, scratch32
, O2_PLL_DLL_WDT_CONTROL1
);
110 /* PLL force active */
111 scratch32
|= O2_PLL_FORCE_ACTIVE
;
112 sdhci_writel(host
, scratch32
, O2_PLL_DLL_WDT_CONTROL1
);
115 timeout
= ktime_add_ms(ktime_get(), 20);
117 bool timedout
= ktime_after(ktime_get(), timeout
);
119 scratch
= sdhci_readw(host
, O2_PLL_DLL_WDT_CONTROL1
);
120 if (scratch
& O2_PLL_LOCK_STATUS
)
123 pr_err("%s: Internal clock never stabilised.\n",
124 mmc_hostname(host
->mmc
));
125 sdhci_dumpregs(host
);
131 /* Wait for card detect finish */
133 sdhci_o2_wait_card_detect_stable(host
);
136 /* Cancel PLL force active */
137 scratch32
= sdhci_readl(host
, O2_PLL_DLL_WDT_CONTROL1
);
138 scratch32
&= ~O2_PLL_FORCE_ACTIVE
;
139 sdhci_writel(host
, scratch32
, O2_PLL_DLL_WDT_CONTROL1
);
142 static int sdhci_o2_get_cd(struct mmc_host
*mmc
)
144 struct sdhci_host
*host
= mmc_priv(mmc
);
146 if (!(sdhci_readw(host
, O2_PLL_DLL_WDT_CONTROL1
) & O2_PLL_LOCK_STATUS
))
147 sdhci_o2_enable_internal_clock(host
);
149 return !!(sdhci_readl(host
, SDHCI_PRESENT_STATE
) & SDHCI_CARD_PRESENT
);
152 static void o2_pci_set_baseclk(struct sdhci_pci_chip
*chip
, u32 value
)
156 pci_read_config_dword(chip
->pdev
,
157 O2_SD_PLL_SETTING
, &scratch_32
);
159 scratch_32
&= 0x0000FFFF;
162 pci_write_config_dword(chip
->pdev
,
163 O2_SD_PLL_SETTING
, scratch_32
);
166 static u32
sdhci_o2_pll_dll_wdt_control(struct sdhci_host
*host
)
168 return sdhci_readl(host
, O2_PLL_DLL_WDT_CONTROL1
);
172 * This function is used to detect dll lock status.
173 * Since the dll lock status bit will toggle randomly
174 * with very short interval which needs to be polled
175 * as fast as possible. Set sleep_us as 1 microsecond.
177 static int sdhci_o2_wait_dll_detect_lock(struct sdhci_host
*host
)
181 return readx_poll_timeout(sdhci_o2_pll_dll_wdt_control
, host
,
182 scratch32
, !(scratch32
& O2_DLL_LOCK_STATUS
), 1, 1000000);
185 static void sdhci_o2_set_tuning_mode(struct sdhci_host
*host
)
189 /* enable hardware tuning */
190 reg
= sdhci_readw(host
, O2_SD_VENDOR_SETTING
);
191 reg
&= ~O2_SD_HW_TUNING_DISABLE
;
192 sdhci_writew(host
, reg
, O2_SD_VENDOR_SETTING
);
195 static void __sdhci_o2_execute_tuning(struct sdhci_host
*host
, u32 opcode
)
199 sdhci_send_tuning(host
, MMC_SEND_TUNING_BLOCK_HS200
);
201 for (i
= 0; i
< 150; i
++) {
202 u16 ctrl
= sdhci_readw(host
, SDHCI_HOST_CONTROL2
);
204 if (!(ctrl
& SDHCI_CTRL_EXEC_TUNING
)) {
205 if (ctrl
& SDHCI_CTRL_TUNED_CLK
) {
206 host
->tuning_done
= true;
209 pr_warn("%s: HW tuning failed !\n",
210 mmc_hostname(host
->mmc
));
217 pr_info("%s: Tuning failed, falling back to fixed sampling clock\n",
218 mmc_hostname(host
->mmc
));
219 sdhci_reset_tuning(host
);
223 * This function is used to fix o2 dll shift issue.
224 * It isn't necessary to detect card present before recovery.
225 * Firstly, it is used by bht emmc card, which is embedded.
226 * Second, before call recovery card present will be detected
227 * outside of the execute tuning function.
229 static int sdhci_o2_dll_recovery(struct sdhci_host
*host
)
234 struct sdhci_pci_slot
*slot
= sdhci_priv(host
);
235 struct sdhci_pci_chip
*chip
= slot
->chip
;
236 struct o2_host
*o2_host
= sdhci_pci_priv(slot
);
239 pci_read_config_byte(chip
->pdev
,
240 O2_SD_LOCK_WP
, &scratch_8
);
242 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch_8
);
243 while (o2_host
->dll_adjust_count
< DMDN_SZ
&& !ret
) {
245 sdhci_writeb(host
, 0, SDHCI_CLOCK_CONTROL
);
247 /* PLL software reset */
248 scratch_32
= sdhci_readl(host
, O2_PLL_DLL_WDT_CONTROL1
);
249 scratch_32
|= O2_PLL_SOFT_RESET
;
250 sdhci_writel(host
, scratch_32
, O2_PLL_DLL_WDT_CONTROL1
);
252 pci_read_config_dword(chip
->pdev
,
255 /* Enable Base Clk setting change */
256 scratch_32
|= O2_SD_FREG4_ENABLE_CLK_SET
;
257 pci_write_config_dword(chip
->pdev
, O2_SD_FUNC_REG4
, scratch_32
);
258 o2_pci_set_baseclk(chip
, dmdn_table
[o2_host
->dll_adjust_count
]);
260 /* Enable internal clock */
261 scratch_8
= SDHCI_CLOCK_INT_EN
;
262 sdhci_writeb(host
, scratch_8
, SDHCI_CLOCK_CONTROL
);
264 if (sdhci_o2_get_cd(host
->mmc
)) {
266 * need wait at least 5ms for dll status stable,
267 * after enable internal clock
269 usleep_range(5000, 6000);
270 if (sdhci_o2_wait_dll_detect_lock(host
)) {
271 scratch_8
|= SDHCI_CLOCK_CARD_EN
;
272 sdhci_writeb(host
, scratch_8
,
273 SDHCI_CLOCK_CONTROL
);
276 pr_warn("%s: DLL unlocked when dll_adjust_count is %d.\n",
277 mmc_hostname(host
->mmc
),
278 o2_host
->dll_adjust_count
);
281 pr_err("%s: card present detect failed.\n",
282 mmc_hostname(host
->mmc
));
286 o2_host
->dll_adjust_count
++;
288 if (!ret
&& o2_host
->dll_adjust_count
== DMDN_SZ
)
289 pr_err("%s: DLL adjust over max times\n",
290 mmc_hostname(host
->mmc
));
292 pci_read_config_byte(chip
->pdev
,
293 O2_SD_LOCK_WP
, &scratch_8
);
295 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch_8
);
299 static int sdhci_o2_execute_tuning(struct mmc_host
*mmc
, u32 opcode
)
301 struct sdhci_host
*host
= mmc_priv(mmc
);
302 int current_bus_width
= 0;
305 * This handler only implements the eMMC tuning that is specific to
306 * this controller. Fall back to the standard method for other TIMING.
308 if (host
->timing
!= MMC_TIMING_MMC_HS200
)
309 return sdhci_execute_tuning(mmc
, opcode
);
311 if (WARN_ON(opcode
!= MMC_SEND_TUNING_BLOCK_HS200
))
314 * Judge the tuning reason, whether caused by dll shift
315 * If cause by dll shift, should call sdhci_o2_dll_recovery
317 if (!sdhci_o2_wait_dll_detect_lock(host
))
318 if (!sdhci_o2_dll_recovery(host
)) {
319 pr_err("%s: o2 dll recovery failed\n",
320 mmc_hostname(host
->mmc
));
324 * o2 sdhci host didn't support 8bit emmc tuning
326 if (mmc
->ios
.bus_width
== MMC_BUS_WIDTH_8
) {
327 current_bus_width
= mmc
->ios
.bus_width
;
328 mmc
->ios
.bus_width
= MMC_BUS_WIDTH_4
;
329 sdhci_set_bus_width(host
, MMC_BUS_WIDTH_4
);
332 sdhci_o2_set_tuning_mode(host
);
334 sdhci_start_tuning(host
);
336 __sdhci_o2_execute_tuning(host
, opcode
);
338 sdhci_end_tuning(host
);
340 if (current_bus_width
== MMC_BUS_WIDTH_8
) {
341 mmc
->ios
.bus_width
= MMC_BUS_WIDTH_8
;
342 sdhci_set_bus_width(host
, current_bus_width
);
345 host
->flags
&= ~SDHCI_HS400_TUNING
;
349 static void o2_pci_led_enable(struct sdhci_pci_chip
*chip
)
354 /* Set led of SD host function enable */
355 ret
= pci_read_config_dword(chip
->pdev
,
356 O2_SD_FUNC_REG0
, &scratch_32
);
360 scratch_32
&= ~O2_SD_FREG0_LEDOFF
;
361 pci_write_config_dword(chip
->pdev
,
362 O2_SD_FUNC_REG0
, scratch_32
);
364 ret
= pci_read_config_dword(chip
->pdev
,
365 O2_SD_TEST_REG
, &scratch_32
);
369 scratch_32
|= O2_SD_LED_ENABLE
;
370 pci_write_config_dword(chip
->pdev
,
371 O2_SD_TEST_REG
, scratch_32
);
375 static void sdhci_pci_o2_fujin2_pci_init(struct sdhci_pci_chip
*chip
)
379 /* Improve write performance for SD3.0 */
380 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_DEV_CTRL
, &scratch_32
);
383 scratch_32
&= ~((1 << 12) | (1 << 13) | (1 << 14));
384 pci_write_config_dword(chip
->pdev
, O2_SD_DEV_CTRL
, scratch_32
);
386 /* Enable Link abnormal reset generating Reset */
387 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_MISC_REG5
, &scratch_32
);
390 scratch_32
&= ~((1 << 19) | (1 << 11));
391 scratch_32
|= (1 << 10);
392 pci_write_config_dword(chip
->pdev
, O2_SD_MISC_REG5
, scratch_32
);
394 /* set card power over current protection */
395 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_TEST_REG
, &scratch_32
);
398 scratch_32
|= (1 << 4);
399 pci_write_config_dword(chip
->pdev
, O2_SD_TEST_REG
, scratch_32
);
401 /* adjust the output delay for SD mode */
402 pci_write_config_dword(chip
->pdev
, O2_SD_DELAY_CTRL
, 0x00002492);
404 /* Set the output voltage setting of Aux 1.2v LDO */
405 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_LD0_CTRL
, &scratch_32
);
408 scratch_32
&= ~(3 << 12);
409 pci_write_config_dword(chip
->pdev
, O2_SD_LD0_CTRL
, scratch_32
);
411 /* Set Max power supply capability of SD host */
412 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_CAP_REG0
, &scratch_32
);
415 scratch_32
&= ~(0x01FE);
416 scratch_32
|= 0x00CC;
417 pci_write_config_dword(chip
->pdev
, O2_SD_CAP_REG0
, scratch_32
);
418 /* Set DLL Tuning Window */
419 ret
= pci_read_config_dword(chip
->pdev
,
420 O2_SD_TUNING_CTRL
, &scratch_32
);
423 scratch_32
&= ~(0x000000FF);
424 scratch_32
|= 0x00000066;
425 pci_write_config_dword(chip
->pdev
, O2_SD_TUNING_CTRL
, scratch_32
);
427 /* Set UHS2 T_EIDLE */
428 ret
= pci_read_config_dword(chip
->pdev
,
429 O2_SD_UHS2_L1_CTRL
, &scratch_32
);
432 scratch_32
&= ~(0x000000FC);
433 scratch_32
|= 0x00000084;
434 pci_write_config_dword(chip
->pdev
, O2_SD_UHS2_L1_CTRL
, scratch_32
);
436 /* Set UHS2 Termination */
437 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_FUNC_REG3
, &scratch_32
);
440 scratch_32
&= ~((1 << 21) | (1 << 30));
442 pci_write_config_dword(chip
->pdev
, O2_SD_FUNC_REG3
, scratch_32
);
444 /* Set L1 Entrance Timer */
445 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_CAPS
, &scratch_32
);
448 scratch_32
&= ~(0xf0000000);
449 scratch_32
|= 0x30000000;
450 pci_write_config_dword(chip
->pdev
, O2_SD_CAPS
, scratch_32
);
452 ret
= pci_read_config_dword(chip
->pdev
,
453 O2_SD_MISC_CTRL4
, &scratch_32
);
456 scratch_32
&= ~(0x000f0000);
457 scratch_32
|= 0x00080000;
458 pci_write_config_dword(chip
->pdev
, O2_SD_MISC_CTRL4
, scratch_32
);
461 static void sdhci_pci_o2_enable_msi(struct sdhci_pci_chip
*chip
,
462 struct sdhci_host
*host
)
466 ret
= pci_find_capability(chip
->pdev
, PCI_CAP_ID_MSI
);
468 pr_info("%s: unsupport msi, use INTx irq\n",
469 mmc_hostname(host
->mmc
));
473 ret
= pci_alloc_irq_vectors(chip
->pdev
, 1, 1,
474 PCI_IRQ_MSI
| PCI_IRQ_MSIX
);
476 pr_err("%s: enable PCI MSI failed, err=%d\n",
477 mmc_hostname(host
->mmc
), ret
);
481 host
->irq
= pci_irq_vector(chip
->pdev
, 0);
484 static void sdhci_o2_enable_clk(struct sdhci_host
*host
, u16 clk
)
486 /* Enable internal clock */
487 clk
|= SDHCI_CLOCK_INT_EN
;
488 sdhci_writew(host
, clk
, SDHCI_CLOCK_CONTROL
);
490 sdhci_o2_enable_internal_clock(host
);
491 if (sdhci_o2_get_cd(host
->mmc
)) {
492 clk
|= SDHCI_CLOCK_CARD_EN
;
493 sdhci_writew(host
, clk
, SDHCI_CLOCK_CONTROL
);
497 void sdhci_pci_o2_set_clock(struct sdhci_host
*host
, unsigned int clock
)
501 host
->mmc
->actual_clock
= 0;
503 sdhci_writew(host
, 0, SDHCI_CLOCK_CONTROL
);
508 clk
= sdhci_calc_clk(host
, clock
, &host
->mmc
->actual_clock
);
509 sdhci_o2_enable_clk(host
, clk
);
512 int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot
*slot
)
514 struct sdhci_pci_chip
*chip
;
515 struct sdhci_host
*host
;
516 struct o2_host
*o2_host
= sdhci_pci_priv(slot
);
523 o2_host
->dll_adjust_count
= 0;
524 caps
= sdhci_readl(host
, SDHCI_CAPABILITIES
);
527 * mmc_select_bus_width() will test the bus to determine the actual bus
530 if (caps
& SDHCI_CAN_DO_8BIT
)
531 host
->mmc
->caps
|= MMC_CAP_8_BIT_DATA
;
533 switch (chip
->pdev
->device
) {
534 case PCI_DEVICE_ID_O2_SDS0
:
535 case PCI_DEVICE_ID_O2_SEABIRD0
:
536 case PCI_DEVICE_ID_O2_SEABIRD1
:
537 case PCI_DEVICE_ID_O2_SDS1
:
538 case PCI_DEVICE_ID_O2_FUJIN2
:
539 reg
= sdhci_readl(host
, O2_SD_VENDOR_SETTING
);
541 host
->quirks
|= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12
;
543 sdhci_pci_o2_enable_msi(chip
, host
);
545 if (chip
->pdev
->device
== PCI_DEVICE_ID_O2_SEABIRD0
) {
546 ret
= pci_read_config_dword(chip
->pdev
,
547 O2_SD_MISC_SETTING
, ®
);
550 if (reg
& (1 << 4)) {
551 pr_info("%s: emmc 1.8v flag is set, force 1.8v signaling voltage\n",
552 mmc_hostname(host
->mmc
));
553 host
->flags
&= ~SDHCI_SIGNALING_330
;
554 host
->flags
|= SDHCI_SIGNALING_180
;
555 host
->mmc
->caps2
|= MMC_CAP2_NO_SD
;
556 host
->mmc
->caps2
|= MMC_CAP2_NO_SDIO
;
557 pci_write_config_dword(chip
->pdev
,
558 O2_SD_DETECT_SETTING
, 3);
561 slot
->host
->mmc_host_ops
.get_cd
= sdhci_o2_get_cd
;
564 host
->mmc_host_ops
.execute_tuning
= sdhci_o2_execute_tuning
;
566 if (chip
->pdev
->device
!= PCI_DEVICE_ID_O2_FUJIN2
)
568 /* set dll watch dog timer */
569 reg
= sdhci_readl(host
, O2_SD_VENDOR_SETTING2
);
571 sdhci_writel(host
, reg
, O2_SD_VENDOR_SETTING2
);
581 int sdhci_pci_o2_probe(struct sdhci_pci_chip
*chip
)
587 switch (chip
->pdev
->device
) {
588 case PCI_DEVICE_ID_O2_8220
:
589 case PCI_DEVICE_ID_O2_8221
:
590 case PCI_DEVICE_ID_O2_8320
:
591 case PCI_DEVICE_ID_O2_8321
:
592 /* This extra setup is required due to broken ADMA. */
593 ret
= pci_read_config_byte(chip
->pdev
,
594 O2_SD_LOCK_WP
, &scratch
);
598 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
600 /* Set Multi 3 to VCC3V# */
601 pci_write_config_byte(chip
->pdev
, O2_SD_MULTI_VCC3V
, 0x08);
603 /* Disable CLK_REQ# support after media DET */
604 ret
= pci_read_config_byte(chip
->pdev
,
605 O2_SD_CLKREQ
, &scratch
);
609 pci_write_config_byte(chip
->pdev
, O2_SD_CLKREQ
, scratch
);
611 /* Choose capabilities, enable SDMA. We have to write 0x01
612 * to the capabilities register first to unlock it.
614 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CAPS
, &scratch
);
618 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, scratch
);
619 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, 0x73);
621 /* Disable ADMA1/2 */
622 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA1
, 0x39);
623 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA2
, 0x08);
625 /* Disable the infinite transfer mode */
626 ret
= pci_read_config_byte(chip
->pdev
,
627 O2_SD_INF_MOD
, &scratch
);
631 pci_write_config_byte(chip
->pdev
, O2_SD_INF_MOD
, scratch
);
634 ret
= pci_read_config_byte(chip
->pdev
,
635 O2_SD_LOCK_WP
, &scratch
);
639 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
641 case PCI_DEVICE_ID_O2_SDS0
:
642 case PCI_DEVICE_ID_O2_SDS1
:
643 case PCI_DEVICE_ID_O2_FUJIN2
:
645 ret
= pci_read_config_byte(chip
->pdev
,
646 O2_SD_LOCK_WP
, &scratch
);
651 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
653 /* DevId=8520 subId= 0x11 or 0x12 Type Chip support */
654 if (chip
->pdev
->device
== PCI_DEVICE_ID_O2_FUJIN2
) {
655 ret
= pci_read_config_dword(chip
->pdev
,
658 scratch_32
= ((scratch_32
& 0xFF000000) >> 24);
660 /* Check Whether subId is 0x11 or 0x12 */
661 if ((scratch_32
== 0x11) || (scratch_32
== 0x12)) {
662 scratch_32
= 0x25100000;
664 o2_pci_set_baseclk(chip
, scratch_32
);
665 ret
= pci_read_config_dword(chip
->pdev
,
669 /* Enable Base Clk setting change */
670 scratch_32
|= O2_SD_FREG4_ENABLE_CLK_SET
;
671 pci_write_config_dword(chip
->pdev
,
675 /* Set Tuning Window to 4 */
676 pci_write_config_byte(chip
->pdev
,
677 O2_SD_TUNING_CTRL
, 0x44);
683 /* Enable 8520 led function */
684 o2_pci_led_enable(chip
);
686 /* Set timeout CLK */
687 ret
= pci_read_config_dword(chip
->pdev
,
688 O2_SD_CLK_SETTING
, &scratch_32
);
692 scratch_32
&= ~(0xFF00);
693 scratch_32
|= 0x07E0C800;
694 pci_write_config_dword(chip
->pdev
,
695 O2_SD_CLK_SETTING
, scratch_32
);
697 ret
= pci_read_config_dword(chip
->pdev
,
698 O2_SD_CLKREQ
, &scratch_32
);
702 pci_write_config_dword(chip
->pdev
, O2_SD_CLKREQ
, scratch_32
);
704 ret
= pci_read_config_dword(chip
->pdev
,
705 O2_SD_PLL_SETTING
, &scratch_32
);
709 scratch_32
&= ~(0x1F3F070E);
710 scratch_32
|= 0x18270106;
711 pci_write_config_dword(chip
->pdev
,
712 O2_SD_PLL_SETTING
, scratch_32
);
714 /* Disable UHS1 funciton */
715 ret
= pci_read_config_dword(chip
->pdev
,
716 O2_SD_CAP_REG2
, &scratch_32
);
719 scratch_32
&= ~(0xE0);
720 pci_write_config_dword(chip
->pdev
,
721 O2_SD_CAP_REG2
, scratch_32
);
723 if (chip
->pdev
->device
== PCI_DEVICE_ID_O2_FUJIN2
)
724 sdhci_pci_o2_fujin2_pci_init(chip
);
727 ret
= pci_read_config_byte(chip
->pdev
,
728 O2_SD_LOCK_WP
, &scratch
);
732 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
734 case PCI_DEVICE_ID_O2_SEABIRD0
:
735 case PCI_DEVICE_ID_O2_SEABIRD1
:
737 ret
= pci_read_config_byte(chip
->pdev
,
738 O2_SD_LOCK_WP
, &scratch
);
743 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
745 ret
= pci_read_config_dword(chip
->pdev
,
746 O2_SD_PLL_SETTING
, &scratch_32
);
748 if ((scratch_32
& 0xff000000) == 0x01000000) {
749 scratch_32
&= 0x0000FFFF;
750 scratch_32
|= 0x1F340000;
752 pci_write_config_dword(chip
->pdev
,
753 O2_SD_PLL_SETTING
, scratch_32
);
755 scratch_32
&= 0x0000FFFF;
756 scratch_32
|= 0x25100000;
758 pci_write_config_dword(chip
->pdev
,
759 O2_SD_PLL_SETTING
, scratch_32
);
761 ret
= pci_read_config_dword(chip
->pdev
,
764 scratch_32
|= (1 << 22);
765 pci_write_config_dword(chip
->pdev
,
766 O2_SD_FUNC_REG4
, scratch_32
);
769 /* Set Tuning Windows to 5 */
770 pci_write_config_byte(chip
->pdev
,
771 O2_SD_TUNING_CTRL
, 0x55);
773 ret
= pci_read_config_byte(chip
->pdev
,
774 O2_SD_LOCK_WP
, &scratch
);
778 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
785 #ifdef CONFIG_PM_SLEEP
786 int sdhci_pci_o2_resume(struct sdhci_pci_chip
*chip
)
788 sdhci_pci_o2_probe(chip
);
789 return sdhci_pci_resume_host(chip
);
793 static const struct sdhci_ops sdhci_pci_o2_ops
= {
794 .set_clock
= sdhci_pci_o2_set_clock
,
795 .enable_dma
= sdhci_pci_enable_dma
,
796 .set_bus_width
= sdhci_set_bus_width
,
797 .reset
= sdhci_reset
,
798 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
801 const struct sdhci_pci_fixes sdhci_o2
= {
802 .probe
= sdhci_pci_o2_probe
,
803 .quirks
= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
,
804 .quirks2
= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD
,
805 .probe_slot
= sdhci_pci_o2_probe_slot
,
806 #ifdef CONFIG_PM_SLEEP
807 .resume
= sdhci_pci_o2_resume
,
809 .ops
= &sdhci_pci_o2_ops
,
810 .priv_size
= sizeof(struct o2_host
),