From patchwork Sun Dec 2 11:04:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152659 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5642802ljp; Sun, 2 Dec 2018 03:06:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/UnKZrhIKnj+BOTwwPYVd+KtvTN1i5Abslas9/R0f6aj0PjR0U4HGWC0Cs+YZVYllS8Ceev X-Received: by 2002:a62:53c5:: with SMTP id h188mr11795015pfb.190.1543748781192; Sun, 02 Dec 2018 03:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543748781; cv=none; d=google.com; s=arc-20160816; b=c/DD+qq25f0WA7Vp1iGf/2sHrc2vebnKa8lH5frXAuYxOMgOJfE2mlwMx6I7K0IeJy ZGo7ueYB9USoWqp5zSd1s8qbgvZw687mlGRhjkrGGvQvIw148VhFiyzCMT3gWtok2lXY ZKzvKdCfmMuLCvPYU9N6C+1wqU2TKVYZ+GNIbMCNyUSfuNjGkHd+sSe85tmM159CMVtD Tn09naiTCBms5jR5VmQ9wFYBgjr1ciln7j59WzMMbrNawzf5xZVmqVjnLKSa2wja1Vvs gW4jVG8myTmnrHEsFjdSk4yoBTs6kWPPHBEKPxeph+vZH/HInyRCKMLbNd/i7u+VWsMv Jx8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PsEhV7aTxVfit+SDymQ3mIoyn9JPfPo34DSHPnTgPuI=; b=xXFG9ye9Xx8Nf7tdUXGZrGxkhB6z/9/kmY2BIOiDCqD+av8Ng0kRBkHCNzubCMBmpl C3+FHWwbIQY6vYX4/EAsdB5b3gVnPZptWpvYovzAFcN5oFyMiEgxxNYSpRXyadDvMgzx zqMmzydjrkgowucZ5xi6iQtRNU8K5sWHX4Ds90M6tbp9DygW+18ooyTWXDH4XkqV7WaK BBdaJBSM5D8ZAFS7FXju+nfdZHnZZkZet6RRHiTvM7J20dvJoFXxF0JOuF6SoKTYaj1u Ytk1OlbCEYmiab330br5X8KRBiVmZK/IFvTE9208VVmKXAx8Ddw9k6yV0+8iAeNYpUR5 4f1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XUW6K6Hp; 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=pass (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 64si9060600pge.261.2018.12.02.03.06.20 for ; Sun, 02 Dec 2018 03:06:21 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=XUW6K6Hp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725791AbeLBLGU (ORCPT ); Sun, 2 Dec 2018 06:06:20 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41991 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbeLBLGU (ORCPT ); Sun, 2 Dec 2018 06:06:20 -0500 Received: by mail-lj1-f194.google.com with SMTP id l15-v6so8741165lja.9 for ; Sun, 02 Dec 2018 03:06:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PsEhV7aTxVfit+SDymQ3mIoyn9JPfPo34DSHPnTgPuI=; b=XUW6K6HpICaIKrasx5a6jKWhyEOYH2ELKj+5k0I7B/n+6Ta8B1qfvFGM/PitnX7TPk NLmWkUOY33WGdfH/IOgrHyY2UM3URjIYzvDPAhpTTCfXd7hFWkaZ+gzxZcoULtxCRmA5 inIYew6wSWOhpiJmRu3PVRlWmWWauPGlC9x2w= 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:mime-version :content-transfer-encoding; bh=PsEhV7aTxVfit+SDymQ3mIoyn9JPfPo34DSHPnTgPuI=; b=DlP26NksLv8OKmjsdsa28ur8zJbGJOopijas7jO2Ti0qQgeAwjAHGZ/oVuuWkUyHbN tx7bLezReksvkal8RlKW64vzNaXX93to1OupFUgMSNbiEtv4nZk/s6x2hjT73G9TJoF/ BVU57kMoQXUbyWGJvaEdJG/vZ7dnTZT5MRuIB5yxnxbghvwUbcAySomchotrq15w5BYj jkawd2EY3rgSRVuTEfUnlYhzhoEotRyfo7VdV3EDRtmBfoRM3S6xbgQhn8Y30aQnLCdA mQd1n1AZKEaEqQYc5uFkg5usiT+cTDy/SIKnbR5cCgeLuiAAOBRS3RYbn0bDDiR28eP1 CXLw== X-Gm-Message-State: AA+aEWb7cBanzYkPbeOjsWOL7SvZX4Tw/LfYbCmjRdXjKhkcetDVPAin bh65UC5WfngwEKkkY8I6QEA25Q== X-Received: by 2002:a2e:5703:: with SMTP id l3-v6mr8377950ljb.106.1543748776530; Sun, 02 Dec 2018 03:06:16 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id g17sm1889801lfj.36.2018.12.02.03.06.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 02 Dec 2018 03:06:15 -0800 (PST) From: Linus Walleij To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Linus Walleij , Johannes Thumshirn , Johannes Thumshirn , Johannes Thumshirn Subject: [PATCH] watchdog: mena21_wdt: Convert to GPIO descriptors Date: Sun, 2 Dec 2018 12:04:10 +0100 Message-Id: <20181202110410.17562-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org This drops the old OF API use to look up global GPIO numbers and replace it with the GPIO descriptor API. Cc: Johannes Thumshirn Cc: Johannes Thumshirn Cc: Johannes Thumshirn Signed-off-by: Linus Walleij --- drivers/watchdog/mena21_wdt.c | 73 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 37 deletions(-) -- 2.19.1 Acked-by: Johannes Thumshirn Reviewed-by: Guenter Roeck diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c index 0be7f50e8ff9..6db69883ece6 100644 --- a/drivers/watchdog/mena21_wdt.c +++ b/drivers/watchdog/mena21_wdt.c @@ -13,10 +13,10 @@ #include #include #include -#include -#include +#include #include #include +#include #define NUM_GPIOS 6 @@ -31,7 +31,7 @@ enum a21_wdt_gpios { struct a21_wdt_drv { struct watchdog_device wdt; - unsigned gpios[NUM_GPIOS]; + struct gpio_desc *gpios[NUM_GPIOS]; }; static bool nowayout = WATCHDOG_NOWAYOUT; @@ -43,9 +43,9 @@ static unsigned int a21_wdt_get_bootstatus(struct a21_wdt_drv *drv) { int reset = 0; - reset |= gpio_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0; - reset |= gpio_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0; - reset |= gpio_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0; + reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0; + reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0; + reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0; return reset; } @@ -54,7 +54,7 @@ static int a21_wdt_start(struct watchdog_device *wdt) { struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt); - gpio_set_value(drv->gpios[GPIO_WD_ENAB], 1); + gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 1); return 0; } @@ -63,7 +63,7 @@ static int a21_wdt_stop(struct watchdog_device *wdt) { struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt); - gpio_set_value(drv->gpios[GPIO_WD_ENAB], 0); + gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0); return 0; } @@ -72,9 +72,9 @@ static int a21_wdt_ping(struct watchdog_device *wdt) { struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt); - gpio_set_value(drv->gpios[GPIO_WD_TRIG], 0); + gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 0); ndelay(10); - gpio_set_value(drv->gpios[GPIO_WD_TRIG], 1); + gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 1); return 0; } @@ -96,9 +96,9 @@ static int a21_wdt_set_timeout(struct watchdog_device *wdt, } if (timeout == 1) - gpio_set_value(drv->gpios[GPIO_WD_FAST], 1); + gpiod_set_value(drv->gpios[GPIO_WD_FAST], 1); else - gpio_set_value(drv->gpios[GPIO_WD_FAST], 0); + gpiod_set_value(drv->gpios[GPIO_WD_FAST], 0); wdt->timeout = timeout; @@ -127,7 +127,6 @@ static struct watchdog_device a21_wdt = { static int a21_wdt_probe(struct platform_device *pdev) { - struct device_node *node; struct a21_wdt_drv *drv; unsigned int reset = 0; int num_gpios; @@ -138,40 +137,40 @@ static int a21_wdt_probe(struct platform_device *pdev) if (!drv) return -ENOMEM; - /* Fill GPIO pin array */ - node = pdev->dev.of_node; - - num_gpios = of_gpio_count(node); + num_gpios = gpiod_count(&pdev->dev, NULL); if (num_gpios != NUM_GPIOS) { dev_err(&pdev->dev, "gpios DT property wrong, got %d want %d", num_gpios, NUM_GPIOS); return -ENODEV; } - for (i = 0; i < num_gpios; i++) { - int val; - - val = of_get_gpio(node, i); - if (val < 0) - return val; - - drv->gpios[i] = val; - } - /* Request the used GPIOs */ for (i = 0; i < num_gpios; i++) { - ret = devm_gpio_request(&pdev->dev, drv->gpios[i], - "MEN A21 Watchdog"); - if (ret) - return ret; + enum gpiod_flags gflags; if (i < GPIO_WD_RST0) - ret = gpio_direction_output(drv->gpios[i], - gpio_get_value(drv->gpios[i])); - else /* GPIO_WD_RST[0..2] are inputs */ - ret = gpio_direction_input(drv->gpios[i]); - if (ret) + gflags = GPIOD_ASIS; + else + gflags = GPIOD_IN; + drv->gpios[i] = devm_gpiod_get_index(&pdev->dev, NULL, i, + gflags); + if (IS_ERR(drv->gpios[i])) { + ret = PTR_ERR(drv->gpios[i]); return ret; + } + + gpiod_set_consumer_name(drv->gpios[i], "MEN A21 Watchdog"); + + /* + * Retrieve the initial value from the GPIOs that should be + * output, then set up the line as output with that value. + */ + if (i < GPIO_WD_RST0) { + int val; + + val = gpiod_get_value(drv->gpios[i]); + gpiod_direction_output(drv->gpios[i], val); + } } watchdog_init_timeout(&a21_wdt, 30, &pdev->dev); @@ -207,7 +206,7 @@ static void a21_wdt_shutdown(struct platform_device *pdev) { struct a21_wdt_drv *drv = dev_get_drvdata(&pdev->dev); - gpio_set_value(drv->gpios[GPIO_WD_ENAB], 0); + gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0); } static const struct of_device_id a21_wdt_ids[] = {