From patchwork Thu Mar 3 16:51:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 548691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5536C433EF for ; Thu, 3 Mar 2022 16:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235202AbiCCQwh (ORCPT ); Thu, 3 Mar 2022 11:52:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235203AbiCCQwg (ORCPT ); Thu, 3 Mar 2022 11:52:36 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7114119DE8F for ; Thu, 3 Mar 2022 08:51:50 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id u20so9592249lff.2 for ; Thu, 03 Mar 2022 08:51:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q0hlDMq4glELTxqqeCYQhCGVz6ASynOhyADKIGNkHxI=; b=lM+FtnlKckXCQpElr2JR138CKdeX+U2eun4ELTIZ4sBj13l1AyGsYj/7EbHk76vCy3 9uZ3XCUX/iKFykOm6EMZNk3bW6ElUA0DOK3o/9ae8J7YDlZv94eOunX4aC1a65y/dMHX Jv9rjacTnnoq0vF/+I+UVl281Fmbve3tsoMWsnftCNg3k5Wa+6vWwvQSgx/X3P0MZHsM OGW3BGtkPwrceeR/E1z//0w8RGdkjhN6JHG7dQyuFYJNmtfXT1pWbM0vkXqiLwwfZFSc V1gr0L20OnEyZQBD/TyZjt51y8g+EWlP5Y3tXHnXxoQLqUfVn8IU9KTRejwkulSLiGVI TqOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q0hlDMq4glELTxqqeCYQhCGVz6ASynOhyADKIGNkHxI=; b=d8rajtyqttyK8Bb41Mx+0GNts7I+OeG6O3iQMiCwsCG6iu98ll1AM6xcC+BW35UwGZ 3+VLoelk7NBfAByWwiN826XW6SjGcakCim5Y6zaMMXYy0c0P1COz+tCE3rN2P/XPNm1o 7sNes7ZxJvHgD4GnC6YfDTjiv9WmEke5TGlhKNyhAcWRl2vKTwk0DzQjUBuMY/wYMnku yI+HVn1qCGgLojKzxmctjYziCyj1YQeL/vOdAT2HpxRxmcFuXazo7AlG8eJzxbeV04B/ hb2c9c9MhcNbQkDvsT5w9nn7qsDBCxD7rS6FsE17cMMTmGbUgF1qimyQQTkIoEMS8hTH k5ww== X-Gm-Message-State: AOAM530CSJINwuRiqgYXGByd4eNP0prSpnzBMzKHV6PaUM8/sVDbmSsw T/DViM/Lgsz3JHoNVzgoXjMduKy1yI2DVg== X-Google-Smtp-Source: ABdhPJz9ZBx87iKT0e1+HeehvcT+hS0gckoWv62UmqP+hGy6tSdepldUbJCmRSoXrlZbeJ6croDQmg== X-Received: by 2002:a05:6512:33c6:b0:446:e0ce:5c3c with SMTP id d6-20020a05651233c600b00446e0ce5c3cmr1163571lfg.26.1646326306369; Thu, 03 Mar 2022 08:51:46 -0800 (PST) Received: from localhost.localdomain (h-155-4-129-34.NA.cust.bahnhof.se. [155.4.129.34]) by smtp.gmail.com with ESMTPSA id g27-20020ac2539b000000b0044392f8d4c6sm521749lfh.1.2022.03.03.08.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 08:51:45 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mmc: host: Return an error when ->enable_sdio_irq() ops is missing Date: Thu, 3 Mar 2022 17:51:42 +0100 Message-Id: <20220303165142.129745-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Even if the current WARN() notifies the user that something is severely wrong, we can still end up in a PANIC() when trying to invoke the missing ->enable_sdio_irq() ops. Therefore, let's also return an error code and prevent the host from being added. While at it, move the code into a separate function to prepare for subsequent changes and for further host caps validations. Signed-off-by: Ulf Hansson --- drivers/mmc/core/host.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index cf140f4ec864..d739e2b631fe 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -588,6 +588,16 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) EXPORT_SYMBOL(mmc_alloc_host); +static int mmc_validate_host_caps(struct mmc_host *host) +{ + if (host->caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) { + dev_warn(host->parent, "missing ->enable_sdio_irq() ops\n"); + return -EINVAL; + } + + return 0; +} + /** * mmc_add_host - initialise host hardware * @host: mmc host @@ -600,8 +610,9 @@ int mmc_add_host(struct mmc_host *host) { int err; - WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) && - !host->ops->enable_sdio_irq); + err = mmc_validate_host_caps(host); + if (err) + return err; err = device_add(&host->class_dev); if (err) From patchwork Thu Mar 3 16:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 548002 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33455C433EF for ; Thu, 3 Mar 2022 16:52:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234822AbiCCQwp (ORCPT ); Thu, 3 Mar 2022 11:52:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235211AbiCCQwo (ORCPT ); Thu, 3 Mar 2022 11:52:44 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D47BF19DE8F for ; Thu, 3 Mar 2022 08:51:58 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id f37so9534834lfv.8 for ; Thu, 03 Mar 2022 08:51:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x8Lu3oFI2ZSXIjn4HjXJkzNerbpjcjtzRyNcVMXGM4A=; b=qu09WohgsJ0hjJOyszWoqeJPQoUnp8CED/1vHL0hzJnV/3MUQ1j90bmMqoD6Hzh7JE VFfKcYMk7dTuoYhKLN9R8wR2Ko5C+1oBs1/Km2IuTCdtebufAqR6+2ih5doOoWdsy2l3 sz+6rftOqCstvRW08U7Al0P9YLy5tqIbRE1exjFS6xQAu/zPuM1kaDGpEcsXVewApGGB dcm+v3rORuzehmsyVG55C/QVKEc2B2yNGBM1oGsKSKN/W4IKL2XOHMzLstDfU4vmPRD+ RwiRGgpptJI+jBL+82J2UBe4/hmrXJClISEcFlzkATPw/WGWM0xYo483CUgc7ieqB8Yw CMTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x8Lu3oFI2ZSXIjn4HjXJkzNerbpjcjtzRyNcVMXGM4A=; b=rlohoqoIMgtKn/7GRhlzg4Id7SoMjSLSmvoByyNCtjbk//X5v0X8WvoWAzf0LUxqJn +6dagHE/W/xxJ0B0F4l6ma7kxrTsFRpSGQY8vsr3TB1A/4DT2jz0KrVY41lq0Zzac/tl JN0mlZm0LhbiimTsEWCgzPj9AUUan8ENXWsUzZxZchmSfJhbl7ZaHSf29k08RO40fZIq kVYfKlVIFR5TNch7noDJdwCJEHp4VWLUxGOf+1HpM/ytZOLZiaJm3wKAINhENnNaHXFF /LkOKR1J1AeaFqZMpQAoQZe3qax1kYWbH1ZWysn6bO81ay66w0njJaSL71dXVHSSUEFh 0U2Q== X-Gm-Message-State: AOAM530B1JGi7xQRxaKfPn10SQNeFhnDF3jMKI2iAJfDBpVdiHI8Bkj6 wS3PbNmE7cE0mOqBIH02rMLJhjpW+VPHIg== X-Google-Smtp-Source: ABdhPJxqSxDqDpbg5z4fk4n3/acDJIJSK9XvXCRU68aYBiPocCyO6iolHI6ogsNslNeph62IASQexw== X-Received: by 2002:a05:6512:1382:b0:445:9536:903 with SMTP id p2-20020a056512138200b0044595360903mr14611090lfa.89.1646326314602; Thu, 03 Mar 2022 08:51:54 -0800 (PST) Received: from localhost.localdomain (h-155-4-129-34.NA.cust.bahnhof.se. [155.4.129.34]) by smtp.gmail.com with ESMTPSA id q10-20020ac2528a000000b00445bcfca461sm519338lfm.249.2022.03.03.08.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 08:51:53 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mmc: core: Drop HS400 caps unless 8-bit bus is supported too Date: Thu, 3 Mar 2022 17:51:51 +0100 Message-Id: <20220303165151.129806-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org When mmc_select_hs400es() tries to switch to the HS400 ES mode, it may bail out early if the host doesn't support an 8-bit buswidth, as it's required for the HS400 mode. To improve the situation, let's instead drop the HS400 bits from the capability field if the 8-bit bus isn't supported. In this way, we allow the mmc initialization to continue by trying a lower speed mode. Signed-off-by: Ulf Hansson --- drivers/mmc/core/host.c | 13 +++++++++++-- drivers/mmc/core/mmc.c | 5 ----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index d739e2b631fe..2ed2b4d5e5a5 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -590,11 +590,20 @@ EXPORT_SYMBOL(mmc_alloc_host); static int mmc_validate_host_caps(struct mmc_host *host) { - if (host->caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) { - dev_warn(host->parent, "missing ->enable_sdio_irq() ops\n"); + struct device *dev = host->parent; + u32 caps = host->caps, caps2 = host->caps2; + + if (caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) { + dev_warn(dev, "missing ->enable_sdio_irq() ops\n"); return -EINVAL; } + if (caps2 & (MMC_CAP2_HS400_ES | MMC_CAP2_HS400) && + !(caps & MMC_CAP_8_BIT_DATA)) { + dev_warn(dev, "drop HS400 support since no 8-bit bus\n"); + host->caps2 = caps2 & ~MMC_CAP2_HS400_ES & ~MMC_CAP2_HS400; + } + return 0; } diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 13abfcd130a5..141f851c9f58 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1355,11 +1355,6 @@ static int mmc_select_hs400es(struct mmc_card *card) int err = -EINVAL; u8 val; - if (!(host->caps & MMC_CAP_8_BIT_DATA)) { - err = -ENOTSUPP; - goto out_err; - } - if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);