From patchwork Sun Oct 8 23:28:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 115173 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1960274qgn; Sun, 8 Oct 2017 16:30:54 -0700 (PDT) X-Received: by 10.98.185.26 with SMTP id z26mr8537069pfe.218.1507505454072; Sun, 08 Oct 2017 16:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507505454; cv=none; d=google.com; s=arc-20160816; b=B2QlOi9D0ZViNGfn4bKDRB2iZsUwTgWMMR9K6l5qpSawCDVDsGCMv6M2AHF9L12z+U TugRixch9/Qx7Lw2d1LA0yCcMdp84Prh2UIaWFWBhINn00p8WQSeV+2E73i/Cq9SIdo1 6KWkitHd6UbyMC/CLDGgnrzKWtSi6NI+C8GkVdfiKdJgRHdWt61fdgvzelv36oTD41ex 9Foy29uEjFmyWE4HQK3Jhf1tNQSY8vJyyHQ+FrsBgriJghrNyDcTSB2TkTt94PUr4WnW HuLWpSTecaR5IZtITW+JY3twl+vxMZn1TnMiw8Yn0elYuBMBId9Ct/6jG38lf2Pj7B8O LM1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=60z9KLDbYt7YIkE3INeQ3WgZvhXns9TPduswSc7KuoE=; b=R3aNa7ST/RtLrLr46oYDRLpp3gW3XE6d4rhoplc1oTqHHDStBwSXMiHqlUhsUD5W5G 1HLgTX9bQq0mnpc+a2syFa881YNA4X2ifdsV02J4QiRmpE0NFPd0qC+SouomMBT/tsnj CZxqT71N5Uv9/JBrUbdrRY9nM3WTB1Jqz/RwWqyUr9RY+mfDfj9N4GCGStbSzcy8innM H8QALu9/FPG0nAwhBFCbTLxxTLE5ZaXrN0YOROKncF5IgBZHCHJkIeI+6K4VSdDJe0SB +5m74D+yi5CpsW7dGhuW37VyggKBjwBYi4d/0JysIFQXoFUbdvl6pXXcqbr8AOFW8p3c /oGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JHjXSeEj; 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 s5si5076273pgq.650.2017.10.08.16.30.53 for ; Sun, 08 Oct 2017 16:30:54 -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=JHjXSeEj; 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 S1751545AbdJHXax (ORCPT ); Sun, 8 Oct 2017 19:30:53 -0400 Received: from mail-lf0-f54.google.com ([209.85.215.54]:50197 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751489AbdJHXax (ORCPT ); Sun, 8 Oct 2017 19:30:53 -0400 Received: by mail-lf0-f54.google.com with SMTP id a132so17407287lfa.7 for ; Sun, 08 Oct 2017 16:30:52 -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; bh=fwudXSwF0yIUEpzF7eRmAq2vc+/q0mvM6FNuvdPlfBQ=; b=JHjXSeEj12QKHLjiMiHmxBd91If6FjWZUHIBNfw2X3KjphH/faQiffjzNGoNVgsre7 qKGmmdcBBUE+M6Phb25qZNf0aZWu5bIbD5w/F+kjv8wJpr+coaKYlb30dKJQVvLAZ6xn /BgjHz5hImKNJpbD1Maz2BOMT8I11pg3w00rk= 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; bh=fwudXSwF0yIUEpzF7eRmAq2vc+/q0mvM6FNuvdPlfBQ=; b=T2t5EDW9CX/g/H8I0rwvjH3q0cTlvhvrdyuRkmCGrOxgeLk1K28e2xsd13xym7WlC9 ZYQd0raufWjWWu6RRUBryXzn1L/J5zbAUYndRExcZ2UnQvs/SAGAxzSoPAzgi+UzQyDl 8t+6KFPwryNgon1uVEG3kvlk61/2OC1SJTBx8HmNh6TmFsU9ZtTSXEqkW41SkPFaPD1J zEJw1I7CHmrVZjRDtIcfub4YX3qPfvbjX7ahrf02vZXKz2GGbBWbOA9ZZf7+OGpbHCpK 62CM8xSY9LIcSvXDfAJBFhstOppYwo6muRSFHaWwFn1ZJQKk5DmakWTgXjtqyppZ/ZIZ wevw== X-Gm-Message-State: AMCzsaXDPyF8H8iwVi7Ahg3F1WNuZo57c5hoiLAozTp1tw0+BI5Q4G7n r3TdXGY9qJ26OuDZv9oI83VwjVSU8Tw= X-Google-Smtp-Source: AOwi7QCuGGYcjmgiCDtn+TKbcGdQ6dyXSJDWB0Ie4gO2T0QXHcJchp3/tLzOPVsiQAFdgYj2QoYGHw== X-Received: by 10.46.87.77 with SMTP id r13mr3848440ljd.44.1507505451615; Sun, 08 Oct 2017 16:30:51 -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.30.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 08 Oct 2017 16:30:50 -0700 (PDT) From: Linus Walleij To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Linus Walleij Subject: [PATCH 1/2 v2] watchdog: gpio: Add some local helper variables Date: Mon, 9 Oct 2017 01:28:46 +0200 Message-Id: <20171008232847.7358-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org This add "dev" and "np" variables to make the probe() function a bit easier to read. Reviewed-by: Guenter Roeck Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Collected Guenther's review tag. --- drivers/watchdog/gpio_wdt.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 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 diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c index cb66c2f99ff1..448e6c3ba73c 100644 --- a/drivers/watchdog/gpio_wdt.c +++ b/drivers/watchdog/gpio_wdt.c @@ -101,6 +101,8 @@ static const struct watchdog_ops gpio_wdt_ops = { 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; unsigned int hw_margin; @@ -108,19 +110,19 @@ static int gpio_wdt_probe(struct platform_device *pdev) const char *algo; int ret; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; platform_set_drvdata(pdev, priv); - priv->gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); + 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(pdev->dev.of_node, "hw_algo", &algo); + ret = of_property_read_string(np, "hw_algo", &algo); if (ret) return ret; if (!strcmp(algo, "toggle")) { @@ -133,12 +135,12 @@ static int gpio_wdt_probe(struct platform_device *pdev) return -EINVAL; } - ret = devm_gpio_request_one(&pdev->dev, priv->gpio, f, - dev_name(&pdev->dev)); + ret = devm_gpio_request_one(dev, priv->gpio, f, + dev_name(dev)); if (ret) return ret; - ret = of_property_read_u32(pdev->dev.of_node, + ret = of_property_read_u32(np, "hw_margin_ms", &hw_margin); if (ret) return ret; @@ -146,7 +148,7 @@ static int gpio_wdt_probe(struct platform_device *pdev) if (hw_margin < 2 || hw_margin > 65535) return -EINVAL; - priv->always_running = of_property_read_bool(pdev->dev.of_node, + priv->always_running = of_property_read_bool(np, "always-running"); watchdog_set_drvdata(&priv->wdd, priv); @@ -155,9 +157,9 @@ static int gpio_wdt_probe(struct platform_device *pdev) priv->wdd.ops = &gpio_wdt_ops; priv->wdd.min_timeout = SOFT_TIMEOUT_MIN; priv->wdd.max_hw_heartbeat_ms = hw_margin; - priv->wdd.parent = &pdev->dev; + priv->wdd.parent = dev; - if (watchdog_init_timeout(&priv->wdd, 0, &pdev->dev) < 0) + if (watchdog_init_timeout(&priv->wdd, 0, dev) < 0) priv->wdd.timeout = SOFT_TIMEOUT_DEF; watchdog_stop_on_reboot(&priv->wdd); 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);