From patchwork Sun Oct 8 23:28:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 115174 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1960891qgn; Sun, 8 Oct 2017 16:31:56 -0700 (PDT) X-Received: by 10.99.121.201 with SMTP id u192mr7617344pgc.69.1507505516779; Sun, 08 Oct 2017 16:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507505516; cv=none; d=google.com; s=arc-20160816; b=gaWGnCof/VTjVmBTeQfuUXS4KazZbfkREb7EKvxxhLxy+r6/nl8IQu913pvJMssdrk GPVFemjHBP+G9KpJasoRTs1eIYdV58prgILalmM1YwPDdPEDLjxQ6gV8JRrI740KMokm 8UIie5bIyM3jiy4mFmWMtjo5lZhT92ViKwtEgq1b6aJfn5yU8SXKQd/uGUBD7cBcKAxo qsZtM3aFV3jBzmexe6cpD5j5b7a37zdYTC9oqyZuVwu3TcPLSIi/cOf8J1+zRDNU4EKE yjSpAg3pOi9U7vCiitmpTbsNc/njsYgVPMoLpy0VZD6EhzZ6bzV2aAv/6KjwxOSayndc qLxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fszGF05HVS65wFhp3IeC15uJZ+Z0KeGT7Arah/oC7OU=; b=ESqtE12MB2W8ufgq2S5HADlr0W+/PNVsqMpvg0Uvkn+nGNsdhqP+miHuxcxAIUg3v+ qfkNDMcmrBamhR8IOT6gL3sXn+diF4krpnoidLtC4wIhipuSBBLLmkSkyMApirZzXZVj 0S5RPtUztuRmXFIIUDCZIdDeBa1Yr9l5uwbVxloQp51nVs0pt98YmxFJ4TRvLkd2vG6x NqjuubdWMht5ietrsdbRlIPzJCQ4gv4vq2dC2v8+duf09G4OulfADAzr/9IwRFH7wn+L nEfnFCz9mxXmzVsJZmFdbz0LLPCHE99dQx+qzMYwYJwBnAtHPh5tzjTcSlDsp1IKoO5t MmCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V3NqkVLf; spf=pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si5701844pff.463.2017.10.08.16.31.56 for ; Sun, 08 Oct 2017 16:31:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V3NqkVLf; spf=pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751545AbdJHXb4 (ORCPT ); Sun, 8 Oct 2017 19:31:56 -0400 Received: from mail-lf0-f52.google.com ([209.85.215.52]:47555 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751489AbdJHXbz (ORCPT ); Sun, 8 Oct 2017 19:31:55 -0400 Received: by mail-lf0-f52.google.com with SMTP id k40so6010199lfi.4 for ; Sun, 08 Oct 2017 16:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cwMqFVLbMlz1c8LWWVMsLlBydDedQXvslY4Vr44JNHk=; b=V3NqkVLf+kFM4ykOJ6UUg9erJm/yzzlJLcjUB25gt3kj9LGUvh8wC674WNWGsaJhW3 9Io+WEguM3NmTjn8tVSePbfwkRIl7Jw4tPBSSMlRPKxKfvC0lEocvIznMZq1ZNj4EKg1 jQ7XzjU6o7pdoPP41U0rZEkruYo2SstjVSSV0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cwMqFVLbMlz1c8LWWVMsLlBydDedQXvslY4Vr44JNHk=; b=QOrQ3FIkz92XCbchthnU73O4yfkK12nfFfUi7bNkf3wGS4n6ndt1FNVTZD+bZpTbZO 1lhsbbmPsEnoQFhSjh8eVywqcX/2e9OqmObGe5wmdTshmLWjMkET9PZrw6bmmvC/jYAn gIQWAnTXf6N46JIZzIKT33irXeCwcaZRMJCHryOM5tPTIjPCTtHbQCAjr4MBLp41iCfW eeMmDXhAJrUjZ/aK9PwAomM7LQNQJ7o44GCtTjvjwYHt4wKWf4n+rGlC9NNaevBp3VZa VIBy75LyHHnQqb986gpwpvPWdtjviuXeHlgiMzAgtS8Dyi22lPjrjsOmedBONI5OHXqC RH8A== X-Gm-Message-State: AMCzsaUhGMHeF7oFvBiBLOtWO/oeTJKje2NfniJCMqVpBdwTCXhrNs1O zUAPTxRNsM3afGESoHRW1LVM7A== X-Google-Smtp-Source: AOwi7QDG25hS+7o/h8ebdVb5MczNqeNf/Eu5OsrYJXTG8ZJ4YmSiBk3cAxTjMoIxmKuu470rYib9bQ== X-Received: by 10.25.221.196 with SMTP id w65mr2532353lfi.89.1507505514226; Sun, 08 Oct 2017 16:31:54 -0700 (PDT) Received: from localhost.localdomain (c-367171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.54]) by smtp.gmail.com with ESMTPSA id e33sm1131439lfi.36.2017.10.08.16.31.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 08 Oct 2017 16:31:52 -0700 (PDT) From: Linus Walleij To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Linus Walleij Subject: [PATCH 2/2 v2] watchdog: gpio: Convert to use GPIO descriptors Date: Mon, 9 Oct 2017 01:28:47 +0200 Message-Id: <20171008232847.7358-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20171008232847.7358-1-linus.walleij@linaro.org> References: <20171008232847.7358-1-linus.walleij@linaro.org> Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org This converts the GPIO watchdog driver to use GPIO descriptors instead of relying on the old method to read out GPIO numbers from the device tree and then using those with the old GPIO API. The descriptor API keeps track of whether the line is active low so we can remove all active low handling and rely on the GPIO descriptor to deal with this for us. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Fix a logic error spotted by Guenther: we have to drive the ping line HIGH when disabling the watchdog, so nothing fires. Constantly feeding the wdog. Got it backwards :/ --- drivers/watchdog/gpio_wdt.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) -- 2.13.5 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Guenter Roeck diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c index 448e6c3ba73c..b077c88a5ceb 100644 --- a/drivers/watchdog/gpio_wdt.c +++ b/drivers/watchdog/gpio_wdt.c @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include #include #include @@ -25,8 +26,7 @@ enum { }; struct gpio_wdt_priv { - int gpio; - bool active_low; + struct gpio_desc *gpiod; bool state; bool always_running; unsigned int hw_algo; @@ -35,11 +35,12 @@ struct gpio_wdt_priv { static void gpio_wdt_disable(struct gpio_wdt_priv *priv) { - gpio_set_value_cansleep(priv->gpio, !priv->active_low); + /* Eternal ping */ + gpiod_set_value_cansleep(priv->gpiod, 1); /* Put GPIO back to tristate */ if (priv->hw_algo == HW_ALGO_TOGGLE) - gpio_direction_input(priv->gpio); + gpiod_direction_input(priv->gpiod); } static int gpio_wdt_ping(struct watchdog_device *wdd) @@ -50,13 +51,13 @@ static int gpio_wdt_ping(struct watchdog_device *wdd) case HW_ALGO_TOGGLE: /* Toggle output pin */ priv->state = !priv->state; - gpio_set_value_cansleep(priv->gpio, priv->state); + gpiod_set_value_cansleep(priv->gpiod, priv->state); break; case HW_ALGO_LEVEL: /* Pulse */ - gpio_set_value_cansleep(priv->gpio, !priv->active_low); + gpiod_set_value_cansleep(priv->gpiod, 1); udelay(1); - gpio_set_value_cansleep(priv->gpio, priv->active_low); + gpiod_set_value_cansleep(priv->gpiod, 0); break; } return 0; @@ -66,8 +67,8 @@ static int gpio_wdt_start(struct watchdog_device *wdd) { struct gpio_wdt_priv *priv = watchdog_get_drvdata(wdd); - priv->state = priv->active_low; - gpio_direction_output(priv->gpio, priv->state); + priv->state = 0; + gpiod_direction_output(priv->gpiod, priv->state); set_bit(WDOG_HW_RUNNING, &wdd->status); @@ -104,9 +105,8 @@ static int gpio_wdt_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct gpio_wdt_priv *priv; - enum of_gpio_flags flags; + enum gpiod_flags gflags; unsigned int hw_margin; - unsigned long f = 0; const char *algo; int ret; @@ -116,29 +116,22 @@ static int gpio_wdt_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); - priv->gpio = of_get_gpio_flags(np, 0, &flags); - if (!gpio_is_valid(priv->gpio)) - return priv->gpio; - - priv->active_low = flags & OF_GPIO_ACTIVE_LOW; - ret = of_property_read_string(np, "hw_algo", &algo); if (ret) return ret; if (!strcmp(algo, "toggle")) { priv->hw_algo = HW_ALGO_TOGGLE; - f = GPIOF_IN; + gflags = GPIOD_IN; } else if (!strcmp(algo, "level")) { priv->hw_algo = HW_ALGO_LEVEL; - f = priv->active_low ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; + gflags = GPIOD_OUT_LOW; } else { return -EINVAL; } - ret = devm_gpio_request_one(dev, priv->gpio, f, - dev_name(dev)); - if (ret) - return ret; + priv->gpiod = devm_gpiod_get(dev, NULL, gflags); + if (IS_ERR(priv->gpiod)) + return PTR_ERR(priv->gpiod); ret = of_property_read_u32(np, "hw_margin_ms", &hw_margin);