Lines Matching +full:watchdog +full:- +full:timeout +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ACPI Hardware Watchdog (WDAT) driver.
14 #include <linux/watchdog.h>
19 * struct wdat_instruction - Single ACPI WDAT instruction
31 * struct wdat_wdt - ACPI WDAT watchdog device
33 * @wdd: Watchdog core device
34 * @period: How long is one watchdog period in ms
35 * @stopped_in_sleep: Is this watchdog stopped by the firmware in S1-S5
36 * @stopped: Was the watchdog stopped by the driver in suspend
54 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
59 static int timeout = WDAT_DEFAULT_TIMEOUT; variable
60 module_param(timeout, int, 0);
61 MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default="
67 const struct acpi_generic_address *gas = &instr->entry.register_region; in wdat_wdt_read()
69 switch (gas->access_width) { in wdat_wdt_read()
71 *value = ioread8(instr->reg); in wdat_wdt_read()
74 *value = ioread16(instr->reg); in wdat_wdt_read()
77 *value = ioread32(instr->reg); in wdat_wdt_read()
80 return -EINVAL; in wdat_wdt_read()
83 dev_dbg(&wdat->pdev->dev, "Read %#x from 0x%08llx\n", *value, in wdat_wdt_read()
84 gas->address); in wdat_wdt_read()
92 const struct acpi_generic_address *gas = &instr->entry.register_region; in wdat_wdt_write()
94 switch (gas->access_width) { in wdat_wdt_write()
96 iowrite8((u8)value, instr->reg); in wdat_wdt_write()
99 iowrite16((u16)value, instr->reg); in wdat_wdt_write()
102 iowrite32(value, instr->reg); in wdat_wdt_write()
105 return -EINVAL; in wdat_wdt_write()
108 dev_dbg(&wdat->pdev->dev, "Wrote %#x to 0x%08llx\n", value, in wdat_wdt_write()
109 gas->address); in wdat_wdt_write()
119 if (action >= ARRAY_SIZE(wdat->instructions)) in wdat_wdt_run_action()
120 return -EINVAL; in wdat_wdt_run_action()
122 if (!wdat->instructions[action]) in wdat_wdt_run_action()
123 return -EOPNOTSUPP; in wdat_wdt_run_action()
125 dev_dbg(&wdat->pdev->dev, "Running action %#x\n", action); in wdat_wdt_run_action()
128 list_for_each_entry(instr, wdat->instructions[action], node) { in wdat_wdt_run_action()
129 const struct acpi_wdat_entry *entry = &instr->entry; in wdat_wdt_run_action()
135 gas = &entry->register_region; in wdat_wdt_run_action()
137 preserve = entry->instruction & ACPI_WDAT_PRESERVE_REGISTER; in wdat_wdt_run_action()
138 flags = entry->instruction & ~ACPI_WDAT_PRESERVE_REGISTER; in wdat_wdt_run_action()
139 value = entry->value; in wdat_wdt_run_action()
140 mask = entry->mask; in wdat_wdt_run_action()
147 x >>= gas->bit_offset; in wdat_wdt_run_action()
157 x >>= gas->bit_offset; in wdat_wdt_run_action()
165 x <<= gas->bit_offset; in wdat_wdt_run_action()
170 y = y & ~(mask << gas->bit_offset); in wdat_wdt_run_action()
181 x <<= gas->bit_offset; in wdat_wdt_run_action()
186 y = y & ~(mask << gas->bit_offset); in wdat_wdt_run_action()
195 dev_err(&wdat->pdev->dev, "Unknown instruction: %u\n", in wdat_wdt_run_action()
197 return -EINVAL; in wdat_wdt_run_action()
209 * WDAT specification says that the watchdog is required to reboot in wdat_wdt_enable_reboot()
215 if (ret && ret != -EOPNOTSUPP) { in wdat_wdt_enable_reboot()
216 dev_err(&wdat->pdev->dev, in wdat_wdt_enable_reboot()
217 "Failed to enable reboot when watchdog triggers\n"); in wdat_wdt_enable_reboot()
230 if (ret && ret != -EOPNOTSUPP) { in wdat_wdt_boot_status()
231 dev_err(&wdat->pdev->dev, "Failed to read boot status\n"); in wdat_wdt_boot_status()
236 wdat->wdd.bootstatus = WDIOF_CARDRESET; in wdat_wdt_boot_status()
240 if (ret && ret != -EOPNOTSUPP) in wdat_wdt_boot_status()
241 dev_err(&wdat->pdev->dev, "Failed to clear boot status\n"); in wdat_wdt_boot_status()
251 if (ret && ret != -EOPNOTSUPP) in wdat_wdt_set_running()
252 dev_err(&wdat->pdev->dev, "Failed to read running state\n"); in wdat_wdt_set_running()
255 set_bit(WDOG_HW_RUNNING, &wdat->wdd.status); in wdat_wdt_set_running()
276 unsigned int timeout) in wdat_wdt_set_timeout() argument
282 periods = timeout * 1000 / wdat->period; in wdat_wdt_set_timeout()
285 wdd->timeout = timeout; in wdat_wdt_set_timeout()
295 return periods * wdat->period / 1000; in wdat_wdt_get_timeleft()
314 struct device *dev = &pdev->dev; in wdat_wdt_probe()
326 return -ENODEV; in wdat_wdt_probe()
330 return -ENOMEM; in wdat_wdt_probe()
332 regs = devm_kcalloc(dev, pdev->num_resources, sizeof(*regs), in wdat_wdt_probe()
335 return -ENOMEM; in wdat_wdt_probe()
337 /* WDAT specification wants to have >= 1ms period */ in wdat_wdt_probe()
338 if (tbl->timer_period < 1) in wdat_wdt_probe()
339 return -EINVAL; in wdat_wdt_probe()
340 if (tbl->min_count > tbl->max_count) in wdat_wdt_probe()
341 return -EINVAL; in wdat_wdt_probe()
343 wdat->period = tbl->timer_period; in wdat_wdt_probe()
344 wdat->wdd.min_timeout = DIV_ROUND_UP(wdat->period * tbl->min_count, 1000); in wdat_wdt_probe()
345 wdat->wdd.max_timeout = wdat->period * tbl->max_count / 1000; in wdat_wdt_probe()
346 wdat->stopped_in_sleep = tbl->flags & ACPI_WDAT_STOPPED; in wdat_wdt_probe()
347 wdat->wdd.info = &wdat_wdt_info; in wdat_wdt_probe()
348 wdat->wdd.ops = &wdat_wdt_ops; in wdat_wdt_probe()
349 wdat->pdev = pdev; in wdat_wdt_probe()
352 for (i = 0; i < pdev->num_resources; i++) { in wdat_wdt_probe()
355 res = &pdev->resource[i]; in wdat_wdt_probe()
361 reg = devm_ioport_map(dev, res->start, 1); in wdat_wdt_probe()
363 return -ENOMEM; in wdat_wdt_probe()
366 return -EINVAL; in wdat_wdt_probe()
373 for (i = 0; i < tbl->entries; i++) { in wdat_wdt_probe()
389 return -ENOMEM; in wdat_wdt_probe()
391 INIT_LIST_HEAD(&instr->node); in wdat_wdt_probe()
392 instr->entry = entries[i]; in wdat_wdt_probe()
397 r.start = gas->address; in wdat_wdt_probe()
398 r.end = r.start + ACPI_ACCESS_BYTE_WIDTH(gas->access_width) - 1; in wdat_wdt_probe()
399 if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { in wdat_wdt_probe()
401 } else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { in wdat_wdt_probe()
405 gas->space_id); in wdat_wdt_probe()
410 for (j = 0; j < pdev->num_resources; j++) { in wdat_wdt_probe()
411 res = &pdev->resource[j]; in wdat_wdt_probe()
413 instr->reg = regs[j] + r.start - res->start; in wdat_wdt_probe()
418 if (!instr->reg) { in wdat_wdt_probe()
420 return -EINVAL; in wdat_wdt_probe()
423 instructions = wdat->instructions[action]; in wdat_wdt_probe()
429 return -ENOMEM; in wdat_wdt_probe()
432 wdat->instructions[action] = instructions; in wdat_wdt_probe()
435 list_add_tail(&instr->node, instructions); in wdat_wdt_probe()
438 if (wdat->instructions[ACPI_WDAT_GET_CURRENT_COUNTDOWN]) in wdat_wdt_probe()
451 * Set initial timeout so that userspace has time to configure the in wdat_wdt_probe()
452 * watchdog properly after it has opened the device. In some cases in wdat_wdt_probe()
455 if (watchdog_timeout_invalid(&wdat->wdd, timeout)) { in wdat_wdt_probe()
456 dev_warn(dev, "Invalid timeout %d given, using %d\n", in wdat_wdt_probe()
457 timeout, WDAT_DEFAULT_TIMEOUT); in wdat_wdt_probe()
458 timeout = WDAT_DEFAULT_TIMEOUT; in wdat_wdt_probe()
461 ret = wdat_wdt_set_timeout(&wdat->wdd, timeout); in wdat_wdt_probe()
465 watchdog_set_nowayout(&wdat->wdd, nowayout); in wdat_wdt_probe()
466 watchdog_stop_on_reboot(&wdat->wdd); in wdat_wdt_probe()
467 watchdog_stop_on_unregister(&wdat->wdd); in wdat_wdt_probe()
468 return devm_watchdog_register_device(dev, &wdat->wdd); in wdat_wdt_probe()
476 if (!watchdog_active(&wdat->wdd)) in wdat_wdt_suspend_noirq()
480 * We need to stop the watchdog if firmware is not doing it or if we in wdat_wdt_suspend_noirq()
482 * firmware is stopping the watchdog we kick it here one more time in wdat_wdt_suspend_noirq()
485 wdat->stopped = false; in wdat_wdt_suspend_noirq()
487 !wdat->stopped_in_sleep) { in wdat_wdt_suspend_noirq()
488 ret = wdat_wdt_stop(&wdat->wdd); in wdat_wdt_suspend_noirq()
490 wdat->stopped = true; in wdat_wdt_suspend_noirq()
492 ret = wdat_wdt_ping(&wdat->wdd); in wdat_wdt_suspend_noirq()
503 if (!watchdog_active(&wdat->wdd)) in wdat_wdt_resume_noirq()
506 if (!wdat->stopped) { in wdat_wdt_resume_noirq()
508 * Looks like the boot firmware reinitializes the watchdog in wdat_wdt_resume_noirq()
510 * stop and reprogram the watchdog here. in wdat_wdt_resume_noirq()
512 ret = wdat_wdt_stop(&wdat->wdd); in wdat_wdt_resume_noirq()
516 ret = wdat_wdt_set_timeout(&wdat->wdd, wdat->wdd.timeout); in wdat_wdt_resume_noirq()
524 ret = wdat_wdt_ping(&wdat->wdd); in wdat_wdt_resume_noirq()
529 return wdat_wdt_start(&wdat->wdd); in wdat_wdt_resume_noirq()
547 MODULE_DESCRIPTION("ACPI Hardware Watchdog (WDAT) driver");