From patchwork Wed Mar 6 01:06:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10840275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CECF180E for ; Wed, 6 Mar 2019 01:06:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4845B2C747 for ; Wed, 6 Mar 2019 01:06:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C1472D01A; Wed, 6 Mar 2019 01:06:26 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 640A42C747 for ; Wed, 6 Mar 2019 01:06:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbfCFBGY (ORCPT ); Tue, 5 Mar 2019 20:06:24 -0500 Received: from mail-eopbgr30053.outbound.protection.outlook.com ([40.107.3.53]:7087 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726069AbfCFBGY (ORCPT ); Tue, 5 Mar 2019 20:06:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lstlvRVFaNybFNYyRP0/WcidFtx3xmweWnbVkiSHfUA=; b=E1spJU6cFror6/LXSesMgz2se1KaNN24aXCNZWBDa3+JNDUlDnP/8TYJ3LIvcp8wMPQVG2I0+6YzBc8aOqPFgORB/bbkkmS3nOh2CRDQK4qsobl/FX4zVHLPDy8IPOkFzwYTJha02tyn083yF3BvP7O/4o+3DDAtuQDfj8Oqq6Q= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3723.eurprd04.prod.outlook.com (52.134.72.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.17; Wed, 6 Mar 2019 01:06:18 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::1cb4:3e1c:fc85:7ed7]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::1cb4:3e1c:fc85:7ed7%2]) with mapi id 15.20.1686.016; Wed, 6 Mar 2019 01:06:18 +0000 From: Anson Huang To: "catalin.marinas@arm.com" , "will.deacon@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "wim@linux-watchdog.org" , "linux@roeck-us.net" , Andy Gross , "heiko@sntech.de" , "horms+renesas@verge.net.au" , "arnd@arndb.de" , "maxime.ripard@bootlin.com" , "jagan@amarulasolutions.com" , "bjorn.andersson@linaro.org" , "enric.balletbo@collabora.com" , "marc.w.gonzalez@free.fr" , "olof@lixom.net" , Aisheng Dong , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-watchdog@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH V7 1/3] watchdog: imx_sc: Add i.MX system controller watchdog support Thread-Topic: [PATCH V7 1/3] watchdog: imx_sc: Add i.MX system controller watchdog support Thread-Index: AQHU07jNtorBWhAbJkylCtaCxH6iDA== Date: Wed, 6 Mar 2019 01:06:17 +0000 Message-ID: <1551834095-19950-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK2PR0302CA0006.apcprd03.prod.outlook.com (2603:1096:202::16) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 610a886a-ed35-406c-a46d-08d6a1cfefea x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:DB3PR0402MB3723; x-ms-traffictypediagnostic: DB3PR0402MB3723: x-ld-processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr x-microsoft-exchange-diagnostics: =?iso-8859-1?q?1=3BDB3PR0402MB3723=3B23=3A?= =?iso-8859-1?q?/Zsl+xT7jTwfVfI5wsL0ncHdtqinoEDdxxtqReolxsM15JtNZEQ0kbFQd0U4?= =?iso-8859-1?q?ryPJuuUEBzWeb7s2WDY6H+f9mHFMbVtCrgtf8Q6fvV3mB7CMNwhPZ0CKXSjY?= =?iso-8859-1?q?LeVk8aHXu80jE1ZsbQNGJa+wYokbVv6Bacq7QMxSOJEiQqW8L4TfiC6M1gwG?= =?iso-8859-1?q?SAVLVYZD89FZtm/l7Y8UlOaWT7L+HHc/RYodo7Hg/xiaa3EP6qSZLhXK6fiY?= =?iso-8859-1?q?zcabhIT/Y4oaXhWULfXt/6/IUZxX7hU/HqPokyBa7MYXs52S1LiNK+UStjlD?= =?iso-8859-1?q?cZzmEj6Q117ytjthTfUDLJ0RhW2jpCcPEKtvLkCQ/cEGDveI0emZG9u/G/wG?= =?iso-8859-1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Xjkb4md4B76YZasT/8GzqsX/9Y9A=3D=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 0968D37274 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(396003)(136003)(346002)(376002)(39860400002)(189003)(199004)(36756003)(68736007)(71190400001)(14444005)(71200400001)(86362001)(256004)(2906002)(110136005)(316002)(105586002)(106356001)(6436002)(2501003)(6512007)(7736002)(305945005)(2201001)(6486002)(53936002)(478600001)(8936002)(7416002)(476003)(2616005)(486006)(4326008)(14454004)(81156014)(5660300002)(3846002)(6116002)(25786009)(81166006)(8676002)(50226002)(52116002)(6506007)(99286004)(386003)(26005)(66066001)(102836004)(97736004)(186003)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3723;H:DB3PR0402MB3916.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: HodDSv+kuRYCdITK21gNj2GVqiR59iaH5YPkI2wR3OfuxIcmLHoXrx7MczlRLkshpLD83pk7XhFpSYUnHSOFiTiSCwfJp2zDF/WhuDcwBGFkgLY/zTYpp6r4y5tj1iqKCGZa0dXdQnyre9OqpRfRvxbmr3uxeycsWgVTxLby/J88tk//o3Vuc1icCWNIKzTUgQMVYaSstMo5Nh3xCvH2jqdTU4PkqmUYrXzWwlOzbw1RJPU6Oq+RipGZHdUcOCDtkEenfgArckG8ERO9YZlh0LmjApIUXoMSj4tw0FAyYAmQLu/uu1KMr1O1UL/66+Gc1yYP3ESiRDK5zYjDFcrJosAWnl4OvpQQbnJf4hD3FC93xfRZ7iElOZPXgUIgQU5TBjtdzebNRF6itfwKylSOXy7/wFt8ilrXdjU575u5Klw= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 610a886a-ed35-406c-a46d-08d6a1cfefea X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Mar 2019 01:06:17.9641 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3723 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and watchdog etc.. This patch adds i.MX system controller watchdog driver support, watchdog operation needs to be done in secure EL3 mode via ARM-Trusted-Firmware, using SMC call, CPU will trap into ARM-Trusted-Firmware and then it will request system controller to do watchdog operation via IPC. Signed-off-by: Anson Huang Reviewed-by: Guenter Roeck --- Changes since V6: - use module_platform_driver() instead of module_init/exit to make code simple. --- drivers/watchdog/Kconfig | 14 ++++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 174 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 242eea8..33a6523 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -641,6 +641,20 @@ config IMX2_WDT To compile this driver as a module, choose M here: the module will be called imx2_wdt. +config IMX_SC_WDT + tristate "IMX SC Watchdog" + depends on IMX_SCU + depends on HAVE_ARM_SMCCC + select WATCHDOG_CORE + help + This is the driver for the system controller watchdog + on the NXP i.MX SoCs with system controller inside. + If you have one of these processors and wish to have + watchdog support enabled, say Y, otherwise say N. + + To compile this driver as a module, choose M here: the + module will be called imx_sc_wdt. + config UX500_WATCHDOG tristate "ST-Ericsson Ux500 watchdog" depends on MFD_DB8500_PRCMU diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index ba930e4..136d9f0 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -68,6 +68,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o obj-$(CONFIG_TS4800_WATCHDOG) += ts4800_wdt.o obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o +obj-$(CONFIG_IMX_SC_WDT) += imx_sc_wdt.o obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c new file mode 100644 index 0000000..ee48709 --- /dev/null +++ b/drivers/watchdog/imx_sc_wdt.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018-2019 NXP. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_TIMEOUT 60 +/* + * Software timer tick implemented in scfw side, support 10ms to 0xffffffff ms + * in theory, but for normal case, 1s~128s is enough, you can change this max + * value in case it's not enough. + */ +#define MAX_TIMEOUT 128 + +#define IMX_SIP_TIMER 0xC2000002 +#define IMX_SIP_TIMER_START_WDOG 0x01 +#define IMX_SIP_TIMER_STOP_WDOG 0x02 +#define IMX_SIP_TIMER_SET_WDOG_ACT 0x03 +#define IMX_SIP_TIMER_PING_WDOG 0x04 +#define IMX_SIP_TIMER_SET_TIMEOUT_WDOG 0x05 +#define IMX_SIP_TIMER_GET_WDOG_STAT 0x06 +#define IMX_SIP_TIMER_SET_PRETIME_WDOG 0x07 + +#define SC_TIMER_WDOG_ACTION_PARTITION 0 + +static bool nowayout = WATCHDOG_NOWAYOUT; +module_param(nowayout, bool, 0000); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout = DEFAULT_TIMEOUT; +module_param(timeout, uint, 0000); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static int imx_sc_wdt_ping(struct watchdog_device *wdog) +{ + struct arm_smccc_res res; + + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_PING_WDOG, + 0, 0, 0, 0, 0, 0, &res); + + return 0; +} + +static int imx_sc_wdt_start(struct watchdog_device *wdog) +{ + struct arm_smccc_res res; + + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_START_WDOG, + 0, 0, 0, 0, 0, 0, &res); + if (res.a0) + return -EACCES; + + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_SET_WDOG_ACT, + SC_TIMER_WDOG_ACTION_PARTITION, + 0, 0, 0, 0, 0, &res); + return res.a0 ? -EACCES : 0; +} + +static int imx_sc_wdt_stop(struct watchdog_device *wdog) +{ + struct arm_smccc_res res; + + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_STOP_WDOG, + 0, 0, 0, 0, 0, 0, &res); + + return res.a0 ? -EACCES : 0; +} + +static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, + unsigned int timeout) +{ + struct arm_smccc_res res; + + wdog->timeout = timeout; + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_SET_TIMEOUT_WDOG, + timeout * 1000, 0, 0, 0, 0, 0, &res); + + return res.a0 ? -EACCES : 0; +} + +static const struct watchdog_ops imx_sc_wdt_ops = { + .owner = THIS_MODULE, + .start = imx_sc_wdt_start, + .stop = imx_sc_wdt_stop, + .ping = imx_sc_wdt_ping, + .set_timeout = imx_sc_wdt_set_timeout, +}; + +static const struct watchdog_info imx_sc_wdt_info = { + .identity = "i.MX SC watchdog timer", + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE | WDIOF_PRETIMEOUT, +}; + +static int imx_sc_wdt_probe(struct platform_device *pdev) +{ + struct watchdog_device *imx_sc_wdd; + int ret; + + imx_sc_wdd = devm_kzalloc(&pdev->dev, sizeof(*imx_sc_wdd), GFP_KERNEL); + if (!imx_sc_wdd) + return -ENOMEM; + + platform_set_drvdata(pdev, imx_sc_wdd); + + imx_sc_wdd->info = &imx_sc_wdt_info; + imx_sc_wdd->ops = &imx_sc_wdt_ops; + imx_sc_wdd->min_timeout = 1; + imx_sc_wdd->max_timeout = MAX_TIMEOUT; + imx_sc_wdd->parent = &pdev->dev; + imx_sc_wdd->timeout = DEFAULT_TIMEOUT; + + ret = watchdog_init_timeout(imx_sc_wdd, timeout, &pdev->dev); + if (ret) + dev_warn(&pdev->dev, "Failed to set timeout value, using default\n"); + + watchdog_stop_on_reboot(imx_sc_wdd); + watchdog_stop_on_unregister(imx_sc_wdd); + + ret = devm_watchdog_register_device(&pdev->dev, imx_sc_wdd); + if (ret) { + dev_err(&pdev->dev, "Failed to register watchdog device\n"); + return ret; + } + + return 0; +} + +static int __maybe_unused imx_sc_wdt_suspend(struct device *dev) +{ + struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev); + + if (watchdog_active(imx_sc_wdd)) + imx_sc_wdt_stop(imx_sc_wdd); + + return 0; +} + +static int __maybe_unused imx_sc_wdt_resume(struct device *dev) +{ + struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev); + + if (watchdog_active(imx_sc_wdd)) + imx_sc_wdt_start(imx_sc_wdd); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(imx_sc_wdt_pm_ops, + imx_sc_wdt_suspend, imx_sc_wdt_resume); + +static struct platform_driver imx_sc_wdt_driver = { + .probe = imx_sc_wdt_probe, + .driver = { + .name = "imx-sc-wdt", + .pm = &imx_sc_wdt_pm_ops, + }, +}; +module_platform_driver(imx_sc_wdt_driver); + +MODULE_AUTHOR("Robin Gong "); +MODULE_DESCRIPTION("NXP i.MX system controller watchdog driver"); +MODULE_LICENSE("GPL v2");