diff options
author | Wim Van Sebroeck <wim@iguana.be> | 2007-07-20 17:22:58 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2007-07-23 13:23:49 -0400 |
commit | de81225a8719494f5149980ea8a50de28da653f6 (patch) | |
tree | 6970209ff84cb32a663ca567868b57eb050219ac | |
parent | 7d831bf59a6991f399170bd2934dad4450891024 (diff) |
[WATCHDOG] mpc5200_wdt clean-up
* Add MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
* Add mandatory WDIOC_GETSTATUS and WDIOC_GETBOOTSTATUS ioctl's.
* If unknown ioctl is used we should return -ENOTTY.
* All watchdog device drivers are VFSs (Virtual File Systems).
We thus return a nonseekable_open(inode, file) when we open the VFS.
* Make sure that /dev/watchdog can be opened by 1 parent
* Add spin-locking to prevent that forked children can disturb
each other's operations.
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
-rw-r--r-- | drivers/char/watchdog/mpc5200_wdt.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/drivers/char/watchdog/mpc5200_wdt.c b/drivers/char/watchdog/mpc5200_wdt.c index cc3299c03683..564143d40610 100644 --- a/drivers/char/watchdog/mpc5200_wdt.c +++ b/drivers/char/watchdog/mpc5200_wdt.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <linux/miscdevice.h> | 3 | #include <linux/miscdevice.h> |
4 | #include <linux/watchdog.h> | 4 | #include <linux/watchdog.h> |
5 | #include <linux/io.h> | 5 | #include <linux/io.h> |
6 | #include <linux/spinlock.h> | ||
6 | #include <asm/of_platform.h> | 7 | #include <asm/of_platform.h> |
7 | #include <asm/uaccess.h> | 8 | #include <asm/uaccess.h> |
8 | #include <asm/mpc52xx.h> | 9 | #include <asm/mpc52xx.h> |
@@ -19,8 +20,11 @@ struct mpc5200_wdt { | |||
19 | struct miscdevice miscdev; | 20 | struct miscdevice miscdev; |
20 | struct resource mem; | 21 | struct resource mem; |
21 | struct mpc52xx_gpt __iomem *regs; | 22 | struct mpc52xx_gpt __iomem *regs; |
23 | spinlock_t io_lock; | ||
22 | }; | 24 | }; |
23 | 25 | ||
26 | /* is_active stores wether or not the /dev/watchdog device is opened */ | ||
27 | static unsigned long is_active; | ||
24 | 28 | ||
25 | /* misc devices don't provide a way, to get back to 'dev' or 'miscdev' from | 29 | /* misc devices don't provide a way, to get back to 'dev' or 'miscdev' from |
26 | * file operations, which sucks. But there can be max 1 watchdog anyway, so... | 30 | * file operations, which sucks. But there can be max 1 watchdog anyway, so... |
@@ -47,24 +51,31 @@ static int mpc5200_wdt_get_timeout(struct mpc5200_wdt *wdt) | |||
47 | /* watchdog operations */ | 51 | /* watchdog operations */ |
48 | static int mpc5200_wdt_start(struct mpc5200_wdt *wdt) | 52 | static int mpc5200_wdt_start(struct mpc5200_wdt *wdt) |
49 | { | 53 | { |
54 | spin_lock(&wdt->io_lock); | ||
50 | /* disable */ | 55 | /* disable */ |
51 | out_be32(&wdt->regs->mode, 0); | 56 | out_be32(&wdt->regs->mode, 0); |
52 | /* set timeout, with maximum prescaler */ | 57 | /* set timeout, with maximum prescaler */ |
53 | out_be32(&wdt->regs->count, 0x0 | wdt->count); | 58 | out_be32(&wdt->regs->count, 0x0 | wdt->count); |
54 | /* enable watchdog */ | 59 | /* enable watchdog */ |
55 | out_be32(&wdt->regs->mode, GPT_MODE_CE | GPT_MODE_WDT | GPT_MODE_MS_TIMER); | 60 | out_be32(&wdt->regs->mode, GPT_MODE_CE | GPT_MODE_WDT | GPT_MODE_MS_TIMER); |
61 | spin_unlock(&wdt->io_lock); | ||
56 | 62 | ||
57 | return 0; | 63 | return 0; |
58 | } | 64 | } |
59 | static int mpc5200_wdt_ping(struct mpc5200_wdt *wdt) | 65 | static int mpc5200_wdt_ping(struct mpc5200_wdt *wdt) |
60 | { | 66 | { |
67 | spin_lock(&wdt->io_lock); | ||
61 | /* writing A5 to OCPW resets the watchdog */ | 68 | /* writing A5 to OCPW resets the watchdog */ |
62 | out_be32(&wdt->regs->mode, 0xA5000000 | (0xffffff & in_be32(&wdt->regs->mode))); | 69 | out_be32(&wdt->regs->mode, 0xA5000000 | (0xffffff & in_be32(&wdt->regs->mode))); |
70 | spin_unlock(&wdt->io_lock); | ||
63 | return 0; | 71 | return 0; |
64 | } | 72 | } |
65 | static int mpc5200_wdt_stop(struct mpc5200_wdt *wdt) | 73 | static int mpc5200_wdt_stop(struct mpc5200_wdt *wdt) |
66 | { | 74 | { |
75 | spin_lock(&wdt->io_lock); | ||
76 | /* disable */ | ||
67 | out_be32(&wdt->regs->mode, 0); | 77 | out_be32(&wdt->regs->mode, 0); |
78 | spin_unlock(&wdt->io_lock); | ||
68 | return 0; | 79 | return 0; |
69 | } | 80 | } |
70 | 81 | ||
@@ -91,11 +102,17 @@ static int mpc5200_wdt_ioctl(struct inode *inode, struct file *file, | |||
91 | 102 | ||
92 | switch (cmd) { | 103 | switch (cmd) { |
93 | case WDIOC_GETSUPPORT: | 104 | case WDIOC_GETSUPPORT: |
94 | ret = copy_to_user(data, &mpc5200_wdt_info, sizeof(mpc5200_wdt_info)); | 105 | ret = copy_to_user(data, &mpc5200_wdt_info, |
106 | sizeof(mpc5200_wdt_info)); | ||
95 | if (ret) | 107 | if (ret) |
96 | ret = -EFAULT; | 108 | ret = -EFAULT; |
97 | break; | 109 | break; |
98 | 110 | ||
111 | case WDIOC_GETSTATUS: | ||
112 | case WDIOC_GETBOOTSTATUS: | ||
113 | ret = put_user(0, data); | ||
114 | break; | ||
115 | |||
99 | case WDIOC_KEEPALIVE: | 116 | case WDIOC_KEEPALIVE: |
100 | mpc5200_wdt_ping(wdt); | 117 | mpc5200_wdt_ping(wdt); |
101 | break; | 118 | break; |
@@ -112,15 +129,23 @@ static int mpc5200_wdt_ioctl(struct inode *inode, struct file *file, | |||
112 | timeout = mpc5200_wdt_get_timeout(wdt); | 129 | timeout = mpc5200_wdt_get_timeout(wdt); |
113 | ret = put_user(timeout, data); | 130 | ret = put_user(timeout, data); |
114 | break; | 131 | break; |
132 | |||
133 | default: | ||
134 | ret = -ENOTTY; | ||
115 | } | 135 | } |
116 | return ret; | 136 | return ret; |
117 | } | 137 | } |
118 | static int mpc5200_wdt_open(struct inode *inode, struct file *file) | 138 | static int mpc5200_wdt_open(struct inode *inode, struct file *file) |
119 | { | 139 | { |
140 | /* /dev/watchdog can only be opened once */ | ||
141 | if (test_and_set_bit(0, &is_active)) | ||
142 | return -EBUSY; | ||
143 | |||
144 | /* Set and activate the watchdog */ | ||
120 | mpc5200_wdt_set_timeout(wdt_global, 30); | 145 | mpc5200_wdt_set_timeout(wdt_global, 30); |
121 | mpc5200_wdt_start(wdt_global); | 146 | mpc5200_wdt_start(wdt_global); |
122 | file->private_data = wdt_global; | 147 | file->private_data = wdt_global; |
123 | return 0; | 148 | return nonseekable_open(inode, file); |
124 | } | 149 | } |
125 | static int mpc5200_wdt_release(struct inode *inode, struct file *file) | 150 | static int mpc5200_wdt_release(struct inode *inode, struct file *file) |
126 | { | 151 | { |
@@ -129,6 +154,7 @@ static int mpc5200_wdt_release(struct inode *inode, struct file *file) | |||
129 | mpc5200_wdt_stop(wdt); | 154 | mpc5200_wdt_stop(wdt); |
130 | wdt->count = 0; /* == disabled */ | 155 | wdt->count = 0; /* == disabled */ |
131 | #endif | 156 | #endif |
157 | clear_bit(0, &is_active); | ||
132 | return 0; | 158 | return 0; |
133 | } | 159 | } |
134 | 160 | ||
@@ -173,6 +199,7 @@ static int mpc5200_wdt_probe(struct of_device *op, const struct of_device_id *ma | |||
173 | } | 199 | } |
174 | 200 | ||
175 | dev_set_drvdata(&op->dev, wdt); | 201 | dev_set_drvdata(&op->dev, wdt); |
202 | spin_lock_init(&wdt->io_lock); | ||
176 | 203 | ||
177 | wdt->miscdev = (struct miscdevice) { | 204 | wdt->miscdev = (struct miscdevice) { |
178 | .minor = WATCHDOG_MINOR, | 205 | .minor = WATCHDOG_MINOR, |
@@ -256,3 +283,4 @@ module_exit(mpc5200_wdt_exit); | |||
256 | 283 | ||
257 | MODULE_AUTHOR("Domen Puncer <domen.puncer@telargo.com>"); | 284 | MODULE_AUTHOR("Domen Puncer <domen.puncer@telargo.com>"); |
258 | MODULE_LICENSE("Dual BSD/GPL"); | 285 | MODULE_LICENSE("Dual BSD/GPL"); |
286 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||