watchdog: WatchDog Timer Driver Core - Add ioctl call
[linux-block.git] / drivers / watchdog / watchdog_core.c
CommitLineData
43316044
WVS
1/*
2 * watchdog_core.c
3 *
4 * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
5 * All Rights Reserved.
6 *
7 * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
8 *
9 * This source code is part of the generic code that can be used
10 * by all the watchdog timer drivers.
11 *
12 * Based on source code of the following authors:
13 * Matt Domsch <Matt_Domsch@dell.com>,
14 * Rob Radez <rob@osinvestor.com>,
15 * Rusty Lynch <rusty@linux.co.intel.com>
16 * Satyam Sharma <satyam@infradead.org>
17 * Randy Dunlap <randy.dunlap@oracle.com>
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
23 *
24 * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
25 * admit liability nor provide warranty for any of this software.
26 * This material is provided "AS-IS" and at no charge.
27 */
28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
31#include <linux/module.h> /* For EXPORT_SYMBOL/module stuff/... */
32#include <linux/types.h> /* For standard types */
33#include <linux/errno.h> /* For the -ENODEV/... values */
34#include <linux/kernel.h> /* For printk/panic/... */
35#include <linux/watchdog.h> /* For watchdog specific items */
36#include <linux/init.h> /* For __init/__exit/... */
37
38#include "watchdog_dev.h" /* For watchdog_dev_register/... */
39
40/**
41 * watchdog_register_device() - register a watchdog device
42 * @wdd: watchdog device
43 *
44 * Register a watchdog device with the kernel so that the
45 * watchdog timer can be accessed from userspace.
46 *
47 * A zero is returned on success and a negative errno code for
48 * failure.
49 */
50int watchdog_register_device(struct watchdog_device *wdd)
51{
52 int ret;
53
54 if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
55 return -EINVAL;
56
57 /* Mandatory operations need to be supported */
58 if (wdd->ops->start == NULL || wdd->ops->stop == NULL)
59 return -EINVAL;
60
61 /*
62 * Note: now that all watchdog_device data has been verified, we
63 * will not check this anymore in other functions. If data gets
64 * corrupted in a later stage then we expect a kernel panic!
65 */
66
67 /* We only support 1 watchdog device via the /dev/watchdog interface */
68 ret = watchdog_dev_register(wdd);
69 if (ret) {
70 pr_err("error registering /dev/watchdog (err=%d).\n", ret);
71 return ret;
72 }
73
74 return 0;
75}
76EXPORT_SYMBOL_GPL(watchdog_register_device);
77
78/**
79 * watchdog_unregister_device() - unregister a watchdog device
80 * @wdd: watchdog device to unregister
81 *
82 * Unregister a watchdog device that was previously successfully
83 * registered with watchdog_register_device().
84 */
85void watchdog_unregister_device(struct watchdog_device *wdd)
86{
87 int ret;
88
89 if (wdd == NULL)
90 return;
91
92 ret = watchdog_dev_unregister(wdd);
93 if (ret)
94 pr_err("error unregistering /dev/watchdog (err=%d).\n", ret);
95}
96EXPORT_SYMBOL_GPL(watchdog_unregister_device);
97
98MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
99MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
100MODULE_DESCRIPTION("WatchDog Timer Driver Core");
101MODULE_LICENSE("GPL");