From patchwork Fri Jan 11 17:03:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 1966771 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 1A7C33FF0F for ; Fri, 11 Jan 2013 17:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754262Ab3AKREU (ORCPT ); Fri, 11 Jan 2013 12:04:20 -0500 Received: from mail-qc0-f201.google.com ([209.85.216.201]:39600 "EHLO mail-qc0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754562Ab3AKRER (ORCPT ); Fri, 11 Jan 2013 12:04:17 -0500 Received: by mail-qc0-f201.google.com with SMTP id a6so239432qch.4 for ; Fri, 11 Jan 2013 09:04:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=G5S4e99rJOtAqACFuJoTYCg9EEUMd/sh9TQef1oVpJc=; b=c5KNub+uyUGrYoepdxIbaMkqT4GlFD+xr5pAa/xCmv3d5UHXP3QVAURMdDf4i+PKlF +ggAhnDmDFu8slk4pICQ4A22zmKkS3GUcRPlcsfId7ev8RA6+L5gonchloiL/EiRks2W ZswMUzjryo4o+znCdutgnT/Ebe0iW8OQmYxWfcJxfjLe0unX3DblFsb5FQozs70BPBqD c+g4lwlMj8isCbFk5qipEIMd/HmDtLTrMXHvq1QwZIlSjg520V0Xl64hhFMRanSL0oFU 88QrAnc2HXYMQC4vFwhXRKgsO2ScRFFfJKTJFZyMLKwce4TBcEWgND2StJcJT/sfLOL/ j26g== X-Received: by 10.101.151.23 with SMTP id d23mr11094092ano.6.1357923856285; Fri, 11 Jan 2013 09:04:16 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id j11si142834ank.2.2013.01.11.09.04.15 (version=TLSv1 cipher=AES128-SHA bits=128/128); Fri, 11 Jan 2013 09:04:15 -0800 (PST) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.73.80]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id BB1B78200AD; Fri, 11 Jan 2013 09:04:15 -0800 (PST) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 6DDB881389; Fri, 11 Jan 2013 09:04:15 -0800 (PST) From: Doug Anderson To: linux-mmc@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org, Thomas Abraham , Kukjin Kim , Olof Johansson , Arnd Bergmann , Will Newton , Chris Ball , Jaehoon Chung , Seungwon Jeon , linux-kernel@vger.kernel.org, Doug Anderson , Kyungmin Park Subject: [PATCH v4 4/5] mmc: dw_mmc: Handle wp-gpios from device tree Date: Fri, 11 Jan 2013 09:03:53 -0800 Message-Id: <1357923834-31641-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1357923834-31641-1-git-send-email-dianders@chromium.org> References: <1357842269-15062-1-git-send-email-dianders@chromium.org> <1357923834-31641-1-git-send-email-dianders@chromium.org> X-Gm-Message-State: ALoCoQnuM3WNGSB09KeZ6ZfHbG5mRHV6UYBUv7Mya+zIzQr+Vffmvt+BkZarE7D6NwfTda+bmwdYqAz3uUxF3/V3x6+RuSzq9dEyqKxpD/y7b4t0iyoLObC7iR8AGtFcsHOkykPZEKpAaljS0x5YYpMRbn3eH6d87mdoUVLtQ0uDDyNiyC9yn1WLYuLGSeDsXBS0ZyqPT3c+NjpWtmpTQ3239ZLu4xk4OQ== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org On some SoCs (like exynos5250) you need to use an external GPIO for write protect. Add support for wp-gpios to the core dw_mmc driver since it could be useful across multiple SoCs. With this change I am able to make use of the write protect for the external SD slot on exynos5250-snow. Signed-off-by: Doug Anderson Acked-by: Seungwon Jeon Acked-by: Olof Johansson --- Changes in v4: None Changes in v3: None Changes in v2: - Fixed return type from u32 to int - Return -EINVAL instead of -1 drivers/mmc/host/dw_mmc.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 90f7d99..df62079 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "dw_mmc.h" @@ -75,6 +76,7 @@ struct idmac_desc { * @mmc: The mmc_host representing this slot. * @host: The MMC controller this slot is using. * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX) + * @wp_gpio: If gpio_is_valid() we'll use this to read write protect. * @ctype: Card type for this slot. * @mrq: mmc_request currently being processed or waiting to be * processed, or NULL when the slot is idle. @@ -90,6 +92,7 @@ struct dw_mci_slot { struct dw_mci *host; int quirks; + int wp_gpio; u32 ctype; @@ -838,6 +841,8 @@ static int dw_mci_get_ro(struct mmc_host *mmc) read_only = 0; else if (brd->get_ro) read_only = brd->get_ro(slot->id); + else if (gpio_is_valid(slot->wp_gpio)) + read_only = gpio_get_value(slot->wp_gpio); else read_only = mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0; @@ -1832,6 +1837,29 @@ static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot) " as 1\n"); return bus_wd; } + +/* find the write protect gpio for a given slot; or -1 if none specified */ +static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) +{ + struct device_node *np = dw_mci_of_find_slot_node(dev, slot); + int gpio; + + if (!np) + return -EINVAL; + + gpio = of_get_named_gpio(np, "wp-gpios", 0); + + /* Having a missing entry is valid; return silently */ + if (!gpio_is_valid(gpio)) + return -EINVAL; + + if (devm_gpio_request(dev, gpio, "dw-mci-wp")) { + dev_warn(dev, "gpio [%d] request failed\n", gpio); + return -EINVAL; + } + + return gpio; +} #else /* CONFIG_OF */ static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) { @@ -1845,6 +1873,10 @@ static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) { return NULL; } +static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) +{ + return -EINVAL; +} #endif /* CONFIG_OF */ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) @@ -1962,6 +1994,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) else clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); + slot->wp_gpio = dw_mci_of_get_wp_gpio(host->dev, slot->id); + mmc_add_host(mmc); #if defined(CONFIG_DEBUG_FS)