[Midnightbsd-cvs] src [8677] trunk/sys/dev/atkbdc: Pass the device_t into atkbd_{probe, attach}_unit andget the controller unit and keyboard unit from there.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 17:59:17 EDT 2016


Revision: 8677
          http://svnweb.midnightbsd.org/src/?rev=8677
Author:   laffer1
Date:     2016-09-25 17:59:16 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
Pass the device_t into atkbd_{probe,attach}_unit andget the controller unit and keyboard unit from there.

Modified Paths:
--------------
    trunk/sys/dev/atkbdc/atkbd.c
    trunk/sys/dev/atkbdc/atkbd_atkbdc.c
    trunk/sys/dev/atkbdc/atkbdreg.h

Modified: trunk/sys/dev/atkbdc/atkbd.c
===================================================================
--- trunk/sys/dev/atkbdc/atkbd.c	2016-09-25 20:42:49 UTC (rev 8676)
+++ trunk/sys/dev/atkbdc/atkbd.c	2016-09-25 21:59:16 UTC (rev 8677)
@@ -66,7 +66,7 @@
 static void		atkbd_shutdown_final(void *v);
 
 int
-atkbd_probe_unit(int unit, int ctlr, int irq, int flags)
+atkbd_probe_unit(device_t dev, int irq, int flags)
 {
 	keyboard_switch_t *sw;
 	int args[2];
@@ -76,9 +76,9 @@
 	if (sw == NULL)
 		return ENXIO;
 
-	args[0] = ctlr;
+	args[0] = device_get_unit(device_get_parent(dev));
 	args[1] = irq;
-	error = (*sw->probe)(unit, args, flags);
+	error = (*sw->probe)(device_get_unit(dev), args, flags);
 	if (error)
 		return error;
 	return 0;
@@ -85,11 +85,12 @@
 }
 
 int
-atkbd_attach_unit(int unit, keyboard_t **kbd, int ctlr, int irq, int flags)
+atkbd_attach_unit(device_t dev, keyboard_t **kbd, int irq, int flags)
 {
 	keyboard_switch_t *sw;
 	int args[2];
 	int error;
+	int unit;
 
 	sw = kbd_get_switch(ATKBD_DRIVER_NAME);
 	if (sw == NULL)
@@ -96,7 +97,8 @@
 		return ENXIO;
 
 	/* reset, initialize and enable the device */
-	args[0] = ctlr;
+	unit = device_get_unit(dev);
+	args[0] = device_get_unit(device_get_parent(dev));
 	args[1] = irq;
 	*kbd = NULL;
 	error = (*sw->probe)(unit, args, flags);
@@ -401,7 +403,7 @@
 		bcopy(&key_map, keymap, sizeof(key_map));
 		bcopy(&accent_map, accmap, sizeof(accent_map));
 		bcopy(fkey_tab, fkeymap,
-		      imin(fkeymap_size*sizeof(fkeymap[0]), sizeof(fkey_tab)));
+		    imin(fkeymap_size * sizeof(fkeymap[0]), sizeof(fkey_tab)));
 		kbd_set_maps(kbd, keymap, accmap, fkeymap, fkeymap_size);
 		kbd->kb_data = (void *)state;
 	
@@ -424,8 +426,8 @@
 	if (!KBD_IS_INITIALIZED(kbd) && !(flags & KB_CONF_PROBE_ONLY)) {
 		kbd->kb_config = flags & ~KB_CONF_PROBE_ONLY;
 		if (KBD_HAS_DEVICE(kbd)
-	    	    && init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config)
-	    	    && (kbd->kb_config & KB_CONF_FAIL_IF_NO_KBD)) {
+		    && init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config)
+		    && (kbd->kb_config & KB_CONF_FAIL_IF_NO_KBD)) {
 			kbd_unregister(kbd);
 			error = ENXIO;
 			goto bad;
@@ -485,8 +487,7 @@
 		 * The keyboard was not detected before;
 		 * it must have been reconnected!
 		 */
-		init_keyboard(state->kbdc, &kbd->kb_type,
-			      kbd->kb_config);
+		init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config);
 		KBD_FOUND_DEVICE(kbd);
 		atkbd_ioctl(kbd, KDSETLED, (caddr_t)&state->ks_state);
 		get_typematic(kbd);
@@ -645,7 +646,7 @@
 			goto next_code;
 		}
 		break;
-	case 0xE0:      /* 0xE0 prefix */
+	case 0xE0:		/* 0xE0 prefix */
 		state->ks_prefix = 0;
 		switch (keycode) {
 		case 0x1C:	/* right enter key */
@@ -655,57 +656,57 @@
 			keycode = 0x5A;
 			break;
 		case 0x35:	/* keypad divide key */
-	    		keycode = 0x5B;
-	    		break;
+			keycode = 0x5B;
+			break;
 		case 0x37:	/* print scrn key */
-	    		keycode = 0x5C;
-	    		break;
+			keycode = 0x5C;
+			break;
 		case 0x38:	/* right alt key (alt gr) */
-	    		keycode = 0x5D;
-	    		break;
+			keycode = 0x5D;
+			break;
 		case 0x46:	/* ctrl-pause/break on AT 101 (see below) */
 			keycode = 0x68;
-	    		break;
+			break;
 		case 0x47:	/* grey home key */
-	    		keycode = 0x5E;
-	    		break;
+			keycode = 0x5E;
+			break;
 		case 0x48:	/* grey up arrow key */
-	    		keycode = 0x5F;
-	    		break;
+			keycode = 0x5F;
+			break;
 		case 0x49:	/* grey page up key */
-	    		keycode = 0x60;
-	    		break;
+			keycode = 0x60;
+			break;
 		case 0x4B:	/* grey left arrow key */
-	    		keycode = 0x61;
-	    		break;
+			keycode = 0x61;
+			break;
 		case 0x4D:	/* grey right arrow key */
-	    		keycode = 0x62;
-	    		break;
+			keycode = 0x62;
+			break;
 		case 0x4F:	/* grey end key */
-	    		keycode = 0x63;
-	    		break;
+			keycode = 0x63;
+			break;
 		case 0x50:	/* grey down arrow key */
-	    		keycode = 0x64;
-	    		break;
+			keycode = 0x64;
+			break;
 		case 0x51:	/* grey page down key */
-	    		keycode = 0x65;
-	    		break;
+			keycode = 0x65;
+			break;
 		case 0x52:	/* grey insert key */
-	    		keycode = 0x66;
-	    		break;
+			keycode = 0x66;
+			break;
 		case 0x53:	/* grey delete key */
-	    		keycode = 0x67;
-	    		break;
-		/* the following 3 are only used on the MS "Natural" keyboard */
+			keycode = 0x67;
+			break;
+			/* the following 3 are only used on the MS "Natural" keyboard */
 		case 0x5b:	/* left Window key */
-	    		keycode = 0x69;
-	    		break;
+			keycode = 0x69;
+			break;
 		case 0x5c:	/* right Window key */
-	    		keycode = 0x6a;
-	    		break;
+			keycode = 0x6a;
+			break;
 		case 0x5d:	/* menu key */
-	    		keycode = 0x6b;
-	    		break;
+			keycode = 0x6b;
+			break;
 		case 0x5e:	/* power key */
 			keycode = 0x6d;
 			break;
@@ -716,10 +717,10 @@
 			keycode = 0x6f;
 			break;
 		default:	/* ignore everything else */
-	    		goto next_code;
+			goto next_code;
 		}
 		break;
-    	case 0xE1:	/* 0xE1 prefix */
+   	case 0xE1:	/* 0xE1 prefix */
 		/* 
 		 * The pause/break key on the 101 keyboard produces:
 		 * E1-1D-45 E1-9D-C5
@@ -728,10 +729,10 @@
 		 */
 		state->ks_prefix = 0;
 		if (keycode == 0x1D)
-	    		state->ks_prefix = 0x1D;
+			state->ks_prefix = 0x1D;
 		goto next_code;
 		/* NOT REACHED */
-    	case 0x1D:	/* pause / break */
+   	case 0x1D:	/* pause / break */
 		state->ks_prefix = 0;
 		if (keycode != 0x45)
 			goto next_code;
@@ -743,7 +744,7 @@
 		switch (keycode) {
 		case 0x37:	/* *(numpad)/print screen */
 			if (state->ks_flags & SHIFTS)
-	    			keycode = 0x5c;	/* print screen */
+				keycode = 0x5c;	/* print screen */
 			break;
 		case 0x45:	/* num lock/pause */
 			if (state->ks_flags & CTLS)
@@ -1177,7 +1178,7 @@
 		 */
 		return ENXIO;
 	}
-    
+
 	return 0;
 }
 
@@ -1275,7 +1276,7 @@
 	}
 	if (bootverbose)
 		printf("atkbd: the current kbd controller command byte %04x\n",
-		       c);
+		   c);
 #if 0
 	/* override the keyboard lock switch */
 	c |= KBD_OVERRIDE_KBD_LOCK;
@@ -1415,52 +1416,49 @@
 static int
 write_kbd(KBDC kbdc, int command, int data)
 {
-    int s;
+	int s;
 
-    /* prevent the timeout routine from polling the keyboard */
-    if (!kbdc_lock(kbdc, TRUE)) 
-	return EBUSY;
+	/* prevent the timeout routine from polling the keyboard */
+	if (!kbdc_lock(kbdc, TRUE)) 
+		return EBUSY;
 
-    /* disable the keyboard and mouse interrupt */
-    s = spltty();
+	/* disable the keyboard and mouse interrupt */
+	s = spltty();
 #if 0
-    c = get_controller_command_byte(kbdc);
-    if ((c == -1) 
-	|| !set_controller_command_byte(kbdc, 
-            kbdc_get_device_mask(kbdc),
-            KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
-                | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
-	/* CONTROLLER ERROR */
-        kbdc_lock(kbdc, FALSE);
+	c = get_controller_command_byte(kbdc);
+	if ((c == -1) 
+	    || !set_controller_command_byte(kbdc, 
+		kbdc_get_device_mask(kbdc),
+		KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT
+		| KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
+		/* CONTROLLER ERROR */
+		kbdc_lock(kbdc, FALSE);
+		splx(s);
+		return EIO;
+	}
+	/* 
+	 * Now that the keyboard controller is told not to generate 
+	 * the keyboard and mouse interrupts, call `splx()' to allow 
+	 * the other tty interrupts. The clock interrupt may also occur, 
+	 * but the timeout routine (`scrn_timer()') will be blocked 
+	 * by the lock flag set via `kbdc_lock()'
+	 */
 	splx(s);
-	return EIO;
-    }
-    /* 
-     * Now that the keyboard controller is told not to generate 
-     * the keyboard and mouse interrupts, call `splx()' to allow 
-     * the other tty interrupts. The clock interrupt may also occur, 
-     * but the timeout routine (`scrn_timer()') will be blocked 
-     * by the lock flag set via `kbdc_lock()'
-     */
-    splx(s);
 #endif
-
-    if (send_kbd_command_and_data(kbdc, command, data) != KBD_ACK)
-        send_kbd_command(kbdc, KBDC_ENABLE_KBD);
-
+	if (send_kbd_command_and_data(kbdc, command, data) != KBD_ACK)
+		send_kbd_command(kbdc, KBDC_ENABLE_KBD);
 #if 0
-    /* restore the interrupts */
-    if (!set_controller_command_byte(kbdc,
-            kbdc_get_device_mask(kbdc),
+	/* restore the interrupts */
+	if (!set_controller_command_byte(kbdc, kbdc_get_device_mask(kbdc),
 	    c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) { 
-	/* CONTROLLER ERROR */
-    }
+		/* CONTROLLER ERROR */
+	}
 #else
-    splx(s);
+	splx(s);
 #endif
-    kbdc_lock(kbdc, FALSE);
+	kbdc_lock(kbdc, FALSE);
 
-    return 0;
+	return 0;
 }
 
 static int

Modified: trunk/sys/dev/atkbdc/atkbd_atkbdc.c
===================================================================
--- trunk/sys/dev/atkbdc/atkbd_atkbdc.c	2016-09-25 20:42:49 UTC (rev 8676)
+++ trunk/sys/dev/atkbdc/atkbd_atkbdc.c	2016-09-25 21:59:16 UTC (rev 8677)
@@ -104,9 +104,7 @@
 	bus_release_resource(dev, SYS_RES_IRQ, rid, res);
 
 	/* probe the device */
-	return atkbd_probe_unit(device_get_unit(dev),
-				device_get_unit(device_get_parent(dev)),
-				irq, flags);
+	return atkbd_probe_unit(dev, irq, flags);
 }
 
 static int
@@ -124,9 +122,7 @@
 	rid = KBDC_RID_KBD;
 	irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
 	flags = device_get_flags(dev);
-	error = atkbd_attach_unit(device_get_unit(dev), &kbd,
-				  device_get_unit(device_get_parent(dev)),
-				  irq, flags);
+	error = atkbd_attach_unit(dev, &kbd, irq, flags);
 	if (error)
 		return error;
 

Modified: trunk/sys/dev/atkbdc/atkbdreg.h
===================================================================
--- trunk/sys/dev/atkbdc/atkbdreg.h	2016-09-25 20:42:49 UTC (rev 8676)
+++ trunk/sys/dev/atkbdc/atkbdreg.h	2016-09-25 21:59:16 UTC (rev 8677)
@@ -39,9 +39,8 @@
 
 #ifdef _KERNEL
 
-int		atkbd_probe_unit(int unit, int ctlr, int irq, int flags);
-int		atkbd_attach_unit(int unit, keyboard_t **kbd,
-				 int ctlr, int irq, int flags);
+int		atkbd_probe_unit(device_t dev, int irq, int flags);
+int		atkbd_attach_unit(device_t dev, keyboard_t **kbd, int irq, int flags);
 
 #endif
 



More information about the Midnightbsd-cvs mailing list