~ubuntu-branches/ubuntu/saucy/linux-ti-omap4/saucy-proposed

« back to all changes in this revision

Viewing changes to drivers/watchdog/watchdog_core.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati, Stefan Bader, Upstream Kernel Changes
  • Date: 2012-08-15 17:17:43 UTC
  • Revision ID: package-import@ubuntu.com-20120815171743-h5wnuf51xe7pvdid
Tags: 3.5.0-207.13
[ Paolo Pisati ]

* Start new release

[ Stefan Bader ]

* (config) Enable getabis to use local package copies

[ Upstream Kernel Changes ]

* fixup: gargabe collect iva_seq[0|1] init
* [Config] enable all SND_OMAP_SOC_*s
* fixup: cm2xxx_3xxx.o is needed for omap2_cm_read|write_reg
* fixup: add some snd_soc_dai* helper functions
* fixup: s/snd_soc_dpcm_params/snd_soc_dpcm/g
* fixup: typo, no_host_mode and useless SDP4430 init
* fixup: enable again aess hwmod

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <linux/kernel.h>       /* For printk/panic/... */
35
35
#include <linux/watchdog.h>     /* For watchdog specific items */
36
36
#include <linux/init.h>         /* For __init/__exit/... */
37
 
 
38
 
#include "watchdog_dev.h"       /* For watchdog_dev_register/... */
 
37
#include <linux/idr.h>          /* For ida_* macros */
 
38
#include <linux/err.h>          /* For IS_ERR macros */
 
39
 
 
40
#include "watchdog_core.h"      /* For watchdog_dev_register/... */
 
41
 
 
42
static DEFINE_IDA(watchdog_ida);
 
43
static struct class *watchdog_class;
39
44
 
40
45
/**
41
46
 * watchdog_register_device() - register a watchdog device
49
54
 */
50
55
int watchdog_register_device(struct watchdog_device *wdd)
51
56
{
52
 
        int ret;
 
57
        int ret, id, devno;
53
58
 
54
59
        if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
55
60
                return -EINVAL;
74
79
         * corrupted in a later stage then we expect a kernel panic!
75
80
         */
76
81
 
77
 
        /* We only support 1 watchdog device via the /dev/watchdog interface */
 
82
        mutex_init(&wdd->lock);
 
83
        id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
 
84
        if (id < 0)
 
85
                return id;
 
86
        wdd->id = id;
 
87
 
78
88
        ret = watchdog_dev_register(wdd);
79
89
        if (ret) {
80
 
                pr_err("error registering /dev/watchdog (err=%d)\n", ret);
 
90
                ida_simple_remove(&watchdog_ida, id);
 
91
                if (!(id == 0 && ret == -EBUSY))
 
92
                        return ret;
 
93
 
 
94
                /* Retry in case a legacy watchdog module exists */
 
95
                id = ida_simple_get(&watchdog_ida, 1, MAX_DOGS, GFP_KERNEL);
 
96
                if (id < 0)
 
97
                        return id;
 
98
                wdd->id = id;
 
99
 
 
100
                ret = watchdog_dev_register(wdd);
 
101
                if (ret) {
 
102
                        ida_simple_remove(&watchdog_ida, id);
 
103
                        return ret;
 
104
                }
 
105
        }
 
106
 
 
107
        devno = wdd->cdev.dev;
 
108
        wdd->dev = device_create(watchdog_class, wdd->parent, devno,
 
109
                                        NULL, "watchdog%d", wdd->id);
 
110
        if (IS_ERR(wdd->dev)) {
 
111
                watchdog_dev_unregister(wdd);
 
112
                ida_simple_remove(&watchdog_ida, id);
 
113
                ret = PTR_ERR(wdd->dev);
81
114
                return ret;
82
115
        }
83
116
 
95
128
void watchdog_unregister_device(struct watchdog_device *wdd)
96
129
{
97
130
        int ret;
 
131
        int devno = wdd->cdev.dev;
98
132
 
99
133
        if (wdd == NULL)
100
134
                return;
102
136
        ret = watchdog_dev_unregister(wdd);
103
137
        if (ret)
104
138
                pr_err("error unregistering /dev/watchdog (err=%d)\n", ret);
 
139
        device_destroy(watchdog_class, devno);
 
140
        ida_simple_remove(&watchdog_ida, wdd->id);
 
141
        wdd->dev = NULL;
105
142
}
106
143
EXPORT_SYMBOL_GPL(watchdog_unregister_device);
107
144
 
 
145
static int __init watchdog_init(void)
 
146
{
 
147
        int err;
 
148
 
 
149
        watchdog_class = class_create(THIS_MODULE, "watchdog");
 
150
        if (IS_ERR(watchdog_class)) {
 
151
                pr_err("couldn't create class\n");
 
152
                return PTR_ERR(watchdog_class);
 
153
        }
 
154
 
 
155
        err = watchdog_dev_init();
 
156
        if (err < 0) {
 
157
                class_destroy(watchdog_class);
 
158
                return err;
 
159
        }
 
160
 
 
161
        return 0;
 
162
}
 
163
 
 
164
static void __exit watchdog_exit(void)
 
165
{
 
166
        watchdog_dev_exit();
 
167
        class_destroy(watchdog_class);
 
168
        ida_destroy(&watchdog_ida);
 
169
}
 
170
 
 
171
subsys_initcall(watchdog_init);
 
172
module_exit(watchdog_exit);
 
173
 
108
174
MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
109
175
MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
110
176
MODULE_DESCRIPTION("WatchDog Timer Driver Core");