aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hwmon/sch5627.c2
-rw-r--r--drivers/hwmon/sch5636.c2
-rw-r--r--drivers/hwmon/sch56xx-common.c371
-rw-r--r--drivers/hwmon/sch56xx-common.h2
4 files changed, 61 insertions, 316 deletions
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
index 8ec6dfbccb64..8342275378b8 100644
--- a/drivers/hwmon/sch5627.c
+++ b/drivers/hwmon/sch5627.c
@@ -579,7 +579,7 @@ static int __devinit sch5627_probe(struct platform_device *pdev)
579 } 579 }
580 580
581 /* Note failing to register the watchdog is not a fatal error */ 581 /* Note failing to register the watchdog is not a fatal error */
582 data->watchdog = sch56xx_watchdog_register(data->addr, 582 data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
583 (build_code << 24) | (build_id << 8) | hwmon_rev, 583 (build_code << 24) | (build_id << 8) | hwmon_rev,
584 &data->update_lock, 1); 584 &data->update_lock, 1);
585 585
diff --git a/drivers/hwmon/sch5636.c b/drivers/hwmon/sch5636.c
index 906d4ed32d81..96a7e68718ca 100644
--- a/drivers/hwmon/sch5636.c
+++ b/drivers/hwmon/sch5636.c
@@ -510,7 +510,7 @@ static int __devinit sch5636_probe(struct platform_device *pdev)
510 } 510 }
511 511
512 /* Note failing to register the watchdog is not a fatal error */ 512 /* Note failing to register the watchdog is not a fatal error */
513 data->watchdog = sch56xx_watchdog_register(data->addr, 513 data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
514 (revision[0] << 8) | revision[1], 514 (revision[0] << 8) | revision[1],
515 &data->update_lock, 0); 515 &data->update_lock, 0);
516 516
diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c
index ce52fc57d41d..419a8e8f5191 100644
--- a/drivers/hwmon/sch56xx-common.c
+++ b/drivers/hwmon/sch56xx-common.c
@@ -66,15 +66,9 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
66 66
67struct sch56xx_watchdog_data { 67struct sch56xx_watchdog_data {
68 u16 addr; 68 u16 addr;
69 u32 revision;
70 struct mutex *io_lock; 69 struct mutex *io_lock;
71 struct mutex watchdog_lock; 70 struct watchdog_info wdinfo;
72 struct list_head list; /* member of the watchdog_data_list */ 71 struct watchdog_device wddev;
73 struct kref kref;
74 struct miscdevice watchdog_miscdev;
75 unsigned long watchdog_is_open;
76 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
77 char watchdog_expect_close;
78 u8 watchdog_preset; 72 u8 watchdog_preset;
79 u8 watchdog_control; 73 u8 watchdog_control;
80 u8 watchdog_output_enable; 74 u8 watchdog_output_enable;
@@ -82,15 +76,6 @@ struct sch56xx_watchdog_data {
82 76
83static struct platform_device *sch56xx_pdev; 77static struct platform_device *sch56xx_pdev;
84 78
85/*
86 * Somewhat ugly :( global data pointer list with all sch56xx devices, so that
87 * we can find our device data as when using misc_register there is no other
88 * method to get to ones device data from the open fop.
89 */
90static LIST_HEAD(watchdog_data_list);
91/* Note this lock not only protect list access, but also data.kref access */
92static DEFINE_MUTEX(watchdog_data_mutex);
93
94/* Super I/O functions */ 79/* Super I/O functions */
95static inline int superio_inb(int base, int reg) 80static inline int superio_inb(int base, int reg)
96{ 81{
@@ -272,22 +257,13 @@ EXPORT_SYMBOL(sch56xx_read_virtual_reg12);
272 * Watchdog routines 257 * Watchdog routines
273 */ 258 */
274 259
275/* 260static int watchdog_set_timeout(struct watchdog_device *wddev,
276 * Release our data struct when the platform device has been released *and* 261 unsigned int timeout)
277 * all references to our watchdog device are released.
278 */
279static void sch56xx_watchdog_release_resources(struct kref *r)
280{
281 struct sch56xx_watchdog_data *data =
282 container_of(r, struct sch56xx_watchdog_data, kref);
283 kfree(data);
284}
285
286static int watchdog_set_timeout(struct sch56xx_watchdog_data *data,
287 int timeout)
288{ 262{
289 int ret, resolution; 263 struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev);
264 unsigned int resolution;
290 u8 control; 265 u8 control;
266 int ret;
291 267
292 /* 1 second or 60 second resolution? */ 268 /* 1 second or 60 second resolution? */
293 if (timeout <= 255) 269 if (timeout <= 255)
@@ -298,12 +274,6 @@ static int watchdog_set_timeout(struct sch56xx_watchdog_data *data,
298 if (timeout < resolution || timeout > (resolution * 255)) 274 if (timeout < resolution || timeout > (resolution * 255))
299 return -EINVAL; 275 return -EINVAL;
300 276
301 mutex_lock(&data->watchdog_lock);
302 if (!data->addr) {
303 ret = -ENODEV;
304 goto leave;
305 }
306
307 if (resolution == 1) 277 if (resolution == 1)
308 control = data->watchdog_control | SCH56XX_WDOG_TIME_BASE_SEC; 278 control = data->watchdog_control | SCH56XX_WDOG_TIME_BASE_SEC;
309 else 279 else
@@ -316,7 +286,7 @@ static int watchdog_set_timeout(struct sch56xx_watchdog_data *data,
316 control); 286 control);
317 mutex_unlock(data->io_lock); 287 mutex_unlock(data->io_lock);
318 if (ret) 288 if (ret)
319 goto leave; 289 return ret;
320 290
321 data->watchdog_control = control; 291 data->watchdog_control = control;
322 } 292 }
@@ -326,38 +296,17 @@ static int watchdog_set_timeout(struct sch56xx_watchdog_data *data,
326 * the watchdog countdown. 296 * the watchdog countdown.
327 */ 297 */
328 data->watchdog_preset = DIV_ROUND_UP(timeout, resolution); 298 data->watchdog_preset = DIV_ROUND_UP(timeout, resolution);
299 wddev->timeout = data->watchdog_preset * resolution;
329 300
330 ret = data->watchdog_preset * resolution; 301 return 0;
331leave:
332 mutex_unlock(&data->watchdog_lock);
333 return ret;
334}
335
336static int watchdog_get_timeout(struct sch56xx_watchdog_data *data)
337{
338 int timeout;
339
340 mutex_lock(&data->watchdog_lock);
341 if (data->watchdog_control & SCH56XX_WDOG_TIME_BASE_SEC)
342 timeout = data->watchdog_preset;
343 else
344 timeout = data->watchdog_preset * 60;
345 mutex_unlock(&data->watchdog_lock);
346
347 return timeout;
348} 302}
349 303
350static int watchdog_start(struct sch56xx_watchdog_data *data) 304static int watchdog_start(struct watchdog_device *wddev)
351{ 305{
306 struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev);
352 int ret; 307 int ret;
353 u8 val; 308 u8 val;
354 309
355 mutex_lock(&data->watchdog_lock);
356 if (!data->addr) {
357 ret = -ENODEV;
358 goto leave_unlock_watchdog;
359 }
360
361 /* 310 /*
362 * The sch56xx's watchdog cannot really be started / stopped 311 * The sch56xx's watchdog cannot really be started / stopped
363 * it is always running, but we can avoid the timer expiring 312 * it is always running, but we can avoid the timer expiring
@@ -405,39 +354,29 @@ static int watchdog_start(struct sch56xx_watchdog_data *data)
405 354
406leave: 355leave:
407 mutex_unlock(data->io_lock); 356 mutex_unlock(data->io_lock);
408leave_unlock_watchdog:
409 mutex_unlock(&data->watchdog_lock);
410 return ret; 357 return ret;
411} 358}
412 359
413static int watchdog_trigger(struct sch56xx_watchdog_data *data) 360static int watchdog_trigger(struct watchdog_device *wddev)
414{ 361{
362 struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev);
415 int ret; 363 int ret;
416 364
417 mutex_lock(&data->watchdog_lock);