From patchwork Fri Nov 6 21:55:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 7573641 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 2F11A9F2F7 for ; Fri, 6 Nov 2015 21:57:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29FB7206FA for ; Fri, 6 Nov 2015 21:57:30 +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 3F886206F9 for ; Fri, 6 Nov 2015 21:57:29 +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 1ZuozB-0006i7-KA; Fri, 06 Nov 2015 21:55:53 +0000 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zuoyw-0006Az-JO for linux-arm-kernel@lists.infradead.org; Fri, 06 Nov 2015 21:55:39 +0000 Received: by wikq8 with SMTP id q8so38237811wik.1 for ; Fri, 06 Nov 2015 13:55:16 -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=SHsxdmrTe/9dM/6B6UMjur1cewiRkJQTif4bPUqKU2Q=; b=kDfUKa0CrtM3PLRnEkUhXbaROQcbFv8G7xTrgfueQgzVSTSBFdagW/jGk7Fv2tsYY4 EBy2mj1PVwRJHErBnB8H+cOQfNqsjS/hhSeXb3eLqz2O//OTA/y4rM2s3X+qymq3B6sc gAQ7ABJSFfkam0LLEj8eE2FaSLocvRbakdFT/jVn3W7nvW0fmTsz8KJr5MMkBsz3+jzL Uydtb6k1rD2t+08g1675deKVj0PSr64PujJw9Z1VyZ6ZUCT6Aa+pVrr407KdVfy1Cr4y 9roWo/RlDV5PEi4iMYnsoMxfA67bIDiDHnMu8LX7OWjUaUQeLXFO34d49wTw9lJSQPfD fGIQ== X-Received: by 10.194.188.112 with SMTP id fz16mr2840170wjc.65.1446846916574; Fri, 06 Nov 2015 13:55:16 -0800 (PST) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id q125sm928468wmd.5.2015.11.06.13.55.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Nov 2015 13:55:15 -0800 (PST) From: Carlo Caione To: 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 1/4] watchdog: meson: Enable meson SoC specific data Date: Fri, 6 Nov 2015 22:55:03 +0100 Message-Id: <1446846906-31520-2-git-send-email-carlo@caione.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446846906-31520-1-git-send-email-carlo@caione.org> References: <1446846906-31520-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151106_135538_956770_683A6F35 X-CRM114-Status: GOOD ( 18.03 ) 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 | 55 ++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c index 1f4155e..89944ed 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,34 +28,45 @@ #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 shift_enable; + unsigned int terminal_count_mask; + unsigned int count_unit; +}; + +static struct meson_wdt_data meson6_wdt_data = { + .shift_enable = 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; + 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 |= BIT(meson_wdt->data->shift_enable); while (1) { writel(tc_reboot, meson_wdt->wdt_base + MESON_WDT_TC); @@ -80,8 +92,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 +114,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 &= ~BIT(meson_wdt->data->shift_enable); writel(reg, meson_wdt->wdt_base + MESON_WDT_TC); return 0; @@ -117,7 +129,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 |= BIT(meson_wdt->data->shift_enable); writel(reg, meson_wdt->wdt_base + MESON_WDT_TC); return 0; @@ -138,10 +150,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 +172,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 setup WDT data\n"); + return -ENODEV; + } + meson_wdt->data = (struct 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 +231,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,