Skip to contentSkip to conversation

Add watchdog DT nodes and use syscon regmap interfac to configure pmu registers

PATCH Superseded Leela Krishna Amudala 3 participants 9 messages Nov 12, 2013 – Nov 18, 2013

Subsystems (3)

v8 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v8 cover Add watchdog DT nodes and use syscon regmap interfac to configure pmu registers

This patchset does the following things
- Adds pmusysreg device node to exynos5.dtsi file
- Adds watchdog DT nodes to Exynos5250 and 5420
- Uses syscon regmap interface to configure pmu registers to mask/unmask enable/disable of watchdog.

This patch set is rebased on Kgene's for-next branch and tested on SMDK5420

changes since V7:
- re-ordered the patches in the series
- moved pmu_config_s3c2410 structure out of ifdef CONFIG_OF and limited only this structure to platform match table
- renamed structure name from s3c_wdt_driver_ids to s3c2410_wdt_ids
- removed exynos variants from platform match table (suggested by Tomasz Figa <[email protected]>)

changes since V6:
- added SoC-specific compatible value to syscon node and documented it
- given more patch description for below patch
ARM: dts: update watchdog device nodes for Exynos5250 and Exynos5420
- added platform_device_id array for watchdog devices
- selected MFD_SYSCON in Kconfig entry for watchdog

Changes since V5:
- removed status property in DT nodes
- changed the return type for the function s3c2410wdt_mask_and_disable_reset() and handled error cases
- Handled to get driver data in non-DT cases
- Addressed comments given by Tomasz Figa <[email protected]>

Changes since V4:
- changed the node name from pmusysreg to syscon and node label from pmu_sys_reg to pmu_syscon
- changed the property name from samsung,pmusysreg to samsung,syscon-phandle
- used regmap_update_bits instead of remap_read/regmap_write
- Addressed other comments given by Tomasz Figa <[email protected]>

Changes since V3:
- changed the compatible strings for watchdog node
- splitted up adding pmusysreg node and made it separate patch
- Addressed comments given by Sachin Kamat <[email protected]>

Changes since V2:
- used syscon regmap interface to configure pmu registers in WDT driver (suggested by Tomasz Figa <[email protected]>)

Changes since V1:
- Added new compatible string for Exynos5 SoCs
- Introduced quirk mechanism to program PMU registers
- Addressed comments given by Tomasz Figa <[email protected]>

Leela Krishna Amudala (3):
ARM: dts: Add pmu sysreg node to exynos5250 and exynos5420 dtsi files
watchdog: s3c2410_wdt: add device tree support and use syscon regmap
interface to configure pmu register
ARM: dts: update watchdog device nodes for Exynos5250 and Exynos5420

 .../devicetree/bindings/arm/samsung/pmu.txt        |   13 ++
 .../devicetree/bindings/watchdog/samsung-wdt.txt   |   21 ++-
 arch/arm/boot/dts/exynos5.dtsi                     |    7 -
 arch/arm/boot/dts/exynos5250.dtsi                  |   11 +-
 arch/arm/boot/dts/exynos5420.dtsi                  |   14 ++
 drivers/watchdog/Kconfig                           |    1 +
 drivers/watchdog/s3c2410_wdt.c                     |  148 ++++++++++++++++++--
 7 files changed, 198 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/samsung/pmu.txt
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v8 1/3 ARM: dts: Add pmu sysreg node to exynos5250 and exynos5420 dtsi files

This patch adds pmusysreg node to exynos5250 and exynos5420 dtsi files to handle PMU register accesses in a centralized way using syscon driver

---
 Documentation/devicetree/bindings/arm/samsung/pmu.txt |   13 +++++++++++++
 arch/arm/boot/dts/exynos5250.dtsi                     |    5 +++++
 arch/arm/boot/dts/exynos5420.dtsi                     |    5 +++++
 3 files changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/samsung/pmu.txt
Documentation/devicetree/bindings/arm/samsung/pmu.txt new file +13 -0
new file mode 100644
index 0000000..90f975d
@@ -0,0 +1,13 @@
+SAMSUNG Exynos SoC series PMU Registers
+
+Properties:
+ - name : should be 'syscon';
+ - compatible : should contain "samsung,<chip name>-pmu", "syscon";
+   For Exynos5250 SoC it should be "samsung,exynos5250-pmu", "syscon";
+ - reg : offset and length of the register set.
+
+Example :
+pmu_syscon: syscon@10040000 {
+	compatible = "samsung,exynos5250-pmu", "syscon";
+	reg = <0x10040000 0x5000>;
+};
arch/arm/boot/dts/exynos5250.dtsi +5 -0
index c4a8662..6056a83 100644
@@ -158,6 +158,11 @@
 		interrupts = <0 47 0>;
 	};
 
+	pmu_syscon: syscon@10040000 {
+		compatible = "samsung,exynos5250-pmu", "syscon";
+		reg = <0x10040000 0x5000>;
+	};
+
 	watchdog {
 		clocks = <&clock 336>;
 		clock-names = "watchdog";
arch/arm/boot/dts/exynos5420.dtsi +5 -0
index 6ffefd1..39ce15a 100644
@@ -369,4 +369,9 @@
 		clock-names = "gscl";
 		samsung,power-domain = <&gsc_pd>;
 	};
+
+	pmu_syscon: syscon@10040000 {
+		compatible = "samsung,exynos5420-pmu", "syscon";
+		reg = <0x10040000 0x5000>;
+	};
 };
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH V8 1/3] ARM: dts: Add pmu sysreg node to exynos5250 and exynos5420 dtsi files

Quoted 18 lines · On Tuesday 12 of November 2013 12:04:46 Leela Krishna Amudala wrote:

This patch adds pmusysreg node to exynos5250 and exynos5420 dtsi files to handle PMU register accesses in a centralized way using syscon driver

---
 Documentation/devicetree/bindings/arm/samsung/pmu.txt |   13 +++++++++++++
 arch/arm/boot/dts/exynos5250.dtsi                     |    5 +++++
 arch/arm/boot/dts/exynos5420.dtsi                     |    5 +++++
 3 files changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/samsung/pmu.txt
Documentation/devicetree/bindings/arm/samsung/pmu.txt new file +0 -0
new file mode 100644
index 0000000..90f975d

Documentation/devicetree/bindings/arm/samsung/pmu.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/arm/samsung/pmu.txt new file +5 -0
@@ -0,0 +1,13 @@
+SAMSUNG Exynos SoC series PMU Registers
+
+Properties:
+ - name : should be 'syscon';
+ - compatible : should contain "samsung,<chip name>-pmu", "syscon";

AFAIR there was a discussion about using <chip name> wildcards some time ago and if I remember correctly, the conclusion was that the list of all supported compatible values should be provided anyway, so there is no point in using such wildcards.

This is how I would write this:

- compatible : should contain two values. First value must be one from following list:
- "samsung,exynos5250-pmu" - for Exynos5250 SoC,
- "samsung,exynos5420-pmu" - for Exynos5420 SoC.
Second value must be always "syscon".

Best regards,
Tomasz

#3 lore raw

Re: [PATCH V8 1/3] ARM: dts: Add pmu sysreg node to exynos5250 and exynos5420 dtsi files

Hi Tomasz,

Quoted 30 lines · Tomasz Figa
Quoted 18 lines · On Tuesday 12 of November 2013 12:04:46 Leela Krishna Amudala wrote:

This patch adds pmusysreg node to exynos5250 and exynos5420 dtsi files to handle PMU register accesses in a centralized way using syscon driver

---
 Documentation/devicetree/bindings/arm/samsung/pmu.txt |   13 +++++++++++++
 arch/arm/boot/dts/exynos5250.dtsi                     |    5 +++++
 arch/arm/boot/dts/exynos5420.dtsi                     |    5 +++++
 3 files changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/samsung/pmu.txt
Documentation/devicetree/bindings/arm/samsung/pmu.txt new file +0 -0
new file mode 100644
index 0000000..90f975d

Documentation/devicetree/bindings/arm/samsung/pmu.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/arm/samsung/pmu.txt new file +5 -0
@@ -0,0 +1,13 @@
+SAMSUNG Exynos SoC series PMU Registers
+
+Properties:
+ - name : should be 'syscon';
+ - compatible : should contain "samsung,<chip name>-pmu", "syscon";

AFAIR there was a discussion about using <chip name> wildcards some time ago and if I remember correctly, the conclusion was that the list of all supported compatible values should be provided anyway, so there is no point in using such wildcards.

Quoted 8 lines

This is how I would write this:

- compatible : should contain two values. First value must be one from following list:
- "samsung,exynos5250-pmu" - for Exynos5250 SoC,
- "samsung,exynos5420-pmu" - for Exynos5420 SoC.
Second value must be always "syscon".

Okay, will change it

Best Wishes,
Leela Krishna

Quoted 7 lines

Best regards,
Tomasz

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

PATCH v8 2/3 watchdog: s3c2410_wdt: add device tree support and use syscon regmap interface to configure pmu register

In reply to Leela Krishna Amudala

Add device tree support and use syscon regmap interface to configure AUTOMATIC_WDT_RESET_DISABLE and MASK_WDT_RESET_REQUEST registers of PMU to mask/unmask enable/disable of watchdog in probe and s2r scenarios.

---
 .../devicetree/bindings/watchdog/samsung-wdt.txt   |   21 ++-
 drivers/watchdog/Kconfig                           |    1 +
 drivers/watchdog/s3c2410_wdt.c                     |  148 ++++++++++++++++++--
 3 files changed, 161 insertions(+), 9 deletions(-)
Documentation/devicetree/bindings/watchdog/samsung-wdt.txt +20 -1
index 2aa486c..5dea363 100644
@@ -5,10 +5,29 @@ after a preset amount of time during which the WDT reset event has not
 occurred.
 
 Required properties:
-- compatible : should be "samsung,s3c2410-wdt"
+- compatible : should be one among the following
+	(a) "samsung,s3c2410-wdt" for Exynos4 and previous SoCs
+	(b) "samsung,exynos5250-wdt" for Exynos5250
+	(c) "samsung,exynos5420-wdt" for Exynos5420
+
 - reg : base physical address of the controller and length of memory mapped
 	region.
 - interrupts : interrupt number to the cpu.
+- samsung,syscon-phandle : reference to syscon node (This property required only
+	in case of compatible being "samsung,exynos5250-wdt" or "samsung,exynos5420-wdt".
+	In case of Exynos5250 and 5420 this property points to syscon node holding the PMU
+	base address)
 
 Optional properties:
 - timeout-sec : contains the watchdog timeout in seconds.
+
+Example:
+
+watchdog@101D0000 {
+	compatible = "samsung,exynos5250-wdt";
+	reg = <0x101D0000 0x100>;
+	interrupts = <0 42 0>;
+	clocks = <&clock 336>;
+	clock-names = "watchdog";
+	samsung,syscon-phandle = <&pmu_sys_reg>;
+};
drivers/watchdog/Kconfig +1 -0
index d1d53f3..0d272ae 100644
@@ -188,6 +188,7 @@ config S3C2410_WATCHDOG
 	tristate "S3C2410 Watchdog"
 	depends on HAVE_S3C2410_WATCHDOG
 	select WATCHDOG_CORE
+	select MFD_SYSCON if ARCH_EXYNOS5
 	help
 	  Watchdog timer block in the Samsung SoCs. This will reboot
 	  the system when the timer expires with the watchdog enabled.
drivers/watchdog/s3c2410_wdt.c +140 -8

248 lines not on this page · raw message

Signature · 1 line
1.7.10.4
maintainer
#5 lore raw

Re: [PATCH V8 2/3] watchdog: s3c2410_wdt: add device tree support and use syscon regmap interface to configure pmu register

Quoted 4 lines · Leela Krishna Amudala

Add device tree support and use syscon regmap interface to configure AUTOMATIC_WDT_RESET_DISABLE and MASK_WDT_RESET_REQUEST registers of PMU to mask/unmask enable/disable of watchdog in probe and s2r scenarios.

If the driver didn't support devicetree before, why did it have #ifdef CONFIG_OF, and why does its devicetree bindings file already exist ?

Seems to me the description does not match the patch; it appears that you are really adding Exynos5 support to the driver.

Quoted 130 lines
---
  .../devicetree/bindings/watchdog/samsung-wdt.txt   |   21 ++-
  drivers/watchdog/Kconfig                           |    1 +
  drivers/watchdog/s3c2410_wdt.c                     |  148 ++++++++++++++++++--
  3 files changed, 161 insertions(+), 9 deletions(-)
Documentation/devicetree/bindings/watchdog/samsung-wdt.txt +20 -1
index 2aa486c..5dea363 100644
@@ -5,10 +5,29 @@ after a preset amount of time during which the WDT reset event has not
  occurred.
 
  Required properties:
-- compatible : should be "samsung,s3c2410-wdt"
+- compatible : should be one among the following
+	(a) "samsung,s3c2410-wdt" for Exynos4 and previous SoCs
+	(b) "samsung,exynos5250-wdt" for Exynos5250
+	(c) "samsung,exynos5420-wdt" for Exynos5420
+
  - reg : base physical address of the controller and length of memory mapped
  	region.
  - interrupts : interrupt number to the cpu.
+- samsung,syscon-phandle : reference to syscon node (This property required only
+	in case of compatible being "samsung,exynos5250-wdt" or "samsung,exynos5420-wdt".
+	In case of Exynos5250 and 5420 this property points to syscon node holding the PMU
+	base address)
 
  Optional properties:
  - timeout-sec : contains the watchdog timeout in seconds.
+
+Example:
+
+watchdog@101D0000 {
+	compatible = "samsung,exynos5250-wdt";
+	reg = <0x101D0000 0x100>;
+	interrupts = <0 42 0>;
+	clocks = <&clock 336>;
+	clock-names = "watchdog";
+	samsung,syscon-phandle = <&pmu_sys_reg>;
+};
drivers/watchdog/Kconfig +1 -0
index d1d53f3..0d272ae 100644
@@ -188,6 +188,7 @@ config S3C2410_WATCHDOG
  	tristate "S3C2410 Watchdog"
  	depends on HAVE_S3C2410_WATCHDOG
  	select WATCHDOG_CORE
+	select MFD_SYSCON if ARCH_EXYNOS5
  	help
  	  Watchdog timer block in the Samsung SoCs. This will reboot
  	  the system when the timer expires with the watchdog enabled.
drivers/watchdog/s3c2410_wdt.c +45 -0
index 23aad7c..ccf755d 100644
@@ -41,6 +41,8 @@
  #include <linux/slab.h>
  #include <linux/err.h>
  #include <linux/of.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
 
  #define S3C2410_WTCON		0x00
  #define S3C2410_WTDAT		0x04
@@ -61,6 +63,10 @@
  #define CONFIG_S3C2410_WATCHDOG_ATBOOT		(0)
  #define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME	(15)
 
+#define WDT_DISABLE_REG_OFFSET		0x0408
+#define WDT_MASK_RESET_REG_OFFSET	0x040c
+#define QUIRK_NEEDS_PMU_CONFIG		(1 << 0)
+
  static bool nowayout	= WATCHDOG_NOWAYOUT;
  static int tmr_margin;
  static int tmr_atboot	= CONFIG_S3C2410_WATCHDOG_ATBOOT;
@@ -84,6 +90,13 @@ MODULE_PARM_DESC(soft_noboot, "Watchdog action, set to 1 to ignore reboots, "
  			"0 to reboot (default 0)");
  MODULE_PARM_DESC(debug, "Watchdog debug, set to >1 for debug (default 0)");
 
+struct s3c2410_wdt_variant {
+	int disable_reg;
+	int mask_reset_reg;
+	int mask_bit;
+	u32 quirks;
+};
+
  struct s3c2410_wdt {
  	struct device		*dev;
  	struct clk		*clock;
@@ -94,8 +107,50 @@ struct s3c2410_wdt {
  	unsigned long		wtdat_save;
  	struct watchdog_device	wdt_device;
  	struct notifier_block	freq_transition;
+	struct s3c2410_wdt_variant *pmu_config;
+	struct regmap *pmureg;
+};
+
+static const struct s3c2410_wdt_variant pmu_config_s3c2410 = {
+	.quirks = 0
+};
+
+#ifdef CONFIG_OF
+static const struct s3c2410_wdt_variant pmu_config_5250  = {
+	.disable_reg = WDT_DISABLE_REG_OFFSET,
+	.mask_reset_reg = WDT_MASK_RESET_REG_OFFSET,
+	.mask_bit = 20,
+	.quirks = QUIRK_NEEDS_PMU_CONFIG
  };
 
+static const struct s3c2410_wdt_variant pmu_config_5420 = {
+	.disable_reg = WDT_DISABLE_REG_OFFSET,
+	.mask_reset_reg = WDT_MASK_RESET_REG_OFFSET,
+	.mask_bit = 0,
+	.quirks = QUIRK_NEEDS_PMU_CONFIG
+};
+
+static const struct of_device_id s3c2410_wdt_match[] = {
+	{ .compatible = "samsung,s3c2410-wdt",
+	  .data = &pmu_config_s3c2410 },
+	{ .compatible = "samsung,exynos5250-wdt",
+	  .data = &pmu_config_5250 },
+	{ .compatible = "samsung,exynos5420-wdt",
+	  .data = &pmu_config_5420 },
+	{},
+};
+MODULE_DEVICE_TABLE(of, s3c2410_wdt_match);
+#endif

drivers/watchdog/s3c2410_wdt.c struct s3c2410_wdt { · line 153

Quoted 10 lines
drivers/watchdog/s3c2410_wdt.c +10 -0
+
+static const struct platform_device_id s3c2410_wdt_ids[] = {
+	{
+		.name = "s3c2410-wdt",
+		.driver_data = (unsigned long)&pmu_config_s3c2410,
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(platform, s3c2410_wdt_ids);
+

What is this second device ID and MODULE_DEVICE_TABLE for ?
I assume it is to provide driver_data. If so, you should probably remove the platform MODULE_ALIAS at the end of the driver.

Quoted 19 lines
drivers/watchdog/s3c2410_wdt.c +12 -0
  /* watchdog control routines */
 
  #define DBG(fmt, ...)					\
@@ -111,6 +166,30 @@ static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb)
  	return container_of(nb, struct s3c2410_wdt, freq_transition);
  }
 
+static int s3c2410wdt_mask_and_disable_reset(struct s3c2410_wdt *wdt, bool mask)
+{
+	int ret;
+	u32 mask_val = 1 << wdt->pmu_config->mask_bit;
+	u32 val = 0;
+
+	if (mask)
+		val = mask_val;
+
+	ret = regmap_update_bits(wdt->pmureg,
+			wdt->pmu_config->disable_reg,
+			mask_val, val);

drivers/watchdog/s3c2410_wdt.c static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb) · line 190

Quoted 10 lines
drivers/watchdog/s3c2410_wdt.c +10 -0
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_update_bits(wdt->pmureg,
+			wdt->pmu_config->mask_reset_reg,
+			mask_val, val);
+	if (ret < 0)
+		return ret;
+
+	return 0;

The above code is identical to

	return ret;
Quoted 44 lines
drivers/watchdog/s3c2410_wdt.c +26 -0
+}
+
  static int s3c2410wdt_keepalive(struct watchdog_device *wdd)
  {
  	struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd);
@@ -332,6 +411,20 @@ static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt)
  }
  #endif
 
+/* s3c2410_get_wdt_driver_data */
+static inline struct s3c2410_wdt_variant *
+get_wdt_drv_data(struct platform_device *pdev)
+{
+	if (pdev->dev.of_node) {
+		const struct of_device_id *match;
+		match = of_match_node(s3c2410_wdt_match, pdev->dev.of_node);
+		return (struct s3c2410_wdt_variant *)match->data;
+	} else {
+		return (struct s3c2410_wdt_variant *)
+			platform_get_device_id(pdev)->driver_data;
+	}
+}
+
  static int s3c2410wdt_probe(struct platform_device *pdev)
  {
  	struct device *dev;
@@ -354,6 +447,16 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
  	spin_lock_init(&wdt->lock);
  	wdt->wdt_device = s3c2410_wdd;
 
+	wdt->pmu_config = get_wdt_drv_data(pdev);
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+		wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
+							"samsung,syscon-phandle");
+		if (IS_ERR(wdt->pmureg)) {
+			dev_err(dev, "syscon regmap lookup failed.\n");
+			return PTR_ERR(wdt->pmureg);
+		}
+	}
+
  	wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  	if (wdt_irq == NULL) {
  		dev_err(dev, "no irq resource specified\n");

drivers/watchdog/s3c2410_wdt.c static int s3c2410wdt_probe(struct platform_device *pdev) · line 550

Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +1 -0
@@ -444,6 +547,14 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
  		 (wtcon & S3C2410_WTCON_RSTEN) ? "en" : "dis",
  		 (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis");
 
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {

Might be easier to check for wdt->pmureg in all those secondary conditionals.

drivers/watchdog/s3c2410_wdt.c static int s3c2410wdt_probe(struct platform_device *pdev) · line 553

Quoted 3 lines
drivers/watchdog/s3c2410_wdt.c +3 -0
+		ret = s3c2410wdt_mask_and_disable_reset(wdt, false);
+		if (ret < 0) {
+			dev_warn(wdt->dev, "failed to update pmu register");

Is this a warning or an error ?

If it is (only) a warning, why do you bail out ?

On a side note, I am not sure if all those errors can really happen in practice. Becasue if not, all you do is to increase code size with no real benefit.

Quoted 101 lines
drivers/watchdog/s3c2410_wdt.c +33 -8
+			goto err_cpufreq;
+		}
+	}
+
  	return 0;
 
   err_cpufreq:
@@ -459,8 +570,15 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
 
  static int s3c2410wdt_remove(struct platform_device *dev)
  {
+	int ret;
  	struct s3c2410_wdt *wdt = platform_get_drvdata(dev);
 
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+		ret = s3c2410wdt_mask_and_disable_reset(wdt, true);
+		if (ret < 0)
+			dev_warn(wdt->dev, "failed to update pmu register");
+	}
+
  	watchdog_unregister_device(&wdt->wdt_device);
 
  	s3c2410wdt_cpufreq_deregister(wdt);
@@ -473,8 +591,15 @@ static int s3c2410wdt_remove(struct platform_device *dev)
 
  static void s3c2410wdt_shutdown(struct platform_device *dev)
  {
+	int ret;
  	struct s3c2410_wdt *wdt = platform_get_drvdata(dev);
 
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+		ret = s3c2410wdt_mask_and_disable_reset(wdt, true);
+		if (ret < 0)
+			dev_warn(wdt->dev, "failed to update pmu register");
+	}
+
  	s3c2410wdt_stop(&wdt->wdt_device);
  }
 
@@ -482,12 +607,19 @@ static void s3c2410wdt_shutdown(struct platform_device *dev)
 
  static int s3c2410wdt_suspend(struct device *dev)
  {
+	int ret;
  	struct s3c2410_wdt *wdt = dev_get_drvdata(dev);
 
  	/* Save watchdog state, and turn it off. */
  	wdt->wtcon_save = readl(wdt->reg_base + S3C2410_WTCON);
  	wdt->wtdat_save = readl(wdt->reg_base + S3C2410_WTDAT);
 
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+		ret = s3c2410wdt_mask_and_disable_reset(wdt, true);
+		if (ret < 0)
+			dev_warn(wdt->dev, "failed to update pmu register");
+	}
+
  	/* Note that WTCNT doesn't need to be saved. */
  	s3c2410wdt_stop(&wdt->wdt_device);
 
@@ -496,6 +628,7 @@ static int s3c2410wdt_suspend(struct device *dev)
 
  static int s3c2410wdt_resume(struct device *dev)
  {
+	int ret;
  	struct s3c2410_wdt *wdt = dev_get_drvdata(dev);
 
  	/* Restore watchdog state. */
@@ -503,6 +636,12 @@ static int s3c2410wdt_resume(struct device *dev)
  	writel(wdt->wtdat_save, wdt->reg_base + S3C2410_WTCNT);/* Reset count */
  	writel(wdt->wtcon_save, wdt->reg_base + S3C2410_WTCON);
 
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+		ret = s3c2410wdt_mask_and_disable_reset(wdt, false);
+		if (ret < 0)
+			dev_warn(wdt->dev, "failed to update pmu register");
+	}
+
  	dev_info(dev, "watchdog %sabled\n",
  		(wdt->wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis");
 
@@ -513,18 +652,11 @@ static int s3c2410wdt_resume(struct device *dev)
  static SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops, s3c2410wdt_suspend,
  			s3c2410wdt_resume);
 
-#ifdef CONFIG_OF
-static const struct of_device_id s3c2410_wdt_match[] = {
-	{ .compatible = "samsung,s3c2410-wdt" },
-	{},
-};
-MODULE_DEVICE_TABLE(of, s3c2410_wdt_match);
-#endif
-
  static struct platform_driver s3c2410wdt_driver = {
  	.probe		= s3c2410wdt_probe,
  	.remove		= s3c2410wdt_remove,
  	.shutdown	= s3c2410wdt_shutdown,
+	.id_table	= s3c2410_wdt_ids,
  	.driver		= {
  		.owner	= THIS_MODULE,
  		.name	= "s3c2410-wdt",
#6 lore raw

Re: [PATCH V8 2/3] watchdog: s3c2410_wdt: add device tree support and use syscon regmap interface to configure pmu register

Quoted 10 lines · On Thursday 14 of November 2013 18:49:34 Guenter Roeck wrote:
Quoted 4 lines · Leela Krishna Amudala

Add device tree support and use syscon regmap interface to configure AUTOMATIC_WDT_RESET_DISABLE and MASK_WDT_RESET_REQUEST registers of PMU to mask/unmask enable/disable of watchdog in probe and s2r scenarios.

If the driver didn't support devicetree before, why did it have #ifdef CONFIG_OF, and why does its devicetree bindings file already exist ?

Seems to me the description does not match the patch; it appears that you are really adding Exynos5 support to the driver.

Yes, the driver did support Device Tree before. Patch description needs to be corrected.

Quoted 4 lines
Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +0 -0
index 23aad7c..ccf755d 100644

[snip]

Quoted 6 lines
Quoted 6 lines
drivers/watchdog/s3c2410_wdt.c +6 -0
+
+static const struct platform_device_id s3c2410_wdt_ids[] = {
+	{
+		.name = "s3c2410-wdt",
+		.driver_data = (unsigned long)&pmu_config_s3c2410,
+	},
Quoted 8 lines

drivers/watchdog/s3c2410_wdt.c struct s3c2410_wdt { · line 153

Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +4 -0
+	{}
+};
+MODULE_DEVICE_TABLE(platform, s3c2410_wdt_ids);
+

What is this second device ID and MODULE_DEVICE_TABLE for ?
I assume it is to provide driver_data. If so, you should probably remove the platform MODULE_ALIAS at the end of the driver.

Yes. I suggested adding it to simplify the code a bit by having driver data supplied even when booting without DT. Good catch with MODULE_ALIAS, though.

Quoted 32 lines
Quoted 20 lines

/* watchdog control routines */

  #define DBG(fmt, ...)					\
drivers/watchdog/s3c2410_wdt.c +12 -0
@@ -111,6 +166,30 @@ static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb)
  	return container_of(nb, struct s3c2410_wdt, freq_transition);
  }
 
+static int s3c2410wdt_mask_and_disable_reset(struct s3c2410_wdt *wdt, bool mask)
+{
+	int ret;
+	u32 mask_val = 1 << wdt->pmu_config->mask_bit;
+	u32 val = 0;
+
+	if (mask)
+		val = mask_val;
+
+	ret = regmap_update_bits(wdt->pmureg,
+			wdt->pmu_config->disable_reg,
+			mask_val, val);

drivers/watchdog/s3c2410_wdt.c static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb) · line 190

Quoted 10 lines
drivers/watchdog/s3c2410_wdt.c +10 -0
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_update_bits(wdt->pmureg,
+			wdt->pmu_config->mask_reset_reg,
+			mask_val, val);
+	if (ret < 0)
+		return ret;
+
+	return 0;

The above code is identical to

Quoted 1 line
	return ret;

I'd even say that the above code is identical to

	return regmap_update_bits(wdt->pmureg,
			wdt->pmu_config->mask_reset_reg,
			mask_val, val);
Quoted 48 lines
Quoted 48 lines
drivers/watchdog/s3c2410_wdt.c +26 -0
+}
+
  static int s3c2410wdt_keepalive(struct watchdog_device *wdd)
  {
  	struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd);
@@ -332,6 +411,20 @@ static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt)
  }
  #endif
 
+/* s3c2410_get_wdt_driver_data */
+static inline struct s3c2410_wdt_variant *
+get_wdt_drv_data(struct platform_device *pdev)
+{
+	if (pdev->dev.of_node) {
+		const struct of_device_id *match;
+		match = of_match_node(s3c2410_wdt_match, pdev->dev.of_node);
+		return (struct s3c2410_wdt_variant *)match->data;
+	} else {
+		return (struct s3c2410_wdt_variant *)
+			platform_get_device_id(pdev)->driver_data;
+	}
+}
+
  static int s3c2410wdt_probe(struct platform_device *pdev)
  {
  	struct device *dev;
@@ -354,6 +447,16 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
  	spin_lock_init(&wdt->lock);
  	wdt->wdt_device = s3c2410_wdd;
 
+	wdt->pmu_config = get_wdt_drv_data(pdev);
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+		wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
+							"samsung,syscon-phandle");
+		if (IS_ERR(wdt->pmureg)) {
+			dev_err(dev, "syscon regmap lookup failed.\n");
+			return PTR_ERR(wdt->pmureg);
+		}
+	}
+
  	wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  	if (wdt_irq == NULL) {
  		dev_err(dev, "no irq resource specified\n");
@@ -444,6 +547,14 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
  		 (wtcon & S3C2410_WTCON_RSTEN) ? "en" : "dis",
  		 (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis");
 
Quoted 3 lines

drivers/watchdog/s3c2410_wdt.c static int s3c2410wdt_probe(struct platform_device *pdev) · line 550

Quoted 1 line
drivers/watchdog/s3c2410_wdt.c +1 -0
+	if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {

Might be easier to check for wdt->pmureg in all those secondary conditionals.

IMHO not really much easier and less meaningful. Furthermore, in case of other quirks showing up in future that wouldn't have alternative way of checking, they will have consistent style of checks.

However, I think I missed to point out the ugly field name in my previous reviews. Instead of calling it "pmu_config", "drv_data" would be much better.

Quoted 11 lines

drivers/watchdog/s3c2410_wdt.c static int s3c2410wdt_probe(struct platform_device *pdev) · line 553

Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +3 -0
+		ret = s3c2410wdt_mask_and_disable_reset(wdt, false);
+		if (ret < 0) {
+			dev_warn(wdt->dev, "failed to update pmu register");

Is this a warning or an error ?

If it is (only) a warning, why do you bail out ?

On a side note, I am not sure if all those errors can really happen in practice. Becasue if not, all you do is to increase code size with no real benefit.

Yes, that's a good point. I was under impression that returned error codes should not be ignored, but maybe I was a bit too strict over this.

Generally on currently supported platforms that will end up as a simple MMIO register access locked with a spinlock, so really no way to fail.

Anyway, a failure to write these PMU registers would end up with the watchdog not generating the reset, so IMHO it would be an error.

Best regards,
Tomasz

#7 lore raw

Re: [PATCH V8 2/3] watchdog: s3c2410_wdt: add device tree support and use syscon regmap interface to configure pmu register

Hi Tomasz

Quoted 6 lines · Tomasz Figa
Quoted 5 lines · On Thursday 14 of November 2013 18:49:34 Guenter Roeck wrote:
Quoted 4 lines · Leela Krishna Amudala

Add device tree support and use syscon regmap interface to configure AUTOMATIC_WDT_RESET_DISABLE and MASK_WDT_RESET_REQUEST registers of PMU to mask/unmask enable/disable of watchdog in probe and s2r scenarios.

Quoted 9 lines
Quoted 5 lines

If the driver didn't support devicetree before, why did it have #ifdef CONFIG_OF, and why does its devicetree bindings file already exist ?

Seems to me the description does not match the patch; it appears that you are really adding Exynos5 support to the driver.

Yes, the driver did support Device Tree before. Patch description needs to be corrected.

Okay, modified the patch description

Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +0 -0
index 23aad7c..ccf755d 100644

[snip]

Quoted 6 lines
Quoted 6 lines
drivers/watchdog/s3c2410_wdt.c +6 -0
+
+static const struct platform_device_id s3c2410_wdt_ids[] = {
+   {
+           .name = "s3c2410-wdt",
+           .driver_data = (unsigned long)&pmu_config_s3c2410,
+   },
Quoted 8 lines

drivers/watchdog/s3c2410_wdt.c struct s3c2410_wdt { · line 153

Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +4 -0
+   {}
+};
+MODULE_DEVICE_TABLE(platform, s3c2410_wdt_ids);
+

What is this second device ID and MODULE_DEVICE_TABLE for ?
I assume it is to provide driver_data. If so, you should probably remove the platform MODULE_ALIAS at the end of the driver.

Quoted 4 lines

Yes. I suggested adding it to simplify the code a bit by having driver data supplied even when booting without DT. Good catch with MODULE_ALIAS, though.

Okay, Deleted MODULE_ALIAS and tested non-dt case also on 5420 SoC

Quoted 34 lines
Quoted 32 lines
Quoted 20 lines

/* watchdog control routines */

  #define DBG(fmt, ...)                                     \
drivers/watchdog/s3c2410_wdt.c +12 -0
@@ -111,6 +166,30 @@ static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb)
    return container_of(nb, struct s3c2410_wdt, freq_transition);
  }
 
+static int s3c2410wdt_mask_and_disable_reset(struct s3c2410_wdt *wdt, bool mask)
+{
+   int ret;
+   u32 mask_val = 1 << wdt->pmu_config->mask_bit;
+   u32 val = 0;
+
+   if (mask)
+           val = mask_val;
+
+   ret = regmap_update_bits(wdt->pmureg,
+                   wdt->pmu_config->disable_reg,
+                   mask_val, val);

drivers/watchdog/s3c2410_wdt.c static inline struct s3c2410_wdt *freq_to_wdt(struct notifier_block *nb) · line 190

Quoted 10 lines
drivers/watchdog/s3c2410_wdt.c +10 -0
+   if (ret < 0)
+           return ret;
+
+   ret = regmap_update_bits(wdt->pmureg,
+                   wdt->pmu_config->mask_reset_reg,
+                   mask_val, val);
+   if (ret < 0)
+           return ret;
+
+   return 0;

The above code is identical to

Quoted 1 line
      return ret;
Quoted 6 lines

I'd even say that the above code is identical to

        return regmap_update_bits(wdt->pmureg,
                        wdt->pmu_config->mask_reset_reg,
                        mask_val, val);

Okay, looks fine changed it

Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
drivers/watchdog/s3c2410_wdt.c +26 -0
+}
+
  static int s3c2410wdt_keepalive(struct watchdog_device *wdd)
  {
    struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd);
@@ -332,6 +411,20 @@ static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt)
  }
  #endif
 
+/* s3c2410_get_wdt_driver_data */
+static inline struct s3c2410_wdt_variant *
+get_wdt_drv_data(struct platform_device *pdev)
+{
+   if (pdev->dev.of_node) {
+           const struct of_device_id *match;
+           match = of_match_node(s3c2410_wdt_match, pdev->dev.of_node);
+           return (struct s3c2410_wdt_variant *)match->data;
+   } else {
+           return (struct s3c2410_wdt_variant *)
+                   platform_get_device_id(pdev)->driver_data;
+   }
+}
+
  static int s3c2410wdt_probe(struct platform_device *pdev)
  {
    struct device *dev;
@@ -354,6 +447,16 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
    spin_lock_init(&wdt->lock);
    wdt->wdt_device = s3c2410_wdd;
 
+   wdt->pmu_config = get_wdt_drv_data(pdev);
+   if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {
+           wdt->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
+                                                   "samsung,syscon-phandle");
+           if (IS_ERR(wdt->pmureg)) {
+                   dev_err(dev, "syscon regmap lookup failed.\n");
+                   return PTR_ERR(wdt->pmureg);
+           }
+   }
+
    wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
    if (wdt_irq == NULL) {
            dev_err(dev, "no irq resource specified\n");
@@ -444,6 +547,14 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
             (wtcon & S3C2410_WTCON_RSTEN) ? "en" : "dis",
             (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis");
 
Quoted 8 lines
Quoted 3 lines

drivers/watchdog/s3c2410_wdt.c static int s3c2410wdt_probe(struct platform_device *pdev) · line 550

Quoted 1 line
drivers/watchdog/s3c2410_wdt.c +1 -0
+   if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) {

Might be easier to check for wdt->pmureg in all those secondary conditionals.

IMHO not really much easier and less meaningful. Furthermore, in case of other quirks showing up in future that wouldn't have alternative way of checking, they will have consistent style of checks.

Yes, Still used if (wdt->pmu_config->quirks & QUIRK_NEEDS_PMU_CONFIG) for
conditional checks.

Quoted 4 lines

However, I think I missed to point out the ugly field name in my previous reviews. Instead of calling it "pmu_config", "drv_data" would be much better.

Okay, changed from "pmu_config" to "drv_data"

Quoted 12 lines
Quoted 11 lines

drivers/watchdog/s3c2410_wdt.c static int s3c2410wdt_probe(struct platform_device *pdev) · line 553

Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +3 -0
+           ret = s3c2410wdt_mask_and_disable_reset(wdt, false);
+           if (ret < 0) {
+                   dev_warn(wdt->dev, "failed to update pmu register");

Is this a warning or an error ?

If it is (only) a warning, why do you bail out ?

On a side note, I am not sure if all those errors can really happen in practice. Becasue if not, all you do is to increase code size with no real benefit.

Quoted 9 lines

Yes, that's a good point. I was under impression that returned error codes should not be ignored, but maybe I was a bit too strict over this.

Generally on currently supported platforms that will end up as a simple MMIO register access locked with a spinlock, so really no way to fail.

Anyway, a failure to write these PMU registers would end up with the watchdog not generating the reset, so IMHO it would be an error.

Yes, changed it to dev_err and kept the dev_warn in other functions as it is

Best Wishes,
Leela Krishna.

Quoted 7 lines

Best regards,
Tomasz

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

PATCH v8 3/3 ARM: dts: update watchdog device nodes for Exynos5250 and Exynos5420

In reply to Leela Krishna Amudala

In Exynos5 series SoCs, PMU has registers to enable/disable mask/unmask watchdog timer which is not the case with s3c series SoCs so, there is a need to have different compatible names for watchdog to handle these pmu registers access.

Hence this patch removes watchdog node from Exynos5.dtsi common file and make it separate by updating existing node in Exynos5250 and adding new node to Exynos5420. This patch also makes the watchdog node enabled by default

---
 arch/arm/boot/dts/exynos5.dtsi    |    7 -------
 arch/arm/boot/dts/exynos5250.dtsi |    6 +++++-
 arch/arm/boot/dts/exynos5420.dtsi |    9 +++++++++
 3 files changed, 14 insertions(+), 8 deletions(-)
arch/arm/boot/dts/exynos5.dtsi +0 -7
index e52b038..f1fea28 100644
@@ -81,13 +81,6 @@
 		status = "disabled";
 	};
 
-	watchdog {
-		compatible = "samsung,s3c2410-wdt";
-		reg = <0x101D0000 0x100>;
-		interrupts = <0 42 0>;
-		status = "disabled";
-	};
-
 	fimd@14400000 {
 		compatible = "samsung,exynos5250-fimd";
 		interrupt-parent = <&combiner>;
arch/arm/boot/dts/exynos5250.dtsi +5 -1
index 6056a83..69f6c6a 100644
@@ -163,9 +163,13 @@
 		reg = <0x10040000 0x5000>;
 	};
 
-	watchdog {
+	watchdog@101D0000 {
+		compatible = "samsung,exynos5250-wdt";
+		reg = <0x101D0000 0x100>;
+		interrupts = <0 42 0>;
 		clocks = <&clock 336>;
 		clock-names = "watchdog";
+		samsung,syscon-phandle = <&pmu_syscon>;
 	};
 
 	g2d@10850000 {
arch/arm/boot/dts/exynos5420.dtsi +9 -0
index 39ce15a..61764bb 100644
@@ -374,4 +374,13 @@
 		compatible = "samsung,exynos5420-pmu", "syscon";
 		reg = <0x10040000 0x5000>;
 	};
+
+        watchdog@101D0000 {
+		compatible = "samsung,exynos5420-wdt";
+		reg = <0x101D0000 0x100>;
+		interrupts = <0 42 0>;
+		clocks = <&clock 316>;
+		clock-names = "watchdog";
+		samsung,syscon-phandle = <&pmu_syscon>;
+        };
 };
Signature · 1 line
1.7.10.4