From patchwork Sun Nov 8 12:18:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 7578231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 16993C05C6 for ; Sun, 8 Nov 2015 12:22:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C98A20546 for ; Sun, 8 Nov 2015 12:22:17 +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 2CDE12053B for ; Sun, 8 Nov 2015 12:22:16 +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 1ZvOwh-0003ei-Jk; Sun, 08 Nov 2015 12:19:43 +0000 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZvOwP-0003aZ-07 for linux-arm-kernel@lists.infradead.org; Sun, 08 Nov 2015 12:19:26 +0000 Received: by wiby19 with SMTP id y19so3481283wib.0 for ; Sun, 08 Nov 2015 04:19:02 -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=84JCtZBDcIPWlxxg4oiEYvb8rC7tAtqpHXtsE9J0Y8Q=; b=V5WOd+XXcqZQZUjyrYn79YkQDt33O2XZvJxoUfem5m0O2xLaqBm2JwNLMAig8Kb4VW kjxcWt8s07W1wab3C9lCX8AC5JYitiXRk5ODVGQNxIBcBF5xXNZX/5XVCzvkod7XnHgi KZQ4M1YIfrt5Ta4SyZFarC5jCl6lHatfYJqac3jv2vf9DXrWsQpUWjId1MZ3rctdZbVm QBW2Qt1387CvfJmWK+k2qUrrmqiuSIDhKHPawQfJsf075DStPLJas7bfCxTV/qkaOhbV lYGyjM5hKvuqB93o6lQQd4VSC7YxJy7+XQgKh0pBUBByvG17R2UfFQsMaBDeAp6EHF+m uEhw== X-Received: by 10.194.159.100 with SMTP id xb4mr24090218wjb.136.1446985142301; Sun, 08 Nov 2015 04:19:02 -0800 (PST) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id hu2sm9762060wjb.21.2015.11.08.04.19.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Nov 2015 04:19:01 -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 v3 1/4] watchdog: meson: Enable meson SoC specific data Date: Sun, 8 Nov 2015 13:18:54 +0100 Message-Id: <1446985137-25498-2-git-send-email-carlo@caione.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446985137-25498-1-git-send-email-carlo@caione.org> References: <1446985137-25498-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151108_041925_295278_AF8B9533 X-CRM114-Status: GOOD ( 17.95 ) 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. The new default timeout is also now chosen considering the maximum timeout allowed by the SoC. Signed-off-by: Carlo Caione Reviewed-by: Guenter Roeck --- drivers/watchdog/meson_wdt.c | 58 +++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c index 1f4155e..89734f0 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_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,12 +173,22 @@ 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; + meson_wdt->wdt_dev.timeout = min_t(unsigned int, + MESON_WDT_TIMEOUT, + meson_wdt->wdt_dev.max_timeout); watchdog_set_drvdata(&meson_wdt->wdt_dev, meson_wdt); @@ -204,12 +234,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,