[U-Boot-Users] [PATCH] usb: codying style cleanup

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Tue May 20 21:19:42 CEST 2008


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 common/cmd_usb.c |  261 ++++++++++++++++++++-----------------
 common/usb.c     |  385 ++++++++++++++++++++++++++++--------------------------
 common/usb_kbd.c |  317 +++++++++++++++++++++++----------------------
 3 files changed, 506 insertions(+), 457 deletions(-)

diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index 23413b5..b7d3d14 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -32,7 +32,7 @@
 #include <usb.h>
 
 #ifdef CONFIG_USB_STORAGE
-static int usb_stor_curr_dev=-1; /* current device */
+static int usb_stor_curr_dev = -1; /* current device */
 #endif
 
 /* some display routines (info command) */
@@ -62,7 +62,7 @@ char * usb_get_class_desc(unsigned char dclass)
 	}
 }
 
-void usb_display_class_sub(unsigned char dclass,unsigned char subclass,unsigned char proto)
+void usb_display_class_sub(unsigned char dclass, unsigned char subclass, unsigned char proto)
 {
 	switch(dclass) {
 		case USB_CLASS_PER_INTERFACE:
@@ -139,32 +139,41 @@ void usb_display_class_sub(unsigned char dclass,unsigned char subclass,unsigned
 	}
 }
 
-void usb_display_string(struct usb_device *dev,int index)
+void usb_display_string(struct usb_device *dev, int index)
 {
 	char buffer[256];
-	if (index!=0) {
-		if (usb_string(dev,index,&buffer[0],256)>0);
-			printf("String: \"%s\"",buffer);
+
+	if (index != 0) {
+		if (usb_string(dev, index, &buffer[0], 256) > 0);
+			printf("String: \"%s\"", buffer);
 	}
 }
 
 void usb_display_desc(struct usb_device *dev)
 {
-	if (dev->descriptor.bDescriptorType==USB_DT_DEVICE) {
-		printf("%d: %s,  USB Revision %x.%x\n",dev->devnum,usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
-			(dev->descriptor.bcdUSB>>8) & 0xff,dev->descriptor.bcdUSB & 0xff);
+	if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) {
+		printf("%d: %s,  USB Revision %x.%x\n", dev->devnum,
+			usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
+			(dev->descriptor.bcdUSB>>8) & 0xff ,dev->descriptor.bcdUSB & 0xff);
 		if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
-			printf(" - %s %s %s\n",dev->mf,dev->prod,dev->serial);
+			printf(" - %s %s %s\n", dev->mf, dev->prod, dev->serial);
 		if (dev->descriptor.bDeviceClass) {
 			printf(" - Class: ");
-			usb_display_class_sub(dev->descriptor.bDeviceClass,dev->descriptor.bDeviceSubClass,dev->descriptor.bDeviceProtocol);
+			usb_display_class_sub(dev->descriptor.bDeviceClass,
+				dev->descriptor.bDeviceSubClass,
+				dev->descriptor.bDeviceProtocol);
 			printf("\n");
 		}
 		else {
-			printf(" - Class: (from Interface) %s\n",usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass));
+			printf(" - Class: (from Interface) %s\n",
+				usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass));
 		}
-		printf(" - PacketSize: %d  Configurations: %d\n",dev->descriptor.bMaxPacketSize0,dev->descriptor.bNumConfigurations);
-		printf(" - Vendor: 0x%04x  Product 0x%04x Version %d.%d\n",dev->descriptor.idVendor,dev->descriptor.idProduct,(dev->descriptor.bcdDevice>>8) & 0xff,dev->descriptor.bcdDevice & 0xff);
+		printf(" - PacketSize: %d  Configurations: %d\n",
+			dev->descriptor.bMaxPacketSize0,dev->descriptor.bNumConfigurations);
+		printf(" - Vendor: 0x%04x  Product 0x%04x Version %d.%d\n",
+			dev->descriptor.idVendor, dev->descriptor.idProduct,
+			(dev->descriptor.bcdDevice >> 8) & 0xff,
+			dev->descriptor.bcdDevice & 0xff);
 	}
 
 }
@@ -172,42 +181,54 @@ void usb_display_desc(struct usb_device *dev)
 void usb_display_conf_desc(struct usb_config_descriptor *config,struct usb_device *dev)
 {
 	printf("   Configuration: %d\n",config->bConfigurationValue);
-	printf("   - Interfaces: %d %s%s%dmA\n",config->bNumInterfaces,(config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
-	(config->bmAttributes & 0x20) ? "Remote Wakeup " : "",config->MaxPower*2);
+	printf("   - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces,
+		(config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
+		(config->bmAttributes & 0x20) ? "Remote Wakeup " : "", config->MaxPower * 2);
 	if (config->iConfiguration) {
 		printf("   - ");
-		usb_display_string(dev,config->iConfiguration);
+		usb_display_string(dev, config->iConfiguration);
 		printf("\n");
 	}
 }
 
-void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,struct usb_device *dev)
+void usb_display_if_desc(struct usb_interface_descriptor *ifdesc, struct usb_device *dev)
 {
 	printf("     Interface: %d\n",ifdesc->bInterfaceNumber);
-	printf("     - Alternate Setting %d, Endpoints: %d\n",ifdesc->bAlternateSetting,ifdesc->bNumEndpoints);
+	printf("     - Alternate Setting %d, Endpoints: %d\n",
+		ifdesc->bAlternateSetting, ifdesc->bNumEndpoints);
 	printf("     - Class ");
-	usb_display_class_sub(ifdesc->bInterfaceClass,ifdesc->bInterfaceSubClass,ifdesc->bInterfaceProtocol);
+	usb_display_class_sub(ifdesc->bInterfaceClass, ifdesc->bInterfaceSubClass,
+		ifdesc->bInterfaceProtocol);
 	printf("\n");
 	if (ifdesc->iInterface) {
 		printf("     - ");
-		usb_display_string(dev,ifdesc->iInterface);
+		usb_display_string(dev, ifdesc->iInterface);
 		printf("\n");
 	}
 }
 
 void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
 {
-	printf("     - Endpoint %d %s ",epdesc->bEndpointAddress & 0xf,(epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
+	printf("     - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf,
+		(epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
 	switch((epdesc->bmAttributes & 0x03))
 	{
-		case 0: printf("Control"); break;
-		case 1: printf("Isochronous"); break;
-		case 2: printf("Bulk"); break;
-		case 3: printf("Interrupt"); break;
+		case 0:
+			printf("Control");
+			break;
+		case 1:
+			printf("Isochronous");
+			break;
+		case 2:
+			printf("Bulk");
+			break;
+		case 3:
+			printf("Interrupt");
+			break;
 	}
-	printf(" MaxPacket %d",epdesc->wMaxPacketSize);
-	if ((epdesc->bmAttributes & 0x03)==0x3)
-		printf(" Interval %dms",epdesc->bInterval);
+	printf(" MaxPacket %d", epdesc->wMaxPacketSize);
+	if ((epdesc->bmAttributes & 0x03) == 0x3)
+		printf(" Interval %dms", epdesc->bInterval);
 	printf("\n");
 }
 
@@ -217,15 +238,15 @@ void usb_display_config(struct usb_device *dev)
 	struct usb_config_descriptor *config;
 	struct usb_interface_descriptor *ifdesc;
 	struct usb_endpoint_descriptor *epdesc;
-	int i,ii;
+	int i, ii;
 
-	config= &dev->config;
+	config = &dev->config;
 	usb_display_conf_desc(config,dev);
-	for(i=0;i<config->no_of_if;i++) {
-		ifdesc= &config->if_desc[i];
+	for(i = 0; i < config->no_of_if; i++) {
+		ifdesc = &config->if_desc[i];
 		usb_display_if_desc(ifdesc,dev);
-		for(ii=0;ii<ifdesc->no_of_ep;ii++) {
-			epdesc= &ifdesc->ep_desc[ii];
+		for(ii = 0; ii < ifdesc->no_of_ep; ii++) {
+			epdesc = &ifdesc->ep_desc[ii];
 			usb_display_ep_desc(epdesc);
 		}
 	}
@@ -233,31 +254,31 @@ void usb_display_config(struct usb_device *dev)
 }
 
 /* shows the device tree recursively */
-void usb_show_tree_graph(struct usb_device *dev,char *pre)
+void usb_show_tree_graph(struct usb_device *dev, char *pre)
 {
 	int i,index;
-	int has_child,last_child,port;
+	int has_child, last_child, port;
 
-	index=strlen(pre);
+	index = strlen(pre);
 	printf(" %s",pre);
 	/* check if the device has connected children */
-	has_child=0;
-	for(i=0;i<dev->maxchild;i++) {
-		if (dev->children[i]!=NULL)
-			has_child=1;
+	has_child = 0;
+	for(i = 0; i < dev->maxchild; i++) {
+		if (dev->children[i] != NULL)
+			has_child = 1;
 	}
 	/* check if we are the last one */
-	last_child=1;
-	if (dev->parent!=NULL) {
-		for(i=0;i<dev->parent->maxchild;i++) {
+	last_child = 1;
+	if (dev->parent != NULL) {
+		for(i = 0; i < dev->parent->maxchild; i++) {
 			/* search for children */
-			if (dev->parent->children[i]==dev) {
+			if (dev->parent->children[i] == dev) {
 				/* found our pointer, see if we have a little sister */
-				port=i;
-				while(i++<dev->parent->maxchild) {
-					if (dev->parent->children[i]!=NULL) {
+				port = i;
+				while(i++ < dev->parent->maxchild) {
+					if (dev->parent->children[i] != NULL) {
 						/* found a sister */
-						last_child=0;
+						last_child = 0;
 						break;
 					} /* if */
 				} /* while */
@@ -265,28 +286,28 @@ void usb_show_tree_graph(struct usb_device *dev,char *pre)
 		} /* for all children of the parent */
 		printf("\b+-");
 		/* correct last child */
-		if (last_child) {
-			pre[index-1]=' ';
-		}
+		if (last_child)
+			pre[index-1] =' ';
 	} /* if not root hub */
-	else
+	else {
 		printf(" ");
-	printf("%d ",dev->devnum);
-	pre[index++]=' ';
-	pre[index++]= has_child ? '|' : ' ';
-	pre[index]=0;
-	printf(" %s (%s, %dmA)\n",usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
-		dev->slow ? "1.5MBit/s" : "12MBit/s",dev->config.MaxPower * 2);
-	if (strlen(dev->mf) ||
-	   strlen(dev->prod) ||
-	   strlen(dev->serial))
-		printf(" %s  %s %s %s\n",pre,dev->mf,dev->prod,dev->serial);
-	printf(" %s\n",pre);
-	if (dev->maxchild>0) {
-		for(i=0;i<dev->maxchild;i++) {
-			if (dev->children[i]!=NULL) {
-				usb_show_tree_graph(dev->children[i],pre);
-				pre[index]=0;
+	}
+	printf("%d ", dev->devnum);
+	pre[index++] = ' ';
+	pre[index++] = has_child ? '|' : ' ';
+	pre[index] = 0;
+	printf(" %s (%s, %dmA)\n", usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
+		dev->slow ? "1.5MBit/s" : "12MBit/s", dev->config.MaxPower * 2);
+
+	if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
+		printf(" %s  %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
+
+	printf(" %s\n", pre);
+	if (dev->maxchild > 0) {
+		for(i = 0; i < dev->maxchild; i++) {
+			if (dev->children[i] != NULL) {
+				usb_show_tree_graph(dev->children[i], pre);
+				pre[index] = 0;
 			}
 		}
 	}
@@ -297,8 +318,8 @@ void usb_show_tree(struct usb_device *dev)
 {
 	char preamble[32];
 
-	memset(preamble,0,32);
-	usb_show_tree_graph(dev,&preamble[0]);
+	memset(preamble, 0, 32);
+	usb_show_tree_graph(dev, &preamble[0]);
 }
 
 
@@ -310,7 +331,8 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	char *boot_device = NULL;
 	char *ep;
-	int dev, part=1, rcode;
+	int dev, rcode;
+	int part = 1;
 	ulong addr, cnt;
 	disk_partition_t info;
 	image_header_t *hdr;
@@ -348,7 +370,7 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		printf ("\n** Device %d not available\n", dev);
 		return 1;
 	}
-	if (stor_dev->block_read==NULL) {
+	if (stor_dev->block_read == NULL) {
 		printf("storage device not initialized. Use usb scan\n");
 		return 1;
 	}
@@ -364,13 +386,13 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		/* try to boot raw .... */
 		strncpy((char *)&info.type[0], BOOT_PART_TYPE, sizeof(BOOT_PART_TYPE));
 		strncpy((char *)&info.name[0], "Raw", 4);
-		info.start=0;
-		info.blksz=0x200;
-		info.size=2880;
+		info.start = 0;
+		info.blksz = 0x200;
+		info.size = 2880;
 		printf("error reading partinfo...try to boot raw\n");
 	}
 	if ((strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) &&
-	    (strncmp((char *)info.type, BOOT_PART_COMP, sizeof(info.type)) != 0)) {
+		(strncmp((char *)info.type, BOOT_PART_COMP, sizeof(info.type)) != 0)) {
 		printf ("\n** Invalid partition type \"%.32s\""
 			" (expect \"" BOOT_PART_TYPE "\")\n",
 			info.type);
@@ -422,8 +444,8 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	cnt /= info.blksz;
 	cnt -= 1;
 
-	if (stor_dev->block_read (dev, info.start+1, cnt,
-		      (ulong *)(addr+info.blksz)) != cnt) {
+	if (stor_dev->block_read (dev, info.start + 1, cnt,
+			(ulong *)(addr+info.blksz)) != cnt) {
 		printf ("\n** Read error on %d:%d\n", dev, part);
 		return 1;
 	}
@@ -437,23 +459,23 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	/* Loading ok, update default load address */
 	load_addr = addr;
 
-	flush_cache (addr, (cnt+1)*info.blksz);
+	flush_cache (addr, (cnt + 1) * info.blksz);
 
 	/* Check if we should attempt an auto-start */
-	if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
+	if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) {
 		char *local_args[2];
 		extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
+
 		local_args[0] = argv[0];
 		local_args[1] = NULL;
 		printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
-		rcode=do_bootm (cmdtp, 0, 1, local_args);
+		rcode = do_bootm (cmdtp, 0, 1, local_args);
 		return rcode;
 	}
 	return 0;
 }
 #endif /* CONFIG_USB_STORAGE */
 
-
 /*********************************************************************************
  * usb command intepreter
  */
@@ -475,14 +497,14 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #ifdef CONFIG_USB_STORAGE
 		/* try to recognize storage devices immediately */
 		if (i >= 0)
-	 		usb_stor_curr_dev = usb_stor_scan(1);
+			usb_stor_curr_dev = usb_stor_scan(1);
 #endif
 		return 0;
 	}
-	if (strncmp(argv[1],"stop",4) == 0) {
+	if (strncmp(argv[1], "stop", 4) == 0) {
 #ifdef CONFIG_USB_KEYBOARD
-		if (argc==2) {
-			if (usb_kbd_deregister()!=0) {
+		if (argc == 2) {
+			if (usb_kbd_deregister() != 0) {
 				printf("USB not stopped: usbkbd still using USB\n");
 				return 1;
 			}
@@ -500,17 +522,18 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		printf("USB is stopped. Please issue 'usb start' first.\n");
 		return 1;
 	}
-	if (strncmp(argv[1],"tree",4) == 0) {
+	if (strncmp(argv[1], "tree", 4) == 0) {
 		printf("\nDevice Tree:\n");
 		usb_show_tree(usb_get_dev_index(0));
 		return 0;
 	}
-	if (strncmp(argv[1],"inf",3) == 0) {
+	if (strncmp(argv[1], "inf", 3) == 0) {
 		int d;
-		if (argc==2) {
-			for(d=0;d<USB_MAX_DEVICE;d++) {
-				dev=usb_get_dev_index(d);
-				if (dev==NULL)
+
+		if (argc == 2) {
+			for(d = 0; d < USB_MAX_DEVICE; d++) {
+				dev = usb_get_dev_index(d);
+				if (dev == NULL)
 					break;
 				usb_display_desc(dev);
 				usb_display_config(dev);
@@ -518,18 +541,16 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 			return 0;
 		}
 		else {
-			int d;
-
-			i=simple_strtoul(argv[2], NULL, 16);
-			printf("config for device %d\n",i);
-			for(d=0;d<USB_MAX_DEVICE;d++) {
-				dev=usb_get_dev_index(d);
-				if (dev==NULL)
+			i = simple_strtoul(argv[2], NULL, 16);
+			printf("config for device %d\n", i);
+			for(d = 0; d < USB_MAX_DEVICE; d++) {
+				dev = usb_get_dev_index(d);
+				if (dev == NULL)
 					break;
-				if (dev->devnum==i)
+				if (dev->devnum == i)
 					break;
 			}
-			if (dev==NULL) {
+			if (dev == NULL) {
 				printf("*** NO Device avaiable ***\n");
 				return 0;
 			}
@@ -548,19 +569,19 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		return 0;
 	}
 
-	if (strncmp(argv[1], "stor", 4) == 0) {
+	if (strncmp(argv[1], "stor", 4) == 0)
 		return usb_stor_info();
-	}
 
-	if (strncmp(argv[1],"part",4) == 0) {
+	if (strncmp(argv[1], "part", 4) == 0) {
 		int devno, ok;
-		for (ok=0, devno=0; devno<USB_MAX_STOR_DEV; ++devno) {
-			stor_dev=usb_stor_get_dev(devno);
-			if (stor_dev->type!=DEV_TYPE_UNKNOWN) {
+
+		for (ok = 0, devno = 0; devno < USB_MAX_STOR_DEV; ++devno) {
+			stor_dev = usb_stor_get_dev(devno);
+			if (stor_dev->type != DEV_TYPE_UNKNOWN) {
 				ok++;
 				if (devno)
 					printf("\n");
-				printf("print_part of %x\n",devno);
+				printf("print_part of %x\n", devno);
 				print_part(stor_dev);
 			}
 		}
@@ -570,22 +591,23 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		}
 		return 0;
 	}
-	if (strcmp(argv[1],"read") == 0) {
-		if (usb_stor_curr_dev<0) {
+	if (strcmp(argv[1], "read") == 0) {
+		if (usb_stor_curr_dev < 0) {
 			printf("no current device selected\n");
 			return 1;
 		}
-		if (argc==5) {
+		if (argc == 5) {
 			unsigned long addr = simple_strtoul(argv[2], NULL, 16);
-			unsigned long blk  = simple_strtoul(argv[3], NULL, 16);
-			unsigned long cnt  = simple_strtoul(argv[4], NULL, 16);
+			unsigned long blk = simple_strtoul(argv[3], NULL, 16);
+			unsigned long cnt = simple_strtoul(argv[4], NULL, 16);
 			unsigned long n;
+
 			printf ("\nUSB read: device %d block # %ld, count %ld ... ",
 					usb_stor_curr_dev, blk, cnt);
-			stor_dev=usb_stor_get_dev(usb_stor_curr_dev);
+			stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
 			n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt, (ulong *)addr);
 			printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR");
-			if (n==cnt)
+			if (n == cnt)
 				return 0;
 			return 1;
 		}
@@ -593,13 +615,14 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	if (strncmp(argv[1], "dev", 3) == 0) {
 		if (argc == 3) {
 			int dev = (int)simple_strtoul(argv[2], NULL, 10);
+
 			printf ("\nUSB device %d: ", dev);
 			if (dev >= USB_MAX_STOR_DEV) {
 				printf("unknown device\n");
 				return 1;
 			}
 			printf ("\n    Device %d: ", dev);
-			stor_dev=usb_stor_get_dev(dev);
+			stor_dev = usb_stor_get_dev(dev);
 			dev_print(stor_dev);
 			if (stor_dev->type == DEV_TYPE_UNKNOWN) {
 				return 1;
@@ -610,7 +633,7 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		}
 		else {
 			printf ("\nUSB device %d: ", usb_stor_curr_dev);
-			stor_dev=usb_stor_get_dev(usb_stor_curr_dev);
+			stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
 			dev_print(stor_dev);
 			if (stor_dev->type == DEV_TYPE_UNKNOWN) {
 				return 1;
diff --git a/common/usb.c b/common/usb.c
index 4df01ea..6c10282 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -1,5 +1,4 @@
 /*
- *
  * Most of this source has been derived from the Linux USB
  * project:
  * (C) Copyright Linus Torvalds 1999
@@ -10,7 +9,7 @@
  * (C) Copyright Randy Dunlap 2000
  * (C) Copyright David Brownell 2000 (kernel hotplug, usb_device_id)
  * (C) Copyright Yggdrasil Computing, Inc. 2000
- *     (usb_device_id matching changes by Adam J. Richter)
+ *	(usb_device_id matching changes by Adam J. Richter)
  *
  * Adapted for U-Boot:
  * (C) Copyright 2001 Denis Peter, MPL AG Switzerland
@@ -82,7 +81,6 @@ void usb_scan_devices(void);
 int usb_hub_probe(struct usb_device *dev, int ifnum);
 void usb_hub_reset(void);
 
-
 /***********************************************************************
  * wait_ms
  */
@@ -100,17 +98,17 @@ int usb_init(void)
 {
 	int result;
 
-	running=0;
-	dev_index=0;
-	asynch_allowed=1;
+	running = 0;
+	dev_index = 0;
+	asynch_allowed = 1;
 	usb_hub_reset();
 	/* init low_level USB */
 	printf("USB:   ");
 	result = usb_lowlevel_init();
 	/* if lowlevel init is OK, scan the bus for devices i.e. search HUBs and configure them */
-	if(result==0) {
+	if(result == 0) {
 		printf("scanning bus for devices... ");
-		running=1;
+		running = 1;
 		usb_scan_devices();
 		usb_started = 1;
 		return 0;
@@ -127,7 +125,7 @@ int usb_init(void)
  */
 int usb_stop(void)
 {
-	asynch_allowed=1;
+	asynch_allowed = 1;
 	usb_started = 0;
 	usb_hub_reset();
 	return usb_lowlevel_stop();
@@ -139,10 +137,9 @@ int usb_stop(void)
  */
 void usb_disable_asynch(int disable)
 {
-	asynch_allowed=!disable;
+	asynch_allowed = !disable;
 }
 
-
 /*-------------------------------------------------------------------
  * Message wrappers.
  *
@@ -154,11 +151,11 @@ void usb_disable_asynch(int disable)
 int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 			void *buffer,int transfer_len, int interval)
 {
-	return submit_int_msg(dev,pipe,buffer,transfer_len,interval);
+	return submit_int_msg(dev, pipe, buffer, transfer_len, interval);
 }
 
 /*
- * submits a control message and waits for comletion (at least timeout * 1ms)
+ * submits a control message and waits for completion (at least timeout * 1ms)
  * If timeout is 0, we don't wait for completion (used as example to set and
  * clear keyboards LEDs). For data transfers, (storage transfers) we don't
  * allow control messages with 0 timeout, by previousely resetting the flag
@@ -171,7 +168,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 			unsigned short value, unsigned short index,
 			void *data, unsigned short size, int timeout)
 {
-	if((timeout==0)&&(!asynch_allowed)) /* request for a asynch control pipe is not allowed */
+	if((timeout == 0) && (!asynch_allowed)) /* request for a asynch control pipe is not allowed */
 		return -1;
 
 	/* set setup command */
@@ -180,12 +177,12 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 	setup_packet.value = swap_16(value);
 	setup_packet.index = swap_16(index);
 	setup_packet.length = swap_16(size);
- 	USB_PRINTF("usb_control_msg: request: 0x%X, requesttype: 0x%X\nvalue 0x%X index 0x%X length 0x%X\n",
+	USB_PRINTF("usb_control_msg: request: 0x%X, requesttype: 0x%X\nvalue 0x%X index 0x%X length 0x%X\n",
 		request,requesttype,value,index,size);
-	dev->status=USB_ST_NOT_PROC; /*not yet processed */
+	dev->status = USB_ST_NOT_PROC; /*not yet processed */
 
-	submit_control_msg(dev,pipe,data,size,&setup_packet);
-	if(timeout==0) {
+	submit_control_msg(dev, pipe, data, size, &setup_packet);
+	if(timeout == 0) {
 		return (int)size;
 	}
 	while(timeout--) {
@@ -193,11 +190,10 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 			break;
 		wait_ms(1);
 	}
-	if(dev->status==0)
+	if(dev->status == 0)
 		return dev->act_len;
-	else {
-		return -1;
-	}
+
+	return -1;
 }
 
 /*-------------------------------------------------------------------
@@ -210,20 +206,19 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
 {
 	if (len < 0)
 		return -1;
-	dev->status=USB_ST_NOT_PROC; /*not yet processed */
-	submit_bulk_msg(dev,pipe,data,len);
+	dev->status = USB_ST_NOT_PROC; /*not yet processed */
+	submit_bulk_msg(dev, pipe, data, len);
 	while(timeout--) {
 		if(!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
 			break;
 		wait_ms(1);
 	}
-	*actual_length=dev->act_len;
-	if(dev->status==0)
+	*actual_length = dev->act_len;
+	if(dev->status == 0)
 		return 0;
-	else
-		return -1;
-}
 
+	return -1;
+}
 
 /*-------------------------------------------------------------------
  * Max Packet stuff
@@ -236,9 +231,9 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
 int usb_maxpacket(struct usb_device *dev,unsigned long pipe)
 {
 	if((pipe & USB_DIR_IN)==0) /* direction is out -> use emaxpacket out */
-		return(dev->epmaxpacketout[((pipe>>15) & 0xf)]);
+		return(dev->epmaxpacketout[((pipe >> 15) & 0xf)]);
 	else
-		return(dev->epmaxpacketin[((pipe>>15) & 0xf)]);
+		return(dev->epmaxpacketin[((pipe >> 15) & 0xf)]);
 }
 
 /*
@@ -249,27 +244,31 @@ int usb_set_maxpacket(struct usb_device *dev)
 	int i,ii,b;
 	struct usb_endpoint_descriptor *ep;
 
-	for(i=0; i<dev->config.bNumInterfaces;i++) {
-		for(ii=0; ii<dev->config.if_desc[i].bNumEndpoints; ii++) {
-			ep=&dev->config.if_desc[i].ep_desc[ii];
-			b=ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
+	for(i = 0; i < dev->config.bNumInterfaces; i++) {
+		for(ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++) {
+			ep = &dev->config.if_desc[i].ep_desc[ii];
+			b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
 
-			if((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)==USB_ENDPOINT_XFER_CONTROL) {	/* Control => bidirectional */
+			if((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
+				USB_ENDPOINT_XFER_CONTROL) {	/* Control => bidirectional */
 				dev->epmaxpacketout[b] = ep->wMaxPacketSize;
 				dev->epmaxpacketin [b] = ep->wMaxPacketSize;
-				USB_PRINTF("##Control EP epmaxpacketout/in[%d] = %d\n",b,dev->epmaxpacketin[b]);
+				USB_PRINTF("##Control EP epmaxpacketout/in[%d] = %d\n",
+					b, dev->epmaxpacketin[b]);
 			}
 			else {
-				if ((ep->bEndpointAddress & 0x80)==0) { /* OUT Endpoint */
+				if ((ep->bEndpointAddress & 0x80) == 0) { /* OUT Endpoint */
 					if(ep->wMaxPacketSize > dev->epmaxpacketout[b]) {
 						dev->epmaxpacketout[b] = ep->wMaxPacketSize;
-						USB_PRINTF("##EP epmaxpacketout[%d] = %d\n",b,dev->epmaxpacketout[b]);
+						USB_PRINTF("##EP epmaxpacketout[%d] = %d\n",
+							b, dev->epmaxpacketout[b]);
 					}
 				}
-				else  { /* IN Endpoint */
+				else { /* IN Endpoint */
 					if(ep->wMaxPacketSize > dev->epmaxpacketin[b]) {
 						dev->epmaxpacketin[b] = ep->wMaxPacketSize;
-						USB_PRINTF("##EP epmaxpacketin[%d] = %d\n",b,dev->epmaxpacketin[b]);
+						USB_PRINTF("##EP epmaxpacketin[%d] = %d\n",
+							b, dev->epmaxpacketin[b]);
 					}
 				} /* if out */
 			} /* if control */
@@ -294,7 +293,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
 	curr_if_num = -1;
 
 	dev->configno = cfgno;
-	head = (struct usb_descriptor_header *) &buffer[0];
+	head = (struct usb_descriptor_header *)&buffer[0];
 	if(head->bDescriptorType != USB_DT_CONFIG) {
 		printf(" ERROR: NOT USB_CONFIG_DESC %x\n", head->bDescriptorType);
 		return -1;
@@ -305,11 +304,11 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
 
 	index = dev->config.bLength;
 	/* Ok the first entry must be a configuration entry, now process the others */
-	head = (struct usb_descriptor_header *) &buffer[index];
+	head = (struct usb_descriptor_header *)&buffer[index];
 	while(index + 1 < dev->config.wTotalLength) {
 		switch(head->bDescriptorType) {
 			case USB_DT_INTERFACE:
-				if(((struct usb_interface_descriptor *) &buffer[index])->
+				if(((struct usb_interface_descriptor *)&buffer[index])->
 					bInterfaceNumber != curr_if_num) {
 					/* this is a new interface, copy new desc */
 					ifno = dev->config.no_of_if;
@@ -359,10 +358,11 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
 int usb_clear_halt(struct usb_device *dev, int pipe)
 {
 	int result;
-	int endp = usb_pipeendpoint(pipe)|(usb_pipein(pipe)<<7);
+	int endp = usb_pipeendpoint(pipe) | (usb_pipein(pipe) << 7);
 
 	result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
-		USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0, endp, NULL, 0, USB_CNTL_TIMEOUT * 3);
+		USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0, endp, NULL,
+		0, USB_CNTL_TIMEOUT * 3);
 
 	/* don't clear if failed */
 	if (result < 0)
@@ -384,10 +384,11 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
 /**********************************************************************
  * get_descriptor type
  */
-int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size)
+int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index,
+			void *buf, int size)
 {
 	int res;
- 	res = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+	res = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
 			USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
 			(type << 8) + index, 0,
 			buf, size, USB_CNTL_TIMEOUT);
@@ -399,18 +400,17 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char
  */
 int usb_get_configuration_no(struct usb_device *dev,unsigned char *buffer,int cfgno)
 {
- 	int result;
+	int result;
 	unsigned int tmp;
 	struct usb_config_descriptor *config;
 
-
-	config=(struct usb_config_descriptor *)&buffer[0];
+	config = (struct usb_config_descriptor *)&buffer[0];
 	result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 8);
 	if (result < 8) {
 		if (result < 0)
-			printf("unable to get descriptor, error %lX\n",dev->status);
+			printf("unable to get descriptor, error %lX\n", dev->status);
 		else
-			printf("config descriptor too short (expected %i, got %i)\n",8,result);
+			printf("config descriptor too short (expected %i, got %i)\n", 8, result);
 		return -1;
 	}
 	tmp=swap_16(config->wTotalLength);
@@ -422,7 +422,7 @@ int usb_get_configuration_no(struct usb_device *dev,unsigned char *buffer,int cf
 	}
 
 	result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, tmp);
-	USB_PRINTF("get_conf_no %d Result %d, wLength %d\n",cfgno,result,tmp);
+	USB_PRINTF("get_conf_no %d Result %d, wLength %d\n", cfgno, result, tmp);
 	return result;
 }
 
@@ -435,10 +435,10 @@ int usb_set_address(struct usb_device *dev)
 	int res;
 
 	USB_PRINTF("set address %d\n",dev->devnum);
-	res=usb_control_msg(dev, usb_snddefctrl(dev),
+	res = usb_control_msg(dev, usb_snddefctrl(dev),
 		USB_REQ_SET_ADDRESS, 0,
-		(dev->devnum),0,
-		NULL,0, USB_CNTL_TIMEOUT);
+		(dev->devnum), 0,
+		NULL, 0, USB_CNTL_TIMEOUT);
 	return res;
 }
 
@@ -470,8 +470,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
 		return 0;
 
 	if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
-	    USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate,
-	    interface, NULL, 0, USB_CNTL_TIMEOUT * 5)) < 0)
+		USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate,
+		interface, NULL, 0, USB_CNTL_TIMEOUT * 5)) < 0)
 		return ret;
 
 	return 0;
@@ -483,19 +483,20 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
 int usb_set_configuration(struct usb_device *dev, int configuration)
 {
 	int res;
-	USB_PRINTF("set configuration %d\n",configuration);
+
+	USB_PRINTF("set configuration %d\n", configuration);
 	/* set setup command */
-	res=usb_control_msg(dev, usb_sndctrlpipe(dev,0),
+	res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
 		USB_REQ_SET_CONFIGURATION, 0,
-		configuration,0,
-		NULL,0, USB_CNTL_TIMEOUT);
-	if(res==0) {
+		configuration, 0,
+		NULL, 0, USB_CNTL_TIMEOUT);
+	if(res == 0) {
 		dev->toggle[0] = 0;
 		dev->toggle[1] = 0;
 		return 0;
 	}
-	else
-		return -1;
+
+	return -1;
 }
 
 /********************************************************************
@@ -521,7 +522,8 @@ int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id)
 /********************************************************************
  * get report
  */
-int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, unsigned char id, void *buf, int size)
+int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
+			unsigned char id, void *buf, int size)
 {
 	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
 		USB_REQ_GET_REPORT, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
@@ -542,7 +544,8 @@ int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
 /********************************************************************
  * get string index in buffer
  */
-int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char index, void *buf, int size)
+int usb_get_string(struct usb_device *dev, unsigned short langid,
+		unsigned char index, void *buf, int size)
 {
 	int i;
 	int result;
@@ -561,10 +564,10 @@ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char
 	return result;
 }
 
-
 static void usb_try_string_workarounds(unsigned char *buf, int *length)
 {
-	int newlength, oldlength = *length;
+	int newlength;
+	int oldlength = *length;
 
 	for (newlength = 2; newlength + 1 < oldlength; newlength += 2)
 		if (!isprint(buf[newlength]) || buf[newlength + 1])
@@ -576,7 +579,6 @@ static void usb_try_string_workarounds(unsigned char *buf, int *length)
 	}
 }
 
-
 static int usb_string_sub(struct usb_device *dev, unsigned int langid,
 		unsigned int index, unsigned char *buf)
 {
@@ -611,7 +613,6 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,
 	return rc;
 }
 
-
 /********************************************************************
  * usb_string:
  * Get string index and translate it to ascii.
@@ -627,20 +628,21 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
 	if (size <= 0 || !buf || !index)
 		return -1;
 	buf[0] = 0;
-	tbuf=&mybuf[0];
+	tbuf = &mybuf[0];
 
 	/* get langid for strings if it's not yet known */
 	if (!dev->have_langid) {
 		err = usb_string_sub(dev, 0, 0, tbuf);
 		if (err < 0) {
-			USB_PRINTF("error getting string descriptor 0 (error=%x)\n",dev->status);
+			USB_PRINTF("error getting string descriptor 0 (error=%x)\n",
+				dev->status);
 			return -1;
 		} else if (tbuf[0] < 4) {
 			USB_PRINTF("string descriptor 0 too short\n");
 			return -1;
 		} else {
 			dev->have_langid = -1;
-			dev->string_langid = tbuf[2] | (tbuf[3]<< 8);
+			dev->string_langid = tbuf[2] | (tbuf[3] << 8);
 				/* always use the first langid listed */
 			USB_PRINTF("USB device number %d default language ID 0x%x\n",
 				dev->devnum, dev->string_langid);
@@ -655,8 +657,8 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
 	for (idx = 0, u = 2; u < err; u += 2) {
 		if (idx >= size)
 			break;
-		if (tbuf[u+1])			/* high byte */
-			buf[idx++] = '?';  /* non-ASCII character */
+		if (tbuf[u + 1])		/* high byte */
+			buf[idx++] = '?';	/* non-ASCII character */
 		else
 			buf[idx++] = tbuf[u];
 	}
@@ -665,70 +667,47 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
 	return err;
 }
 
-
 /********************************************************************
  * USB device handling:
  * the USB device are static allocated [USB_MAX_DEVICE].
  */
 
-
 /* returns a pointer to the device with the index [index].
  * if the device is not assigned (dev->devnum==-1) returns NULL
  */
 struct usb_device * usb_get_dev_index(int index)
 {
-	if(usb_dev[index].devnum==-1)
+	if(usb_dev[index].devnum == -1)
 		return NULL;
-	else
-		return &usb_dev[index];
-}
 
+	return &usb_dev[index];
+}
 
 /* returns a pointer of a new device structure or NULL, if
  * no device struct is available
  */
-struct usb_device * usb_alloc_new_device(void)
+struct usb_device* usb_alloc_new_device(void)
 {
 	int i;
+
 	USB_PRINTF("New Device %d\n",dev_index);
-	if(dev_index==USB_MAX_DEVICE) {
-		printf("ERROR, too many USB Devices, max=%d\n",USB_MAX_DEVICE);
+	if(dev_index == USB_MAX_DEVICE) {
+		printf("ERROR, too many USB Devices, max=%d\n", USB_MAX_DEVICE);
 		return NULL;
 	}
-	usb_dev[dev_index].devnum=dev_index+1; /* default Address is 0, real addresses start with 1 */
-	usb_dev[dev_index].maxchild=0;
-	for(i=0;i<USB_MAXCHILDREN;i++)
-		usb_dev[dev_index].children[i]=NULL;
-	usb_dev[dev_index].parent=NULL;
+	usb_dev[dev_index].devnum = dev_index + 1; /* default Address is 0, real addresses start with 1 */
+	usb_dev[dev_index].maxchild = 0;
+	for(i = 0; i < USB_MAXCHILDREN; i++)
+		usb_dev[dev_index].children[i] = NULL;
+	usb_dev[dev_index].parent = NULL;
 	dev_index++;
-	return &usb_dev[dev_index-1];
+	return &usb_dev[dev_index - 1];
 }
 
-
-/*
- * By the time we get here, the device has gotten a new device ID
- * and is in the default state. We need to identify the thing and
- * get the ball rolling..
- *
- * Returns 0 for success, != 0 for error.
- */
-int usb_new_device(struct usb_device *dev)
-{
-	int addr, err;
-	int tmp;
-	unsigned char tmpbuf[USB_BUFSIZ];
-
-	dev->descriptor.bMaxPacketSize0 = 8;  /* Start off at 8 bytes  */
-	dev->maxpacketsize = 0;		/* Default to 8 byte max packet size */
-	dev->epmaxpacketin [0] = 8;
-	dev->epmaxpacketout[0] = 8;
-
-	/* We still haven't set the Address yet */
-	addr = dev->devnum;
-	dev->devnum = 0;
-
 #undef NEW_INIT_SEQ
 #ifdef NEW_INIT_SEQ
+static inline init_sec(struct usb_device *dev)
+{
 	/* this is a Windows scheme of initialization sequence, with double
 	 * reset of the device. Some equipment is said to work only with such
 	 * init sequence; this patch is based on the work by Alan Stern:
@@ -740,8 +719,8 @@ int usb_new_device(struct usb_device *dev)
 	struct usb_device *parent = dev->parent;
 	unsigned short portstatus;
 
-	/* send 64-byte GET-DEVICE-DESCRIPTOR request.  Since the descriptor is
-	 * only 18 bytes long, this will terminate with a short packet.  But if
+	/* send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
+	 * only 18 bytes long, this will terminate with a short packet. But if
 	 * the maxpacket size is 8 or 16 the device may be waiting to transmit
 	 * some more. */
 
@@ -777,22 +756,65 @@ int usb_new_device(struct usb_device *dev)
 			return 1;
 		}
 	}
+
+	return 0;
+}
 #else
+int init_sec(struct usb_device *dev)
+{
+	int err;
+
 	/* and this is the old and known way of initializing devices */
 	err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8);
 	if (err < 8) {
 		printf("\n      USB device not responding, giving up (status=%lX)\n",dev->status);
 		return 1;
 	}
+
+	return 0;
+}
 #endif
+/*
+ * By the time we get here, the device has gotten a new device ID
+ * and is in the default state. We need to identify the thing and
+ * get the ball rolling..
+ *
+ * Returns 0 for success, != 0 for error.
+ */
+int usb_new_device(struct usb_device *dev)
+{
+	int addr, err;
+	int tmp;
+	unsigned char tmpbuf[USB_BUFSIZ];
+
+	dev->descriptor.bMaxPacketSize0 = 8;	/* Start off at 8 bytes */
+	dev->maxpacketsize = 0;			/* Default to 8 byte max packet size */
+	dev->epmaxpacketin [0] = 8;
+	dev->epmaxpacketout[0] = 8;
+
+	/* We still haven't set the Address yet */
+	addr = dev->devnum;
+	dev->devnum = 0;
+
+	err = init_sec(dev);
+	if(err)
+		return err;
 
 	dev->epmaxpacketin [0] = dev->descriptor.bMaxPacketSize0;
 	dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
 	switch (dev->descriptor.bMaxPacketSize0) {
-		case 8: dev->maxpacketsize = 0; break;
-		case 16: dev->maxpacketsize = 1; break;
-		case 32: dev->maxpacketsize = 2; break;
-		case 64: dev->maxpacketsize = 3; break;
+		case 8:
+			dev->maxpacketsize = 0;
+			break;
+		case 16:
+			dev->maxpacketsize = 1;
+			break;
+		case 32:
+			dev->maxpacketsize = 2;
+			break;
+		case 64:
+			dev->maxpacketsize = 3;
+			break;
 	}
 	dev->devnum = addr;
 
@@ -812,21 +834,21 @@ int usb_new_device(struct usb_device *dev)
 		if (err < 0)
 			printf("unable to get device descriptor (error=%d)\n",err);
 		else
-			printf("USB device descriptor short read (expected %i, got %i)\n",tmp,err);
+			printf("USB device descriptor short read (expected %i, got %i)\n", tmp, err);
 		return 1;
 	}
 	/* correct le values */
-	dev->descriptor.bcdUSB=swap_16(dev->descriptor.bcdUSB);
-	dev->descriptor.idVendor=swap_16(dev->descriptor.idVendor);
-	dev->descriptor.idProduct=swap_16(dev->descriptor.idProduct);
-	dev->descriptor.bcdDevice=swap_16(dev->descriptor.bcdDevice);
+	dev->descriptor.bcdUSB = swap_16(dev->descriptor.bcdUSB);
+	dev->descriptor.idVendor = swap_16(dev->descriptor.idVendor);
+	dev->descriptor.idProduct = swap_16(dev->descriptor.idProduct);
+	dev->descriptor.bcdDevice = swap_16(dev->descriptor.bcdDevice);
 	/* only support for one config for now */
-	usb_get_configuration_no(dev,&tmpbuf[0],0);
-	usb_parse_config(dev,&tmpbuf[0],0);
+	usb_get_configuration_no(dev, &tmpbuf[0], 0);
+	usb_parse_config(dev, &tmpbuf[0], 0);
 	usb_set_maxpacket(dev);
 	/* we set the default configuration here */
 	if (usb_set_configuration(dev, dev->config.bConfigurationValue)) {
-		printf("failed to set default configuration len %d, status %lX\n",dev->act_len,dev->status);
+		printf("failed to set default configuration len %d, status %lX\n", dev->act_len, dev->status);
 		return -1;
 	}
 	USB_PRINTF("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
@@ -848,22 +870,22 @@ int usb_new_device(struct usb_device *dev)
 	return 0;
 }
 
-/* build device Tree  */
+/* build device Tree */
 void usb_scan_devices(void)
 {
 	int i;
 	struct usb_device *dev;
 
 	/* first make all devices unknown */
-	for(i=0;i<USB_MAX_DEVICE;i++) {
-		memset(&usb_dev[i],0,sizeof(struct usb_device));
-		usb_dev[i].devnum=-1;
+	for(i = 0; i < USB_MAX_DEVICE; i++) {
+		memset(&usb_dev[i], 0, sizeof(struct usb_device));
+		usb_dev[i].devnum = -1;
 	}
-	dev_index=0;
+	dev_index = 0;
 	/* device 0 is always present (root hub, so let it analyze) */
-	dev=usb_alloc_new_device();
+	dev = usb_alloc_new_device();
 	usb_new_device(dev);
-	printf("%d USB Device(s) found\n",dev_index);
+	printf("%d USB Device(s) found\n", dev_index);
 	/* insert "driver" if possible */
 #ifdef CONFIG_USB_KEYBOARD
 	drv_usb_kbd_init();
@@ -871,7 +893,6 @@ void usb_scan_devices(void)
 #endif
 }
 
-
 /****************************************************************************
  * HUB "Driver"
  * Probes device for being a hub and configurate it
@@ -885,11 +906,9 @@ void usb_scan_devices(void)
 #define USB_HUB_PRINTF(fmt,args...)
 #endif
 
-
 static struct usb_hub_device hub_dev[USB_MAX_HUB];
 static int usb_hub_index;
 
-
 int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
 {
 	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
@@ -940,22 +959,22 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
 	USB_HUB_PRINTF("enabling power on all ports\n");
 	for (i = 0; i < dev->maxchild; i++) {
 		usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
-		USB_HUB_PRINTF("port %d returns %lX\n",i+1,dev->status);
+		USB_HUB_PRINTF("port %d returns %lX\n", i + 1, dev->status);
 		wait_ms(hub->desc.bPwrOn2PwrGood * 2);
 	}
 }
 
 void usb_hub_reset(void)
 {
-	usb_hub_index=0;
+	usb_hub_index = 0;
 }
 
 struct usb_hub_device *usb_hub_allocate(void)
 {
-	if(usb_hub_index<USB_MAX_HUB) {
+	if(usb_hub_index < USB_MAX_HUB) {
 		return &hub_dev[usb_hub_index++];
 	}
-	printf("ERROR: USB_MAX_HUB (%d) reached\n",USB_MAX_HUB);
+	printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB);
 	return NULL;
 }
 
@@ -968,15 +987,14 @@ static int hub_port_reset(struct usb_device *dev, int port,
 	struct usb_port_status portsts;
 	unsigned short portstatus, portchange;
 
-
 	USB_HUB_PRINTF("hub_port_reset: resetting port %d...\n", port);
-	for(tries=0;tries<MAX_TRIES;tries++) {
+	for(tries = 0; tries < MAX_TRIES; tries++) {
 
 		usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
 		wait_ms(200);
 
-		if (usb_get_port_status(dev, port + 1, &portsts)<0) {
-			USB_HUB_PRINTF("get_port_status failed status %lX\n",dev->status);
+		if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
+			USB_HUB_PRINTF("get_port_status failed status %lX\n", dev->status);
 			return -1;
 		}
 		portstatus = swap_16(portsts.wPortStatus);
@@ -988,19 +1006,18 @@ static int hub_port_reset(struct usb_device *dev, int port,
 			(portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0,
 			(portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0);
 		if ((portchange & USB_PORT_STAT_C_CONNECTION) ||
-		    !(portstatus & USB_PORT_STAT_CONNECTION))
+			!(portstatus & USB_PORT_STAT_CONNECTION))
 			return -1;
 
-		if (portstatus & USB_PORT_STAT_ENABLE) {
-
+		if (portstatus & USB_PORT_STAT_ENABLE)
 			break;
-		}
 
 		wait_ms(200);
 	}
 
-	if (tries==MAX_TRIES) {
-		USB_HUB_PRINTF("Cannot enable port %i after %i retries, disabling port.\n", port+1, MAX_TRIES);
+	if (tries == MAX_TRIES) {
+		USB_HUB_PRINTF("Cannot enable port %i after %i retries, disabling port.\n",
+				port + 1, MAX_TRIES);
 		USB_HUB_PRINTF("Maybe the USB cable is bad?\n");
 		return -1;
 	}
@@ -1019,7 +1036,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 	unsigned short portstatus, portchange;
 
 	/* Check status */
-	if (usb_get_port_status(dev, port + 1, &portsts)<0) {
+	if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
 		USB_HUB_PRINTF("get_port_status failed\n");
 		return;
 	}
@@ -1034,7 +1051,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 
 	/* Disconnect any existing devices under this port */
 	if (((!(portstatus & USB_PORT_STAT_CONNECTION)) &&
-	     (!(portstatus & USB_PORT_STAT_ENABLE)))|| (dev->children[port])) {
+		(!(portstatus & USB_PORT_STAT_ENABLE)))|| (dev->children[port])) {
 		USB_HUB_PRINTF("usb_disconnect(&hub->children[port]);\n");
 		/* Return now if nothing is connected */
 		if (!(portstatus & USB_PORT_STAT_CONNECTION))
@@ -1051,11 +1068,11 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 	wait_ms(200);
 
 	/* Allocate a new device struct for it */
-	usb=usb_alloc_new_device();
+	usb = usb_alloc_new_device();
 	usb->slow = (portstatus & USB_PORT_STAT_LOW_SPEED) ? 1 : 0;
 
 	dev->children[port] = usb;
-	usb->parent=dev;
+	usb->parent = dev;
 	/* Run it through the hoops (find a driver, etc) */
 	if (usb_new_device(usb)) {
 		/* Woops, disable the port */
@@ -1064,23 +1081,25 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 	}
 }
 
-
 int usb_hub_configure(struct usb_device *dev)
 {
-	unsigned char buffer[USB_BUFSIZ], *bitmap;
+	unsigned char buffer[USB_BUFSIZ];
+	unsigned char *bitmap;
 	struct usb_hub_descriptor *descriptor;
 	struct usb_hub_status *hubsts;
 	int i;
 	struct usb_hub_device *hub;
 
 	/* "allocate" Hub device */
-	hub=usb_hub_allocate();
-	if(hub==NULL)
+	hub = usb_hub_allocate();
+	if(hub == NULL)
 		return -1;
-	hub->pusb_dev=dev;
+
+	hub->pusb_dev = dev;
 	/* Get the the hub descriptor */
 	if (usb_get_hub_descriptor(dev, buffer, 4) < 0) {
-		USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor, giving up %lX\n",dev->status);
+		USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor, giving up %lX\n",
+			dev->status);
 		return -1;
 	}
 	descriptor = (struct usb_hub_descriptor *)buffer;
@@ -1088,29 +1107,30 @@ int usb_hub_configure(struct usb_device *dev)
 	/* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */
 	i = descriptor->bLength;
 	if (i > USB_BUFSIZ) {
-		USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor - too long: %d\N",
+		USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor - too long: %d\n",
 			descriptor->bLength);
 		return -1;
 	}
 
 	if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) {
-		USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor 2nd giving up %lX\n",dev->status);
+		USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor 2nd giving up %lX\n",
+			dev->status);
 		return -1;
 	}
-	memcpy((unsigned char *)&hub->desc,buffer,descriptor->bLength);
+	memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
 	/* adjust 16bit values */
 	hub->desc.wHubCharacteristics=swap_16(descriptor->wHubCharacteristics);
 	/* set the bitmap */
 	bitmap=(unsigned char *)&hub->desc.DeviceRemovable[0];
-	memset(bitmap,0xff,(USB_MAXCHILDREN+1+7)/8); /* devices not removable by default */
+	memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); /* devices not removable by default */
 	bitmap=(unsigned char *)&hub->desc.PortPowerCtrlMask[0];
-	memset(bitmap,0xff,(USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
-	for(i=0;i<((hub->desc.bNbrPorts + 1 + 7)/8);i++) {
-		hub->desc.DeviceRemovable[i]=descriptor->DeviceRemovable[i];
-	}
-	for(i=0;i<((hub->desc.bNbrPorts + 1 + 7)/8);i++) {
-		hub->desc.DeviceRemovable[i]=descriptor->PortPowerCtrlMask[i];
-	}
+	memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); /* PowerMask = 1B */
+	for(i = 0; i < ((hub->desc.bNbrPorts + 1 + 7) / 8); i++)
+		hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
+
+	for(i = 0; i < ((hub->desc.bNbrPorts + 1 + 7) / 8); i++)
+		hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i];
+
 	dev->maxchild = descriptor->bNbrPorts;
 	USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
 
@@ -1142,13 +1162,13 @@ int usb_hub_configure(struct usb_device *dev)
 		case 0x10:
 		case 0x18:
 			USB_HUB_PRINTF("no over-current protection\n");
-      break;
+			break;
 	}
 	USB_HUB_PRINTF("power on to power good time: %dms\n", descriptor->bPwrOn2PwrGood * 2);
 	USB_HUB_PRINTF("hub controller current requirement: %dmA\n", descriptor->bHubContrCurrent);
 	for (i = 0; i < dev->maxchild; i++)
 		USB_HUB_PRINTF("port %d is%s removable\n", i + 1,
-			hub->desc.DeviceRemovable[(i + 1)/8] & (1 << ((i + 1)%8)) ? " not" : "");
+			hub->desc.DeviceRemovable[(i + 1) / 8] & (1 << ((i + 1) % 8)) ? " not" : "");
 	if (sizeof(struct usb_hub_status) > USB_BUFSIZ) {
 		USB_HUB_PRINTF("usb_hub_configure: failed to get Status - too long: %d\n",
 			descriptor->bLength);
@@ -1161,7 +1181,7 @@ int usb_hub_configure(struct usb_device *dev)
 	}
 	hubsts = (struct usb_hub_status *)buffer;
 	USB_HUB_PRINTF("get_hub_status returned status %X, change %X\n",
-		swap_16(hubsts->wHubStatus),swap_16(hubsts->wHubChange));
+		swap_16(hubsts->wHubStatus), swap_16(hubsts->wHubChange));
 	USB_HUB_PRINTF("local power source is %s\n",
 		(swap_16(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good");
 	USB_HUB_PRINTF("%sover-current condition exists\n",
@@ -1175,9 +1195,10 @@ int usb_hub_configure(struct usb_device *dev)
 			USB_HUB_PRINTF("get_port_status failed\n");
 			continue;
 		}
+
 		portstatus = swap_16(portsts.wPortStatus);
 		portchange = swap_16(portsts.wPortChange);
-		USB_HUB_PRINTF("Port %d Status %X Change %X\n",i+1,portstatus,portchange);
+		USB_HUB_PRINTF("Port %d Status %X Change %X\n", i + 1, portstatus, portchange);
 		if (portchange & USB_PORT_STAT_C_CONNECTION) {
 			USB_HUB_PRINTF("port %d connection change\n", i + 1);
 			usb_hub_port_connect_change(dev, i);
@@ -1198,7 +1219,7 @@ int usb_hub_configure(struct usb_device *dev)
 		}
 		if (portstatus & USB_PORT_STAT_SUSPEND) {
 			USB_HUB_PRINTF("port %d suspend change\n", i + 1);
-			usb_clear_port_feature(dev, i + 1,  USB_PORT_FEAT_SUSPEND);
+			usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND);
 		}
 
 		if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
@@ -1229,7 +1250,7 @@ int usb_hub_probe(struct usb_device *dev, int ifnum)
 	/* Some hubs have a subclass of 1, which AFAICT according to the */
 	/*  specs is not defined, but it works */
 	if ((iface->bInterfaceSubClass != 0) &&
-	    (iface->bInterfaceSubClass != 1))
+		(iface->bInterfaceSubClass != 1))
 		return 0;
 	/* Multiple endpoints? What kind of mutant ninja-hub is this? */
 	if (iface->bNumEndpoints != 1)
@@ -1243,10 +1264,8 @@ int usb_hub_probe(struct usb_device *dev, int ifnum)
 		return 0;
 	/* We found a hub */
 	USB_HUB_PRINTF("USB hub found\n");
-	ret=usb_hub_configure(dev);
+	ret = usb_hub_configure(dev);
 	return ret;
 }
 
 #endif
-
-/* EOF */
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index 1703b23..e5cdb43 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -53,25 +53,25 @@ int overwrite_console (void)
 #endif
 
 
-#define REPEAT_RATE  40/4 /* 40msec -> 25cps */
-#define REPEAT_DELAY 10 /* 10 x REAPEAT_RATE = 400msec */
+#define REPEAT_RATE	40/4 /* 40msec -> 25cps */
+#define REPEAT_DELAY	10 /* 10 x REAPEAT_RATE = 400msec */
 
 #define NUM_LOCK	0x53
-#define CAPS_LOCK 0x39
-#define SCROLL_LOCK 0x47
+#define CAPS_LOCK	0x39
+#define SCROLL_LOCK	0x47
 
 
 /* Modifier bits */
-#define LEFT_CNTR		0
+#define LEFT_CNTR	0
 #define LEFT_SHIFT	1
-#define LEFT_ALT		2
-#define LEFT_GUI		3
+#define LEFT_ALT	2
+#define LEFT_GUI	3
 #define RIGHT_CNTR	4
 #define RIGHT_SHIFT	5
-#define RIGHT_ALT		6
-#define RIGHT_GUI		7
+#define RIGHT_ALT	6
+#define RIGHT_GUI	7
 
-#define USB_KBD_BUFFER_LEN 0x20  /* size of the keyboardbuffer */
+#define USB_KBD_BUFFER_LEN 0x20	/* size of the keyboardbuffer */
 
 static volatile char usb_kbd_buffer[USB_KBD_BUFFER_LEN];
 static volatile int usb_in_pointer = 0;
@@ -103,18 +103,17 @@ static unsigned char usb_kbd_numkey_shifted[] = {
 /* puts character in the queue and sets up the in and out pointer */
 static void usb_kbd_put_queue(char data)
 {
-	if((usb_in_pointer+1)==USB_KBD_BUFFER_LEN) {
-		if(usb_out_pointer==0) {
+	if((usb_in_pointer + 1) == USB_KBD_BUFFER_LEN) {
+		if(usb_out_pointer == 0)
 			return; /* buffer full */
-		} else{
-			usb_in_pointer=0;
-		}
+		else
+			usb_in_pointer = 0;
 	} else {
-		if((usb_in_pointer+1)==usb_out_pointer)
+		if((usb_in_pointer + 1) == usb_out_pointer)
 			return; /* buffer full */
 		usb_in_pointer++;
 	}
-	usb_kbd_buffer[usb_in_pointer]=data;
+	usb_kbd_buffer[usb_in_pointer] = data;
 	return;
 }
 
@@ -124,7 +123,7 @@ static int usb_kbd_testc(void)
 #ifdef CFG_USB_EVENT_POLL
 	usb_event_poll();
 #endif
-	if(usb_in_pointer==usb_out_pointer)
+	if(usb_in_pointer == usb_out_pointer)
 		return(0); /* no data */
 	else
 		return(1);
@@ -133,16 +132,17 @@ static int usb_kbd_testc(void)
 static int usb_kbd_getc(void)
 {
 	char c;
-	while(usb_in_pointer==usb_out_pointer) {
+
+	while(usb_in_pointer == usb_out_pointer) {
 #ifdef CFG_USB_EVENT_POLL
 		usb_event_poll();
 #endif
 	}
-	if((usb_out_pointer+1)==USB_KBD_BUFFER_LEN)
-		usb_out_pointer=0;
+	if((usb_out_pointer + 1) == USB_KBD_BUFFER_LEN)
+		usb_out_pointer = 0;
 	else
 		usb_out_pointer++;
-	c=usb_kbd_buffer[usb_out_pointer];
+	c = usb_kbd_buffer[usb_out_pointer];
 	return (int)c;
 
 }
@@ -153,23 +153,23 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum);
 /* search for keyboard and register it if found */
 int drv_usb_kbd_init(void)
 {
-	int error,i,index;
-	device_t usb_kbd_dev,*old_dev;
+	int error, i, index;
+	device_t usb_kbd_dev, *old_dev;
 	struct usb_device *dev;
-	char *stdinname  = getenv ("stdin");
+	char *stdinname = getenv ("stdin");
 
-	usb_in_pointer=0;
-	usb_out_pointer=0;
+	usb_in_pointer = 0;
+	usb_out_pointer = 0;
 	/* scan all USB Devices */
-	for(i=0;i<USB_MAX_DEVICE;i++) {
-		dev=usb_get_dev_index(i); /* get device */
-		if(dev->devnum!=-1) {
-			if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */
+	for(i = 0; i < USB_MAX_DEVICE; i++) {
+		dev = usb_get_dev_index(i); /* get device */
+		if(dev->devnum !=- 1) {
+			if(usb_kbd_probe(dev,0) == 1) { /* Ok, we found a keyboard */
 				/* check, if it is already registered */
 				USB_KBD_PRINTF("USB KBD found set up device.\n");
-				for (index=1; index<=ListNumItems(devlist); index++) {
+				for (index = 1; index <= ListNumItems(devlist); index++) {
 					old_dev = ListGetPtrToItem(devlist, index);
-					if(strcmp(old_dev->name,DEVNAME)==0) {
+					if(strcmp(old_dev->name, DEVNAME) == 0) {
 						/* ok, already registered, just return ok */
 						USB_KBD_PRINTF("USB KBD is already registered.\n");
 						return 1;
@@ -177,23 +177,23 @@ int drv_usb_kbd_init(void)
 				}
 				/* register the keyboard */
 				USB_KBD_PRINTF("USB KBD register.\n");
-				memset (&usb_kbd_dev, 0, sizeof(device_t));
+				memset(&usb_kbd_dev, 0, sizeof(device_t));
 				strcpy(usb_kbd_dev.name, DEVNAME);
-				usb_kbd_dev.flags =  DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
+				usb_kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
 				usb_kbd_dev.putc = NULL;
 				usb_kbd_dev.puts = NULL;
 				usb_kbd_dev.getc = usb_kbd_getc;
 				usb_kbd_dev.tstc = usb_kbd_testc;
-				error = device_register (&usb_kbd_dev);
-				if(error==0) {
+				error = device_register(&usb_kbd_dev);
+				if(error == 0) {
 					/* check if this is the standard input device */
-					if(strcmp(stdinname,DEVNAME)==0) {
+					if(strcmp(stdinname, DEVNAME) == 0) {
 						/* reassign the console */
-						if(overwrite_console()) {
+						if(overwrite_console())
 							return 1;
-						}
-						error=console_assign(stdin,DEVNAME);
-						if(error==0)
+
+						error = console_assign(stdin, DEVNAME);
+						if(error == 0)
 							return 1;
 						else
 							return error;
@@ -208,7 +208,6 @@ int drv_usb_kbd_init(void)
 	return -1;
 }
 
-
 /* deregistering the keyboard */
 int usb_kbd_deregister(void)
 {
@@ -226,78 +225,81 @@ int usb_kbd_deregister(void)
 static void usb_kbd_setled(struct usb_device *dev)
 {
 	struct usb_interface_descriptor *iface;
+
 	iface = &dev->config.if_desc[0];
-	leds=0;
-	if(scroll_lock!=0)
-		leds|=1;
-	leds<<=1;
-	if(caps_lock!=0)
-		leds|=1;
-	leds<<=1;
-	if(num_lock!=0)
-		leds|=1;
+	leds = 0;
+	if(scroll_lock != 0)
+		leds |= 1;
+	leds <<= 1;
+	if(caps_lock != 0)
+		leds |= 1;
+	leds <<= 1;
+	if(num_lock != 0)
+		leds |= 1;
 	usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
 		USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
- 		0x200, iface->bInterfaceNumber,(void *)&leds, 1, 0);
+		0x200, iface->bInterfaceNumber, (void *)&leds, 1, 0);
 
 }
 
 
 #define CAPITAL_MASK 0x20
 /* Translate the scancode in ASCII */
-static int usb_kbd_translate(unsigned char scancode,unsigned char modifier,int pressed)
+static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int pressed)
 {
 	unsigned char keycode;
 
-	if(pressed==0) {
+	if(pressed == 0) {
 		/* key released */
- 		repeat_delay=0;
+		repeat_delay = 0;
 		return 0;
 	}
-	if(pressed==2) {
+	if(pressed == 2) {
 		repeat_delay++;
-		if(repeat_delay<REPEAT_DELAY)
+		if(repeat_delay < REPEAT_DELAY)
 			return 0;
-		repeat_delay=REPEAT_DELAY;
+		repeat_delay = REPEAT_DELAY;
 	}
-	keycode=0;
-	if((scancode>3) && (scancode<=0x1d)) { /* alpha numeric values */
-		keycode=scancode-4 + 0x61;
+	keycode = 0;
+	if((scancode > 3) && (scancode <= 0x1d)) { /* alpha numeric values */
+		keycode = scancode - 4 + 0x61;
 		if(caps_lock)
-			keycode&=~CAPITAL_MASK; /* switch to capital Letters */
-		if(((modifier&(1<<LEFT_SHIFT))!=0)||((modifier&(1<<RIGHT_SHIFT))!=0)) {
+			keycode &= ~CAPITAL_MASK; /* switch to capital Letters */
+		if(((modifier&(1 << LEFT_SHIFT)) != 0) ||
+			((modifier&(1 << RIGHT_SHIFT)) != 0)) {
 			if(keycode & CAPITAL_MASK)
-				keycode&=~CAPITAL_MASK; /* switch to capital Letters */
+				keycode& = ~CAPITAL_MASK;	/* switch to capital Letters */
 			else
-				keycode|=CAPITAL_MASK; /* switch to non capital Letters */
+				keycode |= CAPITAL_MASK;	/* switch to non capital Letters */
 		}
 	}
-	if((scancode>0x1d) && (scancode<0x3A)) {
-		if(((modifier&(1<<LEFT_SHIFT))!=0)||((modifier&(1<<RIGHT_SHIFT))!=0))  /* shifted */
-			keycode=usb_kbd_numkey_shifted[scancode-0x1e];
+	if((scancode > 0x1d) && (scancode < 0x3A)) {
+		if(((modifier&(1 << LEFT_SHIFT)) != 0) ||
+			((modifier&(1 << RIGHT_SHIFT)) != 0)) /* shifted */
+			keycode = usb_kbd_numkey_shifted[scancode - 0x1e];
 		else /* non shifted */
-			keycode=usb_kbd_numkey[scancode-0x1e];
+			keycode = usb_kbd_numkey[scancode - 0x1e];
 	}
 
 	if (ctrl)
 		keycode = scancode - 0x3;
 
-	if(pressed==1) {
-		if(scancode==NUM_LOCK) {
-			num_lock=~num_lock;
+	if(pressed == 1) {
+		if(scancode == NUM_LOCK) {
+			num_lock = ~num_lock;
 			return 1;
 		}
-		if(scancode==CAPS_LOCK) {
-			caps_lock=~caps_lock;
+		if(scancode == CAPS_LOCK) {
+			caps_lock = ~caps_lock;
 			return 1;
 		}
-		if(scancode==SCROLL_LOCK) {
-			scroll_lock=~scroll_lock;
+		if(scancode == SCROLL_LOCK) {
+			scroll_lock = ~scroll_lock;
 			return 1;
 		}
 	}
-	if(keycode!=0) {
-		USB_KBD_PRINTF("%c",keycode);
+	if(keycode != 0) {
+		USB_KBD_PRINTF("%c", keycode);
 		usb_kbd_put_queue(keycode);
 	}
 	return 0;
@@ -306,14 +308,15 @@ static int usb_kbd_translate(unsigned char scancode,unsigned char modifier,int p
 /* Interrupt service routine */
 static int usb_kbd_irq(struct usb_device *dev)
 {
-	int i,res;
+	int i, res;
 
-	if((dev->irq_status!=0)||(dev->irq_act_len!=8))
+	if((dev->irq_status != 0) || (dev->irq_act_len != 8))
 	{
-		USB_KBD_PRINTF("usb_keyboard Error %lX, len %d\n",dev->irq_status,dev->irq_act_len);
+		USB_KBD_PRINTF("usb_keyboard Error %lX, len %d\n",
+			dev->irq_status, dev->irq_act_len);
 		return 1;
 	}
-	res=0;
+	res = 0;
 
 	switch (new[0]) {
 	case 0x0:	/* No combo key pressed */
@@ -326,18 +329,18 @@ static int usb_kbd_irq(struct usb_device *dev)
 	}
 
 	for (i = 2; i < 8; i++) {
-		if (old[i] > 3 && memscan(&new[2], old[i], 6) == &new[8]) {
-			res|=usb_kbd_translate(old[i],new[0],0);
-		}
-		if (new[i] > 3 && memscan(&old[2], new[i], 6) == &old[8]) {
-			res|=usb_kbd_translate(new[i],new[0],1);
-		}
+		if (old[i] > 3 && memscan(&new[2], old[i], 6) == &new[8])
+			res |= usb_kbd_translate(old[i], new[0], 0);
+
+		if (new[i] > 3 && memscan(&old[2], new[i], 6) == &old[8])
+			res |= usb_kbd_translate(new[i], new[0], 1);
+
 	}
-	if((new[2]>3) && (old[2]==new[2])) /* still pressed */
-		res|=usb_kbd_translate(new[2],new[0],2);
-	if(res==1)
+	if((new[2] > 3) && (old[2] == new[2])) /* still pressed */
+		res |= usb_kbd_translate(new[2], new[0], 2);
+	if(res == 1)
 		usb_kbd_setled(dev);
-	memcpy(&old[0],&new[0], 8);
+	memcpy(&old[0], &new[0], 8);
 	return 1; /* install IRQ Handler again */
 }
 
@@ -346,20 +349,27 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
 {
 	struct usb_interface_descriptor *iface;
 	struct usb_endpoint_descriptor *ep;
-	int pipe,maxp;
+	int pipe, maxp;
 
-	if (dev->descriptor.bNumConfigurations != 1) return 0;
+	if (dev->descriptor.bNumConfigurations != 1)
+		return 0;
 	iface = &dev->config.if_desc[ifnum];
 
-	if (iface->bInterfaceClass != 3) return 0;
-	if (iface->bInterfaceSubClass != 1) return 0;
-	if (iface->bInterfaceProtocol != 1) return 0;
-	if (iface->bNumEndpoints != 1) return 0;
+	if (iface->bInterfaceClass != 3)
+		return 0;
+	if (iface->bInterfaceSubClass != 1)
+		return 0;
+	if (iface->bInterfaceProtocol != 1)
+		return 0;
+	if (iface->bNumEndpoints != 1)
+		return 0;
 
 	ep = &iface->ep_desc[0];
 
-	if (!(ep->bEndpointAddress & 0x80)) return 0;
-	if ((ep->bmAttributes & 3) != 3) return 0;
+	if (!(ep->bEndpointAddress & 0x80))
+		return 0;
+	if ((ep->bmAttributes & 3) != 3)
+		return 0;
 	USB_KBD_PRINTF("USB KBD found set protocol...\n");
 	/* ok, we found a USB Keyboard, install it */
 	/* usb_kbd_get_hid_desc(dev); */
@@ -368,24 +378,23 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
 	usb_set_idle(dev, iface->bInterfaceNumber, REPEAT_RATE, 0);
 	memset(&new[0], 0, 8);
 	memset(&old[0], 0, 8);
-	repeat_delay=0;
+	repeat_delay = 0;
 	pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
 	maxp = usb_maxpacket(dev, pipe);
-	dev->irq_handle=usb_kbd_irq;
+	dev->irq_handle = usb_kbd_irq;
 	USB_KBD_PRINTF("USB KBD enable interrupt pipe...\n");
-	usb_submit_int_msg(dev,pipe,&new[0], maxp > 8 ? 8 : maxp,ep->bInterval);
+	usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval);
 	return 1;
 }
 
-
 #if 0
 struct usb_hid_descriptor {
-	unsigned char  bLength;
-	unsigned char  bDescriptorType; /* 0x21 for HID */
+	unsigned char bLength;
+	unsigned char bDescriptorType; /* 0x21 for HID */
 	unsigned short bcdHID; /* release number */
-	unsigned char  bCountryCode;
-	unsigned char  bNumDescriptors;
-	unsigned char  bReportDescriptorType;
+	unsigned char bCountryCode;
+	unsigned char bNumDescriptors;
+	unsigned char bReportDescriptorType;
 	unsigned short wDescriptorLength;
 } __attribute__ ((packed));
 
@@ -401,13 +410,13 @@ struct hid_item {
 	unsigned char type;
 	unsigned char tag;
 	union {
-	    unsigned char   u8;
-	    char            s8;
-	    unsigned short  u16;
-	    short           s16;
-	    unsigned long   u32;
-	    long            s32;
-	    unsigned char  *longdata;
+		unsigned char u8;
+		char s8;
+		unsigned short u16;
+		short s16;
+		unsigned long u32;
+		long s32;
+		unsigned char *longdata;
 	} data;
 };
 
@@ -430,15 +439,14 @@ static struct usb_hid_descriptor usb_kbd_hid_desc;
 void usb_kbd_display_hid(struct usb_hid_descriptor *hid)
 {
 	printf("USB_HID_DESC:\n");
-	printf("  bLenght               0x%x\n",hid->bLength);
-	printf("  bcdHID                0x%x\n",hid->bcdHID);
-	printf("  bCountryCode          %d\n",hid->bCountryCode);
-	printf("  bNumDescriptors       0x%x\n",hid->bNumDescriptors);
-	printf("  bReportDescriptorType 0x%x\n",hid->bReportDescriptorType);
-	printf("  wDescriptorLength     0x%x\n",hid->wDescriptorLength);
+	printf("  bLenght               0x%x\n", hid->bLength);
+	printf("  bcdHID                0x%x\n", hid->bcdHID);
+	printf("  bCountryCode          %d\n", hid->bCountryCode);
+	printf("  bNumDescriptors       0x%x\n", hid->bNumDescriptors);
+	printf("  bReportDescriptorType 0x%x\n", hid->bReportDescriptorType);
+	printf("  wDescriptorLength     0x%x\n", hid->wDescriptorLength);
 }
 
-
 /*
  * Fetch a report description item from the data stream. We support long
  * items, though they are not used yet.
@@ -449,12 +457,12 @@ static int fetch_item(unsigned char *start,unsigned char *end, struct hid_item *
 	if((end - start) > 0) {
 		unsigned char b = *start++;
 		item->type = (b >> 2) & 3;
-		item->tag  = (b >> 4) & 15;
+		item->tag = (b >> 4) & 15;
 		if (item->tag == HID_ITEM_TAG_LONG) {
 			item->format = HID_ITEM_FORMAT_LONG;
 			if ((end - start) >= 2) {
 				item->size = *start++;
-				item->tag  = *start++;
+				item->tag = *start++;
 				if ((end - start) >= item->size) {
 					item->data.longdata = start;
 					start += item->size;
@@ -476,14 +484,14 @@ static int fetch_item(unsigned char *start,unsigned char *end, struct hid_item *
 				case 2:
 					if ((end - start) >= 2) {
 						item->data.u16 = swap_16((unsigned short *)start);
-						start+=2;
+						start += 2;
 						return item->size;
 					}
 				case 3:
 					item->size++;
 					if ((end - start) >= 4) {
 						item->data.u32 = swap_32((unsigned long *)start);
-						start+=4;
+						start += 4;
 						return item->size;
 					}
 			}
@@ -584,7 +592,7 @@ static void usb_kbd_show_item(struct hid_item *item)
 					printf("Main End Collection");
 					break;
 				default:
-					printf("Main reserved %d",item->tag);
+					printf("Main reserved %d", item->tag);
 					break;
 			}
 			break;
@@ -692,36 +700,36 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev)
 	unsigned char buffer[256];
 	struct usb_descriptor_header *head;
 	struct usb_config_descriptor *config;
-	int index,len,i;
+	int index, len, i;
 	unsigned char *start, *end;
 	struct hid_item item;
 
-	if(usb_get_configuration_no(dev,&buffer[0],0)==-1)
+	if(usb_get_configuration_no(dev, &buffer[0], 0) == -1)
 		return -1;
-	head =(struct usb_descriptor_header *)&buffer[0];
-	if(head->bDescriptorType!=USB_DT_CONFIG) {
-		printf(" ERROR: NOT USB_CONFIG_DESC %x\n",head->bDescriptorType);
+	head = (struct usb_descriptor_header *)&buffer[0];
+	if(head->bDescriptorType != USB_DT_CONFIG) {
+		printf(" ERROR: NOT USB_CONFIG_DESC %x\n", head->bDescriptorType);
 		return -1;
 	}
-	index=head->bLength;
-	config=(struct usb_config_descriptor *)&buffer[0];
-	len=swap_16(config->wTotalLength);
+	index = head->bLength;
+	config = (struct usb_config_descriptor *)&buffer[0];
+	len = swap_16(config->wTotalLength);
 	/* Ok the first entry must be a configuration entry, now process the others */
-	head=(struct usb_descriptor_header *)&buffer[index];
-	while(index+1 < len) {
-		if(head->bDescriptorType==USB_DT_HID) {
+	head = (struct usb_descriptor_header *)&buffer[index];
+	while(index + 1 < len) {
+		if(head->bDescriptorType == USB_DT_HID) {
 			printf("HID desc found\n");
-			memcpy(&usb_kbd_hid_desc,&buffer[index],buffer[index]);
-			usb_kbd_hid_desc.bcdHID=swap_16(usb_kbd_hid_desc.bcdHID);
+			memcpy(&usb_kbd_hid_desc, &buffer[index], buffer[index]);
+			usb_kbd_hid_desc.bcdHID = swap_16(usb_kbd_hid_desc.bcdHID);
 			usb_kbd_hid_desc.wDescriptorLength=swap_16(usb_kbd_hid_desc.wDescriptorLength);
 			usb_kbd_display_hid(&usb_kbd_hid_desc);
-			len=0;
+			len = 0;
 			break;
 		}
-		index+=head->bLength;
-		head=(struct usb_descriptor_header *)&buffer[index];
+		index += head->bLength;
+		head = (struct usb_descriptor_header *)&buffer[index];
 	}
-	if(len>0)
+	if(len > 0)
 		return -1;
 	len=usb_kbd_hid_desc.wDescriptorLength;
 	if((index = usb_get_class_descriptor(dev, 0, USB_DT_REPORT, 0, &buffer[0], len)) < 0) {
@@ -729,23 +737,22 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev)
 		return -1;
 	}
 	printf(" report descriptor (size %u, read %d)\n", len, index);
-	start=&buffer[0];
-	end=&buffer[len];
-	i=0;
+	start = &buffer[0];
+	end = &buffer[len];
+	i = 0;
 	do {
-		index=fetch_item(start,end,&item);
-		i+=index;
+		index = fetch_item(start, end, &item);
+		i += index;
 		i++;
-		if(index>=0)
+		if(index >= 0)
 			usb_kbd_show_item(&item);
 
-		start+=index;
+		start += index;
 		start++;
-	} while(index>=0);
+	} while(index >= 0);
 
 }
 
-
 #endif
 
 #endif /* CONFIG_USB_KEYBOARD */
-- 
1.5.5.1





More information about the U-Boot mailing list