From patchwork Wed Mar 11 10:48:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1252776 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=mLjTv13E; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48cpbT6yfQz9sPF for ; Wed, 11 Mar 2020 21:48:37 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E0F0881333; Wed, 11 Mar 2020 11:48:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="mLjTv13E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 51CDD813AD; Wed, 11 Mar 2020 11:48:33 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 23D5180386 for ; Wed, 11 Mar 2020 11:48:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-wm1-x343.google.com with SMTP id 11so1526408wmo.2 for ; Wed, 11 Mar 2020 03:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JLmhocXYj8KvLiZVZw5+mKyUohDgDiBTODwKt/2hmbc=; b=mLjTv13EhrtSMpR+sps8Rr6XYmvu7yq7qGRbJqzSoLJzon08j6d2YDl0jnsVHkaYY9 ahU2KeLEbS2rIcjGpg/ffb49chrf67JBBcwu+UJ7YnWVIli+1hZsTtPMUn5Ko0erV91K sAXHvKIpcjqymmHADDPFPU+0lbMNw5NXna4mowgtSpgxsZde5GjfZ/wOIO65Y3Tu53yo XnSZ04SvGRX+VQCR+OtXEQk34dXbl06MygNH4U/NN/iyzJhA3PaxuNtYY764LDGI9mT+ DPI8rT6zEN5iXGxHqEmKbSUIDp+Xjt/2G9sohpxVxtHjiWxxNOw6KYAhjokTYSvJ7/Mf l/Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=JLmhocXYj8KvLiZVZw5+mKyUohDgDiBTODwKt/2hmbc=; b=S3ofEZb2bOOXeTiutcRPEdhHO3aD9aQojHX8k8Ibs5gY5YO+unMn9UvWxTHQyOojNn 1KHG672n6nC10nTfPIiel7gdqz41ivynR+Y/GolT/h9lliRg0D4xjXWL6huuU68IGVBy Fn7yQlEnH3Fkq6rag4wfevVc0ncm5JZffuLAtT2V3jsh+dHUAHmfbWWtGPeK3KldgIKL L2+CDUWsbBJ2thXyfpKzYvqRJmVcGKucw9wm6bo2JPGL6TktWHIhN/6bINlQGRV37S7A vJ0P1pITmvNFhub5VwbwZyTpN8RQGSqQJraRXoX5wBeW3RUIZaYkl2ecgefqgw6XTPVz 45wQ== X-Gm-Message-State: ANhLgQ3JKA9DGPEcYA07QdJYltdiOj33Sz7Ci0t0iMKHAuc/cESDENDD zOJghS+EG04Jv1Wk7QRR7zzeAM4qcDiO0g== X-Google-Smtp-Source: ADFU+vsF0i/s+J8uNotd4bJR4W1duXD+9waFmMcSWFUmGBawT5SEjMQt9UkMVglYjdn+JeJShjOlYg== X-Received: by 2002:a1c:9c87:: with SMTP id f129mr3294063wme.26.1583923708316; Wed, 11 Mar 2020 03:48:28 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id l5sm7571595wml.3.2020.03.11.03.48.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 03:48:27 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Ashok Reddy Soma , Alex Nemirovsky , "Andrew F. Davis" , Andy Shevchenko , Bin Meng , Christophe Kerello , Christophe Leroy , Daniel Schwierzeck , Eugeniy Paltsev , Heiko Schocher , Heinrich Schuchardt , Igor Opaniuk , Jagan Teki , Jason Li , Krzysztof Kozlowski , Lokesh Vutla , Marek Vasut , Patrice Chotard , Patrick Delaunay , Prabhakar Kushwaha , Qiang Zhao , Stefan Roese , Suniel Mahesh Subject: [PATCH] versal: watchdog: Add support for Xilinx window watchdog Date: Wed, 11 Mar 2020 11:48:23 +0100 Message-Id: <2204261a8e80503d41bec1b0eb68e00080be5c4c.1583923701.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean From: Ashok Reddy Soma Add support for Xilinx window watchdog, which can be found on Versal platforms. Signed-off-by: Ashok Reddy Soma Signed-off-by: Michal Simek Reviewed-By: Stefan Roese --- MAINTAINERS | 1 + drivers/watchdog/Kconfig | 8 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/xilinx_wwdt.c | 185 +++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 drivers/watchdog/xilinx_wwdt.c diff --git a/MAINTAINERS b/MAINTAINERS index 37ff21a037b4..7cb1bc0957a3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -433,6 +433,7 @@ M: Michal Simek S: Maintained T: git https://gitlab.denx.de/u-boot/custodians/u-boot-microblaze.git F: arch/arm/mach-versal/ +F: drivers/watchdog/xilinx_wwdt.c N: (? + * Ashok Reddy Soma + * + * Copyright (c) 2020, Xilinx Inc. + */ + +#include +#include +#include +#include +#include + +/* Refresh Register Masks */ +#define XWT_WWREF_GWRR_MASK BIT(0) /* Refresh and start new period */ + +/* Generic Control/Status Register Masks */ +#define XWT_WWCSR_GWEN_MASK BIT(0) /* Enable Bit */ + +struct wwdt_regs { + u32 reserved0[1024]; + u32 refresh; /* Refresh Register [0x1000] */ + u32 reserved1[1023]; + u32 csr; /* Control/Status Register [0x2000] */ + u32 reserved2; + u32 offset; /* Offset Register [0x2008] */ + u32 reserved3; + u32 cmp0; /* Compare Value Register0 [0x2010] */ + u32 cmp1; /* Compare Value Register1 [0x2014] */ + u32 reserved4[1006]; + u32 warmrst; /* Warm Reset Register [0x2FD0] */ +}; + +struct xlnx_wwdt_priv { + bool enable_once; + struct wwdt_regs *regs; + struct clk clk; +}; + +struct xlnx_wwdt_platdata { + bool enable_once; + phys_addr_t iobase; +}; + +static int xlnx_wwdt_reset(struct udevice *dev) +{ + struct xlnx_wwdt_priv *wdt = dev_get_priv(dev); + + dev_dbg(dev, "%s ", __func__); + + writel(XWT_WWREF_GWRR_MASK, &wdt->regs->refresh); + + return 0; +} + +static int xlnx_wwdt_stop(struct udevice *dev) +{ + u32 csr; + struct xlnx_wwdt_priv *wdt = dev_get_priv(dev); + + if (wdt->enable_once) { + dev_warn(dev, "Can't stop Xilinx watchdog.\n"); + return -EBUSY; + } + + /* Disable the generic watchdog timer */ + csr = readl(&wdt->regs->csr); + csr &= ~(XWT_WWCSR_GWEN_MASK); + writel(csr, &wdt->regs->csr); + + clk_disable(&wdt->clk); + + dev_dbg(dev, "Watchdog disabled!\n"); + + return 0; +} + +static int xlnx_wwdt_start(struct udevice *dev, u64 timeout, ulong flags) +{ + int ret; + u32 csr; + u64 count; + unsigned long clock_f; + struct xlnx_wwdt_priv *wdt = dev_get_priv(dev); + + dev_dbg(dev, "%s:\n", __func__); + + clock_f = clk_get_rate(&wdt->clk); + if (IS_ERR_VALUE(clock_f)) { + dev_err(dev, "failed to get rate\n"); + return clock_f; + } + + dev_dbg(dev, "%s: CLK %ld\n", __func__, clock_f); + + /* Calculate timeout count */ + count = timeout * clock_f; + + /* clk_enable will return -ENOSYS when it is not implemented */ + ret = clk_enable(&wdt->clk); + if (ret && ret != -ENOSYS) { + dev_err(dev, "failed to enable clock\n"); + return ret; + } + + /* + * Timeout count is half as there are two windows + * first window overflow is ignored (interrupt), + * reset is only generated at second window overflow + */ + count = count >> 1; + + /* Disable the generic watchdog timer */ + csr = readl(&wdt->regs->csr); + csr &= ~(XWT_WWCSR_GWEN_MASK); + writel(csr, &wdt->regs->csr); + + /* Set compare and offset registers for generic watchdog timeout */ + writel((u32)count, &wdt->regs->cmp0); + writel((u32)0, &wdt->regs->cmp1); + writel((u32)count, &wdt->regs->offset); + + /* Enable the generic watchdog timer */ + csr = readl(&wdt->regs->csr); + csr |= (XWT_WWCSR_GWEN_MASK); + writel(csr, &wdt->regs->csr); + + return 0; +} + +static int xlnx_wwdt_probe(struct udevice *dev) +{ + int ret; + struct xlnx_wwdt_platdata *platdata = dev_get_platdata(dev); + struct xlnx_wwdt_priv *wdt = dev_get_priv(dev); + + dev_dbg(dev, "%s: Probing wdt%u\n", __func__, dev->seq); + + wdt->regs = (struct wwdt_regs *)ioremap(platdata->iobase, + sizeof(struct wwdt_regs)); + wdt->enable_once = platdata->enable_once; + + ret = clk_get_by_index(dev, 0, &wdt->clk); + if (ret < 0) + dev_err(dev, "failed to get clock\n"); + + return ret; +} + +static int xlnx_wwdt_ofdata_to_platdata(struct udevice *dev) +{ + struct xlnx_wwdt_platdata *platdata = dev_get_platdata(dev); + + platdata->iobase = dev_read_addr(dev); + platdata->enable_once = dev_read_u32_default(dev, + "xlnx,wdt-enable-once", 0); + dev_dbg(dev, "wdt-enable-once %d\n", platdata->enable_once); + + return 0; +} + +static const struct wdt_ops xlnx_wwdt_ops = { + .start = xlnx_wwdt_start, + .reset = xlnx_wwdt_reset, + .stop = xlnx_wwdt_stop, +}; + +static const struct udevice_id xlnx_wwdt_ids[] = { + { .compatible = "xlnx,versal-wwdt-1.0", }, + {}, +}; + +U_BOOT_DRIVER(xlnx_wwdt) = { + .name = "xlnx_wwdt", + .id = UCLASS_WDT, + .of_match = xlnx_wwdt_ids, + .probe = xlnx_wwdt_probe, + .priv_auto_alloc_size = sizeof(struct xlnx_wwdt_priv), + .platdata_auto_alloc_size = sizeof(struct xlnx_wwdt_platdata), + .ofdata_to_platdata = xlnx_wwdt_ofdata_to_platdata, + .ops = &xlnx_wwdt_ops, +};