/* Translate the specified timeout in seconds into System Clock terms which is what the on-chip Watchdog requires.  */
static int bfin_wdt_set_timeout(unsigned long t)
/* Translate the specified timeout in seconds into System Clock terms which is what the on-chip Watchdog requires.  */
static int bfin_wdt_set_timeout(unsigned long t)
{
	u32 cnt, max_t, sclk;
	unsigned long flags;
	sclk = get_sclk();
	max_t = -1 / sclk;
	cnt = t * sclk;
	stamp("maxtimeout=%us newtimeout=%lus (cnt=%#x)", max_t, t, cnt);
	if (t > max_t) {
		printk(KERN_WARNING PFX "timeout value is too large\n");
		return -EINVAL;
	}
	spin_lock_irqsave(&bfin_wdt_spinlock, flags);
	{
		int run = bfin_wdt_running();
		bfin_wdt_stop();
		bfin_write_WDOG_CNT(cnt);
		if (run)
			bfin_wdt_start();
	}
	spin_unlock_irqrestore(&bfin_wdt_spinlock, flags);
	timeout = t;
	return 0;
}