// SPDX-License-Identifier: GPL-2.0-or-later /* * i6300esb: Watchdog timer driver for Intel 6300ESB chipset * * (c) Copyright 2004 Google Inc. * (c) Copyright 2005 David Härdeman <david@2gen.com> * * based on i810-tco.c which is in turn based on softdog.c * * The timer is implemented in the following I/O controller hubs: * (See the intel documentation on http://developer.intel.com.) * 6300ESB chip : document number 300641-004 * * 2004YYZZ Ross Biro * Initial version 0.01 * 2004YYZZ Ross Biro * Version 0.02 * 20050210 David Härdeman <david@2gen.com> * Ported driver to kernel 2.6 * 20171016 Radu Rendec <rrendec@arista.com> * Change driver to use the watchdog subsystem * Add support for multiple 6300ESB devices
*/
/* * Prepare for reloading the timer by unlocking the proper registers. * This is performed by first writing 0x80 followed by 0x86 to the * reload register. After this the appropriate registers can be written * to once before they need to be unlocked again.
*/ staticinlinevoid esb_unlock_registers(struct esb_dev *edev)
{
writew(ESB_UNLOCK1, ESB_RELOAD_REG(edev));
writew(ESB_UNLOCK2, ESB_RELOAD_REG(edev));
}
/* First, reset timers as suggested by the docs */
esb_unlock_registers(edev);
writew(ESB_WDT_RELOAD, ESB_RELOAD_REG(edev)); /* Then disable the WDT */
pci_write_config_byte(edev->pdev, ESB_LOCK_REG, 0x0);
pci_read_config_byte(edev->pdev, ESB_LOCK_REG, &val);
/* Returns 0 if the timer was disabled, non-zero otherwise */ return val & ESB_WDT_ENABLE;
}
/* We shift by 9, so if we are passed a value of 1 sec, * val will be 1 << 9 = 512, then write that to two * timers => 2 * 512 = 1024 (which is decremented at 1KHz)
*/
val = time << 9;
/* * Data for PCI driver interface
*/ staticconststruct pci_device_id esb_pci_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_9), },
{ 0, }, /* End of list */
};
MODULE_DEVICE_TABLE(pci, esb_pci_tbl);
/* * Init & exit routines
*/
staticunsignedchar esb_getdevice(struct esb_dev *edev)
{ if (pci_enable_device(edev->pdev)) {
dev_err(&edev->pdev->dev, "failed to enable device\n"); goto err_devput;
}
if (pci_request_region(edev->pdev, 0, ESB_MODULE_NAME)) {
dev_err(&edev->pdev->dev, "failed to request region\n"); goto err_disable;
}
edev->base = pci_ioremap_bar(edev->pdev, 0); if (edev->base == NULL) { /* Something's wrong here, BASEADDR has to be set */
dev_err(&edev->pdev->dev, "failed to get BASEADDR\n"); goto err_release;
}
/* * Config register: * Bit 5 : 0 = Enable WDT_OUTPUT * Bit 2 : 0 = set the timer frequency to the PCI clock * divided by 2^15 (approx 1KHz). * Bits 1:0 : 11 = WDT_INT_TYPE Disabled. * The watchdog has two timers, it can be setup so that the * expiry of timer1 results in an interrupt and the expiry of * timer2 results in a reboot. We set it to not generate * any interrupts as there is not much we can do with it * right now.
*/
pci_write_config_word(edev->pdev, ESB_CONFIG_REG, 0x0003);
/* Check that the WDT isn't already locked */
pci_read_config_byte(edev->pdev, ESB_LOCK_REG, &val1); if (val1 & ESB_WDT_LOCK)
dev_warn(&edev->pdev->dev, "nowayout already set\n");
/* Set the timer to watchdog mode and disable it for now */
pci_write_config_byte(edev->pdev, ESB_LOCK_REG, 0x00);
/* Check if the watchdog was previously triggered */
esb_unlock_registers(edev);
val2 = readw(ESB_RELOAD_REG(edev)); if (val2 & ESB_WDT_TIMEOUT)
edev->wdd.bootstatus = WDIOF_CARDRESET;
/* Reset WDT_TIMEOUT flag and timers */
esb_unlock_registers(edev);
writew((ESB_WDT_TIMEOUT | ESB_WDT_RELOAD), ESB_RELOAD_REG(edev));
/* And set the correct timeout value */
esb_timer_set_heartbeat(&edev->wdd, edev->wdd.timeout);
}
edev = devm_kzalloc(&pdev->dev, sizeof(*edev), GFP_KERNEL); if (!edev) return -ENOMEM;
/* Check whether or not the hardware watchdog is there */
edev->pdev = pdev; if (!esb_getdevice(edev)) return -ENODEV;
/* Initialize the watchdog and make sure it does not run */
edev->wdd.info = &esb_info;
edev->wdd.ops = &esb_ops;
edev->wdd.min_timeout = ESB_HEARTBEAT_MIN;
edev->wdd.max_timeout = ESB_HEARTBEAT_MAX;
edev->wdd.timeout = ESB_HEARTBEAT_DEFAULT;
watchdog_init_timeout(&edev->wdd, heartbeat, NULL);
watchdog_set_nowayout(&edev->wdd, nowayout);
watchdog_stop_on_reboot(&edev->wdd);
watchdog_stop_on_unregister(&edev->wdd);
esb_initdevice(edev);
/* Register the watchdog so that userspace has access to it */
ret = watchdog_register_device(&edev->wdd); if (ret != 0) goto err_unmap;
dev_info(&pdev->dev, "initialized. heartbeat=%d sec (nowayout=%d)\n",
edev->wdd.timeout, nowayout); return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.