6060#define O2_SD_VENDOR_SETTING2 0x1C8
6161#define O2_SD_HW_TUNING_DISABLE BIT(4)
6262
63+ #define O2_PLL_WDT_CONTROL1 0x1CC
64+ #define O2_PLL_FORCE_ACTIVE BIT(18)
65+ #define O2_PLL_LOCK_STATUS BIT(14)
66+ #define O2_PLL_SOFT_RESET BIT(12)
67+
68+ #define O2_SD_DETECT_SETTING 0x324
69+
6370static void sdhci_o2_set_tuning_mode (struct sdhci_host * host )
6471{
6572 u16 reg ;
@@ -283,6 +290,113 @@ static void sdhci_pci_o2_enable_msi(struct sdhci_pci_chip *chip,
283290 host -> irq = pci_irq_vector (chip -> pdev , 0 );
284291}
285292
293+ static void sdhci_o2_wait_card_detect_stable (struct sdhci_host * host )
294+ {
295+ ktime_t timeout ;
296+ u32 scratch32 ;
297+
298+ /* Wait max 50 ms */
299+ timeout = ktime_add_ms (ktime_get (), 50 );
300+ while (1 ) {
301+ bool timedout = ktime_after (ktime_get (), timeout );
302+
303+ scratch32 = sdhci_readl (host , SDHCI_PRESENT_STATE );
304+ if ((scratch32 & SDHCI_CARD_PRESENT ) >> SDHCI_CARD_PRES_SHIFT
305+ == (scratch32 & SDHCI_CD_LVL ) >> SDHCI_CD_LVL_SHIFT )
306+ break ;
307+
308+ if (timedout ) {
309+ pr_err ("%s: Card Detect debounce never finished.\n" ,
310+ mmc_hostname (host -> mmc ));
311+ sdhci_dumpregs (host );
312+ return ;
313+ }
314+ udelay (10 );
315+ }
316+ }
317+
318+ static void sdhci_o2_enable_internal_clock (struct sdhci_host * host )
319+ {
320+ ktime_t timeout ;
321+ u16 scratch ;
322+ u32 scratch32 ;
323+
324+ /* PLL software reset */
325+ scratch32 = sdhci_readl (host , O2_PLL_WDT_CONTROL1 );
326+ scratch32 |= O2_PLL_SOFT_RESET ;
327+ sdhci_writel (host , scratch32 , O2_PLL_WDT_CONTROL1 );
328+ udelay (1 );
329+ scratch32 &= ~(O2_PLL_SOFT_RESET );
330+ sdhci_writel (host , scratch32 , O2_PLL_WDT_CONTROL1 );
331+
332+ /* PLL force active */
333+ scratch32 |= O2_PLL_FORCE_ACTIVE ;
334+ sdhci_writel (host , scratch32 , O2_PLL_WDT_CONTROL1 );
335+
336+ /* Wait max 20 ms */
337+ timeout = ktime_add_ms (ktime_get (), 20 );
338+ while (1 ) {
339+ bool timedout = ktime_after (ktime_get (), timeout );
340+
341+ scratch = sdhci_readw (host , O2_PLL_WDT_CONTROL1 );
342+ if (scratch & O2_PLL_LOCK_STATUS )
343+ break ;
344+ if (timedout ) {
345+ pr_err ("%s: Internal clock never stabilised.\n" ,
346+ mmc_hostname (host -> mmc ));
347+ sdhci_dumpregs (host );
348+ goto out ;
349+ }
350+ udelay (10 );
351+ }
352+
353+ /* Wait for card detect finish */
354+ udelay (1 );
355+ sdhci_o2_wait_card_detect_stable (host );
356+
357+ out :
358+ /* Cancel PLL force active */
359+ scratch32 = sdhci_readl (host , O2_PLL_WDT_CONTROL1 );
360+ scratch32 &= ~O2_PLL_FORCE_ACTIVE ;
361+ sdhci_writel (host , scratch32 , O2_PLL_WDT_CONTROL1 );
362+ }
363+
364+ static int sdhci_o2_get_cd (struct mmc_host * mmc )
365+ {
366+ struct sdhci_host * host = mmc_priv (mmc );
367+
368+ sdhci_o2_enable_internal_clock (host );
369+
370+ return !!(sdhci_readl (host , SDHCI_PRESENT_STATE ) & SDHCI_CARD_PRESENT );
371+ }
372+
373+ static void sdhci_o2_enable_clk (struct sdhci_host * host , u16 clk )
374+ {
375+ /* Enable internal clock */
376+ clk |= SDHCI_CLOCK_INT_EN ;
377+ sdhci_writew (host , clk , SDHCI_CLOCK_CONTROL );
378+
379+ if (sdhci_o2_get_cd (host -> mmc )) {
380+ clk |= SDHCI_CLOCK_CARD_EN ;
381+ sdhci_writew (host , clk , SDHCI_CLOCK_CONTROL );
382+ }
383+ }
384+
385+ void sdhci_pci_o2_set_clock (struct sdhci_host * host , unsigned int clock )
386+ {
387+ u16 clk ;
388+
389+ host -> mmc -> actual_clock = 0 ;
390+
391+ sdhci_writew (host , 0 , SDHCI_CLOCK_CONTROL );
392+
393+ if (clock == 0 )
394+ return ;
395+
396+ clk = sdhci_calc_clk (host , clock , & host -> mmc -> actual_clock );
397+ sdhci_o2_enable_clk (host , clk );
398+ }
399+
286400int sdhci_pci_o2_probe_slot (struct sdhci_pci_slot * slot )
287401{
288402 struct sdhci_pci_chip * chip ;
@@ -316,7 +430,11 @@ int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *slot)
316430 host -> flags |= SDHCI_SIGNALING_180 ;
317431 host -> mmc -> caps2 |= MMC_CAP2_NO_SD ;
318432 host -> mmc -> caps2 |= MMC_CAP2_NO_SDIO ;
433+ pci_write_config_dword (chip -> pdev ,
434+ O2_SD_DETECT_SETTING , 3 );
319435 }
436+
437+ slot -> host -> mmc_host_ops .get_cd = sdhci_o2_get_cd ;
320438 }
321439
322440 host -> mmc_host_ops .execute_tuning = sdhci_o2_execute_tuning ;
@@ -490,9 +608,6 @@ int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip)
490608 pci_write_config_byte (chip -> pdev , O2_SD_LOCK_WP , scratch );
491609 break ;
492610 case PCI_DEVICE_ID_O2_SEABIRD0 :
493- if (chip -> pdev -> revision == 0x01 )
494- chip -> quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER ;
495- /* fall through */
496611 case PCI_DEVICE_ID_O2_SEABIRD1 :
497612 /* UnLock WP */
498613 ret = pci_read_config_byte (chip -> pdev ,
@@ -551,6 +666,14 @@ int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip)
551666}
552667#endif
553668
669+ static const struct sdhci_ops sdhci_pci_o2_ops = {
670+ .set_clock = sdhci_pci_o2_set_clock ,
671+ .enable_dma = sdhci_pci_enable_dma ,
672+ .set_bus_width = sdhci_set_bus_width ,
673+ .reset = sdhci_reset ,
674+ .set_uhs_signaling = sdhci_set_uhs_signaling ,
675+ };
676+
554677const struct sdhci_pci_fixes sdhci_o2 = {
555678 .probe = sdhci_pci_o2_probe ,
556679 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC ,
@@ -559,4 +682,5 @@ const struct sdhci_pci_fixes sdhci_o2 = {
559682#ifdef CONFIG_PM_SLEEP
560683 .resume = sdhci_pci_o2_resume ,
561684#endif
685+ .ops = & sdhci_pci_o2_ops ,
562686};
0 commit comments