From patchwork Thu Nov 12 17:50:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 7604421 Return-Path: X-Original-To: patchwork-linux-arm@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 C2B069F1C2 for ; Thu, 12 Nov 2015 17:53:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0047120827 for ; Thu, 12 Nov 2015 17:53:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF59220825 for ; Thu, 12 Nov 2015 17:53:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zww1i-0002lK-1L; Thu, 12 Nov 2015 17:51:14 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zww1e-0002fH-Eo for linux-arm-kernel@lists.infradead.org; Thu, 12 Nov 2015 17:51:11 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id tACHohFt008381; Thu, 12 Nov 2015 11:50:43 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id tACHogP1006165; Thu, 12 Nov 2015 11:50:42 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.224.2; Thu, 12 Nov 2015 11:50:42 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id tACHofdm010264; Thu, 12 Nov 2015 11:50:42 -0600 From: Felipe Balbi To: Javier Martinez Canillas , Santosh Shilimkar , Kevin Hilman , Linus Walleij , Alexandre Courbot Subject: [PATCH] gpio: omap: fix debounce time calculation Date: Thu, 12 Nov 2015 11:50:40 -0600 Message-ID: <1447350640-20347-1-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.6.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151112_095110_609705_0CD516D6 X-CRM114-Status: GOOD ( 11.10 ) X-Spam-Score: -7.3 (-------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tony Lindgren , linux-gpio@vger.kernel.org, Linux OMAP Mailing List , Felipe Balbi , Linux ARM Kernel Mailing List Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 According to TRM, debounce is measured in periods of the functional clock of the GPIO IP. This means that we should divide by the rate of functional clock. Signed-off-by: Felipe Balbi --- drivers/gpio/gpio-omap.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index 56d2d026e62e..2b29fd195521 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -217,15 +217,29 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, u32 val; u32 l; bool enable = !!debounce; + unsigned long flags; if (!bank->dbck_flag) return; if (enable) { - debounce = DIV_ROUND_UP(debounce, 31) - 1; + struct clk *clk; + unsigned long rate; + + clk = clk_get(bank->dev, "fck"); + if (IS_ERR(clk)) { + dev_err(bank->dev, "can't get clock\n"); + return; + } + + rate = clk_get_rate(clk); + clk_put(clk); + + debounce = DIV_ROUND_UP(debounce, rate); debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK; } + raw_spin_lock_irqsave(&bank->lock, flags); l = BIT(offset); clk_enable(bank->dbck); @@ -256,6 +270,7 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, bank->context.debounce = debounce; bank->context.debounce_en = val; } + raw_spin_unlock_irqrestore(&bank->lock, flags); } /** @@ -1002,14 +1017,9 @@ static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value) static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, unsigned debounce) { - struct gpio_bank *bank; - unsigned long flags; - - bank = container_of(chip, struct gpio_bank, chip); + struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); - raw_spin_lock_irqsave(&bank->lock, flags); omap2_set_gpio_debounce(bank, offset, debounce); - raw_spin_unlock_irqrestore(&bank->lock, flags); return 0; }