/* Calculates the watchdog counter value (wdogcmp0) and scaler (wdogscale) to be installed in the watchdog timer.  */
static int wdt_sifive_convtime(uint32_t timeout, int clk, int *scaler)
/* Calculates the watchdog counter value (wdogcmp0) and scaler (wdogscale) to be installed in the watchdog timer.  */
static int wdt_sifive_convtime(uint32_t timeout, int clk, int *scaler)
{
	uint64_t cnt;
	int i;
	cnt = (uint64_t)timeout * clk / 1000;
	for (i = 0; i < 16; i++) {
		if (cnt <= WDOGCMP_MAX) {
			break;
		}
		cnt >>= 1;
	}
	if (i == 16) {
		LOG_ERR("Invalid timeout value allowed range");
		*scaler = WDOGCFG_SCALE_MAX;
		return WDOGCMP_MAX;
	}
	*scaler = i;
	return cnt;
}