From patchwork Tue Sep 26 20:07:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114283 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4230488qgf; Tue, 26 Sep 2017 13:07:21 -0700 (PDT) X-Received: by 10.98.157.201 with SMTP id a70mr11754469pfk.122.1506456441753; Tue, 26 Sep 2017 13:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506456441; cv=none; d=google.com; s=arc-20160816; b=FaGh20wG+t94gD93qmRA1nvFhKtsf3kqzppLXdeWaCBFrOdBNRxxjYjuMLNyupc7Cm FD1FI8JYe6S5JMABFrFptCr2q7D6M9KWMzBXfk7RcHr4St9mnpuvrhQNTRkV3nePReq9 z6GBoN4BivFy0gQyiM8If9VLhL3gsrgs5dUHC2pXe/5tQ4GhypH4gBD9By8PkgqN/eAU DjkC696hCVVf3Q1ztoFXihF5zFy+PV076pl5SdYDLn5T2BD/Nr2VkwLfYi0om/iiFloB F55lGsyykU/1CbTxxMH7NnCfJMhSzkwoSZjNv1/LcxVRfUv5V/gE8twU/zpdNMPmd9kQ kLRw== 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=bbGaw8WT0c+9o733s7YlmrlnfnS/fllvhVZ5hdFqskw=; b=otJ4hB4ADYdO91s4a08e3topzCE9b619o5AiG0mFtobyI+6l0QprJc1fdc/NSOt5G4 xBcDD6/oRcLIJW44kuy42Na4ghRfa8hRF9CNQVDnxzPbv7VxeYK7pHUBjy2P13Qe5OEO hMNx8ko4q14dtC1g9teqZxk1Bea0VUCZ/Y9ncgRHMOZdKGA/S31XD/DfpGv+P5jv8T4N yuPoP0+h2CjpMhrtINZEBJIwF5ez5xKIyDHLUw8CudHTxXxZsZyJgovW1J0JxVF2jCES Q/SxBNYd0OHZCchyrcBVeosb695hpKINeQElB6IAz6pdOalxPejlbrtoVKgQfB9thVPd 578A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AqfYUQGn; 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 y10si4641694pgc.253.2017.09.26.13.07.20 for ; Tue, 26 Sep 2017 13:07:21 -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=AqfYUQGn; 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 S968666AbdIZUHU (ORCPT ); Tue, 26 Sep 2017 16:07:20 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:44977 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968019AbdIZUHT (ORCPT ); Tue, 26 Sep 2017 16:07:19 -0400 Received: by mail-pg0-f50.google.com with SMTP id j16so6506920pga.1 for ; Tue, 26 Sep 2017 13:07:19 -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=aNJrpdi/orfPfdmuTFynqhwwHbZ4LlAjCtQX1Gy/xQI=; b=AqfYUQGnPBAi/tmdgM39lPVSehWKrL0lTmTuTX7idKCxwaucniA0x+o8p9iL0BVNac 3XcbZNPOLYdMF3XKG1PxA3olhopaf1/Wyum76Z6dYp60azpULSHqxw638yzhrX35Wzdn a0UTi9zs5wcOBwwlzffte1/6U461KYoqVeU9k= 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=aNJrpdi/orfPfdmuTFynqhwwHbZ4LlAjCtQX1Gy/xQI=; b=IBi/1qjKy/O6/B9qj77Px9zH/SncfIJs+xi4n3hR8fAHlDsGAghHAa9Ba1xf/OlE2c 2+PwvlWNY6bP4s2OJaVkZAN5RqZswakGTC3e1xKsWJOLdbhcLi6WWr6B6gRNOw+Fxmnc CJs6UFiAXxWcvZvvW8b5VTwyFLLibkpbJXgX8OtiaYqE/RDfcZXSwQfwBMkLrMi0a05w qHvTOoezWABgPLkHFtnV9NnAyMFgeT9uzEHt7c46BhQ8nTIrXUuR9Qml3w1mjsgsyZDS rp5Xnr9nW+Ae3BjExzkaZCbSbb+9iK8VvVRvwa9NVoJtIDT8NZZQ6Yg5xReRSD90MvC6 WLlA== X-Gm-Message-State: AHPjjUgEFisiBEHUEmRRINuP9uIECJkoCecucl6af1AAeTyXfWdyE20M Ae25xXM7IO3EG7ULpR4cAwSMrDQT70Q= X-Google-Smtp-Source: AOwi7QDNbeEDvOvubYa4KxJQ+mnXgJTtxd1ajrygHZNjgt6RALez+VEQzGmzfTum4M9otRINF+/aqg== X-Received: by 10.84.194.3 with SMTP id g3mr11942437pld.246.1506456439151; Tue, 26 Sep 2017 13:07:19 -0700 (PDT) Received: from localhost.localdomain ([70.35.39.2]) by smtp.gmail.com with ESMTPSA id f69sm18978158pff.4.2017.09.26.13.07.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 13:07:18 -0700 (PDT) From: Linus Walleij To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Linus Walleij Subject: [PATCH 1/2] watchdog: gpio: Add some local helper variables Date: Tue, 26 Sep 2017 22:07:11 +0200 Message-Id: <20170926200712.10069-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. Signed-off-by: Linus Walleij --- 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 Reviewed-by: Guenter Roeck 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 Tue Sep 26 20:07:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114284 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4230502qgf; Tue, 26 Sep 2017 13:07:22 -0700 (PDT) X-Received: by 10.101.88.134 with SMTP id d6mr12282309pgu.339.1506456442430; Tue, 26 Sep 2017 13:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506456442; cv=none; d=google.com; s=arc-20160816; b=cEc254cCK2/j0uSstNiB29zKb573H1d3OM3aBvRuMZ/8jxbxAVjZY8T4iOSRuqyghW Qy9rvy6NLff5X1FRlzhl2816C5WgwR3TA2m8NEKPrSTPMgxMlIr4Lkj9rt27o+YmbaSx 5sMmuz8331deyfSld2LYafaKQzXyIeoTdXrc0kHW37VL6lLiDunT67j12Z6CCFAsJUZp ZnVX7eEf/V23bYa+iTFEj5GOzqBAqDCiC4huhswt8JEx5nKLm5S13LC/xJaiRL8PpV/h HudFgp7r81cud5DzS4tADHvbgnNOwrou7+RGejJYsqGlTBPiApgiuq0gaERta+JCaJm3 meDw== 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=KbjoOa/qmGNEsewE/Ss0NpJCzGeFPqjvREnm0HYQ4v8=; b=z2qITMvDvqc6CEQ4ArwfyXDwBpIZ5l6I8i+mQVpipJoJe0CgVAfl+mLLpqPE12SWNg o9On3jpedhxgiUA1txh8wVwQ5GZYXwejlwE1QH8A6mGiqeBaFqfeNcMQcLQxw/jtgTiH Z+bsc15M3uZQbU24vExa6/UAPIfGzdnDfTl5hDa6XeZzegyTqoFQDru2BAw4zUrwYOMx 2uSeOEubc5NuBApWFm4OOVtGGRoS3t98TmUFMFhpW4B2Zhrm0gNd3Gun5dFRJ8ydlOpw S9ZNkqIPyhny0sjvw53aOtu1475FlLH/Vw3wrDCUFhGAp24GsoEi2kYI7pygHcVY9ZM+ AObA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=MXvNH0uY; 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 y10si4641694pgc.253.2017.09.26.13.07.22 for ; Tue, 26 Sep 2017 13:07:22 -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=MXvNH0uY; 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 S968667AbdIZUHW (ORCPT ); Tue, 26 Sep 2017 16:07:22 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:48770 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968019AbdIZUHV (ORCPT ); Tue, 26 Sep 2017 16:07:21 -0400 Received: by mail-pg0-f53.google.com with SMTP id v23so6506523pgc.5 for ; Tue, 26 Sep 2017 13:07:21 -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=KrNtgLT3PHMwIDjxm32d3tXWYkKXwaBpQPIuH5MzQlQ=; b=MXvNH0uYctsWsJmf9q6yFr2bMyjIwo6GCNvYqkAbcFwsXEyQQvOxpNOsI68YZ2edup B9Ugf7PTMg0dzT9v1YkfG4EOwgYN41EbI1DtEy+ZmU5Z8ZphsVO2lEbqBsxBLtRDeM04 +k51nnu0BkM9fLS0wJrbQEHYr+Woir8CzDdwk= 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=KrNtgLT3PHMwIDjxm32d3tXWYkKXwaBpQPIuH5MzQlQ=; b=aiZ/V2KJAlg/xPmGYTmTg3yt+oMR/k/NGTf3YKYuSBT3tLMPepGIHp8cA84T2D060J KNRDlzl2Q7QfX8Yx3d63AY3xPMFdVWVakAuy8op3rsRbDxqujUUIf6pnAVtj6EtdsA/j 7VF5kTzC69beGky0UGotbYbjsBDnLCUlBNPgPV5/BSVYhDz63vUUgdSOePgAjmqi7NvK gb8CTicY7jS4fXIYTUStt44ngG5SWcqp6auMvG5FNreDxvLLW3NOO/cRc1+XzsoMDgyR ass2EiNia0a33Fdd6xQVR12EmJt/9EETqULaL5g4/V5uqj04X6hJgBD334xb0wK86fzu dTSA== X-Gm-Message-State: AHPjjUhFpLb+XHiaAHLNLMjXrgeHD/NdVCfu7RHCVIMO6gxHz6G5Qf3T U6aulKhCisMfMuiEMLetVKH19qO9zgU= X-Google-Smtp-Source: AOwi7QDG2HUAyqQ1zQTO31OhTQLbKob/qQeewsoXY+wI+2AI2KzSSW9CCD9EMni88RO10VGaNazbaA== X-Received: by 10.159.242.196 with SMTP id x4mr11514219plw.286.1506456440940; Tue, 26 Sep 2017 13:07:20 -0700 (PDT) Received: from localhost.localdomain ([70.35.39.2]) by smtp.gmail.com with ESMTPSA id f69sm18978158pff.4.2017.09.26.13.07.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 13:07:20 -0700 (PDT) From: Linus Walleij To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Linus Walleij Subject: [PATCH 2/2] watchdog: gpio: Convert to use GPIO descriptors Date: Tue, 26 Sep 2017 22:07:12 +0200 Message-Id: <20170926200712.10069-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170926200712.10069-1-linus.walleij@linaro.org> References: <20170926200712.10069-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 --- drivers/watchdog/gpio_wdt.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 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 diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c index 448e6c3ba73c..bb699dfa099e 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,11 @@ struct gpio_wdt_priv { static void gpio_wdt_disable(struct gpio_wdt_priv *priv) { - gpio_set_value_cansleep(priv->gpio, !priv->active_low); + gpiod_set_value_cansleep(priv->gpiod, 0); /* 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 +50,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 +66,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 +104,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 +115,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);