From patchwork Sat Nov 7 11:02:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 7575411 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C32989F36A for ; Sat, 7 Nov 2015 11:06:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA018206D2 for ; Sat, 7 Nov 2015 11:06:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D0292206BA for ; Sat, 7 Nov 2015 11:06:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zv1Ik-0000nG-Nw; Sat, 07 Nov 2015 11:04:54 +0000 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zv1Ia-0000ix-AX for linux-arm-kernel@lists.infradead.org; Sat, 07 Nov 2015 11:04:45 +0000 Received: by wicll6 with SMTP id ll6so44091970wic.0 for ; Sat, 07 Nov 2015 03:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ax8MsUjWTDydB5H2GjVp0g2bD06cxBTU5kk9vpLhqq4=; b=0NgagRw7F9sr0UX40OrYZxfaetGR8I6WeW+0AzEUA8fvdZlqRYh6u+ujC9Plbo2q8L vD++Yr1QUE/DdMzNfJc2gPCjcAOwhpKeXsCoYNxJ92/U7ccGPNIJjBKeR2NvRrx7q+gc LYiOM35ibu242kJ2Rv/lBo2ekQDZxa+ecrLUzDGXtwTh2YUOEZBnQ5dCOzAGkvDSeMCj ZOBczsJsyc8Ye3K+JRokGww0pUEJU9P3DBWkJpGDtxHlOBsDj8mB5FbWMRlAm+Opvf+0 LVobSDbtacLN3BmFsmlMGTzdZyzadGYibEnNwDy2hnIVDnEk4tEH/wDpnyne3hWmDF2/ QFhg== X-Received: by 10.194.249.137 with SMTP id yu9mr19418182wjc.108.1446894262062; Sat, 07 Nov 2015 03:04:22 -0800 (PST) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id e63sm3446425wma.7.2015.11.07.03.04.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Nov 2015 03:04:21 -0800 (PST) From: Carlo Caione To: linux@roeck-us.net, wim@iguana.be, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robh+dt@kernel.org, drake@endlessm.com, jerry.cao@amlogic.com, victor.wan@amlogic.com, romain.perier@gmail.com Subject: [PATCH v2 1/4] watchdog: meson: Enable meson SoC specific data Date: Sat, 7 Nov 2015 12:02:16 +0100 Message-Id: <1446894139-6802-2-git-send-email-carlo@caione.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446894139-6802-1-git-send-email-carlo@caione.org> References: <1446894139-6802-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151107_030444_516368_83558E35 X-CRM114-Status: GOOD ( 16.76 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlo Caione MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Carlo Caione With this patch we refactor the driver code to enable watchdog support for all platforms based on Amlogic meson SoCs. Signed-off-by: Carlo Caione --- drivers/watchdog/meson_wdt.c | 56 ++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c index 1f4155e..446af94 100644 --- a/drivers/watchdog/meson_wdt.c +++ b/drivers/watchdog/meson_wdt.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -27,35 +28,47 @@ #define DRV_NAME "meson_wdt" #define MESON_WDT_TC 0x00 -#define MESON_WDT_TC_EN BIT(22) -#define MESON_WDT_TC_TM_MASK 0x3fffff #define MESON_WDT_DC_RESET (3 << 24) #define MESON_WDT_RESET 0x04 -#define MESON_WDT_TIMEOUT 30 +#define MESON_WDT_TIMEOUT 5 #define MESON_WDT_MIN_TIMEOUT 1 -#define MESON_WDT_MAX_TIMEOUT (MESON_WDT_TC_TM_MASK / 100000) -#define MESON_SEC_TO_TC(s) ((s) * 100000) +#define MESON_SEC_TO_TC(s, c) ((s) * (c)) static bool nowayout = WATCHDOG_NOWAYOUT; static unsigned int timeout = MESON_WDT_TIMEOUT; +struct meson_wdt_data { + unsigned int enable; + unsigned int terminal_count_mask; + unsigned int count_unit; +}; + +static struct meson_wdt_data meson6_wdt_data = { + .enable = BIT(22), + .terminal_count_mask = 0x3fffff, + .count_unit = 100000, /* 10 us */ +}; + struct meson_wdt_dev { struct watchdog_device wdt_dev; void __iomem *wdt_base; struct notifier_block restart_handler; + const struct meson_wdt_data *data; }; static int meson_restart_handle(struct notifier_block *this, unsigned long mode, void *cmd) { - u32 tc_reboot = MESON_WDT_DC_RESET | MESON_WDT_TC_EN; + u32 tc_reboot = MESON_WDT_DC_RESET; struct meson_wdt_dev *meson_wdt = container_of(this, struct meson_wdt_dev, restart_handler); + tc_reboot |= meson_wdt->data->enable; + while (1) { writel(tc_reboot, meson_wdt->wdt_base + MESON_WDT_TC); mdelay(5); @@ -80,8 +93,8 @@ static void meson_wdt_change_timeout(struct watchdog_device *wdt_dev, u32 reg; reg = readl(meson_wdt->wdt_base + MESON_WDT_TC); - reg &= ~MESON_WDT_TC_TM_MASK; - reg |= MESON_SEC_TO_TC(timeout); + reg &= ~meson_wdt->data->terminal_count_mask; + reg |= MESON_SEC_TO_TC(timeout, meson_wdt->data->count_unit); writel(reg, meson_wdt->wdt_base + MESON_WDT_TC); } @@ -102,7 +115,7 @@ static int meson_wdt_stop(struct watchdog_device *wdt_dev) u32 reg; reg = readl(meson_wdt->wdt_base + MESON_WDT_TC); - reg &= ~MESON_WDT_TC_EN; + reg &= ~meson_wdt->data->enable; writel(reg, meson_wdt->wdt_base + MESON_WDT_TC); return 0; @@ -117,7 +130,7 @@ static int meson_wdt_start(struct watchdog_device *wdt_dev) meson_wdt_ping(wdt_dev); reg = readl(meson_wdt->wdt_base + MESON_WDT_TC); - reg |= MESON_WDT_TC_EN; + reg |= meson_wdt->data->enable; writel(reg, meson_wdt->wdt_base + MESON_WDT_TC); return 0; @@ -138,10 +151,17 @@ static const struct watchdog_ops meson_wdt_ops = { .set_timeout = meson_wdt_set_timeout, }; +static const struct of_device_id meson_wdt_dt_ids[] = { + { .compatible = "amlogic,meson6-wdt", .data = &meson6_wdt_data }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, meson_wdt_dt_ids); + static int meson_wdt_probe(struct platform_device *pdev) { struct resource *res; struct meson_wdt_dev *meson_wdt; + const struct of_device_id *of_id; int err; meson_wdt = devm_kzalloc(&pdev->dev, sizeof(*meson_wdt), GFP_KERNEL); @@ -153,11 +173,19 @@ static int meson_wdt_probe(struct platform_device *pdev) if (IS_ERR(meson_wdt->wdt_base)) return PTR_ERR(meson_wdt->wdt_base); + of_id = of_match_device(meson_wdt_dt_ids, &pdev->dev); + if (!of_id) { + dev_err(&pdev->dev, "Unable to initialize WDT data\n"); + return -ENODEV; + } + meson_wdt->data = of_id->data; + meson_wdt->wdt_dev.parent = &pdev->dev; meson_wdt->wdt_dev.info = &meson_wdt_info; meson_wdt->wdt_dev.ops = &meson_wdt_ops; meson_wdt->wdt_dev.timeout = MESON_WDT_TIMEOUT; - meson_wdt->wdt_dev.max_timeout = MESON_WDT_MAX_TIMEOUT; + meson_wdt->wdt_dev.max_timeout = + meson_wdt->data->terminal_count_mask / meson_wdt->data->count_unit; meson_wdt->wdt_dev.min_timeout = MESON_WDT_MIN_TIMEOUT; watchdog_set_drvdata(&meson_wdt->wdt_dev, meson_wdt); @@ -204,12 +232,6 @@ static void meson_wdt_shutdown(struct platform_device *pdev) meson_wdt_stop(&meson_wdt->wdt_dev); } -static const struct of_device_id meson_wdt_dt_ids[] = { - { .compatible = "amlogic,meson6-wdt" }, - { /* sentinel */ } -}; -MODULE_DEVICE_TABLE(of, meson_wdt_dt_ids); - static struct platform_driver meson_wdt_driver = { .probe = meson_wdt_probe, .remove = meson_wdt_remove,