Hi, Guenter

Best Regards!
Anson Huang

> -----Original Message-----
> From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter
> Roeck
> Sent: 2019年2月28日 22:58
> To: Anson Huang <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> Andy Gross <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; linux-arm-
> [email protected]; [email protected]; linux-
> [email protected]
> Cc: dl-linux-imx <[email protected]>
> Subject: Re: [PATCH V4 1/2] watchdog: imx_sc: Add i.MX system controller
> watchdog support
> 
> On 2/27/19 11:59 PM, Anson Huang wrote:
> > 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 <[email protected]>
> > ---
> > Changes since V3:
> >          - add ARM64 dependency for this driver;
> >          - change SPDX license to GPL-2.0 to match module license;
> >          - register platform device in driver instead of getting from dts;
> >     - return linux error code instead of system controller firmware error
> code for watchdog operation
> >       failed case.
> > ---
> >   drivers/watchdog/Kconfig      |  13 +++
> >   drivers/watchdog/Makefile     |   1 +
> >   drivers/watchdog/imx_sc_wdt.c | 201
> ++++++++++++++++++++++++++++++++++++++++++
> >   3 files changed, 215 insertions(+)
> >   create mode 100644 drivers/watchdog/imx_sc_wdt.c
> >
> > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index
> > 65c3c42..8c6575e 100644
> > --- a/drivers/watchdog/Kconfig
> > +++ b/drivers/watchdog/Kconfig
> > @@ -625,6 +625,19 @@ 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 (ARCH_MXC && ARM64) || COMPILE_TEST
> > +   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.
> > +
> 
> With this patch applied, alpha:allmodconfig and almost all other
> allmodconfig/allyesconfig builds fail with:
> 
> ERROR: "__arm_smccc_smc" [drivers/watchdog/imx_sc_wdt.ko] undefined!
> scripts/Makefile.modpost:92: recipe for target '__modpost' failed
> make[1]: *** [__modpost] Error 1
> Makefile:1260: recipe for target 'modules' failed
> 
> as I told you before would happen. For the future, please consider that
> forcing me to "prove" such failures does take a significant amount of time,
> which is not always readily available.

Sorry for wasting your time, it is just because I misunderstand your point, NOT
that I did NOT force you to prove it.

I am a little confuse, since this is new to me about these configs, I looked 
into
other drivers which also use arm_smccc_smc, they do NOT add special config
dependency for the failure build cause as you said, can you be more detail about
this build issue, I tried below build, but the failure I met is other, so could 
you please
advise how to fix such dependency issue, adding dummy function looks like NOT
a good way since this arm_smccc_smc() API is widely used in kernel, there 
should be
some common solution for it, Thanks in advanced and appreciate for your time.

Anson.

anson@anson-OptiPlex-790:~/workspace/stash/linux-next$ make.cross ARCH=arm64 
allyesconfig
anson@anson-OptiPlex-790:~/workspace/stash/linux-next$ make.cross ARCH=arm64

arch/arm64/kernel/traps.o: In function `early_brk64':
traps.c:(.init.text+0x24): relocation truncated to fit: R_AARCH64_CALL26 
against `.text'
arch/arm64/kernel/entry.o:(.altinstr_replacement+0x70): relocation truncated to 
fit: R_AARCH64_JUMP26 against `.entry.text'
arch/arm64/kernel/entry.o:(.altinstr_replacement+0x84): relocation truncated to 
fit: R_AARCH64_JUMP26 against `.entry.text'
arch/arm64/kernel/entry.o:(.altinstr_replacement+0x98): relocation truncated to 
fit: R_AARCH64_JUMP26 against `.entry.text'


> 
> Guenter
> 
> 
> >   config UX500_WATCHDOG
> >     tristate "ST-Ericsson Ux500 watchdog"
> >     depends on MFD_DB8500_PRCMU
> > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > index 4e78a8c..0c9da63 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..50b49b2
> > --- /dev/null
> > +++ b/drivers/watchdog/imx_sc_wdt.c
> > @@ -0,0 +1,201 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018-2019 NXP.
> > + */
> > +
> > +#include <linux/arm-smccc.h>
> > +#include <linux/io.h>
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/moduleparam.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/reboot.h>
> > +#include <linux/watchdog.h>
> > +
> > +#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 struct platform_device *imx_sc_wdt_pdev;
> > +
> > +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,
> > +   },
> > +};
> > +
> > +static int __init imx_sc_wdt_init(void) {
> > +   int ret;
> > +
> > +   ret = platform_driver_register(&imx_sc_wdt_driver);
> > +   if (ret)
> > +           return ret;
> > +
> > +   imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt", -
> 1, NULL, 0);
> > +   if (IS_ERR(imx_sc_wdt_pdev)) {
> > +           platform_driver_unregister(&imx_sc_wdt_driver);
> > +           return PTR_ERR(imx_sc_wdt_pdev);
> > +   }
> > +
> > +   return 0;
> > +}
> > +module_init(imx_sc_wdt_init);
> > +
> > +static void __exit imx_sc_wdt_exit(void) {
> > +   platform_driver_unregister(&imx_sc_wdt_driver);
> > +   platform_device_unregister(imx_sc_wdt_pdev);
> > +}
> > +module_exit(imx_sc_wdt_exit);
> > +
> > +MODULE_AUTHOR("Robin Gong <[email protected]>");
> > +MODULE_DESCRIPTION("NXP i.MX system controller watchdog driver");
> > +MODULE_LICENSE("GPL v2");
> >

Reply via email to