summaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/imxwd.c
Commit message (Collapse)AuthorAgeFilesLines
* watchdog: imxwd: Do not suspend in lpm on i.MX27Sascha Hauer9 days1-1/+4
| | | | | | | | | | | | | | | | | | | | | The i.MX watchdog has two different configurable behaviours for low power modes. The watchdog can either be suspended during low power modes or kept running. The useful behaviour is normally to disable it during low power modes to be able to suspend the system without having the watchdog resetting the system. This setting was introduced in the Kernel back in 2014 [1] and in barebox back in 2021 [2]. On i.MX27 however this setting has the effect that the watchdog is suspended during normal cpu_do_idle(), so on an idle system it takes very long time until the watchdog triggers. This renders this setting useless, so disable it on i.MX27. This seems to be fixed on SoCs newer than i.MX35. [1] 1a9c5efa576ec ("watchdog: imx2_wdt: disable watchdog timer during low power mode") [2] c3787a81f26bb ("watchdog: imxwd: suspend watchdog timer in low power mode") Link: https://lore.barebox.org/20240515110156.1920361-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: add MODULE_DEVICE_TABLE markersAhmad Fatoum2023-06-131-0/+1
| | | | | | | | | | | | | | | | Syncing device trees with Linux upstream can lead to breakage, when the device trees are switched to newer bindings, which are not yet supported in barebox. To make it easier to spot such issues, we want to start applying some heuristics to flag possibly problematic DT changes. One step towards being able to do that is to know what nodes barebox actually consumes. Most of the nodes have a compatible entry, which is matched by an array of of_device_id, so let's have MODULE_DEVICE_TABLE point at it for future extraction. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230612125908.1087340-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct driver_d to driverSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | The '_d' suffix was originally meant to distinguish barebox struct names from Linux struct names. struct driver doesn't exist in Linux, so we can rename it and remove the meaningless suffix. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-2/+2
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename device_d::device_node to device_d::of_nodeSascha Hauer2023-01-101-2/+2
| | | | | | | | | | | | | | | | | | | | Linux struct device has the member of_node for the device_node pointer. Rename this in barebox accordingly to minimize the necessary changes when porting Linux code. This was done with the semantic patch: @@ struct device_d E; @@ - E.device_node + E.of_node @@ struct device_d *E; @@ - E->device_node + E->of_node Plus some manual adjustments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: set imxwd-warm as reboot mode default handlerAhmad Fatoum2022-10-271-0/+1
| | | | | | | | | | | | | Set RESTART_FLAG_WARM_BOOTROM for imxwd-warm, so reset -w directly selects this handler. i.MX6QDL/8MM Users now can just do gpr.reboot_mode.next=serial reset -w and it should behave as expected. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221017071000.1458292-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: don't register broken imxwd-warm for i.MX7Ahmad Fatoum2022-10-271-7/+23
| | | | | | | | | | | | Due to erratum e10574 "Watchdog: A watchdog timeout or software trigger will not reset the SOC", any use of the watchdog reset must trigger an external PMIC or reset circuit. Registering imxwd-warm thus serves no purpose, so don't register it for i.MX7. We'll need an alternative for reboot mode, which will follow in a later commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221017071000.1458292-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: Add error messages for some failure points in .probe()Uwe Kleine-König2022-06-301-3/+5
| | | | | | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220629085628.106086-2-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: Convert error messages in .probe to dev_err_probe()Uwe Kleine-König2022-06-301-5/+5
| | | | | | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220629085628.106086-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: suspend watchdog timer in low power modeAndrej Picej2022-01-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | Watchdog timer should be disabled in low power mode. The problem that was observed was that when the watchdog is started from barebox, kernel driver doesn't do its own setup again and in turn this bit is left unset. Moreover, this bit is write-once and has to be set before enabling the watchdog, leaving responsibility for proper setup to a party first using the watchdog timer (e.g. bootloader). Issue manifests itself later on, when device enters low power mode (e.g. suspend) for more amount of time than what is maximum watchdog timeout (128s). After that period of time, device will not recover ever as there is no service patting the watchdog (CPU is suspended). This means that the device can hang in suspend mode or it performs an unexpected reset. Thus to avoid suspend/resume problems when watchdog is started already in the bootloader, align bootloader driver settings with kernel settings. Kernel driver has been already setting this bit since 2014. Signed-off-by: Andrej Picej <andrej.picej@norik.com> Link: https://lore.barebox.org/20211216122653.2335949-1-andrej.picej@norik.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: add missing SPDX-License-IdentifierAhmad Fatoum2021-11-011-10/+1
| | | | | | | | | | | | | | | | | | | | This adds the suitable SPDX-License-Identifier to all files in drivers/ that previously lacked one. To aid manual inspection, following heuristics can be used: * No changes outside of comments/whitespace: git show -U0 HEAD | rg -v '^(@@|diff|index)|[-+]([-+]|//|#|[\s/]\*)' * -or-later come in pairs: git show --inter-hunk-context=19 HEAD | \ perl -0777 -F'/^@/gm' -ne 'for (@F) { @m = /later/g; print if @m & 1 }' Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030175632.2276077-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: register explicit warm reset handlerAhmad Fatoum2021-08-091-0/+16
| | | | | | | | | | | | | | With fsl,ext-reset-output and WDOG_B muxed correctly, the i.MX watchdog will toggle an external signal to effect a PMIC reset. That's good for normal use, but when exchanging information with the BootROM over GPRs, a warm reset is required. This is needed e.g. to set the reboot mode. Support this by defining a second, lower priority, reset that will never toggle external lines. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210803165937.31608-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: get and enable clockSteffen Trumtrar2021-05-031-0/+11
| | | | | | | | | This it (at least) necessary for i.MX7s or otherwise barebox will hang when trying to access the registers of WDOG2/3/4. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Link: https://lore.barebox.org/20210419123747.2373-1-s.trumtrar@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: support .running device parameter on i.MX2+Ahmad Fatoum2019-11-111-0/+14
| | | | | | | | | The i.MX can be fused to start the watchdog on power-on reset. To give users an easy way to determine whether the watchdog is running, implement support for WDOG_HW_RUNNING. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imx: Add big endian register access supportSascha Hauer2019-03-131-2/+10
| | | | | | | Layerscape SoCs feature the same watchdog as the i.MX SoCs, but in big endian mode. Add support for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imx: Add register accessor functionsSascha Hauer2019-03-131-14/+24
| | | | | | In preparation of adding big endian support in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: i.MX: When SRSR shows wdog then lookup reset source in wdogSascha Hauer2018-11-161-3/+7
| | | | | | | | | | | | | On i.MX6 when the watchdog has resetted the system then the SRSR register correctly shows that the watchdog has resetted the system. This is not the desired result though, a "reset" in barebox or "reboot" in Linux should result in "RST" as reset source. So instead of making the SRSR register value overwrite the reset source read from the watchdog registers, interpret the SRSR value corresponding to watchdog reset as "lookup details in the watchdog registers". Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
* watchdog: move max timeout test in to wd_coreOleksij Rempel2018-03-231-6/+4
| | | | | | | this also will be needed for watchdog poller as well Signed-off-by: Oleksij Rempel <linux@rempel-privat.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: rename dev to hwdevSascha Hauer2018-03-221-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/imx'Sascha Hauer2017-06-141-0/+6
|\
| * i.MX/WD: setup the watchdog according to its datasheetJuergen Borleis2017-06-071-0/+6
| | | | | | | | | | | | | | | | | | From earlier SoCs like the i.MX21 up to i.MX7 their datasheets states after reset the watchdog timer has to be set first prior enabling the watchdog itself. This change do it this way. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | watchdog: i.MX: fix i.MX6 resetChristian Hemp2017-06-131-0/+4
|/ | | | | | | | | | | | According to the Errata ERR004346 (WDOG: WDOG SRS bit requires to be written twice), add another two writes to ensure there must be at least two writes happen in the same one 32kHz clock period. Without this two additional writes, the system will not reset always. Tested with i.MX6Quad and i.MX6 UltraLite Signed-off-by: Christian Hemp <c.hemp@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: i.MX: Fix internal/external resetSascha Hauer2017-01-201-2/+14
| | | | | | | | | | | The watchdog can either reset only the SoC or assert the WDOG_B output signal instead. On some boards it's necessary to use the external WDOG_B output to make sure that external devices like the PMIC are also properly resetted. This has been fixed in the Linux driver which honours a fsl,ext-reset-output device tree property to select between both ways. Do the same in the barebox driver. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: i.MX: add soc_reset operationSascha Hauer2017-01-201-15/+25
| | | | | | | | On i.MX21 watchdog type the reset operation is really different from the watchdog enable/set timeout operation, so create an extra callback for this instead of folding both things together. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: replace dev_request_mem_region with dev_request_mem_resourceSascha Hauer2016-03-071-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dev_request_mem_region doesn't work properly one some SoCs on which PTR_ERR() values clash with valid return values from dev_request_mem_region. Replace them with dev_request_mem_resource where possible. This patch has been generated with the following semantic patch: // <smpl> @@ expression d; expression n; expression io; identifier func; @@ func(...) { +struct resource *iores; <+... -io = dev_request_mem_region(d, n); -if (IS_ERR(io)) { +iores = dev_request_mem_resource(d, n); +if (IS_ERR(iores)) { ... - return PTR_ERR(io); -} + return PTR_ERR(iores); +} +io = IOMEM(iores->start); ...+> } @@ expression d; expression n; expression io; identifier func; @@ func(...) { +struct resource *iores; <+... -io = dev_request_mem_region(d, n); -if (IS_ERR(io)) { +iores = dev_request_mem_resource(d, n); +if (IS_ERR(iores)) - return PTR_ERR(io); -} + return PTR_ERR(iores); +io = IOMEM(iores->start); ...+> } @@ expression d; expression n; expression io; identifier func; @@ func(...) { +struct resource *iores; <+... -io = dev_request_mem_region(d, n); -if (IS_ERR(io)) { - ret = PTR_ERR(io); +iores = dev_request_mem_resource(d, n); +if (IS_ERR(iores)) { + ret = PTR_ERR(iores); ... } +io = IOMEM(iores->start); ...+> } @@ expression d; expression n; expression io; identifier func; @@ func(...) { +struct resource *iores; <+... -io = dev_request_mem_region(d, n); +iores = dev_request_mem_resource(d, n); +if (IS_ERR(iores)) + return PTR_ERR(iores); +io = IOMEM(iores->start); ...+> } @@ identifier func; @@ func(...) { <+... struct resource *iores; -struct resource *iores; ...+> } // </smpl> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Fix return check of dev_request_mem_regionSascha Hauer2016-02-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dev_request_mem_region returns an ERR_PTR, fix places which check for a NULL pointer instead. This patch has been generated with this semantic patch, written by me and improved by Andrey Smirnov: // <smpl> @@ expression e; expression e1; @@ e = dev_request_mem_region(...); ... -if (!e) - return e1; +if (IS_ERR(e)) + return PTR_ERR(e); @ rule1 @ expression e; @@ e = dev_request_mem_region(...); @@ expression rule1.e; identifier ret, label; constant errno; @@ if (!e) { ... ( - ret = -errno; + ret = PTR_ERR(e); ... goto label; | - return -errno; + return PTR_ERR(e); ) } @depends on rule1@ expression rule1.e; @@ - if (e == NULL) + if (IS_ERR(e)) { ... } // </smpl> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
* wdog: imx-wd: watchdog cannot be disabled againStefan Christ2015-11-301-1/+4
| | | | | | | | | The i.MX21/i.MX6 watchdog cannot be disabled after it was activated. Bit 2 (WDE) cannot be set to 0 again. Notify the user about that by returning -ENOSYS. Signed-off-by: Stefan Christ <s.christ@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: Give watchdogs a nameSascha Hauer2015-08-271-0/+1
| | | | | | | This adds a dev and name member to struct watchdog which helps distinguishing between different watchdogs. Also add some debugging aids. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* restart: replace reset_cpu with registered restart handlersSascha Hauer2015-08-271-10/+12
| | | | | | | | | | | | | | | | | | | | | | This replaces the reset_cpu() function which every SoC or board must provide with registered handlers. This makes it possible to have multiple reset functions for boards which have multiple ways to reset the machine. Also boards which have no way at all to reset the machine no longer have to provide a dummy reset_cpu() function. The problem this solves is that some machines have external PMICs or similar to reset the system which have to be preferred over the internal SoC reset, because the PMIC can reset not only the SoC but also the external devices. To pick the right way to reset a machine each handler has a priority. The default priority is 100 and all currently existing restart handlers are registered with this priority. of_get_restart_priority() allows to retrieve the priority from the device tree which makes it possible for boards to give certain restart handlers a higher priority in order to use this one instead of the default one. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: imxwd: remove remove callbackSascha Hauer2015-08-261-12/+0
| | | | | | | | | The imxwd is for resetting the system, so we should not unregister it during shutdown_barebox() as it may leave us without a restart handler. Only a bug (not setting reset_wd to NULL in remove()) made the whole thing work. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: use 'const void *' for struct of_device_id.dataAntony Pavlov2015-04-301-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since 2011 barebox' of_device_id struct uses unsigned long type for data field: struct of_device_id { char *compatible; unsigned long data; }; Almost always struct of_device_id.data field are used as pointer and need 'unsigned long' casting. E.g. see 'git grep -A 4 of_device_id drivers/' output: drivers/ata/sata-imx.c:static __maybe_unused struct of_device_id imx_sata_dt_ids[] = { drivers/ata/sata-imx.c- { drivers/ata/sata-imx.c- .compatible = "fsl,imx6q-ahci", drivers/ata/sata-imx.c- .data = (unsigned long)&data_imx6, drivers/ata/sata-imx.c- }, { Here is of_device_id struct in linux kernel v4.0: struct of_device_id { char name[32]; char type[32]; char compatible[128]; const void *data; }; Changing of_device_id.data type to 'const void *data' will increase barebox' linux kernel compatibility and decrease number of 'unsigned long' casts. Part of the patch was done using the 'coccinelle' tool with the following semantic patch: @rule1@ identifier dev; identifier type; identifier func; @@ func(...) { <... - dev_get_drvdata(dev, (unsigned long *)&type) + dev_get_drvdata(dev, (const void **)&type) ...> } @rule2@ identifier dev; identifier type; identifier func; identifier data; @@ func(...) { <... - dev_get_drvdata(dev, (unsigned long *)&type->data) + dev_get_drvdata(dev, (const void **)&type->data) ...> } Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* wdog: imx-wd: Disable watchdog powerdown counterMarkus Pargmann2015-04-131-0/+6
| | | | | | | | | Disable the watchdog powerdown counter at start. Otherwise this may trigger a reset or poweroff over the WDOG_B line to a PMIC. This counter is set to 16 seconds after poweron. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* wdog: imx-wd: Introduce ops struct for imx21/imx1Markus Pargmann2015-04-131-12/+43
| | | | | | | | Replace the set_timeout function in the device platform data by an ops struct which stores a set_timeout and init function. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: i.MX: check requested mem region in imx_wd_probe()Antony Pavlov2014-08-011-0/+4
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* reset_source: rename set_reset_source to reset_source_setSascha Hauer2014-01-291-3/+3
| | | | | | | To get all reset source related functions into the same function namespace. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Add missing includesSascha Hauer2013-11-081-0/+1
| | | | | | | | A lot of files rely on include/driver.h including include/of.h (and this including include/errno.h. include the files explicitly so we can eventually get rid of including of.h from driver.h Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Use new device_platform_driver() macro for driversAlexander Shiyan2013-02-131-7/+1
| | | | | Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM i.MX: move reset source detection codeSascha Hauer2012-10-081-0/+34
| | | | | | | | | - for i.MX1 the register is in the System Control unit, so move the code to arch/arm/mach-imx/imx1.c - for the other i.MX the register is in the watchdog unit, so move the code to drivers/watchdog/imxwd.c Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM i.MX/watchdog: Make i.MX watchdog driver the reset source on i.MXSascha Hauer2012-10-051-6/+27
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* watchdog: Add i.MX watchdog supportSascha Hauer2012-10-051-0/+180
This adds a driver for the watchdog found on i.MX1-i.MX6. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>