From patchwork Wed Aug 27 11:00:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 4787561 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 042ADC0338 for ; Wed, 27 Aug 2014 11:01:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B743D2017E for ; Wed, 27 Aug 2014 11:01:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F6FD2015E for ; Wed, 27 Aug 2014 11:01:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756065AbaH0LBJ (ORCPT ); Wed, 27 Aug 2014 07:01:09 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:56180 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755684AbaH0LBI (ORCPT ); Wed, 27 Aug 2014 07:01:08 -0400 Received: by mail-wi0-f180.google.com with SMTP id n3so228193wiv.7 for ; Wed, 27 Aug 2014 04:01:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b38R9FGh8hApBqajyWSiQ2vFErKRe6uF2IlM80jArRs=; b=f89NXnmydDT7e+RSYwzypoqeQK/FmQ63lS4yldluyMA9nHlo6RW8dVfHaFEM9RHpsm quwrpp8Y8QrAoc1lLEhk+wo54/b6H1Ei+XJXX45ewZXC8/XUbchdGdQBNOS8pWsYJYxL nrx3ajbLMZe8BHG+jonmUaF09rQojUTRph6enLzfFWY/BuBXC4qooy1TKmFXGnYeNmX/ Dx6zmVcPvo1bjEeh6rUAKJxBhoYZSj6Fnt0Gso+yVkbHUEo/mEmFgy9n+tKFgec6uy9w nbTvqEjJTN0ZrHXB9ZV/toAFRLqRrEBcjrcv/8Hot3Uxj3dHukcrRziFvm8ugyVr4brw UWvA== X-Gm-Message-State: ALoCoQl7QbkFoIOUrdvf7Whf5dJpxjSqRaKg/R15PzfnSRUCIr+TX1GIR1c2EZ+9CplEMQP3C4ZY X-Received: by 10.194.179.197 with SMTP id di5mr1622338wjc.125.1409137264018; Wed, 27 Aug 2014 04:01:04 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id y5sm93002wje.32.2014.08.27.04.01.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Aug 2014 04:01:02 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Chris Ball , Ulf Hansson Cc: linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH 2/4] mmc: slot-gpio: add gpiod variant to get wp GPIO Date: Wed, 27 Aug 2014 13:00:51 +0200 Message-Id: <1409137253-25189-2-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409137253-25189-1-git-send-email-linus.walleij@linaro.org> References: <1409137253-25189-1-git-send-email-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 This makes it possible to get the write protect (read only) GPIO line from a GPIO descriptor. Written to exactly mirror the card detect function. Acked-by: Alexandre Courbot Signed-off-by: Linus Walleij --- drivers/mmc/core/slot-gpio.c | 48 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/slot-gpio.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c index 908c2b29e79f..e3fce4493fab 100644 --- a/drivers/mmc/core/slot-gpio.c +++ b/drivers/mmc/core/slot-gpio.c @@ -326,6 +326,54 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, EXPORT_SYMBOL(mmc_gpiod_request_cd); /** + * mmc_gpiod_request_ro - request a gpio descriptor for write protection + * @host: mmc host + * @con_id: function within the GPIO consumer + * @idx: index of the GPIO to obtain in the consumer + * @override_active_level: ignore %GPIO_ACTIVE_LOW flag + * @debounce: debounce time in microseconds + * + * Use this function in place of mmc_gpio_request_ro() to use the GPIO + * descriptor API. Note that it is paired with mmc_gpiod_free_ro() not + * mmc_gpio_free_ro(). + * + * Returns zero on success, else an error. + */ +int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, + unsigned int idx, bool override_active_level, + unsigned int debounce) +{ + struct mmc_gpio *ctx; + struct gpio_desc *desc; + int ret; + + ret = mmc_gpio_alloc(host); + if (ret < 0) + return ret; + + ctx = host->slot.handler_priv; + + if (!con_id) + con_id = ctx->ro_label; + + desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); + if (IS_ERR(desc)) + return PTR_ERR(desc); + + if (debounce) { + ret = gpiod_set_debounce(desc, debounce); + if (ret < 0) + return ret; + } + + ctx->override_ro_active_level = override_active_level; + ctx->ro_gpio = desc; + + return 0; +} +EXPORT_SYMBOL(mmc_gpiod_request_ro); + +/** * mmc_gpiod_free_cd - free the card-detection gpio descriptor * @host: mmc host * diff --git a/include/linux/mmc/slot-gpio.h b/include/linux/mmc/slot-gpio.h index d2433381e828..a0d0442c15bf 100644 --- a/include/linux/mmc/slot-gpio.h +++ b/include/linux/mmc/slot-gpio.h @@ -25,6 +25,9 @@ void mmc_gpio_free_cd(struct mmc_host *host); int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, unsigned int idx, bool override_active_level, unsigned int debounce); +int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, + unsigned int idx, bool override_active_level, + unsigned int debounce); void mmc_gpiod_free_cd(struct mmc_host *host); void mmc_gpiod_request_cd_irq(struct mmc_host *host);