From patchwork Wed Nov 5 00:22:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 5231451 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E5BFAC11AC for ; Wed, 5 Nov 2014 00:24:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D749120160 for ; Wed, 5 Nov 2014 00:24:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC80E20138 for ; Wed, 5 Nov 2014 00:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752067AbaKEAYH (ORCPT ); Tue, 4 Nov 2014 19:24:07 -0500 Received: from mail-la0-f51.google.com ([209.85.215.51]:55444 "EHLO mail-la0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751812AbaKEAYF (ORCPT ); Tue, 4 Nov 2014 19:24:05 -0500 Received: by mail-la0-f51.google.com with SMTP id q1so1893269lam.10 for ; Tue, 04 Nov 2014 16:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=pyz5BkUNrYoDEXoK3UYs3gSqguD1/c11L7EnKWJC8oY=; b=P8E6mFkHCO41bJmU1cGjK8nFV70YMfX4T/u0xP+MVR8XsCZFlxfU7i2f9se1f4ns/Q K30bdZz97GbNGu+6odWSCTAGmevrGudhZMfAHDKKIGe1DWKem2FNT9yr72+uuv7kQjSt cVtiFuDUkESQvu+1ngQUX1DM3v/IIhT7XuqqcpZTV8lvkJl2JUhBWS/FC2rcsleDbbSg nsBXO+2/pK/kb71bN8e8xooyFx86afma9TJmrHdlr/8YcirS2AbyDuodHXoeJTiCgHZ4 +KRJSQ4GseDO/L2mmizXArv7H4IvrtF5uImaSIrmwvZFlx1SonFUVUwNQaP75uZQxMLG 6uSw== X-Received: by 10.152.6.41 with SMTP id x9mr15877548lax.95.1415147043122; Tue, 04 Nov 2014 16:24:03 -0800 (PST) Received: from ipsen.lan (161-167-191-90.dyn.estpak.ee. [90.191.167.161]) by mx.google.com with ESMTPSA id an6sm695648lac.18.2014.11.04.16.24.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Nov 2014 16:24:01 -0800 (PST) From: =?UTF-8?q?Kristina=20Mart=C5=A1enko?= To: Ulf Hansson , Chris Ball Cc: Linus Walleij , Stefan Wahren , Fabio Estevam , Michael Heimpold , linux-mmc@vger.kernel.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Kristina=20Mart=C5=A1enko?= Subject: [PATCH] mmc: core: fix card detection regression Date: Wed, 5 Nov 2014 02:22:41 +0200 Message-Id: <1415146961-25993-1-git-send-email-kristina.martsenko@gmail.com> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1747777414.897866.1414878004147.JavaMail.open-xchange@oxbsltgw09.schlund.de> References: <1747777414.897866.1414878004147.JavaMail.open-xchange@oxbsltgw09.schlund.de> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since commit 89168b489915 ("mmc: core: restore detect line inversion semantics"), the SD card on i.MX28 (and possibly other) devices isn't detected and booting stops at: [ 4.120617] Waiting for root device /dev/mmcblk0p3... This is caused by the MMC_CAP2_CD_ACTIVE_HIGH flag being set incorrectly when the host controller doesn't use a GPIO for card detection (but instead uses a dedicated pin). In this case mmc_gpiod_request_cd() will return before assigning to the gpio_invert variable, leaving the variable uninitialized. The variable then gets used to set the flag. This patch fixes the issue by making sure gpio_invert is set to false when a GPIO isn't used. After this patch, i.MX28 boots fine. The MMC_CAP2_RO_ACTIVE_HIGH (write protect) flag is also set incorrectly for the exact same reason (it uses the same uninitialized variable), so this patch fixes that too. Fixes: 89168b489915 ("mmc: core: restore detect line inversion semantics") Reported-by: Stefan Wahren Signed-off-by: Kristina Martšenko Tested-by: Fabio Estevam --- This is a different version of the previous patch [1], so I haven't included the Reviewed-by and Tested-by's. Would be nice if someone could test this version as well. [1] http://thread.gmane.org/gmane.linux.kernel.gpio/4609/focus=29576 drivers/mmc/core/host.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 03c53b72a2d6..270d58a4c43d 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -311,7 +311,8 @@ int mmc_of_parse(struct mmc_host *host) struct device_node *np; u32 bus_width; int len, ret; - bool cap_invert, gpio_invert; + bool cd_cap_invert, cd_gpio_invert = false; + bool ro_cap_invert, ro_gpio_invert = false; if (!host->parent || !host->parent->of_node) return 0; @@ -359,16 +360,13 @@ int mmc_of_parse(struct mmc_host *host) if (of_find_property(np, "non-removable", &len)) { host->caps |= MMC_CAP_NONREMOVABLE; } else { - if (of_property_read_bool(np, "cd-inverted")) - cap_invert = true; - else - cap_invert = false; + cd_cap_invert = of_property_read_bool(np, "cd-inverted"); if (of_find_property(np, "broken-cd", &len)) host->caps |= MMC_CAP_NEEDS_POLL; ret = mmc_gpiod_request_cd(host, "cd", 0, true, - 0, &gpio_invert); + 0, &cd_gpio_invert); if (ret) { if (ret == -EPROBE_DEFER) return ret; @@ -391,17 +389,14 @@ int mmc_of_parse(struct mmc_host *host) * both inverted, the end result is that the CD line is * not inverted. */ - if (cap_invert ^ gpio_invert) + if (cd_cap_invert ^ cd_gpio_invert) host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; } /* Parse Write Protection */ - if (of_property_read_bool(np, "wp-inverted")) - cap_invert = true; - else - cap_invert = false; + ro_cap_invert = of_property_read_bool(np, "wp-inverted"); - ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &gpio_invert); + ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert); if (ret) { if (ret == -EPROBE_DEFER) goto out; @@ -414,7 +409,7 @@ int mmc_of_parse(struct mmc_host *host) dev_info(host->parent, "Got WP GPIO\n"); /* See the comment on CD inversion above */ - if (cap_invert ^ gpio_invert) + if (ro_cap_invert ^ ro_gpio_invert) host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; if (of_find_property(np, "cap-sd-highspeed", &len))