diff vordog.c @ 1:0b9854adb86c

Remove tedious messages and daemonize vd_watchdog.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 08 Jul 2008 11:07:31 +0800
parents 71475f5afa92
children 60a234c9c03f
line wrap: on
line diff
--- a/vordog.c	Tue Jul 08 09:57:54 2008 +0800
+++ b/vordog.c	Tue Jul 08 11:07:31 2008 +0800
@@ -81,36 +81,15 @@
     int val;
 #define VD_TIMER_RST 0xc
 
-#if 0
-    outb(VD_STATUS, 0xc0);	/* Clear events or it would be reset
-				 * immediately, since it is setted
-				 * by last timeout before PCIRST.
-				 */
-#endif
     val = cfg->init_val & 0xff;
-    printf("setup_timer 1 (%x)\n", val);
-    pause("vordog setup", hz);
     outb(VD_INITVAL, val);
-    printf("setup_timer 2\n");
     val = 0x80 | ((cfg->unit & 0x3) << 4) | VD_TIMER_RST;
-    printf("setup_timer 3 (%x)\n", val);
-    pause("vordog setup", hz);
     outb(VD_CTR, val);
-    printf("setup_timer 4\n");
 }
 
 static void
 reset_timer(int init_val) {
-#if 0
-    printf("reset_timer 1\n");
-    pause("vordog setup", hz);
-    outb(VD_INITVAL, init_val);
-#endif
-    printf("reset_timer 2\n");
-    pause("vordog setup", hz);
     outb(VD_STATUS, 0xc0);
-    printf("reset_timer 3\n");
-    pause("vordog setup", hz);
 }
 
 static void
@@ -129,17 +108,14 @@
     sc = CDEV_2_SOFTC(dev);
     switch(cmd) {
     case VDCTL_ENABLE:
-	printf("VDCTL_ENABLE\n");
 	cfg = (vordog_cfg_t)data;
 	sc->init_val = cfg->init_val & 0xff;
 	setup_timer(cfg);
 	break;
     case VDCTL_RESET:
-	printf("VDCTL_RESET\n");
 	reset_timer(sc->init_val);
 	break;
     case VDCTL_DISABLE:
-	printf("VDCTL_DISABLE\n");
 	disable_timer();
 	break;
     default:
@@ -161,24 +137,23 @@
     
     /* make sure vordog device is not in the bus. */
     vordog = device_find_child(parent, "vordog", 0);
-    if(vordog != NULL) {
-	printf("vordog is still existing!");
+    if(vordog != NULL)
 	return;
-    }
     vordog = BUS_ADD_CHILD(parent, 10, "vordog", 0);
-    printf("vordog_identify\n");
 }
 
 static int vordog_probe(device_t dev) {
     int b;
 
-    printf("vordog_probe\n");
     b = inb(VD_INITVAL);
-    printf("init val: %x\n", b);
+    if(b != 0)
+	return EINVAL;
     b = inb(VD_CTR);
-    printf("ctr: %x\n", b);
+    if(b != 0)
+	return EINVAL;
     b = inb(VD_STATUS);
-    printf("status: %x\n", b);
+    if(b != 0)
+	return EINVAL;
     return 0;
 }
 
@@ -186,13 +161,10 @@
     vd_softc_t sc;
     struct cdev *_cdev;
 
-    printf("vordog_attach 1\n");
-
     sc = (vd_softc_t)malloc(sizeof(struct vd_softc), M_TEMP, M_WAITOK);
     if(sc == NULL)
 	return ENOMEM;
 
-    printf("vordog_attach 2\n");
     _cdev = make_dev(&vordog_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "vordog0");
     if(_cdev == NULL) {
 	free(sc, M_TEMP);
@@ -202,13 +174,15 @@
     sc->_cdev = _cdev;
     sc->dev = dev;
 
-    printf("vordog_attach 3\n");
     device_set_softc(dev, sc);
     CDEV_2_SOFTC(_cdev) = sc;
 
     sc->open_cnt = 0;
     sc->init_val = 0;
 
+    device_set_desc(dev, "Watchdog of Vortex86 SoC");
+    device_printf(dev, "<Vortex86 SoC watchdog> at port 0x%x\n", VD_STATUS);
+
     return 0;
 }
 
@@ -216,17 +190,13 @@
     vd_softc_t sc;
     struct cdev *_cdev;
 
-    printf("vordog_detach 1\n");
     sc = device_get_softc(dev);
     if(sc->open_cnt != 0)
 	return EBUSY;
 
-    printf("vordog_detach 2\n");
     _cdev = sc->_cdev;
 
-    printf("vordog_detach 3\n");
     destroy_dev(_cdev);
-    printf("vordog_detach 4\n");
 
     free(sc, M_TEMP);
 
@@ -253,14 +223,11 @@
 
     switch(cmd) {
     case MOD_LOAD:
-	printf("MOD_LOAD\n");
 	break;
     case MOD_UNLOAD:
-	printf("MOD_UNLOAD\n");
 	vordog_go_detach();	/* remove device from parent */
 	break;
     case MOD_SHUTDOWN:
-	printf("MOD_SHUTDOWN\n");
 	break;
     default:
 	r = EINVAL;