Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp164420ima; Thu, 14 Mar 2019 23:18:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDI/oFE7zFGapUSC6wZjKBR5fb8u/AoxwjxR1z57xx2blZ4A6AECvsCk5bh1zWTJR2pmna X-Received: by 2002:a62:1ac3:: with SMTP id a186mr2324208pfa.48.1552630714558; Thu, 14 Mar 2019 23:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552630714; cv=none; d=google.com; s=arc-20160816; b=fF/KxE6hyERaqQDgmknKfVXvEdxHx4dFJdMWwwrTwzc8MDDiq8AfCS7l0j0oAJJDTr xXDeDdLbg9xOaeW8vlkIs1SV25Dqpzcb+kqK5PDgv6rT26KryfkbqwQMW17lwTM52jmv QLEf76qOhkkpu4u+cyGvj9FBuQBTXjGb+m2WJiUeo7R2YPw8hKR5Jj0UlDhy2NKlRAQM klr9HSeBSREc13nlRwzDFCCVRXUBV17G12qW1gGa6pE+FjecG+Cr//27ZBr/eeJi/rU8 ZaHp64+eK5k6rtunRa+qjuXQsbSSbFMHe0Dgp3S3zynHYSPdaFt293cfagc27t09f62j qXqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=aBZzmugnfRjX35ZGYQ+y8xyL+1XXDFC1r5GBRxrqxNs=; b=UbrJkAq3pkc3iTD0WfcHTUZS6wRmDdRMhHTf+NKbSJdJVRlq1HxjzyvHgNkCd/4xSa Lw4N1zOUEwsmVsNMgOxRD1dYgO9deIrrJ9e2Vahf9T3T0e1gFJea9b4jA2xPtAUL0S3D HHSue1LpRLjdS6yXcCRTENu2vbmOwdOsG1moVBHa1RMbnEv0zVYEFoZRcAIVRNDNHtEX h+BIogWriUmzDVTQwBDFrD05kCcDMT97QZgkxW6f5pmrZKHilcKjMVvfkb1u2DQZ8P1m rvbnDTuxBRTtiWJ+t9KRcB0Hdov30JXWU8YmbXPPBWH1i7FB1A6QOywUuJ7eaWs5VYV8 q2oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=RsBrPLRN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si969023plo.206.2019.03.14.23.18.19; Thu, 14 Mar 2019 23:18:34 -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; dkim=pass header.i=@nxp.com header.s=selector1 header.b=RsBrPLRN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728381AbfCOGRg (ORCPT + 99 others); Fri, 15 Mar 2019 02:17:36 -0400 Received: from mail-eopbgr80043.outbound.protection.outlook.com ([40.107.8.43]:54497 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728050AbfCOGRf (ORCPT ); Fri, 15 Mar 2019 02:17:35 -0400 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=aBZzmugnfRjX35ZGYQ+y8xyL+1XXDFC1r5GBRxrqxNs=; b=RsBrPLRNsWQu08/vJZcTTVPKbLWEI3qcvUkLAA30EaGnI1cLdm8ZP5sOk6HoAqDtHbKdhKmEGkn7lXIP20lsiMZjw7BS0PutEsoec2WR0S1XIgCqpe9J38ZnHk3PKvn1cnMMMnpo5BRpkAmcIT9aGJ+gRbp+r8wIx5peRUs34o8= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Fri, 15 Mar 2019 06:17:25 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::f1b4:a1fb:cfd1:3f08]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::f1b4:a1fb:cfd1:3f08%6]) with mapi id 15.20.1709.011; Fri, 15 Mar 2019 06:17:25 +0000 From: Anson Huang To: "wim@linux-watchdog.org" , "linux@roeck-us.net" , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "catalin.marinas@arm.com" , "will.deacon@arm.com" , Aisheng Dong , Daniel Baluta , "heiko@sntech.de" , "horms+renesas@verge.net.au" , Andy Gross , "maxime.ripard@bootlin.com" , "olof@lixom.net" , "bjorn.andersson@linaro.org" , "jagan@amarulasolutions.com" , "enric.balletbo@collabora.com" , "ezequiel@collabora.com" , "stefan.wahren@i2se.com" , "marc.w.gonzalez@free.fr" , "linux-watchdog@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH V8 2/4] watchdog: imx_sc: Add i.MX system controller watchdog support Thread-Topic: [PATCH V8 2/4] watchdog: imx_sc: Add i.MX system controller watchdog support Thread-Index: AQHU2vbCM1mT6fDRMkeiR+nJMZLh7A== Date: Fri, 15 Mar 2019 06:17:25 +0000 Message-ID: <1552630331-32068-3-git-send-email-Anson.Huang@nxp.com> References: <1552630331-32068-1-git-send-email-Anson.Huang@nxp.com> In-Reply-To: <1552630331-32068-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: HK0PR01CA0002.apcprd01.prod.exchangelabs.com (2603:1096:203:92::14) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 085361ca-9d19-4940-dd3e-08d6a90de470 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:DB3PR0402MB3916; x-ms-traffictypediagnostic: DB3PR0402MB3916: x-ld-processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr x-microsoft-antispam-prvs: x-forefront-prvs: 09778E995A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(396003)(376002)(346002)(39860400002)(366004)(199004)(189003)(8936002)(2501003)(102836004)(2906002)(6436002)(68736007)(5660300002)(7416002)(6116002)(66066001)(36756003)(446003)(71190400001)(486006)(71200400001)(76176011)(6346003)(2616005)(476003)(186003)(386003)(11346002)(3846002)(26005)(52116002)(6506007)(6486002)(305945005)(6512007)(256004)(478600001)(2201001)(86362001)(4326008)(25786009)(106356001)(105586002)(7736002)(316002)(14444005)(110136005)(50226002)(14454004)(99286004)(8676002)(97736004)(81156014)(81166006)(53936002)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3916;H:DB3PR0402MB3916.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 9vrjyeckglcSHkJnqr++Cg/pVb3y93uPTSg54C+qFPrXFv+apW1BaGy/K7FkR0ZwaiIRzYSYsbv5PcfAOQ8B8C5GqUN0UUCGPLDAMXc3L8YZU7uR7FtsfHfPXMgPwSBVVMHTWJLnkLDeJY6IfHCBWDIrwVSFpB+CIQ8IInyE8OxAd2e5sdzzRZwB1XQ6F88rnhJqPbIuKjSBTgcQVv1+QWAdblkfhqqDHcWuqCt5HgGImwuPoWqM80TEgpQ5HDIuYN+xEki9XTUqoDlKs04oiWXePCZgxZRSNZjFJruINByD/Gx554b54mM6SGYROK6AXGWjWfBi2C0t5BIZv9xySw3PmSUEv83OerZv19G0rea3jkHvjaT+AztNza/UOrcOubpOvPyj3e975ln5ckp4b2UewTfB9zZ5H4BBotShnmA= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 085361ca-9d19-4940-dd3e-08d6a90de470 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2019 06:17:25.4256 (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: DB3PR0402MB3916 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes since V7: - remove the dependence of IMX_SCU as it does NOT call SCU API directly; - add more detail info into the help section of how this module works; - add back device id table since now we have watchdog node in DT. --- drivers/watchdog/Kconfig | 16 ++++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 182 ++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 199 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 242eea8..44a3158 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -641,6 +641,22 @@ config IMX2_WDT To compile this driver as a module, choose M here: the module will be called imx2_wdt. =20 +config IMX_SC_WDT + tristate "IMX SC Watchdog" + 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, the + watchdog driver will call ARM SMC API and trap into + ARM-Trusted-Firmware for operations, ARM-Trusted-Firmware + will request system controller to execute the operations. + 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) +=3D nuc900_wdt.o obj-$(CONFIG_TS4800_WATCHDOG) +=3D ts4800_wdt.o obj-$(CONFIG_TS72XX_WATCHDOG) +=3D ts72xx_wdt.o obj-$(CONFIG_IMX2_WDT) +=3D imx2_wdt.o +obj-$(CONFIG_IMX_SC_WDT) +=3D imx_sc_wdt.o obj-$(CONFIG_UX500_WATCHDOG) +=3D ux500_wdt.o obj-$(CONFIG_RETU_WATCHDOG) +=3D retu_wdt.o obj-$(CONFIG_BCM2835_WDT) +=3D 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..c8a087a --- /dev/null +++ b/drivers/watchdog/imx_sc_wdt.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018-2019 NXP. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_TIMEOUT 60 +/* + * Software timer tick implemented in scfw side, support 10ms to 0xfffffff= f 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 =3D WATCHDOG_NOWAYOUT; +module_param(nowayout, bool, 0000); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (defau= lt=3D" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =3D DEFAULT_TIMEOUT; +module_param(timeout, uint, 0000); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=3D" + __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 =3D 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 =3D { + .owner =3D THIS_MODULE, + .start =3D imx_sc_wdt_start, + .stop =3D imx_sc_wdt_stop, + .ping =3D imx_sc_wdt_ping, + .set_timeout =3D imx_sc_wdt_set_timeout, +}; + +static const struct watchdog_info imx_sc_wdt_info =3D { + .identity =3D "i.MX SC watchdog timer", + .options =3D 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 =3D 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 =3D &imx_sc_wdt_info; + imx_sc_wdd->ops =3D &imx_sc_wdt_ops; + imx_sc_wdd->min_timeout =3D 1; + imx_sc_wdd->max_timeout =3D MAX_TIMEOUT; + imx_sc_wdd->parent =3D &pdev->dev; + imx_sc_wdd->timeout =3D DEFAULT_TIMEOUT; + + ret =3D 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 =3D 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 =3D 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 =3D 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 const struct of_device_id imx_sc_wdt_dt_ids[] =3D { + { .compatible =3D "fsl,imx-sc-wdt", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx_sc_wdt_dt_ids); + +static struct platform_driver imx_sc_wdt_driver =3D { + .probe =3D imx_sc_wdt_probe, + .driver =3D { + .name =3D "imx-sc-wdt", + .of_match_table =3D imx_sc_wdt_dt_ids, + .pm =3D &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"); --=20 2.7.4