From patchwork Mon Aug 28 11:35:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 9925345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8635060329 for ; Mon, 28 Aug 2017 11:36:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A45F205FC for ; Mon, 28 Aug 2017 11:36:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F2062582C; Mon, 28 Aug 2017 11:36:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E95F4205FC for ; Mon, 28 Aug 2017 11:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IUGf4k8GROfYEdRFKkjrDaYx5LxnKsiPwO8az8PWjEg=; b=kBvZDg2nnX7mqs 3mnR6fGhTvLXTHhXUuqweddrRL25271Rv8FkVLVzU9kIGdnssQBGT7vfR0TG7wpKBoXQjwnZbAmXO gusyWR0g44h0aJjfmle9KhUG5JeSZn7FXH+Ird54BcE1nz6VJA3VqUM21int/yQNbPJs94343AXJj BpUZxVtxOXL2xN/Czj4CAHlBkb82NlJXyy0IRaYPvwM44M0M59ousfccjaUluHSsYb1RnDf/3O2zH LKXxs8mh99/0a1KEOb+qvGoTy64ey9Qkaeow+dRIiWnlrgj7I7Yw1Vrg36xshr/BnwIWPh/UaEaAy 559WZkTxRu0IpjGRYObw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dmILO-000732-Uf; Mon, 28 Aug 2017 11:36:38 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dmIKi-0006Wq-VL for linux-arm-kernel@lists.infradead.org; Mon, 28 Aug 2017 11:36:00 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 84DD0AC12; Mon, 28 Aug 2017 11:35:36 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] watchdog: Add Realtek RTD1295 Date: Mon, 28 Aug 2017 13:35:30 +0200 Message-Id: <20170828113532.32627-3-afaerber@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170828113532.32627-1-afaerber@suse.de> References: <20170828113532.32627-1-afaerber@suse.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170828_043557_348449_B0EBB640 X-CRM114-Status: GOOD ( 18.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?=E8=92=8B=E4=B8=BD=E7=90=B4?= , linux-kernel@vger.kernel.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Roc He Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a watchdog driver for the Realtek RTD1295 SoC. Based on QNAP's arch/arm/mach-rtk119x/driver/rtk_watchdog.c code and mach-rtk119x/driver/dc2vo/fpga/include/iso_reg.h register defines. Signed-off-by: Andreas Färber --- drivers/watchdog/Kconfig | 10 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/rtd119x_wdt.c | 152 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 drivers/watchdog/rtd119x_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index c722cbfdc7e6..8fa81518c3fa 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -787,6 +787,16 @@ config UNIPHIER_WATCHDOG To compile this driver as a module, choose M here: the module will be called uniphier_wdt. +config RTD119X_WATCHDOG + bool "Realtek RTD119x/RTD129x watchdog support" + depends on ARCH_REALTEK || COMPILE_TEST + depends on OF + select WATCHDOG_CORE + default ARCH_REALTEK + help + Say Y here to include support for the watchdog timer in + Realtek RTD1295 SoCs. + # AVR32 Architecture config AT32AP700X_WDT diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 56adf9fa67d0..63cb3ed8117d 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -87,6 +87,7 @@ obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o obj-$(CONFIG_UNIPHIER_WATCHDOG) += uniphier_wdt.o +obj-$(CONFIG_RTD119X_WATCHDOG) += rtd119x_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o diff --git a/drivers/watchdog/rtd119x_wdt.c b/drivers/watchdog/rtd119x_wdt.c new file mode 100644 index 000000000000..1bd2e86509a7 --- /dev/null +++ b/drivers/watchdog/rtd119x_wdt.c @@ -0,0 +1,152 @@ +/* + * Realtek RTD129x watchdog + * + * Copyright (c) 2017 Andreas Färber + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include + +#define RTD_TCWCR 0x0 +#define RTD_TCWTR 0x4 +#define RTD_TCWOV 0xc + +#define RTD_TCWCR_WDEN_DISABLED 0xa5 +#define RTD_TCWCR_WDEN_ENABLED 0xff +#define RTD_TCWCR_WDEN_MASK 0xff + +#define RTD_TCWTR_WDCLR BIT(0) + +struct rtd119x_watchdog_device { + struct watchdog_device wdt_dev; + void __iomem *base; + struct clk *clk; +}; + +static int rtd119x_wdt_start(struct watchdog_device *wdev) +{ + struct rtd119x_watchdog_device *data = watchdog_get_drvdata(wdev); + u32 val; + + val = readl_relaxed(data->base + RTD_TCWCR); + val &= ~RTD_TCWCR_WDEN_MASK; + val |= RTD_TCWCR_WDEN_ENABLED; + writel(val, data->base + RTD_TCWCR); + + return 0; +} + +static int rtd119x_wdt_stop(struct watchdog_device *wdev) +{ + struct rtd119x_watchdog_device *data = watchdog_get_drvdata(wdev); + u32 val; + + val = readl_relaxed(data->base + RTD_TCWCR); + val &= ~RTD_TCWCR_WDEN_MASK; + val |= RTD_TCWCR_WDEN_DISABLED; + writel(val, data->base + RTD_TCWCR); + + return 0; +} + +static int rtd119x_wdt_ping(struct watchdog_device *wdev) +{ + struct rtd119x_watchdog_device *data = watchdog_get_drvdata(wdev); + + writel_relaxed(RTD_TCWTR_WDCLR, data->base + RTD_TCWTR); + + return rtd119x_wdt_start(wdev); +} + +static int rtd119x_wdt_set_timeout(struct watchdog_device *wdev, unsigned int val) +{ + struct rtd119x_watchdog_device *data = watchdog_get_drvdata(wdev); + + writel(val * 27000000, data->base + RTD_TCWOV); + + return 0; +} + +static const struct watchdog_ops rtd119x_wdt_ops = { + .owner = THIS_MODULE, + .start = rtd119x_wdt_start, + .stop = rtd119x_wdt_stop, + .ping = rtd119x_wdt_ping, + .set_timeout = rtd119x_wdt_set_timeout, +}; + +static const struct watchdog_info rtd119x_wdt_info = { + .identity = "rtd119x-wdt", + .options = 0, +}; + +static const struct of_device_id rtd_wdt_dt_ids[] = { + { .compatible = "realtek,rtd1295-watchdog" }, + { } +}; + +static int rtd_wdt_probe(struct platform_device *pdev) +{ + struct rtd119x_watchdog_device *data; + struct resource *res; + int ret; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(data->base)) + return PTR_ERR(data->base); + + data->clk = of_clk_get(pdev->dev.of_node, 0); + if (IS_ERR(data->clk)) + return PTR_ERR(data->clk); + + ret = clk_prepare_enable(data->clk); + if (ret) { + clk_put(data->clk); + return ret; + } + + data->wdt_dev.info = &rtd119x_wdt_info; + data->wdt_dev.ops = &rtd119x_wdt_ops; + data->wdt_dev.timeout = 120; + data->wdt_dev.max_timeout = 0xffffffff / clk_get_rate(data->clk); + data->wdt_dev.min_timeout = 1; + data->wdt_dev.parent = &pdev->dev; + + watchdog_stop_on_reboot(&data->wdt_dev); + watchdog_set_drvdata(&data->wdt_dev, data); + platform_set_drvdata(pdev, data); + + writel_relaxed(RTD_TCWTR_WDCLR, data->base + RTD_TCWTR); + rtd119x_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout); + rtd119x_wdt_stop(&data->wdt_dev); + + ret = devm_watchdog_register_device(&pdev->dev, &data->wdt_dev); + if (ret) { + clk_disable_unprepare(data->clk); + clk_put(data->clk); + return ret; + } + + return 0; +} + +static struct platform_driver rtd_wdt_driver = { + .probe = rtd_wdt_probe, + .driver = { + .name = "rtd1295-watchdog", + .of_match_table = rtd_wdt_dt_ids, + }, +}; +builtin_platform_driver(rtd_wdt_driver);