Commit d6b469d9 authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck

watchdog: create all the proper device files

Create the watchdog class and it's associated devices.
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 2bbeed01
...@@ -41,6 +41,8 @@ The watchdog device structure looks like this: ...@@ -41,6 +41,8 @@ The watchdog device structure looks like this:
struct watchdog_device { struct watchdog_device {
int id; int id;
struct cdev cdev; struct cdev cdev;
struct device *dev;
struct device *parent;
const struct watchdog_info *info; const struct watchdog_info *info;
const struct watchdog_ops *ops; const struct watchdog_ops *ops;
unsigned int bootstatus; unsigned int bootstatus;
...@@ -58,6 +60,9 @@ It contains following fields: ...@@ -58,6 +60,9 @@ It contains following fields:
watchdog_register_device. watchdog_register_device.
* cdev: cdev for the dynamic /dev/watchdog<id> device nodes. This * cdev: cdev for the dynamic /dev/watchdog<id> device nodes. This
field is also populated by watchdog_register_device. field is also populated by watchdog_register_device.
* dev: device under the watchdog class (created by watchdog_register_device).
* parent: set this to the parent device (or NULL) before calling
watchdog_register_device.
* info: a pointer to a watchdog_info structure. This structure gives some * info: a pointer to a watchdog_info structure. This structure gives some
additional information about the watchdog timer itself. (Like it's unique name) additional information about the watchdog timer itself. (Like it's unique name)
* ops: a pointer to the list of watchdog operations that the watchdog supports. * ops: a pointer to the list of watchdog operations that the watchdog supports.
......
...@@ -35,10 +35,12 @@ ...@@ -35,10 +35,12 @@
#include <linux/watchdog.h> /* For watchdog specific items */ #include <linux/watchdog.h> /* For watchdog specific items */
#include <linux/init.h> /* For __init/__exit/... */ #include <linux/init.h> /* For __init/__exit/... */
#include <linux/idr.h> /* For ida_* macros */ #include <linux/idr.h> /* For ida_* macros */
#include <linux/err.h> /* For IS_ERR macros */
#include "watchdog_core.h" /* For watchdog_dev_register/... */ #include "watchdog_core.h" /* For watchdog_dev_register/... */
static DEFINE_IDA(watchdog_ida); static DEFINE_IDA(watchdog_ida);
static struct class *watchdog_class;
/** /**
* watchdog_register_device() - register a watchdog device * watchdog_register_device() - register a watchdog device
...@@ -52,7 +54,7 @@ static DEFINE_IDA(watchdog_ida); ...@@ -52,7 +54,7 @@ static DEFINE_IDA(watchdog_ida);
*/ */
int watchdog_register_device(struct watchdog_device *wdd) int watchdog_register_device(struct watchdog_device *wdd)
{ {
int ret, id; int ret, id, devno;
if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL) if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
return -EINVAL; return -EINVAL;
...@@ -101,6 +103,16 @@ int watchdog_register_device(struct watchdog_device *wdd) ...@@ -101,6 +103,16 @@ int watchdog_register_device(struct watchdog_device *wdd)
} }
} }
devno = wdd->cdev.dev;
wdd->dev = device_create(watchdog_class, wdd->parent, devno,
NULL, "watchdog%d", wdd->id);
if (IS_ERR(wdd->dev)) {
watchdog_dev_unregister(wdd);
ida_simple_remove(&watchdog_ida, id);
ret = PTR_ERR(wdd->dev);
return ret;
}
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(watchdog_register_device); EXPORT_SYMBOL_GPL(watchdog_register_device);
...@@ -115,6 +127,7 @@ EXPORT_SYMBOL_GPL(watchdog_register_device); ...@@ -115,6 +127,7 @@ EXPORT_SYMBOL_GPL(watchdog_register_device);
void watchdog_unregister_device(struct watchdog_device *wdd) void watchdog_unregister_device(struct watchdog_device *wdd)
{ {
int ret; int ret;
int devno = wdd->cdev.dev;
if (wdd == NULL) if (wdd == NULL)
return; return;
...@@ -122,18 +135,35 @@ void watchdog_unregister_device(struct watchdog_device *wdd) ...@@ -122,18 +135,35 @@ void watchdog_unregister_device(struct watchdog_device *wdd)
ret = watchdog_dev_unregister(wdd); ret = watchdog_dev_unregister(wdd);
if (ret) if (ret)
pr_err("error unregistering /dev/watchdog (err=%d)\n", ret); pr_err("error unregistering /dev/watchdog (err=%d)\n", ret);
device_destroy(watchdog_class, devno);
ida_simple_remove(&watchdog_ida, wdd->id); ida_simple_remove(&watchdog_ida, wdd->id);
wdd->dev = NULL;
} }
EXPORT_SYMBOL_GPL(watchdog_unregister_device); EXPORT_SYMBOL_GPL(watchdog_unregister_device);
static int __init watchdog_init(void) static int __init watchdog_init(void)
{ {
return watchdog_dev_init(); int err;
watchdog_class = class_create(THIS_MODULE, "watchdog");
if (IS_ERR(watchdog_class)) {
pr_err("couldn't create class\n");
return PTR_ERR(watchdog_class);
}
err = watchdog_dev_init();
if (err < 0) {
class_destroy(watchdog_class);
return err;
}
return 0;
} }
static void __exit watchdog_exit(void) static void __exit watchdog_exit(void)
{ {
watchdog_dev_exit(); watchdog_dev_exit();
class_destroy(watchdog_class);
ida_destroy(&watchdog_ida); ida_destroy(&watchdog_ida);
} }
......
...@@ -365,6 +365,7 @@ int watchdog_dev_register(struct watchdog_device *watchdog) ...@@ -365,6 +365,7 @@ int watchdog_dev_register(struct watchdog_device *watchdog)
int err, devno; int err, devno;
if (watchdog->id == 0) { if (watchdog->id == 0) {
watchdog_miscdev.parent = watchdog->parent;
err = misc_register(&watchdog_miscdev); err = misc_register(&watchdog_miscdev);
if (err != 0) { if (err != 0) {
pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n", pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n",
......
...@@ -95,6 +95,8 @@ struct watchdog_ops { ...@@ -95,6 +95,8 @@ struct watchdog_ops {
* *
* @id: The watchdog's ID. (Allocated by watchdog_register_device) * @id: The watchdog's ID. (Allocated by watchdog_register_device)
* @cdev: The watchdog's Character device. * @cdev: The watchdog's Character device.
* @dev: The device for our watchdog
* @parent: The parent bus device
* @info: Pointer to a watchdog_info structure. * @info: Pointer to a watchdog_info structure.
* @ops: Pointer to the list of watchdog operations. * @ops: Pointer to the list of watchdog operations.
* @bootstatus: Status of the watchdog device at boot. * @bootstatus: Status of the watchdog device at boot.
...@@ -113,6 +115,8 @@ struct watchdog_ops { ...@@ -113,6 +115,8 @@ struct watchdog_ops {
struct watchdog_device { struct watchdog_device {
int id; int id;
struct cdev cdev; struct cdev cdev;
struct device *dev;
struct device *parent;
const struct watchdog_info *info; const struct watchdog_info *info;
const struct watchdog_ops *ops; const struct watchdog_ops *ops;
unsigned int bootstatus; unsigned int bootstatus;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment