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: 111149 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4705976qge; Mon, 28 Aug 2017 04:36:20 -0700 (PDT) X-Received: by 10.99.139.65 with SMTP id j62mr214001pge.277.1503920180370; Mon, 28 Aug 2017 04:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503920180; cv=none; d=google.com; s=arc-20160816; b=bqm6b6h5sHbr2ALxGK6TR4h26NfcUUlgJWw5+s/JAplUBkojxImcBc9iYGjbY0I6Vx Gz4uEhz1iCdu09fl69C2tTccTrYKVkpTp9ihWGZq5v8xFl2tbdf3JqdnePPAL86YV55r a/RXJMKRMzDOK5HN3t37o+lmZKbHmV9BSdSF3RjpwNYXMfGUtcSrmGPaHm7OQb2DkJ/T I8Lg+5txcL3QCW+w9iVQ8mNY5Tm+4rw6FLRDgNzkCHDWTRIRZMZrvCIZ80tVCxoTli7H wkOl8iUdU/oXFUJLw4oXvROVCoISgSPky/cHnGnXE+HEl29ALrVpCPSevM6iCcFVVkoX 1LGA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=G5w9haPbNpdswypg5fK4txwyGgFVMLRlfsGjCOk5A4g=; b=NRDvQlFsfB1kXQB9B0bIbVp93STihjyFqwq6akrX1e65yaBa6zAvBhpOexyPVgJ73S BKNHVrSdBb+QSvHwXyt6d/h6XcWaWECslMr+sHx844WOOLBafVNSXp4B2tk2MrZyRuxk jDXjh2HrWIp4weTdnVA2Q4bIQVxKXGrYLKgoydiNVqauKOPwcx89fewz1zHN3EE4qq4F vCrn1fxqGZp99Dhr0KGZpZCwaHzZO5rg8aULh2nfkSBAKqq8/b4WgpTUM7wYTCUJP9cU g2voLi+HAcbn04IeEoEZs9/0C8dz9BcrazLa4lwH8r5wKZfPKFQFWVsWyhh5doOwRLr/ usBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h191si113494pgc.612.2017.08.28.04.36.20; Mon, 28 Aug 2017 04:36:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751596AbdH1LgS (ORCPT + 26 others); Mon, 28 Aug 2017 07:36:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:42444 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751499AbdH1Lfi (ORCPT ); Mon, 28 Aug 2017 07:35:38 -0400 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_F=C3=A4rber?= To: Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Roc He , =?utf-8?b?6JKL?= =?utf-8?b?5Li955C0?= , =?utf-8?q?Andreas_F=C3=A4rber?= 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.12.3 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); From patchwork Mon Aug 28 11:35:31 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: 111148 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4705375qge; Mon, 28 Aug 2017 04:35:47 -0700 (PDT) X-Received: by 10.99.125.84 with SMTP id m20mr215366pgn.169.1503920147386; Mon, 28 Aug 2017 04:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503920147; cv=none; d=google.com; s=arc-20160816; b=NW4rjz5LKS+x4GXA6/bxhsOmqyCPFVHWQKkqPGKKWe7aFuE6bprNcWKodQs2as/4gF Sz/n6xJEVgFcUSnW4SoRPVWNuV5twNbV9tLMl1gycy0Hr5MZeHvgu2ozV+qwMQFJi3UN hw1uRaWlCdJvdS+WWV5xPl0iYfsIs6O6yXniV26Wv9ag9oUDS53BR84VDzrE9N4w/QWe gIpSsJzWOJzpWQuFEdqwZ6EQ+8d3QIklhsEl9MXouAbx8t3MYcYxYyvn2dkBui2SA/F8 kyLBlJNI/L/D7EIiad4RzM6Doy83AWzh/S53251P0dFFuS9Lj0jPuK9cOouesFqBNb4f kybQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hIP+WzdnyL3tLuPfcDRJi+zRDHNOXuMCN+hByWPJlVg=; b=IkZQRbJ2VjkKsDDPetT6coaCSnTJLpI7rUmJJZ9fvixAvWoWG1NHruiZf4+ERtjqaO FHOpg7TWipPNNg7DEp8c5ukW8UIlNNBh/k72SW3f4qYH+bnXHacehSf3biQkDecfIT0E sGiWxdwgNHKj4XU14tCtURVuoCjJLMx5Uh09k4DqD4csWzZcGEnVavDEl0ZxVkNyxn1y /WhO125gQ0rtvxGbOXS0tWGv9DpPbWfAZ1sffBCl/hULkApL5hr3LBgtkdmlChUOAXbQ eCj2C9rOpWogfsLH/lsczMD16b2FYQXerJ9BqSbvyS369D21bc4KRx0cIKCFHjn1+cKX AnrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si125247pfk.462.2017.08.28.04.35.47; Mon, 28 Aug 2017 04:35:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751829AbdH1Lfn (ORCPT + 26 others); Mon, 28 Aug 2017 07:35:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:42454 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751750AbdH1Lfj (ORCPT ); Mon, 28 Aug 2017 07:35:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 50821AC15; Mon, 28 Aug 2017 11:35:37 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Roc He , =?utf-8?b?6JKL?= =?utf-8?b?5Li955C0?= , =?utf-8?q?Andreas_F=C3=A4rber?= , Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , devicetree@vger.kernel.org Subject: [PATCH 3/3] arm64: dts: realtek: Add watchdog node for RTD1295 Date: Mon, 28 Aug 2017 13:35:31 +0200 Message-Id: <20170828113532.32627-4-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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the watchdog node to the RTD1295 Device Tree. Signed-off-by: Andreas Färber --- Depends on the pending clock nodes patch. arch/arm64/boot/dts/realtek/rtd1295.dtsi | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.12.3 diff --git a/arch/arm64/boot/dts/realtek/rtd1295.dtsi b/arch/arm64/boot/dts/realtek/rtd1295.dtsi index fbbd6456079e..f39ab63f879d 100644 --- a/arch/arm64/boot/dts/realtek/rtd1295.dtsi +++ b/arch/arm64/boot/dts/realtek/rtd1295.dtsi @@ -123,6 +123,12 @@ #interrupt-cells = <1>; }; + watchdog@98007680 { + compatible = "realtek,rtd1295-watchdog"; + reg = <0x98007680 0x100>; + clocks = <&osc27M>; + }; + uart0: serial@98007800 { compatible = "snps,dw-apb-uart"; reg = <0x98007800 0x400>;