Lines Matching +full:power +full:- +full:off +full:- +full:time +full:- +full:sec
1 // SPDX-License-Identifier: GPL-2.0+
3 * Berkshire USB-PC Watchdog Card Driver
5 * (c) Copyright 2004-2007 Wim Van Sebroeck <wim@iguana.be>.
12 * Greg Kroah-Hartman <greg@kroah.com>
16 * provided "AS-IS" and at no charge.
28 #include <linux/errno.h> /* For the -ENODEV/... values */
47 #define DRIVER_DESC "Berkshire USB-PC Watchdog driver"
55 delay-time from dip-switches */
59 "(0<heartbeat<65536 or 0=delay-time from dip-switches, default="
67 /* The vendor and product id's for the USB-PC Watchdog card */
78 /* according to documentation max. time to process a command for the USB
84 Re-trigger Watchdog */
89 #define CMD_READ_WATCHDOG_TIMEOUT 0x18 /* Read Current Watchdog Time */
96 5, /* OFF-OFF-OFF = 5 Sec */
97 10, /* OFF-OFF-ON = 10 Sec */
98 30, /* OFF-ON-OFF = 30 Sec */
99 60, /* OFF-ON-ON = 1 Min */
100 300, /* ON-OFF-OFF = 5 Min */
101 600, /* ON-OFF-ON = 10 Min */
102 1800, /* ON-ON-OFF = 30 Min */
103 3600, /* ON-ON-ON = 1 hour */
115 /* save off the usb device pointer */
168 (struct usb_pcwd_private *)urb->context; in usb_pcwd_intr_done()
169 unsigned char *data = usb_pcwd->intr_buffer; in usb_pcwd_intr_done()
170 struct device *dev = &usb_pcwd->interface->dev; in usb_pcwd_intr_done()
173 switch (urb->status) { in usb_pcwd_intr_done()
176 case -ECONNRESET: /* unlink */ in usb_pcwd_intr_done()
177 case -ENOENT: in usb_pcwd_intr_done()
178 case -ESHUTDOWN: in usb_pcwd_intr_done()
180 dev_dbg(dev, "%s - urb shutting down with status: %d", in usb_pcwd_intr_done()
181 __func__, urb->status); in usb_pcwd_intr_done()
183 /* -EPIPE: should clear the halt */ in usb_pcwd_intr_done()
185 dev_dbg(dev, "%s - nonzero urb status received: %d", in usb_pcwd_intr_done()
186 __func__, urb->status); in usb_pcwd_intr_done()
193 usb_pcwd->cmd_command = data[0]; in usb_pcwd_intr_done()
194 usb_pcwd->cmd_data_msb = data[1]; in usb_pcwd_intr_done()
195 usb_pcwd->cmd_data_lsb = data[2]; in usb_pcwd_intr_done()
198 atomic_set(&usb_pcwd->cmd_received, 1); in usb_pcwd_intr_done()
215 if ((!usb_pcwd) || (!usb_pcwd->exists)) in usb_pcwd_send_command()
216 return -1; in usb_pcwd_send_command()
229 dev_dbg(&usb_pcwd->interface->dev, in usb_pcwd_send_command()
233 atomic_set(&usb_pcwd->cmd_received, 0); in usb_pcwd_send_command()
235 if (usb_control_msg(usb_pcwd->udev, usb_sndctrlpipe(usb_pcwd->udev, 0), in usb_pcwd_send_command()
237 0x0200, usb_pcwd->interface_number, buf, 6, in usb_pcwd_send_command()
239 dev_dbg(&usb_pcwd->interface->dev, in usb_pcwd_send_command()
249 if (atomic_read(&usb_pcwd->cmd_received)) in usb_pcwd_send_command()
253 if ((got_response) && (cmd == usb_pcwd->cmd_command)) { in usb_pcwd_send_command()
255 *msb = usb_pcwd->cmd_data_msb; in usb_pcwd_send_command()
256 *lsb = usb_pcwd->cmd_data_lsb; in usb_pcwd_send_command()
276 return -1; in usb_pcwd_start()
294 return -1; in usb_pcwd_stop()
304 /* Re-trigger Watchdog */ in usb_pcwd_keepalive()
316 return -EINVAL; in usb_pcwd_set_heartbeat()
346 /* Read the time that's left before rebooting */ in usb_pcwd_get_timeleft()
376 return -EFAULT; in usb_pcwd_write()
403 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; in usb_pcwd_ioctl()
414 return -EFAULT; in usb_pcwd_ioctl()
421 int new_options, retval = -EINVAL; in usb_pcwd_ioctl()
424 return -EFAULT; in usb_pcwd_ioctl()
448 return -EFAULT; in usb_pcwd_ioctl()
451 return -EINVAL; in usb_pcwd_ioctl()
465 return -EFAULT; in usb_pcwd_ioctl()
471 return -ENOTTY; in usb_pcwd_ioctl()
479 return -EBUSY; in usb_pcwd_open()
490 * Shut off the timer. in usb_pcwd_release()
513 return -EFAULT; in usb_pcwd_temperature_read()
516 return -EFAULT; in usb_pcwd_temperature_read()
539 usb_pcwd_stop(usb_pcwd_device); /* Turn the WDT off */ in usb_pcwd_notify_sys()
587 usb_free_urb(usb_pcwd->intr_urb); in usb_pcwd_delete()
588 usb_free_coherent(usb_pcwd->udev, usb_pcwd->intr_size, in usb_pcwd_delete()
589 usb_pcwd->intr_buffer, usb_pcwd->intr_dma); in usb_pcwd_delete()
607 int retval = -ENOMEM; in usb_pcwd_probe()
616 return -ENODEV; in usb_pcwd_probe()
620 iface_desc = interface->cur_altsetting; in usb_pcwd_probe()
623 if (!(iface_desc->desc.bInterfaceClass == USB_CLASS_HID)) { in usb_pcwd_probe()
625 return -ENODEV; in usb_pcwd_probe()
628 if (iface_desc->desc.bNumEndpoints < 1) in usb_pcwd_probe()
629 return -ENODEV; in usb_pcwd_probe()
632 endpoint = &iface_desc->endpoint[0].desc; in usb_pcwd_probe()
637 return -ENODEV; in usb_pcwd_probe()
641 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); in usb_pcwd_probe()
650 mutex_init(&usb_pcwd->mtx); in usb_pcwd_probe()
651 usb_pcwd->udev = udev; in usb_pcwd_probe()
652 usb_pcwd->interface = interface; in usb_pcwd_probe()
653 usb_pcwd->interface_number = iface_desc->desc.bInterfaceNumber; in usb_pcwd_probe()
654 usb_pcwd->intr_size = (le16_to_cpu(endpoint->wMaxPacketSize) > 8 ? in usb_pcwd_probe()
655 le16_to_cpu(endpoint->wMaxPacketSize) : 8); in usb_pcwd_probe()
658 usb_pcwd->intr_buffer = usb_alloc_coherent(udev, usb_pcwd->intr_size, in usb_pcwd_probe()
659 GFP_KERNEL, &usb_pcwd->intr_dma); in usb_pcwd_probe()
660 if (!usb_pcwd->intr_buffer) { in usb_pcwd_probe()
666 usb_pcwd->intr_urb = usb_alloc_urb(0, GFP_KERNEL); in usb_pcwd_probe()
667 if (!usb_pcwd->intr_urb) in usb_pcwd_probe()
671 usb_fill_int_urb(usb_pcwd->intr_urb, udev, pipe, in usb_pcwd_probe()
672 usb_pcwd->intr_buffer, usb_pcwd->intr_size, in usb_pcwd_probe()
673 usb_pcwd_intr_done, usb_pcwd, endpoint->bInterval); in usb_pcwd_probe()
674 usb_pcwd->intr_urb->transfer_dma = usb_pcwd->intr_dma; in usb_pcwd_probe()
675 usb_pcwd->intr_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in usb_pcwd_probe()
678 if (usb_submit_urb(usb_pcwd->intr_urb, GFP_KERNEL)) { in usb_pcwd_probe()
680 retval = -EIO; /* failure */ in usb_pcwd_probe()
685 usb_pcwd->exists = 1; in usb_pcwd_probe()
704 pr_info("Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", in usb_pcwd_probe()
706 ((option_switches & 0x10) ? "ON" : "OFF"), in usb_pcwd_probe()
707 ((option_switches & 0x08) ? "ON" : "OFF")); in usb_pcwd_probe()
709 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */ in usb_pcwd_probe()
744 pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n", in usb_pcwd_probe()
767 * by clearing dev->udev.
779 mutex_lock(&usb_pcwd->mtx); in usb_pcwd_disconnect()
786 usb_pcwd->exists = 0; in usb_pcwd_disconnect()
793 mutex_unlock(&usb_pcwd->mtx); in usb_pcwd_disconnect()
798 cards_found--; in usb_pcwd_disconnect()