From patchwork Fri Jan 11 17:03:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Anderson X-Patchwork-Id: 1966831 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CD459DF2A2 for ; Fri, 11 Jan 2013 17:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755001Ab3AKRES (ORCPT ); Fri, 11 Jan 2013 12:04:18 -0500 Received: from mail-da0-f74.google.com ([209.85.210.74]:36182 "EHLO mail-da0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754360Ab3AKREQ (ORCPT ); Fri, 11 Jan 2013 12:04:16 -0500 Received: by mail-da0-f74.google.com with SMTP id g27so222035dan.5 for ; Fri, 11 Jan 2013 09:04:15 -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=OI95v4Nu4l28eoDxZ6wwdMNGXJ5SFNYUFDQHk4/sQaY=; b=bmskpxDrfUFpo9S4Xlc9xVOkZDeMXfTJ8bYv0rlfnEjFl8mGoJnHOK87EKc7YWr+wm zU1X8lJCx5SSvVT6BktrEp1NPyB2gL87ZJwnovaZKxEI9WKJOLsjFFpMt1HwD9kshio6 wxRkuglInao93uazNalW8sXv3iv5SPezIiypz6YauGdvPk2d0qCG2oITe0ayetv4Ecgd kaOPzqIN1gMu/1D0m7Co5vzCePPtlWghGJv0JjERyAKufXgDY7ITInSzAo6xGoB87aPI s2CCqCVWNKknKx5b35RUBCP52q4X5iFy4OTbNhTzCQdr28mMGKiMsVlSh75Pe7YVGCLX hYlA== X-Received: by 10.66.75.234 with SMTP id f10mr9715158paw.8.1357923855700; Fri, 11 Jan 2013 09:04:15 -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 r10si143155ann.1.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 7B40B8200AC; Fri, 11 Jan 2013 09:04:15 -0800 (PST) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 14C7C8094E; 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 , Grant Likely , Rob Herring , Rob Landley , Abhilash Kesavan , Kyungmin Park , devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org Subject: [PATCH v4 1/5] mmc: dw_mmc: Add "disable-wp" device tree property Date: Fri, 11 Jan 2013 09:03:50 -0800 Message-Id: <1357923834-31641-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1357842269-15062-1-git-send-email-dianders@chromium.org> References: <1357842269-15062-1-git-send-email-dianders@chromium.org> X-Gm-Message-State: ALoCoQmfkKxtJXew7iFlDQMscwi5oTyAkQxSwZOIBwtF8IuwqsPS77Spvj4B9BLi1B8gktHr2ueoU4wvEgzno4PLXHj4abaTAAqM68EsLj42pnPwLhruLWE/53nkAU1Q7LjYQmbh/ZEjTnuPluNgmHUKYjaPuM08hDjmj/THvCnxGij2znI0QWbBoKS0c+bqPwrtzP4m/NeRlgxUdCCuguRmD5/htbsPLg== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The "disable-wp" property is used to specify that a given SD card slot doesn't have a concept of write protect. This eliminates the need for special case code for SD slots that should never be write protected (like a micro SD slot or a dev board). The dw_mmc driver is special in needing to specify "disable-wp" because the lack of a "wp-gpios" property means to use the special purpose write protect line. On some other mmc devices the lack of "wp-gpios" means that write protect should be disabled. Signed-off-by: Doug Anderson Acked-by: Seungwon Jeon Acked-by: Will Newton Acked-by: Olof Johansson --- Changes in v4: - Added a comment about the fact that a future patch will remove the controller-level quirk; the comments and quirk will be removed in the future change "mmc: dw_mmc: Remove DW_MCI_QUIRK_NO_WRITE_PROTECT". I split the patch up this way to preserve bisectability and also to keep changes logically separated. I will squash if desired. Changes in v3: - New for this version of the patch series. Chose "disable-wp" rather than the discussed "broken-internal-wp" since it mapped more cleanly to an existing quirk (and the only reason to specify that the internal wp is broken is if you're disabling the write protect anyway). .../devicetree/bindings/mmc/synopsis-dw-mshc.txt | 12 +++++- drivers/mmc/host/dw_mmc.c | 41 +++++++++++++++++++- include/linux/mmc/dw_mmc.h | 9 ++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/mmc/synopsis-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/synopsis-dw-mshc.txt index 06cd32d08..726fd21 100644 --- a/Documentation/devicetree/bindings/mmc/synopsis-dw-mshc.txt +++ b/Documentation/devicetree/bindings/mmc/synopsis-dw-mshc.txt @@ -26,8 +26,16 @@ Required Properties: * bus-width: as documented in mmc core bindings. * wp-gpios: specifies the write protect gpio line. The format of the - gpio specifier depends on the gpio controller. If the write-protect - line is not available, this property is optional. + gpio specifier depends on the gpio controller. If a GPIO is not used + for write-protect, this property is optional. + + * disable-wp: If the wp-gpios property isn't present then (by default) + we'd assume that the write protect is hooked up directly to the + controller's special purpose write protect line (accessible via + the WRTPRT register). However, it's possible that we simply don't + want write protect. In that case specify 'disable-wp'. + NOTE: This property is not required for slots known to always + connect to eMMC or SDIO cards. Optional properties: diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 323c502..90f7d99 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -74,6 +74,7 @@ struct idmac_desc { * struct dw_mci_slot - MMC slot state * @mmc: The mmc_host representing this slot. * @host: The MMC controller this slot is using. + * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX) * @ctype: Card type for this slot. * @mrq: mmc_request currently being processed or waiting to be * processed, or NULL when the slot is idle. @@ -88,6 +89,8 @@ struct dw_mci_slot { struct mmc_host *mmc; struct dw_mci *host; + int quirks; + u32 ctype; struct mmc_request *mrq; @@ -825,7 +828,13 @@ static int dw_mci_get_ro(struct mmc_host *mmc) struct dw_mci_board *brd = slot->host->pdata; /* Use platform get_ro function, else try on board write protect */ - if (brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT) + + /* + * NOTE: DW_MCI_QUIRK_NO_WRITE_PROTECT will be removed in a future + * patch in the series once reference to it is removed. + */ + if ((brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT) || + (slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT)) read_only = 0; else if (brd->get_ro) read_only = brd->get_ro(slot->id); @@ -1785,6 +1794,30 @@ static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) return NULL; } +static struct dw_mci_of_slot_quirks { + char *quirk; + int id; +} of_slot_quirks[] = { + { + .quirk = "disable-wp", + .id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT, + }, +}; + +static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) +{ + struct device_node *np = dw_mci_of_find_slot_node(dev, slot); + int quirks = 0; + int idx; + + /* get quirks */ + for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++) + if (of_get_property(np, of_slot_quirks[idx].quirk, NULL)) + quirks |= of_slot_quirks[idx].id; + + return quirks; +} + /* find out bus-width for a given slot */ static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot) { @@ -1800,6 +1833,10 @@ static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot) return bus_wd; } #else /* CONFIG_OF */ +static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) +{ + return 0; +} static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot) { return 1; @@ -1828,6 +1865,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) slot->host = host; host->slot[id] = slot; + slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id); + mmc->ops = &dw_mci_ops; mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510); mmc->f_max = host->bus_hz; diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h index 34be4f4..de61de5 100644 --- a/include/linux/mmc/dw_mmc.h +++ b/include/linux/mmc/dw_mmc.h @@ -209,9 +209,18 @@ struct dw_mci_dma_ops { #define DW_MCI_QUIRK_HIGHSPEED BIT(2) /* Unreliable card detection */ #define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3) + /* Write Protect detection not available */ +/* + * NOTE: DW_MCI_QUIRK_NO_WRITE_PROTECT will be removed in a future + * patch in the series once reference to it is removed. + */ #define DW_MCI_QUIRK_NO_WRITE_PROTECT BIT(4) +/* Slot level quirks */ +/* This slot has no write protect */ +#define DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT BIT(0) + struct dma_pdata; struct block_settings {