From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F3683A9619 for ; Mon, 6 Jul 2026 15:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783352453; cv=none; b=XJTc8k7bTkwio38r5ZUH6Y4hosTjnJIi+KT2A/m/WB88kQRqiO+HSMuG53c3IfSBuwPsedkaZl99yCAeIFWSxRClpwvmnxVYKpSjgepl9Yx6H4ExJP8OpzaqbIT7cbhW9ht3Jz2yEhqaTfFfufevMdIjHNvRFqvksn6GQ/+x5FA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783352453; c=relaxed/simple; bh=0qRk1Ccab5ppm6LnVQAgKi84nDRUH31GO4zylg0MdN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAQjsTPxha6KlLj/B1RjZgn+KVTC+vUQGT2Wo9sJXD9PxN/Jf+0TfHMiVweQal9Awnr4CauGLwS992/yZKLJWJ3c/neZndhVZLSrK+Sn3BA+Q9zvHUWaRuG/1xZMbxXrNVPr+sZhqv0BrAuQRp+JZzZjiw/53umHj0fDr5dzXd8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=starlabs.systems; spf=pass smtp.mailfrom=starlabs.systems; dkim=pass (2048-bit key) header.d=starlabs-systems.20251104.gappssmtp.com header.i=@starlabs-systems.20251104.gappssmtp.com header.b=Pu2vAdiq; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=starlabs.systems Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=starlabs.systems Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=starlabs-systems.20251104.gappssmtp.com header.i=@starlabs-systems.20251104.gappssmtp.com header.b="Pu2vAdiq" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-493bc8fda98so35260065e9.0 for ; Mon, 06 Jul 2026 08:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=starlabs-systems.20251104.gappssmtp.com; s=20251104; t=1783352450; x=1783957250; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VioRyPh/COYBs9Qbi6P5Dnn5InU0S/xx7A/WC4lgww8=; b=Pu2vAdiqPjKdxslSBc838vHybtpLHXwioLu3ISyJOa2PQ/CHSihULfh3aQB05O64Qa zTuSy9Jp5fUpad3G6hVKHCyCZQ5mqDMNURREm8TshcESQuiJYr15QVtwyfI/382iUpuF EcZi7W/JES+dd8n50KaZ93e9fvFSUYEG8jS7X8RwgBqhXJ9EVAbyN2M5qlOaallPXQWp tgXlqN9/Bt9Gs2bId5RmOT5UnZsQcONlmns3WWO1acgf63yTdTvodn38LogbDbp8mgUf Rr3woxina5YPP4knk2qvLjh9vn9zYjEaIsrP/AXCBM4ZtIjTWK3l7p+7i3NgLMokvJwa ceaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783352450; x=1783957250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VioRyPh/COYBs9Qbi6P5Dnn5InU0S/xx7A/WC4lgww8=; b=Nai+PLCd0x3Rbus1YUXGfEnaYO21zGosrI1GOY0pVpaGcA9O6INSFMHxpqsHddA3Io 6IJy74AX5cBzvP8TURNAQ9s2NFpjI+4rWUnepvZZ2o5Y65pkq8BZs4gxGWvLn7I9Cs4Q GmKHyVj1QgvHhGV2I154/a7KuzDVeGqavhRbUhC2ZkJDA0ZYw2N0nFnMnWEMQHjVdNKl psVcBuJrLsRqvpafSMWcIDnSufwP5lAhLlSfgDl3165BOHZJzCR9w+NtWFb5SPPEK0jp 91U+Z3DQ5jS2MmhOZuyH112JRcMd2L0mNPne05QaVQh0TzHwLSZjqTJMn8ChZtxtuKNu TWHA== X-Forwarded-Encrypted: i=1; AHgh+RpBpI1hLKkJvEhoVdWvQ/xMNanwq8EanFZs0vu8jo/hRMSbV3aF//pLuKtm3A+QEJPlGOe7SVi2byoUPNU=@vger.kernel.org X-Gm-Message-State: AOJu0YzU2xLv7p/duKja7QxRkJgZ1ybbfXjE0+0BRTSuRs6yhcX5bDyb mBByWR0LxcdjsRotsEb3LW1NCkpOp11m/feyVs/JpyZHzeWQJHkqC+CWEDoxwa78qw== X-Gm-Gg: AfdE7cmuhLFnzJMDeHIyCr/t9UCE47l3I7oatJtauew3BFY3cNjoBt3JfQrfzRo1JVH exZ7t767RI7hdkjEPQo5kw/n/1sZMCMSSpGIBrPFSNGV0ci92iaMRBAtD7W34jIiaRsRpm5IGRt u5rLzfK44Z0M+s2JIHqr3aJuGfPTAj4OQ1ejDbXerGVBAWbpZjic1yQX9nvgrPvO4PrRr8HqyKG RWmpnTM1zJNu6xfHei7Lboq4/+SbLtvDi2d482ke3TM22VK0PnhaTJ21T1A0Y4bXCOYWKNE8Gqx CM+oO4ooTUGbWVUYiX3N2uP6YsXNB/hKfTfkrcLZvsO4zz/ef39610dcLrLCvmKKzjnb0DcZHUK iCKb7dwiz4EzbK0XcuuFP1EXJcLFGYswohs43fP8JVs7nuCZD2J9Nl07xvvz0tALEAs92fpepS4 9J+vRpXU/gMWmKwGDrfD9rvUFAdl86srgbXXGYFIjOU3gGA/owm6AzsxE= X-Received: by 2002:a05:600c:4f81:b0:493:b8dd:9d68 with SMTP id 5b1f17b1804b1-493df041a17mr11863665e9.10.1783352449883; Mon, 06 Jul 2026 08:40:49 -0700 (PDT) Received: from horizon.localdomain ([150.228.6.107]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493cce03fa1sm283699005e9.11.2026.07.06.08.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 08:40:49 -0700 (PDT) From: Sean Rhodes To: Ulf Hansson Cc: Arnd Bergmann , Greg Kroah-Hartman , Ricky Wu , Sean Rhodes , Lee Jones , Roger Tseng , Dan Carpenter , Jisheng Zhang , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mmc: rtsx_usb_sdmmc: suppress false CD after init timeout Date: Mon, 6 Jul 2026 16:40:44 +0100 Message-ID: <1d6f22a3777e78d6232cbe7dc3aa17ded8fc32e2.1783352430.git.sean@starlabs.systems> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some Realtek USB SD readers with a tray keep raw SD_CD asserted when an empty tray is inserted. The MMC core then repeatedly tries to initialize non-existent media, sees command timeouts, calls ->get_cd() again, and starts the same detect cycle over. Do not qualify media by open-coding MMC commands in ->get_cd(). Instead, let the normal MMC rescan path probe the card. If an initialization command times out before a card has been attached, suppress the raw SD_CD signal so the host can settle and the USB parent can autosuspend. Clear the suppression only when raw SD_CD drops. On the affected tray reader, changing media requires removing and reinserting the tray, so a low CD transition is the signal that a new insertion attempt can be trusted again. Signed-off-by: Sean Rhodes --- drivers/mmc/host/rtsx_usb_sdmmc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c index 84674659a84d..bf37fab233cf 100644 --- a/drivers/mmc/host/rtsx_usb_sdmmc.c +++ b/drivers/mmc/host/rtsx_usb_sdmmc.c @@ -44,6 +44,7 @@ struct rtsx_usb_sdmmc { bool double_clk; bool host_removal; bool card_exist; + bool suppress_cd; bool initial_mode; bool ddr_mode; @@ -774,6 +775,7 @@ static int sdmmc_get_cd(struct mmc_host *mmc) struct rtsx_ucr *ucr = host->ucr; int err; u16 val; + bool cd; if (host->host_removal) return -ENOMEDIUM; @@ -791,8 +793,14 @@ static int sdmmc_get_cd(struct mmc_host *mmc) /* get OCP status */ host->ocp_stat = (val >> 4) & 0x03; + cd = val & SD_CD; - if (val & SD_CD) { + if (!cd) { + WRITE_ONCE(host->suppress_cd, false); + goto no_card; + } + + if (!READ_ONCE(host->suppress_cd)) { host->card_exist = true; return 1; } @@ -874,6 +882,8 @@ static void sdmmc_request(struct mmc_host *mmc, struct mmc_request *mrq) * detect card when fail to update card existence state and * speed up card removal when retry */ + if (!mmc->card && cmd->error == -ETIMEDOUT) + WRITE_ONCE(host->suppress_cd, true); sdmmc_get_cd(mmc); dev_dbg(sdmmc_dev(host), "cmd->error = %d\n", cmd->error); } @@ -1359,6 +1369,7 @@ static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host) host->power_mode = MMC_POWER_OFF; host->ocp_stat = 0; + host->suppress_cd = false; } static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)