From patchwork Fri Mar 21 16:17:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balaji T K X-Patchwork-Id: 3875401 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 316899F334 for ; Fri, 21 Mar 2014 16:18:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29DB220259 for ; Fri, 21 Mar 2014 16:18:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 12CC22017E for ; Fri, 21 Mar 2014 16:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760765AbaCUQSL (ORCPT ); Fri, 21 Mar 2014 12:18:11 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:45965 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761050AbaCUQSJ (ORCPT ); Fri, 21 Mar 2014 12:18:09 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s2LGHqm0028928; Fri, 21 Mar 2014 11:17:52 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2LGHqXI021436; Fri, 21 Mar 2014 11:17:52 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Fri, 21 Mar 2014 11:17:52 -0500 Received: from ulaa0393241.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2LGHavK007067; Fri, 21 Mar 2014 11:17:50 -0500 From: Balaji T K To: , CC: , Andreas Fenkart , Tony Lindgren , Balaji T K Subject: [PATCH 7/9] mmc: omap_hsmmc: Pin remux workaround to support SDIO interrupt on AM335x Date: Fri, 21 Mar 2014 21:47:36 +0530 Message-ID: <1395418658-2375-8-git-send-email-balajitk@ti.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1395418658-2375-1-git-send-email-balajitk@ti.com> References: <1395404448-30030-2-git-send-email-afenkart@gmail.com> <1395418658-2375-1-git-send-email-balajitk@ti.com> 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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 From: Andreas Fenkart The am335x can't detect pending cirq in PM runtime suspend. This patch reconfigures dat1 as a GPIO before going to suspend. SDIO interrupts are detected with the GPIO, the GPIO will only wake the module from suspend, SDIO irq detection will still happen through the IP block. Idea of remuxing the pins and some minor changes by Tony Lindgren. Signed-off-by: Andreas Fenkart Signed-off-by: Tony Lindgren Signed-off-by: Balaji T K --- .../devicetree/bindings/mmc/ti-omap-hsmmc.txt | 50 +++++++++++++ drivers/mmc/host/omap_hsmmc.c | 74 +++++++++++++++++--- 2 files changed, 113 insertions(+), 11 deletions(-) diff --git a/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt b/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt index ce80561..0f9b426 100644 --- a/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt +++ b/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt @@ -56,3 +56,53 @@ Examples: &edma 25>; dma-names = "tx", "rx"; }; + +[workaround for missing swakeup on am33xx] + +This SOC is missing the swakeup line, it will not detect SDIO irq +while in suspend. + + ------ + | PRCM | + ------ + ^ | + swakeup | | fclk + | v + ------ ------- ----- + | card | -- CIRQ --> | hsmmc | -- IRQ --> | CPU | + ------ ------- ----- + +In suspend the fclk is off and the module is disfunctional. Even +register reads will fail. A small logic in the host will request +fclk restore, when an external event is detected. Once the clock +is restored, the host detects the event normally. Since am33xx +doesn't have this line it never wakes from suspend. + +The workaround is to reconfigure the dat1 line as a GPIO upon +suspend. To make this work, we need to set 1) the named pinctrl +states "default", "active" and "idle", 2) the gpio detecting +sdio irq in suspend and 3) compatibe section, see example below. +The MMC driver will then toggle between active and idle during +the runtime. If configuration is incomplete, a warning message is +emitted "falling back to polling". Mind not every application +needs SDIO irq, e.g. MMC cards Affected chips are am335x, +probably others + + + mmc1: mmc@48060100 { + compatible = "ti,am33xx-hsmmc"; + ... + interrupts-extended = <&intc 64 &gpio2 28 0>; + ... + pinctrl-names = "default", "active", "idle" + pinctrl-0 = <&mmc1_pins>; + pinctrl-1 = <&mmc1_pins>; + pinctrl-2 = <&mmc1_cirq_pin>; + ... + }; + + mmc1_cirq_pin: pinmux_cirq_pin { + pinctrl-single,pins = < + 0x0f8 0x3f /* GPIO2_28 */ + >; + }; diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index 0275e0a..dc23ac7 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c @@ -215,6 +215,8 @@ struct omap_hsmmc_host { #define HSMMC_SDIO_IRQ_ENABLED (1 << 3) /* SDIO irq enabled */ #define HSMMC_WAKE_IRQ_ENABLED (1 << 4) struct omap_hsmmc_next next_data; + struct pinctrl *pinctrl; + struct pinctrl_state *active; struct omap_mmc_platform_data *pdata; }; @@ -495,6 +497,47 @@ static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata) gpio_free(pdata->slots[0].switch_pin); } +static int omap_hsmmc_pin_init(struct omap_hsmmc_host *host) +{ + struct pinctrl *_pinctrl; + int ret; + + _pinctrl = devm_pinctrl_get(host->dev); + if (IS_ERR(_pinctrl)) { + /* okay, if the bootloader set it up right */ + dev_warn(host->dev, "no pinctrl handle\n"); + return 0; + } + + /* For most cases we don't have wake-ups, and exit after this */ + host->active = pinctrl_lookup_state(_pinctrl, "active"); + if (IS_ERR(host->active)) { + ret = PTR_ERR(host->active); + host->active = NULL; + goto done; + } + + /* Let's make sure the active and idle states work */ + ret = pinctrl_pm_select_idle_state(host->dev); + if (ret < 0) + goto err; + + ret = pinctrl_select_state(_pinctrl, host->active); + if (ret < 0) + goto err; + + dev_info(mmc_dev(host->mmc), "pins configured for wake-up events\n"); + +done: + host->pinctrl = _pinctrl; + return 0; + +err: + dev_err(mmc_dev(host->mmc), "pins configuration error: %i\n", ret); + devm_pinctrl_put(_pinctrl); + return ret; +} + /* * Start clock to the card */ @@ -1737,7 +1780,7 @@ static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host) /* Prevent auto-enabling of IRQ */ irq_set_status_flags(host->wake_irq, IRQ_NOAUTOEN); - ret = request_irq(host->wake_irq, omap_hsmmc_wake_irq, + ret = devm_request_irq(host->dev, host->wake_irq, omap_hsmmc_wake_irq, IRQF_TRIGGER_LOW | IRQF_ONESHOT, mmc_hostname(mmc), host); if (ret) { @@ -1750,8 +1793,13 @@ static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host) * Some omaps don't have wake-up path from deeper idle states * and need to remux SDIO DAT1 to GPIO for wake-up from idle. */ - if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) + if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) { + if (IS_ERR(host->dev->pins->idle_state)) { + host->wake_irq = 0; + return -EINVAL; + } host->flags |= HSMMC_SWAKEUP_QUIRK; + } return 0; } @@ -1977,7 +2025,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev) const struct of_device_id *match; dma_cap_mask_t mask; unsigned tx_req, rx_req; - struct pinctrl *pinctrl; const struct omap_mmc_of_data *data; match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); @@ -2191,10 +2238,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev) omap_hsmmc_disable_irq(host); - pinctrl = devm_pinctrl_get_select_default(&pdev->dev); - if (IS_ERR(pinctrl)) - dev_warn(&pdev->dev, - "pins are not configured from the driver\n"); + ret = omap_hsmmc_pin_init(host); + if (ret) + goto err_irq_cd; /* * For now, only support SDIO interrupt if we have a separate @@ -2232,16 +2278,14 @@ static int omap_hsmmc_probe(struct platform_device *pdev) err_slot_name: mmc_remove_host(mmc); - if (host->wake_irq) - free_irq(host->wake_irq, host); + if (host->pinctrl) + devm_pinctrl_put(host->pinctrl); err_irq_cd: if (host->use_reg) omap_hsmmc_reg_put(host); err_reg: if (host->pdata->cleanup) host->pdata->cleanup(&pdev->dev); - if (host->wake_irq) - free_irq(host->wake_irq, host); err_irq: if (host->tx_chan) dma_release_channel(host->tx_chan); @@ -2274,6 +2318,8 @@ static int omap_hsmmc_remove(struct platform_device *pdev) dma_release_channel(host->tx_chan); if (host->rx_chan) dma_release_channel(host->rx_chan); + if (host->pinctrl) + devm_pinctrl_put(host->pinctrl); pm_runtime_put_sync(host->dev); pm_runtime_disable(host->dev); @@ -2380,6 +2426,7 @@ static int omap_hsmmc_runtime_suspend(struct device *dev) OMAP_HSMMC_WRITE(host->base, ISE, 0); OMAP_HSMMC_WRITE(host->base, IE, 0); OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); + ret = pinctrl_pm_select_idle_state(host->dev); if (host->wake_irq && !(host->flags & HSMMC_WAKE_IRQ_ENABLED)) { enable_irq(host->wake_irq); host->flags |= HSMMC_WAKE_IRQ_ENABLED; @@ -2408,6 +2455,11 @@ static int omap_hsmmc_runtime_resume(struct device *dev) host->flags &= ~HSMMC_WAKE_IRQ_ENABLED; } + if (host->active) { + ret = pinctrl_select_state(host->pinctrl, host->active); + if (ret < 0) + dev_warn(mmc_dev(host->mmc), "Unable to select active pinmux\n"); + } OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN); OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);