From patchwork Tue Mar 3 12:28:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Fenkart X-Patchwork-Id: 5921971 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 89B359F36A for ; Tue, 3 Mar 2015 12:28:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93A6E202B4 for ; Tue, 3 Mar 2015 12:28:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C2AC20148 for ; Tue, 3 Mar 2015 12:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756070AbbCCM2y (ORCPT ); Tue, 3 Mar 2015 07:28:54 -0500 Received: from mail-wg0-f41.google.com ([74.125.82.41]:40344 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755159AbbCCM2x (ORCPT ); Tue, 3 Mar 2015 07:28:53 -0500 Received: by wghl18 with SMTP id l18so39634716wgh.7; Tue, 03 Mar 2015 04:28:52 -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; bh=lftj7yRDqKaGAaDY0WnkdSfxHxiGix2A33KIGHEr00k=; b=W2PksboONr8ROQsW7L2k//QlvToKktr3uLBBlK2ddFU8A5ormMKNRTdoEI7fuSmTJN XMu5/IkQsoxKITo60FGv8YFxCoO7gB35IVWkMbk6ps/am6/Nw2BchA+1tT1TDY75SLNx nRyXjRebOhSwHg3zjtyKo4+efRjEHqJTPNp+fByd3yc/k4ZOwMrynuPxbRjeL9mh5bhK rB2E0zH3tlKyYFurf0G79biAkxDA+xBjs8PiXFHHrpRKj13ZSuKYXjEZnGoYMUD9K3PG wCFTYPkwRlV/Luz9gsN1eBUyJRvZDmRb5FDZ8ADZIApClHjyMXvnm0YIDRr7c/tQoYRa ucFw== X-Received: by 10.194.175.202 with SMTP id cc10mr69276549wjc.27.1425385732426; Tue, 03 Mar 2015 04:28:52 -0800 (PST) Received: from localhost (ip-94-112-1-170.net.upcbroadband.cz. [94.112.1.170]) by mx.google.com with ESMTPSA id g5sm1122226wjr.19.2015.03.03.04.28.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2015 04:28:51 -0800 (PST) From: Andreas Fenkart To: linux-mmc@vger.kernel.org Cc: linux-omap@vger.kernel.org, NeilBrown , Tony Lindgren , Ulf Hansson , Andreas Fenkart Subject: [PATCH 3/6] mmc: omap_hsmmc: use distinctive code paths for cover / card detect logic Date: Tue, 3 Mar 2015 13:28:15 +0100 Message-Id: <1425385698-6588-4-git-send-email-afenkart@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1425385698-6588-1-git-send-email-afenkart@gmail.com> References: <1425385698-6588-1-git-send-email-afenkart@gmail.com> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 Mobile phones (some) have no card detect pin, but can detect if the cover is removed. The purpose is the same; detect if card is being added/removed, but the details differ. When the cover is removed, it does not mean the card is gone. But it might, since it is accessible now. It's like a warning. All the driver does is to limit write access to the card, see protect_card flag. In contrast, card detect notifies us after the fact, e.g. card is gone, card is inserted. We can't take precautions, but we can rely on those events, -- the card is really gone, or do scan the card. To summarize there is not much code sharing between cover and card detect, it only increases confusion. By splitting, both will be simplified in a followup patch. Signed-off-by: Andreas Fenkart --- drivers/mmc/host/omap_hsmmc.c | 56 +++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index 77ad471..38239fb 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c @@ -230,9 +230,6 @@ struct omap_hsmmc_host { */ int (*get_cover_state)(struct device *dev); - /* Card detection IRQs */ - int card_detect_irq; - int (*card_detect)(struct device *dev); }; @@ -422,6 +419,7 @@ static inline int omap_hsmmc_have_reg(void) #endif static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id); +static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id); static int omap_hsmmc_gpio_init(struct mmc_host *mmc, struct omap_hsmmc_host *host, @@ -429,20 +427,20 @@ static int omap_hsmmc_gpio_init(struct mmc_host *mmc, { int ret; - if (gpio_is_valid(pdata->switch_pin)) { - if (pdata->cover) - host->get_cover_state = - omap_hsmmc_get_cover_state; - else - host->card_detect = omap_hsmmc_card_detect; - host->card_detect_irq = - gpio_to_irq(pdata->switch_pin); - mmc_gpio_set_cd_isr(mmc, omap_hsmmc_detect); + if (pdata->cover && gpio_is_valid(pdata->switch_pin)) { ret = mmc_gpio_request_cd(mmc, pdata->switch_pin, 0); if (ret) return ret; - } else { - pdata->switch_pin = -EINVAL; + + host->get_cover_state = omap_hsmmc_get_cover_state; + mmc_gpio_set_cd_isr(mmc, omap_hsmmc_cover_irq); + } else if (!pdata->cover && gpio_is_valid(pdata->switch_pin)) { + ret = mmc_gpio_request_cd(mmc, pdata->switch_pin, 0); + if (ret) + return ret; + + host->card_detect = omap_hsmmc_card_detect; + mmc_gpio_set_cd_isr(mmc, omap_hsmmc_detect); } if (gpio_is_valid(pdata->gpio_wp)) { @@ -1236,15 +1234,37 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host) } /* - * irq handler to notify the core about card insertion/removal + * irq handler when (cell-phone) cover is mounted/removed */ -static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) +static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id) { struct omap_hsmmc_host *host = dev_id; int carddetect; sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); + if (host->card_detect) { + carddetect = host->card_detect(host->dev); + } else { + omap_hsmmc_protect_card(host); + carddetect = -ENOSYS; + } + + if (carddetect) + mmc_detect_change(host->mmc, (HZ * 200) / 1000); + else + mmc_detect_change(host->mmc, (HZ * 50) / 1000); + return IRQ_HANDLED; +} + +/* + * irq handler to notify the core about card insertion/removal + */ +static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) +{ + struct omap_hsmmc_host *host = dev_id; + int carddetect; + if (host->card_detect) carddetect = host->card_detect(host->dev); else { @@ -2164,9 +2184,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev) if (ret < 0) goto err_slot_name; } - if (host->card_detect_irq && host->get_cover_state) { + if (host->get_cover_state) { ret = device_create_file(&mmc->class_dev, - &dev_attr_cover_switch); + &dev_attr_cover_switch); if (ret < 0) goto err_slot_name; }