From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 096BCC4338F for ; Wed, 11 Aug 2021 12:50:29 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17DE76056C for ; Wed, 11 Aug 2021 12:50:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 17DE76056C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=prevas.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D514C82E85; Wed, 11 Aug 2021 14:49:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="MLhIKPS+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F4FD82DF1; Wed, 11 Aug 2021 14:48:43 +0200 (CEST) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03on0702.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe09::702]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0B6BC82DD9 for ; Wed, 11 Aug 2021 14:48:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=He3zGuLmkbbIaNeSXi21660lr1Bt6vDoT4R4BlGgA6zl42kBqwDwP4pvBMBBHjkr77k4q95HOjHcE0mmfXMv5ZTozvGxrcvJdDZRwaRwqHf7g8YZ3vreyNatxPph6ILqJNOjFliedZCO7HCywZ75a6XGB37VLW0rDxk7m6MMaSsuMqnP8JGG7gG3ql5pNOo01T7hMgRGdyiEQcZ1A75Z80dLQ/OZaJAt/EVhmHnz03zfSJ2oHCdhkLBQLBzVayRQN4/jqDbnq8QECa3b/QiQ3w2oLFl/dyLiV/ZmLh+BYlHxDy5kNdSKWLgEAmw0JEQHSJSUYHCtB7kuLfaeooZmzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wVHtMlh6BnVxk0kZ3R9jr8TMp7CoyIL9ebyTI90EULM=; b=M5me1PtZYPe7Ivk5blhpXGwrIVTkssMqtGHEGQjpAFBMoXuBEBTp55odJWquTjlJvxryfMZ316C0bR0zMCBGci53lRfOSEV7Wzu9oEJZGswHOx0CFDYFaJfMcZ23EEWkqdHxZe7jRQ/E+VXIHNdw5v09i9wOZZ5ri2TdAHjijLF8g4ZU83c9Jl6DEKAXcynPCDNOPPrmZZ3ZVUw4bOQuVYHGJiwEnCPoDTCY7cBm8fF3vRD3yrMmyyBCiGMOKZnCJEtsjA+s4qNqhbjouWYZKqWmHieKfc6OCJPoXAU1vkHdCqVk4/JMb7mZL3JwY0cQHPWtReaxnirKFOJF7gnX1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wVHtMlh6BnVxk0kZ3R9jr8TMp7CoyIL9ebyTI90EULM=; b=MLhIKPS+yKT0T7XQWPyYXdzkfq7DcqFQZd+5hmJ0s37BLaaEbqxmiKruAUmCJQmHOFsIaNqKLb3GtIfqHIahSKrQHkPjsgG6Bk5HFKAVWrkw/MrMhJ3QEldzOgT2rpLS0Z+IhVZGezUHYeio2jDb/1em/qgrJZ4uZOpvCDZKa4w= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM9PR10MB4561.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:265::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.15; Wed, 11 Aug 2021 12:48:17 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::fc83:36a5:db02:3dbb]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::fc83:36a5:db02:3dbb%7]) with mapi id 15.20.4394.025; Wed, 11 Aug 2021 12:48:17 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Stefan Roese , Tom Rini , Rasmus Villemoes Subject: [PATCH v5 10/12] watchdog: add gpio watchdog driver Date: Wed, 11 Aug 2021 14:47:58 +0200 Message-Id: <20210811124800.2593226-11-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210811124800.2593226-1-rasmus.villemoes@prevas.dk> References: <20210811124800.2593226-1-rasmus.villemoes@prevas.dk> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: HE1P190CA0049.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::38) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (81.216.59.226) by HE1P190CA0049.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.15 via Frontend Transport; Wed, 11 Aug 2021 12:48:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78858621-93f2-4ca7-bc50-08d95cc64a42 X-MS-TrafficTypeDiagnostic: AM9PR10MB4561: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T4APQ/WGLeuJBwmMDALD9/kiYon8v/ays5uW1yipufo/+H0C8+kNzoPWaFvgxGrwexS52GVp/NnYZdM2+Dcsp2NPzQRb66zS+nNlvjaqYInhVMo01OH3PsZGn+0Gfv/nSdr8adUIMrLOjATlj9NetkUAvHQsTMSmyNdaY6o+sDVl3E3kggSkuoDgr0Ae/hNUwkgAovNsSjxvsldzQGChbyC10o25BU6ImyVn76jVjhQPxZvw2pAZYlEn8edJ0IKJlBFxkX1fYdCoshfMep9v6SzNT/cWy7g+sR5SUTRNcEuwTVMe70AdpqL5dSmxJD6aXUh/2RE/6Te7LlHIYk9tSDgTCIqdxAijAyv+3Gggyi+jHIpr8XJDb3v+Sfh3AVz5yjixLxcIdsgp7bEuLoedEc4kPLNxHeRE1TejWM//b3i2gBeKdW1Mnng2RzZ7kpTWeCCzaC766bXaAzr6z+0MzQ1zlI2xVWbqw8K+Ykvs545nFGu2WJnqbmxuJRROs+bGGlktddAF6SEAgC1UraEFrIZv3w1M67oBEJ3LPsFmoMC0AV/DL6LFHfSCZUcoSazmroWbS/OWHREM4LdLFEezLxpO0z76qyWF9SmCzRPpVwk3oArPGAPTtXiNlD8pjQafoz0lkQoB8kQwr8rSUnJu8o9mYPt1uorCUX4GyCLc/yVEYszGxrdFnrQrWiKA6uiuCeTj4oVs/F2fe35Zip5ZLoXJtgwKXnIXkcGOTM9FDSmK2mQTddud8+jSkhAxVCTgPeGY61YF/WNSTzIuURW+jlwTVAJDJBJPf8xKdVJlLdE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(136003)(376002)(346002)(39850400004)(396003)(366004)(186003)(44832011)(478600001)(316002)(26005)(8676002)(4326008)(36756003)(6666004)(6506007)(54906003)(1076003)(52116002)(86362001)(83380400001)(966005)(107886003)(2616005)(956004)(2906002)(6916009)(38350700002)(38100700002)(8976002)(8936002)(6512007)(66946007)(5660300002)(6486002)(66476007)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?lnmq38r37DUiqhi4jNo0USZPVeBG7/ZcHDBYdzm1guzY+eIC/NXzaxqClFDr?= =?us-ascii?Q?lCa+cLhyjy+bKz7dUlcX0oIKAPjGJ5Qbkj4xOwbk9Gbmzmf1L2E4WyiJiSEe?= =?us-ascii?Q?KJjeaWHRo+ajj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RbwdSLFkbDdxfVemEUAD?= =?us-ascii?Q?bF7Ga13oW3mI5gb6pEvnomlPQWDsFeyQHIZmMECymWV+Y+Nw19K2FyPoDrBK?= =?us-ascii?Q?54/7+kaE+1b3fjRYvjVZIvRyUIzsoiwsDkqMRXCLzDOy3cPfNM02agHQxfpa?= =?us-ascii?Q?s/3WnWDTCRYlkr/79T/oM9p5Zz8y51QCRUrHsUwyLP31WVXtYdIluhHHAZOo?= =?us-ascii?Q?jDrJ9kzXV9eEVyXWPdMKzubHKobbDHDrivaNMQYl6PLOYYb/+1+Ifs8jpNPU?= =?us-ascii?Q?ASe00SanLTkwmCNQbxOZz9RKz1O4yKJ9Ao51uOeILieIW7eHqBBgl3I2ZlXg?= =?us-ascii?Q?uqV3tBHKdnl12IJNm5fnf6wZ?= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 78858621-93f2-4ca7-bc50-08d95cc64a42 X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2021 12:48:17.0112 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xp0WAH/0s+sLBLV5jx0fwE6B4lVR8U8IX2gjg3gwDscO9nyrVJqDiJOz7JWSt8ilF2BxAEaC1SjUr+qm0J4G78MdXc5tLSQKZDXlEUBEOmc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR10MB4561 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean A rather common kind of external watchdog circuit is one that is kept alive by toggling a gpio. Add a driver for handling such a watchdog. The corresponding linux driver apparently has support for some watchdog circuits which can be disabled by tri-stating the gpio, but I have never actually encountered such a chip in the wild; the whole point of adding an external watchdog is usually that it is not in any way under software control. For forward-compatibility, and to make DT describe the hardware, the current driver only supports devices that have the always-running property. I went a little back and forth on whether I should fail ->probe or only ->start, and ended up deciding ->start was the right place. The compatible string is probably a little odd as it has nothing to do with linux per se - however, I chose that to make .dts snippets reusable between device trees used with U-Boot and linux, and this is the (only) compatible string that linux' corresponding driver and DT binding accepts. I have asked whether one should/could add "wdt-gpio" to that binding, but the answer was no: https://lore.kernel.org/lkml/CAL_JsqKEGaFpiFV_oAtE+S_bnHkg4qry+bhx2EDs=NSbVf_giA@mail.gmail.com/ If someone feels strongly about this, I can certainly remove the "linux," part from the string - it probably wouldn't the only place where one can't reuse a DT snippet as-is between linux and U-Boot. Reviewed-by: Simon Glass Reviewed-by: Stefan Roese Signed-off-by: Rasmus Villemoes --- .../watchdog/gpio-wdt.txt | 19 ++++++ drivers/watchdog/Kconfig | 9 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/gpio_wdt.c | 68 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/gpio-wdt.txt create mode 100644 drivers/watchdog/gpio_wdt.c diff --git a/doc/device-tree-bindings/watchdog/gpio-wdt.txt b/doc/device-tree-bindings/watchdog/gpio-wdt.txt new file mode 100644 index 0000000000..c9a8559a3e --- /dev/null +++ b/doc/device-tree-bindings/watchdog/gpio-wdt.txt @@ -0,0 +1,19 @@ +GPIO watchdog timer + +Describes a simple watchdog timer which is reset by toggling a gpio. + +Required properties: + +- compatible: Must be "linux,wdt-gpio". +- gpios: gpio to toggle when wdt driver reset method is called. +- always-running: Boolean property indicating that the watchdog cannot + be disabled. At present, U-Boot only supports this kind of GPIO + watchdog. + +Example: + + gpio-wdt { + gpios = <&gpio0 1 0>; + compatible = "linux,wdt-gpio"; + always-running; + }; diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index f0ff2612a6..6fbb5c1b6d 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -147,6 +147,15 @@ config WDT_CORTINA This driver support all CPU ISAs supported by Cortina Access CAxxxx SoCs. +config WDT_GPIO + bool "External gpio watchdog support" + depends on WDT + depends on DM_GPIO + help + Support for external watchdog fed by toggling a gpio. See + doc/device-tree-bindings/watchdog/gpio-wdt.txt for + information on how to describe the watchdog in device tree. + config WDT_MPC8xx bool "MPC8xx watchdog timer support" depends on WDT && MPC8xx diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 5c7ef593fe..f14415bb8e 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o +obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c new file mode 100644 index 0000000000..982a66b3f9 --- /dev/null +++ b/drivers/watchdog/gpio_wdt.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include + +struct gpio_wdt_priv { + struct gpio_desc gpio; + bool always_running; + int state; +}; + +static int gpio_wdt_reset(struct udevice *dev) +{ + struct gpio_wdt_priv *priv = dev_get_priv(dev); + + priv->state = !priv->state; + + return dm_gpio_set_value(&priv->gpio, priv->state); +} + +static int gpio_wdt_start(struct udevice *dev, u64 timeout, ulong flags) +{ + struct gpio_wdt_priv *priv = dev_get_priv(dev); + + if (priv->always_running) + return 0; + + return -ENOSYS; +} + +static int dm_probe(struct udevice *dev) +{ + struct gpio_wdt_priv *priv = dev_get_priv(dev); + int ret; + + priv->always_running = dev_read_bool(dev, "always-running"); + ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT); + if (ret < 0) { + dev_err(dev, "Request for wdt gpio failed: %d\n", ret); + return ret; + } + + if (priv->always_running) + ret = gpio_wdt_reset(dev); + + return ret; +} + +static const struct wdt_ops gpio_wdt_ops = { + .start = gpio_wdt_start, + .reset = gpio_wdt_reset, +}; + +static const struct udevice_id gpio_wdt_ids[] = { + { .compatible = "linux,wdt-gpio" }, + {} +}; + +U_BOOT_DRIVER(wdt_gpio) = { + .name = "wdt_gpio", + .id = UCLASS_WDT, + .of_match = gpio_wdt_ids, + .ops = &gpio_wdt_ops, + .probe = dm_probe, + .priv_auto = sizeof(struct gpio_wdt_priv), +}; -- 2.31.1