From patchwork Tue Dec 11 12:04:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 153454 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp530861ljp; Tue, 11 Dec 2018 04:04:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/VPOAZqjXMLQIaFUlgMMxw/aH5mA+TeNjFaa44wkFRxy4IAe/ssfF+NPr80PQrdVegSfVmM X-Received: by 2002:a63:7f4f:: with SMTP id p15mr14494412pgn.296.1544529864487; Tue, 11 Dec 2018 04:04:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544529864; cv=none; d=google.com; s=arc-20160816; b=Md/ajVOPs63q4VqyGoT7SD5x7ekhFXWrdxM5F7zy52fQTCTv15udSHocaN39rFlvmm YHZJhJGVfQJ1hGWUchtSVW5U4C1jaNdFqcIk9c5Ei82bmZmcvImnn4KhkPpyaz3i+Azu EireJzWVjwtZJX7l+gWXQPdneaLQHYBe9YR9QQLP/RrKxtQmcyjdVQwXH+rUiZBL3Vyz gQkZmyD0RBHg/FZPiFkICvDFXVNCxQMCn01bVBGmogApJa5PJhAj9eVIWLBvs2d4aX01 UxaQPdbm1+mauepQi2ipczJdq5waQPjIUal3Phyl4cvFUTvEh+gguGZkpANZgAb5UkDD N/uA== 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=gMEJS25oofGVVCEk04JT4tIJqVKSXCBmSSv8Nyqvu0I=; b=kW881cghIiQ505GdhcIIgefrL9ZT0/bT5kh1/BcR4Fzgk/OkOd5FMWBaL0N3UfZrl1 geTRGdrehdcKiNmK2kc8egbEPfkjZyqJHToEhZ1bSY6W5cd2VMOnS0tp6S66k3JSiXOM fAZ7vRDl4Jf9Kj+FRgXqj/045tYF3hP88jBy3L1iPCrJZvS5SmmTimvXpEWlHWlKhD4g 4HuHaa7QZ3I8s9wlDa8tpUlKtRB2H4TfvfdC4S4ZfHK0oeSbKCHEEG8qUrC8lZA+rkpA osLg25my2c2/UhZGkBYl5W+HdSOXGmp+/2lPhNFz0tjEvHKa6klKeAyBrj82ZktE7358 S7HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fqRZpFvR; 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 18si12053311pgo.331.2018.12.11.04.04.24 for ; Tue, 11 Dec 2018 04:04:24 -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=fqRZpFvR; 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 S1726335AbeLKMEY (ORCPT ); Tue, 11 Dec 2018 07:04:24 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:34519 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbeLKMEX (ORCPT ); Tue, 11 Dec 2018 07:04:23 -0500 Received: by mail-lf1-f66.google.com with SMTP id p6so10594063lfc.1 for ; Tue, 11 Dec 2018 04:04:21 -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=gMEJS25oofGVVCEk04JT4tIJqVKSXCBmSSv8Nyqvu0I=; b=fqRZpFvRDz6JHgeTxykD9e30sqxgCekpW8i6/l9/evkG7SeRoomE7rhTOH18BO/9v9 hTRSyK8GFSj/DuEhqwzbEgPkeblfUcGG29BN3WR/gntXbhlzyQNcozA5eA7yzQtInxjq DVxlgocpPtps4P91il82U4X67OytCYJ2G4ZWo= 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=gMEJS25oofGVVCEk04JT4tIJqVKSXCBmSSv8Nyqvu0I=; b=Ulk5itYpG8y+b1KbZZ8OsekAwTJ7gqtuOEcv7pRO47vj61PHXnTANZK2Db9Hgs6/8V fGjJD3k61zk+K7J9VSWlLoD9FjugloApJ7zjChFHHjEsaZ6knyG6t13Ed5Je/zv8BAOi dON7hz+7CFBwGGF/uEmtm+4H3eK6tW8yvk3DfRf7zA4IQiYWx6gc8yDKZak7i3M8JIbH BCw/74aRBn7qLdyB1QLuojUcwbnVMwJdUE/yOwD3SBUS8YeIbqsyRepozEN1gfGECanf tT9OsxFeqD0Q4dEEKhBO1sSCM/SV7GpowvwI5bphcvZxUBE+8BiNWf/IXOgEkGtg2Dni iCUQ== X-Gm-Message-State: AA+aEWbSZZhliZdiccXVc+kyXhJJwY6Ar0UxPi8rWEG9te/w3IrGHs0R X+/TnGsvZnnl8HR8/BfvMMGjNw== X-Received: by 2002:a19:d145:: with SMTP id i66mr9643838lfg.97.1544529860727; Tue, 11 Dec 2018 04:04:20 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id b69sm2632338lfl.28.2018.12.11.04.04.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Dec 2018 04:04:19 -0800 (PST) From: Linus Walleij To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, Linus Walleij , Florian Fainelli Subject: [PATCH v3] watchdog: mtx-1: Convert to use GPIO descriptor Date: Tue, 11 Dec 2018 13:04:12 +0100 Message-Id: <20181211120412.27773-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org This converts the MTX-1 driver to grab a GPIO descriptor associated with the device instead of using a resource with a global GPIO number. The board using this driver appears to be out-of-tree (OpenWRT), but the users can be easily augmented by adding a machine descriptor table before registering the device. Cc: Florian Fainelli Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Fix to acces .gpiod rather than .gpio - Drop resource assignment in boardfile: no resources left to pass. ChangeLog v1->v2: - Add the correct descriptor table to the board file and register it. I missed the existing board file in the previous iteration. --- arch/mips/alchemy/board-mtx1.c | 18 +++++++++--------- drivers/watchdog/mtx-1_wdt.c | 19 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) -- 2.19.2 Reviewed-by: Florian Fainelli diff --git a/arch/mips/alchemy/board-mtx1.c b/arch/mips/alchemy/board-mtx1.c index d625e6f99ae7..9d9d4ee31605 100644 --- a/arch/mips/alchemy/board-mtx1.c +++ b/arch/mips/alchemy/board-mtx1.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -130,20 +131,18 @@ static struct platform_device mtx1_button = { } }; -static struct resource mtx1_wdt_res[] = { - [0] = { - .start = 215, - .end = 215, - .name = "mtx1-wdt-gpio", - .flags = IORESOURCE_IRQ, - } +static struct gpiod_lookup_table mtx1_wdt_gpio_table = { + .dev_id = "mtx1-wdt.0", + .table = { + /* Global number 215 is offset 15 on Alchemy GPIO 2 */ + GPIO_LOOKUP("alchemy-gpio2", 15, NULL, GPIO_ACTIVE_HIGH), + { }, + }, }; static struct platform_device mtx1_wdt = { .name = "mtx1-wdt", .id = 0, - .num_resources = ARRAY_SIZE(mtx1_wdt_res), - .resource = mtx1_wdt_res, }; static const struct gpio_led default_leds[] = { @@ -310,6 +309,7 @@ static int __init mtx1_register_devices(void) } gpio_direction_input(mtx1_gpio_button[0].gpio); out: + gpiod_add_lookup_table(&mtx1_wdt_gpio_table); return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs)); } arch_initcall(mtx1_register_devices); diff --git a/drivers/watchdog/mtx-1_wdt.c b/drivers/watchdog/mtx-1_wdt.c index 1fa7d2b32494..e028e0a2eca0 100644 --- a/drivers/watchdog/mtx-1_wdt.c +++ b/drivers/watchdog/mtx-1_wdt.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include @@ -55,7 +55,7 @@ static struct { int queue; int default_ticks; unsigned long inuse; - unsigned gpio; + struct gpio_desc *gpiod; unsigned int gstate; } mtx1_wdt_device; @@ -67,7 +67,7 @@ static void mtx1_wdt_trigger(struct timer_list *unused) /* toggle wdt gpio */ mtx1_wdt_device.gstate = !mtx1_wdt_device.gstate; - gpio_set_value(mtx1_wdt_device.gpio, mtx1_wdt_device.gstate); + gpiod_set_value(mtx1_wdt_device.gpiod, mtx1_wdt_device.gstate); if (mtx1_wdt_device.queue && ticks) mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); @@ -90,7 +90,7 @@ static void mtx1_wdt_start(void) if (!mtx1_wdt_device.queue) { mtx1_wdt_device.queue = 1; mtx1_wdt_device.gstate = 1; - gpio_set_value(mtx1_wdt_device.gpio, 1); + gpiod_set_value(mtx1_wdt_device.gpiod, 1); mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); } mtx1_wdt_device.running++; @@ -105,7 +105,7 @@ static int mtx1_wdt_stop(void) if (mtx1_wdt_device.queue) { mtx1_wdt_device.queue = 0; mtx1_wdt_device.gstate = 0; - gpio_set_value(mtx1_wdt_device.gpio, 0); + gpiod_set_value(mtx1_wdt_device.gpiod, 0); } ticks = mtx1_wdt_device.default_ticks; spin_unlock_irqrestore(&mtx1_wdt_device.lock, flags); @@ -198,12 +198,11 @@ static int mtx1_wdt_probe(struct platform_device *pdev) { int ret; - mtx1_wdt_device.gpio = pdev->resource[0].start; - ret = devm_gpio_request_one(&pdev->dev, mtx1_wdt_device.gpio, - GPIOF_OUT_INIT_HIGH, "mtx1-wdt"); - if (ret < 0) { + mtx1_wdt_device.gpiod = devm_gpiod_get(&pdev->dev, + NULL, GPIOD_OUT_HIGH); + if (IS_ERR(mtx1_wdt_device.gpiod)) { dev_err(&pdev->dev, "failed to request gpio"); - return ret; + return PTR_ERR(mtx1_wdt_device.gpiod); } spin_lock_init(&mtx1_wdt_device.lock);