FROMLIST: mmc: sdhci-pci: mitigate Intel BXT/APL card detection race in early boot

When the APL platform is configured to use card detection GPIO, it is
observed a race in early boot that makes the inserted card temporary
malfunction because the driver does not detect the card then it would
turn off the mmc until user manually remove/insert card, or wait a
period of time for runtime suspend/resume to revive it automatically;
from the trace it is generalized the driver has inconsistent status
between GPIO status and the present state of the host controller.

i.e.
kworker/0:3-88    [000] ....     0.812523: mmc_rescan <-process_one_work
...
kworker/0:3-88    [000] ....     0.812527: bxt_get_cd <-mmc_rescan
kworker/0:3-88    [000] ....     0.812546: mmc_power_off <-mmc_rescan
kworker/0:3-88    [000] ....     0.812546: mmc_pwrseq_power_off <-mmc_power_off

Also proved it by adding a hacky dump of GPIO status and present state
register; the GPIO says card existing while controller says not present.

Further investigation I realized when the driver successfully configures
and routes card detection signal to GPIO domain, it immediately decays
the host controller card detection: pin level follows by inserted status,
they disappear a while then they would propagate back automatically,
this generates a small window (while it is one time only) against the card
detection routine; namely when it falls into this window, it behaves like
the above trace. While in case the platform software is not required to
switch the card detection to GPIO, this odd does not happen.

To tackle this odd, did experiment to observe the race window period,
enqueue a mmc detection in 200 ms later when it successfully routes the
card detection to GPIO, this allows margin to make consensus in between
the GPIO and the host controller.

BUG=b:69142876,b:68963628
TEST=script to perform consective reboot, in each cycle examine the sd card
existing by doing 'lsblk /dev/mmcblk0'

(am from https://patchwork.kernel.org/patch/10338975/)

Change-Id: I8984333f4630e5d636472656095c495fea539fb7
Signed-off-by: Harry Pan <harry.pan@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1011487
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
1 file changed