Skip to content

Commit a36c90a

Browse files
Sangwook ShinWim Van Sebroeck
authored andcommitted
watchdog: s3c2410_wdt: Increase max timeout value of watchdog
Increase max_timeout value from 55s to 3665038s (1018h 3min 58s) with 38400000 frequency system if the system has 32-bit WTCNT register. cat /sys/class/watchdog/watchdog0/max_timeout 3665038 [ 0.330082] s3c2410-wdt 10060000.watchdog_cl0: Heartbeat: count=1099511400000, timeout=3665038, freq=300000 [ 0.330087] s3c2410-wdt 10060000.watchdog_cl0: Heartbeat: timeout=3665038, divisor=256, count=1099511400000 (fffffc87) [ 0.330127] s3c2410-wdt 10060000.watchdog_cl0: starting watchdog timer [ 0.330134] s3c2410-wdt 10060000.watchdog_cl0: Starting watchdog: count=0xfffffc87, wtcon=0001ff39 [ 0.330319] s3c2410-wdt 10060000.watchdog_cl0: watchdog active, reset enabled, irq disabled If the system has a 32-bit WTCNT, add QUIRK_HAS_32BIT_CNT to its quirk flags, and it will operate with a 32-bit counter. If not, it will operate with a 16-bit counter like in the previous version. Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org> Signed-off-by: Sangwook Shin <sw617.shin@samsung.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
1 parent df3c6e0 commit a36c90a

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

drivers/watchdog/s3c2410_wdt.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
#define S3C2410_WTCNT 0x08
3535
#define S3C2410_WTCLRINT 0x0c
3636

37-
#define S3C2410_WTCNT_MAXCNT 0xffff
37+
#define S3C2410_WTCNT_MAXCNT_16 0xffff
38+
#define S3C2410_WTCNT_MAXCNT_32 0xffffffff
3839

3940
#define S3C2410_WTCON_RSTEN BIT(0)
4041
#define S3C2410_WTCON_INTEN BIT(2)
@@ -124,13 +125,18 @@
124125
* %QUIRK_HAS_DBGACK_BIT: WTCON register has DBGACK_MASK bit. Setting the
125126
* DBGACK_MASK bit disables the watchdog outputs when the SoC is in debug mode.
126127
* Debug mode is determined by the DBGACK CPU signal.
128+
*
129+
* %QUIRK_HAS_32BIT_CNT: WTDAT and WTCNT are 32-bit registers. With these
130+
* 32-bit registers, larger values will be set, which means that larger timeouts
131+
* value can be set.
127132
*/
128133
#define QUIRK_HAS_WTCLRINT_REG BIT(0)
129134
#define QUIRK_HAS_PMU_MASK_RESET BIT(1)
130135
#define QUIRK_HAS_PMU_RST_STAT BIT(2)
131136
#define QUIRK_HAS_PMU_AUTO_DISABLE BIT(3)
132137
#define QUIRK_HAS_PMU_CNT_EN BIT(4)
133138
#define QUIRK_HAS_DBGACK_BIT BIT(5)
139+
#define QUIRK_HAS_32BIT_CNT BIT(6)
134140

135141
/* These quirks require that we have a PMU register map */
136142
#define QUIRKS_HAVE_PMUREG \
@@ -199,6 +205,7 @@ struct s3c2410_wdt {
199205
struct notifier_block freq_transition;
200206
const struct s3c2410_wdt_variant *drv_data;
201207
struct regmap *pmureg;
208+
u32 max_cnt;
202209
};
203210

204211
static const struct s3c2410_wdt_variant drv_data_s3c2410 = {
@@ -412,7 +419,7 @@ static inline unsigned int s3c2410wdt_max_timeout(struct s3c2410_wdt *wdt)
412419
{
413420
const unsigned long freq = s3c2410wdt_get_freq(wdt);
414421
const u64 n_max = (u64)(S3C2410_WTCON_PRESCALE_MAX + 1) *
415-
S3C2410_WTCON_MAXDIV * S3C2410_WTCNT_MAXCNT;
422+
S3C2410_WTCON_MAXDIV * wdt->max_cnt;
416423
u64 t_max = div64_ul(n_max, freq);
417424

418425
if (t_max > UINT_MAX)
@@ -572,7 +579,7 @@ static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd,
572579
{
573580
struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd);
574581
unsigned long freq = s3c2410wdt_get_freq(wdt);
575-
unsigned int count;
582+
unsigned long count;
576583
unsigned int divisor = 1;
577584
unsigned long wtcon;
578585

@@ -582,24 +589,24 @@ static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd,
582589
freq = DIV_ROUND_UP(freq, 128);
583590
count = timeout * freq;
584591

585-
dev_dbg(wdt->dev, "Heartbeat: count=%d, timeout=%d, freq=%lu\n",
592+
dev_dbg(wdt->dev, "Heartbeat: count=%lu, timeout=%d, freq=%lu\n",
586593
count, timeout, freq);
587594

588595
/* if the count is bigger than the watchdog register,
589596
then work out what we need to do (and if) we can
590597
actually make this value
591598
*/
592599

593-
if (count >= 0x10000) {
594-
divisor = DIV_ROUND_UP(count, 0xffff);
600+
if (count > wdt->max_cnt) {
601+
divisor = DIV_ROUND_UP(count, wdt->max_cnt);
595602

596603
if (divisor > S3C2410_WTCON_PRESCALE_MAX + 1) {
597604
dev_err(wdt->dev, "timeout %d too big\n", timeout);
598605
return -EINVAL;
599606
}
600607
}
601608

602-
dev_dbg(wdt->dev, "Heartbeat: timeout=%d, divisor=%d, count=%d (%08x)\n",
609+
dev_dbg(wdt->dev, "Heartbeat: timeout=%d, divisor=%d, count=%lu (%08lx)\n",
603610
timeout, divisor, count, DIV_ROUND_UP(count, divisor));
604611

605612
count = DIV_ROUND_UP(count, divisor);
@@ -807,6 +814,11 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
807814
if (IS_ERR(wdt->src_clk))
808815
return dev_err_probe(dev, PTR_ERR(wdt->src_clk), "failed to get source clock\n");
809816

817+
if (wdt->drv_data->quirks & QUIRK_HAS_32BIT_CNT)
818+
wdt->max_cnt = S3C2410_WTCNT_MAXCNT_32;
819+
else
820+
wdt->max_cnt = S3C2410_WTCNT_MAXCNT_16;
821+
810822
wdt->wdt_device.min_timeout = 1;
811823
wdt->wdt_device.max_timeout = s3c2410wdt_max_timeout(wdt);
812824

0 commit comments

Comments
 (0)