diff --git a/Makefile b/Makefile index f84903c..8d33c41 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # can be either "Y" or "N" (without quotes). "Y" for using the m68k-elf-, "N" for using the m68k-atari-mint # toolchain -COMPILE_ELF=N +COMPILE_ELF=Y ifeq (Y,$(COMPILE_ELF)) TCPREFIX=m68k-elf- @@ -71,9 +71,9 @@ CSRCS= \ $(SRCDIR)/sd_card.c \ $(SRCDIR)/wait.c \ $(SRCDIR)/s19reader.c \ - $(SRCDIR)/flash.c \ - $(SRCDIR)/fifo.c \ - $(SRCDIR)/i2c_firebee.c \ + $(SRCDIR)/flash.c \ + $(SRCDIR)/fifo.c \ + $(SRCDIR)/i2c_firebee.c \ $(SRCDIR)/usb.c \ $(SRCDIR)/usb_kbd.c \ $(SRCDIR)/usb_mem.c \ diff --git a/include/usb.h b/include/usb.h index 827e39f..6035982 100644 --- a/include/usb.h +++ b/include/usb.h @@ -26,10 +26,10 @@ #ifndef _USB_H_ #define _USB_H_ -#include -#include + #include #include +#include #include "pcixbios.h" #include "mod_devicetable.h" #include "pci_ids.h" @@ -231,6 +231,15 @@ struct usb_device { int usbnum; }; +/* Structure returned by Iorec() */ +typedef struct { + char *ibuf; + short ibufsiz; + volatile short ibufhd; + volatile short ibuftl; + short ibuflow; + short ibufhi; +} _IOREC; /********************************************************************** * this is how the lowlevel part communicate with the outer world */ diff --git a/sources/usb.c b/sources/usb.c index cf84b4b..736daae 100644 --- a/sources/usb.c +++ b/sources/usb.c @@ -72,17 +72,18 @@ extern unsigned long usb_1st_disk_drive; #define USB_BUFSIZ 512 -struct hci { +struct hci +{ /* ------- common part -------- */ - long handle; /* PCI BIOS */ + long handle; /* PCI BIOS */ const struct pci_device_id *ent; int usbnum; - /* ---- end of common part ---- */ +/* ---- end of common part ---- */ }; extern void udelay(long usec); -static struct usb_device *usb_dev; +static struct usb_device *usb_dev; static int bus_index; static int dev_index[USB_MAX_BUS]; static struct hci *controller_priv[USB_MAX_BUS]; @@ -101,14 +102,15 @@ void usb_scan_devices(void *priv); int usb_hub_probe(struct usb_device *dev, int ifnum); void usb_hub_reset(int index_bus); -static int hub_port_reset(struct usb_device *dev, int port, unsigned short *portstat); +static int hub_port_reset(struct usb_device *dev, int port, + unsigned short *portstat); /*********************************************************************** * wait_ms */ inline void wait_ms(unsigned long ms) { - while(ms-- > 0) + while (ms-- > 0) udelay(1000); } @@ -119,20 +121,21 @@ int usb_init(long handle, const struct pci_device_id *ent) { void *priv; int res = 0; - if(bus_index >= USB_MAX_BUS) - return(-1); + if (bus_index >= USB_MAX_BUS) + return (-1); dev_index[bus_index] = 0; asynch_allowed = 1; - if(handle && (ent != NULL)) + if (handle && (ent != NULL )) { - if(usb_mem_init()) + if (usb_mem_init()) { usb_started = 0; return -1; /* out of memoy */ } - if(usb_dev == NULL) - usb_dev = (struct usb_device *)usb_malloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); - if(usb_dev == NULL) + if (usb_dev == NULL ) + usb_dev = (struct usb_device *) usb_malloc( + sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); + if (usb_dev == NULL ) { usb_started = 0; return -1; /* out of memoy */ @@ -142,52 +145,54 @@ int usb_init(long handle, const struct pci_device_id *ent) { int i; res = 0; - for(i = 0; i < USB_MAX_BUS; i++) + for (i = 0; i < USB_MAX_BUS; i++) { - if(controller_priv[i] != NULL) + if (controller_priv[i] != NULL ) { long handle = controller_priv[i]->handle; - if(handle) - res |= usb_init(handle, NULL); + if (handle) + res |= usb_init(handle, NULL ); } } return res; } usb_hub_reset(bus_index); /* init low_level USB */ - Cconws("USB: "); - switch(ent->class) + xprintf("USB: "); + switch (ent->class) { #ifdef CONFIG_USB_UHCI - case PCI_CLASS_SERIAL_USB_UHCI: - res = uhci_usb_lowlevel_init(handle, ent, &priv); - break; + case PCI_CLASS_SERIAL_USB_UHCI: + res = uhci_usb_lowlevel_init(handle, ent, &priv); + break; #endif #ifdef CONFIG_USB_OHCI - case PCI_CLASS_SERIAL_USB_OHCI: - res = ohci_usb_lowlevel_init(handle, ent, &priv); - break; + case PCI_CLASS_SERIAL_USB_OHCI: + res = ohci_usb_lowlevel_init(handle, ent, &priv); + break; #endif #ifdef CONFIG_USB_EHCI - case PCI_CLASS_SERIAL_USB_EHCI: - res = ehci_usb_lowlevel_init(handle, ent, &priv); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + res = ehci_usb_lowlevel_init(handle, ent, &priv); + break; #endif - default: res = -1; break; + default: + res = -1; + break; } - if(!res) + if (!res) { /* if lowlevel init is OK, scan the bus for devices * i.e. search HUBs and configure them */ - if(setup_packet == NULL) - setup_packet = (void *)usb_malloc(sizeof(struct devrequest)); - if(setup_packet == NULL) + if (setup_packet == NULL ) + setup_packet = (void *) usb_malloc(sizeof(struct devrequest)); + if (setup_packet == NULL ) { usb_started = 0; return -1; /* out of memoy */ } - Cconws("Scanning bus for devices... "); - controller_priv[bus_index] = (struct hci *)priv; + xprintf("Scanning bus for devices... "); + controller_priv[bus_index] = (struct hci *) priv; controller_priv[bus_index]->usbnum = bus_index; usb_scan_devices(priv); bus_index++; @@ -196,7 +201,7 @@ int usb_init(long handle, const struct pci_device_id *ent) } else { - Cconws("Error, couldn't init Lowlevel part\r\n"); + xprintf("Error, couldn't init Lowlevel part\r\n"); usb_started = 0; return -1; } @@ -208,33 +213,33 @@ int usb_init(long handle, const struct pci_device_id *ent) int usb_stop(void) { int i, res = 0; - if(usb_started) + if (usb_started) { asynch_allowed = 1; usb_started = 0; usb_hub_reset(bus_index); usb_free(setup_packet); - for(i = 0; i < USB_MAX_BUS; i++) + for (i = 0; i < USB_MAX_BUS; i++) { struct hci *priv = controller_priv[i]; - if(priv != NULL) + if (priv != NULL ) { - switch(priv->ent->class) + switch (priv->ent->class) { #ifdef CONFIG_USB_UHCI - case PCI_CLASS_SERIAL_USB_UHCI: - res |= uhci_usb_lowlevel_stop(priv); - break; + case PCI_CLASS_SERIAL_USB_UHCI: + res |= uhci_usb_lowlevel_stop(priv); + break; #endif #ifdef CONFIG_USB_OHCI - case PCI_CLASS_SERIAL_USB_OHCI: - res |= ohci_usb_lowlevel_stop(priv); - break; + case PCI_CLASS_SERIAL_USB_OHCI: + res |= ohci_usb_lowlevel_stop(priv); + break; #endif #ifdef CONFIG_USB_EHCI - case PCI_CLASS_SERIAL_USB_EHCI: - res |= ehci_usb_lowlevel_stop(priv); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + res |= ehci_usb_lowlevel_stop(priv); + break; #endif } } @@ -279,7 +284,7 @@ void usb_enable_interrupt(int enable) /* * disables the asynch behaviour of the control message. This is used for data - * transfers that uses the exclusiv access to the control and bulk messages. + * transfers that uses the exclusive access to the control and bulk messages. */ void usb_disable_asynch(int disable) { @@ -306,25 +311,26 @@ void usb_disable_asynch(int disable) /* * submits an Interrupt Message */ -int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int transfer_len, int interval) +int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, + int transfer_len, int interval) { - struct hci *priv = (struct hci *)dev->priv_hcd; - switch(priv->ent->class) + struct hci *priv = (struct hci *) dev->priv_hcd; + switch (priv->ent->class) { #ifdef CONFIG_USB_UHCI - case PCI_CLASS_SERIAL_USB_UHCI: - return uhci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); + case PCI_CLASS_SERIAL_USB_UHCI: + return uhci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); #endif #ifdef CONFIG_USB_OHCI - case PCI_CLASS_SERIAL_USB_OHCI: - return ohci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); + case PCI_CLASS_SERIAL_USB_OHCI: + return ohci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); #endif #ifdef CONFIG_USB_EHCI - case PCI_CLASS_SERIAL_USB_EHCI: - return ehci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); + case PCI_CLASS_SERIAL_USB_EHCI: + return ehci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); #endif - default: - return -1; + default: + return -1; } } @@ -338,12 +344,11 @@ int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, * and the current status are stored in the dev->act_len and dev->status. */ int usb_control_msg(struct usb_device *dev, unsigned int pipe, - unsigned char request, unsigned char requesttype, - unsigned short value, unsigned short index, - void *data, unsigned short size, int timeout) + unsigned char request, unsigned char requesttype, unsigned short value, + unsigned short index, void *data, unsigned short size, int timeout) { - struct hci *priv = (struct hci *)dev->priv_hcd; - if((timeout == 0) && (!asynch_allowed)) + struct hci *priv = (struct hci *) dev->priv_hcd; + if ((timeout == 0) && (!asynch_allowed)) { /* request for a asynch control pipe is not allowed */ return -1; @@ -355,32 +360,32 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, setup_packet->index = cpu_to_le16(index); setup_packet->length = cpu_to_le16(size); USB_PRINTF("usb_control_msg: request: 0x%X, requesttype: 0x%X, value 0x%X index 0x%X length 0x%X\r\n", request, requesttype, value, index, size); - switch(priv->ent->class) + switch (priv->ent->class) { #ifdef CONFIG_USB_UHCI - case PCI_CLASS_SERIAL_USB_UHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - uhci_submit_control_msg(dev, pipe, data, size, setup_packet); - break; + case PCI_CLASS_SERIAL_USB_UHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + uhci_submit_control_msg(dev, pipe, data, size, setup_packet); + break; #endif #ifdef CONFIG_USB_OHCI - case PCI_CLASS_SERIAL_USB_OHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ohci_submit_control_msg(dev, pipe, data, size, setup_packet); - break; + case PCI_CLASS_SERIAL_USB_OHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ohci_submit_control_msg(dev, pipe, data, size, setup_packet); + break; #endif #ifdef CONFIG_USB_EHCI - case PCI_CLASS_SERIAL_USB_EHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ehci_submit_control_msg(dev, pipe, data, size, setup_packet); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ehci_submit_control_msg(dev, pipe, data, size, setup_packet); + break; #endif - default: - return -1; + default: + return -1; } - if(timeout == 0) - return (int)size; - if(dev->status != 0) + if (timeout == 0) + return (int) size; + if (dev->status != 0) { /* * Let's wait a while for the timeout to elapse. @@ -397,48 +402,48 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, * -1 if Error. * synchronous behavior */ -int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout) +int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, + int *actual_length, int timeout) { - struct hci *priv = (struct hci *)dev->priv_hcd; - if(len < 0) + struct hci *priv = (struct hci *) dev->priv_hcd; + if (len < 0) return -1; - switch(priv->ent->class) + switch (priv->ent->class) { #ifdef CONFIG_USB_UHCI - case PCI_CLASS_SERIAL_USB_UHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - uhci_submit_bulk_msg(dev, pipe, data, len); - break; + case PCI_CLASS_SERIAL_USB_UHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + uhci_submit_bulk_msg(dev, pipe, data, len); + break; #endif #ifdef CONFIG_USB_OHCI - case PCI_CLASS_SERIAL_USB_OHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ohci_submit_bulk_msg(dev, pipe, data, len); - break; + case PCI_CLASS_SERIAL_USB_OHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ohci_submit_bulk_msg(dev, pipe, data, len); + break; #endif #ifdef CONFIG_USB_EHCI - case PCI_CLASS_SERIAL_USB_EHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ehci_submit_bulk_msg(dev, pipe, data, len); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ehci_submit_bulk_msg(dev, pipe, data, len); + break; #endif - default: - return -1; + default: + return -1; } - while(timeout--) + while (timeout--) { - if(!((volatile unsigned long)dev->status & USB_ST_NOT_PROC)) + if (!((volatile unsigned long) dev->status & USB_ST_NOT_PROC)) break; wait_ms(1); } *actual_length = dev->act_len; - if(dev->status == 0) + if (dev->status == 0) return 0; else return -1; } - /*------------------------------------------------------------------- * Max Packet stuff */ @@ -450,10 +455,10 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int usb_maxpacket(struct usb_device *dev, unsigned long pipe) { /* direction is out -> use emaxpacket out */ - if((pipe & USB_DIR_IN) == 0) - return dev->epmaxpacketout[((pipe>>15) & 0xf)]; + if ((pipe & USB_DIR_IN) == 0) + return dev->epmaxpacketout[((pipe >> 15) & 0xf)]; else - return dev->epmaxpacketin[((pipe>>15) & 0xf)]; + return dev->epmaxpacketin[((pipe >> 15) & 0xf)]; } /* The routine usb_set_maxpacket_ep() is extracted from the loop of routine @@ -464,11 +469,13 @@ int usb_maxpacket(struct usb_device *dev, unsigned long pipe) * to update the compiler (Occurs with at least several GCC 4.{1,2},x * CodeSourcery compilers like e.g. 2007q3, 2008q1, 2008q3 lite editions on ARM) */ -static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev, struct usb_endpoint_descriptor *ep) +static void __attribute__((noinline)) usb_set_maxpacket_ep( + struct usb_device *dev, struct usb_endpoint_descriptor *ep) { int b; b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; - if((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL) + if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) + == USB_ENDPOINT_XFER_CONTROL) { /* Control => bidirectional */ dev->epmaxpacketout[b] = ep->wMaxPacketSize; @@ -477,10 +484,10 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev } else { - if((ep->bEndpointAddress & 0x80) == 0) + if ((ep->bEndpointAddress & 0x80) == 0) { /* OUT Endpoint */ - if(ep->wMaxPacketSize > dev->epmaxpacketout[b]) + if (ep->wMaxPacketSize > dev->epmaxpacketout[b]) { dev->epmaxpacketout[b] = ep->wMaxPacketSize; USB_PRINTF("##EP epmaxpacketout[%d] = %d\r\n", b, dev->epmaxpacketout[b]); @@ -489,7 +496,7 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev else { /* IN Endpoint */ - if(ep->wMaxPacketSize > dev->epmaxpacketin[b]) + if (ep->wMaxPacketSize > dev->epmaxpacketin[b]) { dev->epmaxpacketin[b] = ep->wMaxPacketSize; USB_PRINTF("##EP epmaxpacketin[%d] = %d\r\n", b, dev->epmaxpacketin[b]); @@ -504,9 +511,9 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev int usb_set_maxpacket(struct usb_device *dev) { int i, ii; - for(i = 0; i < dev->config.bNumInterfaces; i++) - for(ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++) - usb_set_maxpacket_ep(dev,&dev->config.if_desc[i].ep_desc[ii]); + for (i = 0; i < dev->config.bNumInterfaces; i++) + for (ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++) + usb_set_maxpacket_ep(dev, &dev->config.if_desc[i].ep_desc[ii]); return 0; } @@ -524,10 +531,11 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno) epno = -1; curr_if_num = -1; dev->configno = cfgno; - head = (struct usb_descriptor_header *)&buffer[0]; - if(head->bDescriptorType != USB_DT_CONFIG) + head = (struct usb_descriptor_header *) &buffer[0]; + if (head->bDescriptorType != USB_DT_CONFIG) { - board_printf(" ERROR: NOT USB_CONFIG_DESC %x\r\n", head->bDescriptorType); + board_printf(" ERROR: NOT USB_CONFIG_DESC %x\r\n", + head->bDescriptorType); return -1; } memcpy(&dev->config, buffer, buffer[0]); @@ -537,49 +545,52 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno) /* Ok the first entry must be a configuration entry, * now process the others */ head = (struct usb_descriptor_header *) &buffer[index]; - while(index + 1 < dev->config.wTotalLength) + while (index + 1 < dev->config.wTotalLength) { switch (head->bDescriptorType) { - case USB_DT_INTERFACE: - 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; - dev->config.no_of_if++; - memcpy(&dev->config.if_desc[ifno], &buffer[index], buffer[index]); - dev->config.if_desc[ifno].no_of_ep = 0; - dev->config.if_desc[ifno].num_altsetting = 1; - curr_if_num = dev->config.if_desc[ifno].bInterfaceNumber; - } - else - { - /* found alternate setting for the interface */ - dev->config.if_desc[ifno].num_altsetting++; - } - break; - case USB_DT_ENDPOINT: - epno = dev->config.if_desc[ifno].no_of_ep; - /* found an endpoint */ - dev->config.if_desc[ifno].no_of_ep++; - memcpy(&dev->config.if_desc[ifno].ep_desc[epno], &buffer[index], buffer[index]); - le16_to_cpus(&(dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize)); - USB_PRINTF("if %d, ep %d\r\n", ifno, epno); - break; - default: - if(head->bLength == 0) - return 1; - USB_PRINTF("unknown Description Type : %x\r\n", head->bDescriptorType); - { - ch = (unsigned char *)head; - for (i = 0; i < head->bLength; i++) - USB_PRINTF(" %02X", *ch++); - USB_PRINTF("\r\n"); - } - break; + case USB_DT_INTERFACE: + 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; + dev->config.no_of_if++; + memcpy(&dev->config.if_desc[ifno], &buffer[index], + buffer[index]); + dev->config.if_desc[ifno].no_of_ep = 0; + dev->config.if_desc[ifno].num_altsetting = 1; + curr_if_num = dev->config.if_desc[ifno].bInterfaceNumber; + } + else + { + /* found alternate setting for the interface */ + dev->config.if_desc[ifno].num_altsetting++; + } + break; + case USB_DT_ENDPOINT: + epno = dev->config.if_desc[ifno].no_of_ep; + /* found an endpoint */ + dev->config.if_desc[ifno].no_of_ep++; + memcpy(&dev->config.if_desc[ifno].ep_desc[epno], &buffer[index], + buffer[index]); + le16_to_cpus( + &(dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize)); + USB_PRINTF("if %d, ep %d\r\n", ifno, epno); + break; + default: + if (head->bLength == 0) + return 1; + USB_PRINTF("unknown Description Type : %x\r\n", head->bDescriptorType); + { + ch = (unsigned char *) head; + for (i = 0; i < head->bLength; i++) + USB_PRINTF(" %02X", *ch++); USB_PRINTF("\r\n"); + } + break; } index += head->bLength; - head = (struct usb_descriptor_header *)&buffer[index]; + head = (struct usb_descriptor_header *) &buffer[index]; } return 1; } @@ -592,11 +603,12 @@ 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) + if (result < 0) return result; /* * NOTE: we do not get status and verify reset was successful @@ -611,34 +623,38 @@ 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), - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, (type << 8) + index, 0, buf, size, USB_CNTL_TIMEOUT); + 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); return res; } /********************************************************************** * gets configuration cfgno and store it in the buffer */ -int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int cfgno) +int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, + int cfgno) { 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, 9); - if(result < 9) + if (result < 9) { - if(result < 0) - board_printf("unable to get descriptor, error %lX\r\n", dev->status); + if (result < 0) + board_printf("unable to get descriptor, error %lX\r\n", + dev->status); else - board_printf("config descriptor too short (expected %i, got %i)\n", 9, result); + board_printf("config descriptor too short (expected %i, got %i)\n", + 9, result); return -1; } tmp = le16_to_cpu(config->wTotalLength); - if(tmp > USB_BUFSIZ) + if (tmp > USB_BUFSIZ) { USB_PRINTF("usb_get_configuration_no: failed to get descriptor - too long: %d\r\n", tmp); return -1; @@ -656,7 +672,8 @@ int usb_set_address(struct usb_device *dev) { int res; USB_PRINTF("set address %d\r\n", dev->devnum); - res = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS, 0, (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT); + res = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS, 0, + (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT); return res; } @@ -667,15 +684,15 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) { struct usb_interface_descriptor *if_face = NULL; int ret, i; - for(i = 0; i < dev->config.bNumInterfaces; i++) + for (i = 0; i < dev->config.bNumInterfaces; i++) { - if(dev->config.if_desc[i].bInterfaceNumber == interface) + if (dev->config.if_desc[i].bInterfaceNumber == interface) { if_face = &dev->config.if_desc[i]; break; } } - if(!if_face) + if (!if_face) { board_printf("selecting invalid interface %d", interface); return -1; @@ -687,11 +704,12 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) * some USB sticks timeouting during initialization and then being * unusable in U-Boot. */ - if(if_face->num_altsetting == 1) + if (if_face->num_altsetting == 1) return 0; - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate, interface, NULL, 0, USB_CNTL_TIMEOUT * 5); - if(ret < 0) + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_INTERFACE, + USB_RECIP_INTERFACE, alternate, interface, NULL, 0, + USB_CNTL_TIMEOUT * 5); + if (ret < 0) return ret; return 0; } @@ -705,8 +723,9 @@ int usb_set_configuration(struct usb_device *dev, int configuration) USB_PRINTF("set configuration %d\r\n", configuration); /* set setup command */ res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, USB_CNTL_TIMEOUT); - if(res == 0) + USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, + USB_CNTL_TIMEOUT); + if (res == 0) { dev->toggle[0] = 0; dev->toggle[1] = 0; @@ -721,9 +740,9 @@ int usb_set_configuration(struct usb_device *dev, int configuration) */ int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_PROTOCOL, USB_TYPE_CLASS | USB_RECIP_INTERFACE, - protocol, ifnum, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_PROTOCOL, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, protocol, ifnum, NULL, 0, + USB_CNTL_TIMEOUT); } /******************************************************************** @@ -731,20 +750,20 @@ int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol) */ int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, - (duration << 8) | report_id, ifnum, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_IDLE, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, (duration << 8) | report_id, + ifnum, NULL, 0, USB_CNTL_TIMEOUT); } /******************************************************************** * get report */ int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, - unsigned char id, void *buf, int size) + 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, - (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_REPORT, + USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, (type << 8) + id, + ifnum, buf, size, USB_CNTL_TIMEOUT); } /******************************************************************** @@ -753,24 +772,27 @@ int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, int usb_get_class_descriptor(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_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, - (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_DESCRIPTOR, + USB_RECIP_INTERFACE | USB_DIR_IN, (type << 8) + id, ifnum, buf, + size, USB_CNTL_TIMEOUT); } /******************************************************************** * 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; - for(i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) { /* some devices are flaky */ - result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, - (USB_DT_STRING << 8) + index, langid, buf, size, USB_CNTL_TIMEOUT); - if(result > 0) + result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, + (USB_DT_STRING << 8) + index, langid, buf, size, + USB_CNTL_TIMEOUT); + if (result > 0) break; } return result; @@ -779,20 +801,21 @@ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char static void usb_try_string_workarounds(unsigned char *buf, int *length) { int newlength, oldlength = *length; - for(newlength = 2; newlength + 1 < oldlength; newlength += 2) + for (newlength = 2; newlength + 1 < oldlength; newlength += 2) { char c = buf[newlength]; - if((c < ' ') || (c >= 127) || buf[newlength + 1]) + if ((c < ' ') || (c >= 127) || buf[newlength + 1]) break; } - if(newlength > 2) + if (newlength > 2) { buf[0] = newlength; *length = newlength; } } -static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned int index, unsigned char *buf) +static int usb_string_sub(struct usb_device *dev, unsigned int langid, + unsigned int index, unsigned char *buf) { int rc; /* Try to read the string descriptor by asking for the maximum @@ -800,13 +823,13 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned rc = usb_get_string(dev, langid, index, buf, 255); /* If that failed try to read the descriptor length, then * ask for just that many bytes */ - if(rc < 2) + if (rc < 2) { rc = usb_get_string(dev, langid, index, buf, 2); - if(rc == 2) + if (rc == 2) rc = usb_get_string(dev, langid, index, buf, buf[0]); } - if(rc >= 2) + if (rc >= 2) { if (!buf[0] && !buf[1]) usb_try_string_workarounds(buf, &rc); @@ -815,7 +838,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned rc = buf[0]; rc = rc - (rc & 1); /* force a multiple of two */ } - if(rc < 2) + if (rc < 2) rc = -1; return rc; } @@ -830,26 +853,26 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) unsigned char *tbuf; int err; unsigned int u, idx; - if(size <= 0 || !buf || !index) + if (size <= 0 || !buf || !index) return -1; buf[0] = 0; - tbuf = (unsigned char *)usb_malloc(USB_BUFSIZ); - if(tbuf == NULL) + tbuf = (unsigned char *) usb_malloc(USB_BUFSIZ); + if (tbuf == NULL ) { USB_PRINTF("usb_string: malloc failure\r\n"); return -1; } /* get langid for strings if it's not yet known */ - if(!dev->have_langid) + if (!dev->have_langid) { err = usb_string_sub(dev, 0, 0, tbuf); - if(err < 0) + if (err < 0) { USB_PRINTF("error getting string descriptor 0 (error=%lx)\r\n", dev->status); usb_free(tbuf); return -1; } - else if(tbuf[0] < 4) + else if (tbuf[0] < 4) { USB_PRINTF("string descriptor 0 too short\r\n"); usb_free(tbuf); @@ -859,23 +882,23 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) { dev->have_langid = -1; dev->string_langid = tbuf[2] | (tbuf[3] << 8); - /* always use the first langid listed */ + /* always use the first langid listed */ USB_PRINTF("USB device number %d default language ID 0x%x\r\n", dev->devnum, dev->string_langid); } } err = usb_string_sub(dev, dev->string_langid, index, tbuf); - if(err < 0) + if (err < 0) { usb_free(tbuf); return err; } - size--; /* leave room for trailing NULL char in output buffer */ - for(idx = 0, u = 2; u < err; u += 2) + size--; /* leave room for trailing NULL char in output buffer */ + for (idx = 0, u = 2; u < err; u += 2) { - if(idx >= size) + 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]; } @@ -896,17 +919,16 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) void usb_disconnect(struct usb_device **pdev) { struct usb_device *dev = *pdev; - if(dev != NULL) + if (dev != NULL ) { int i; - USB_PRINTF("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum); - USB_PRINTF("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum); - if(dev->deregister != NULL) + USB_PRINTF("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum); USB_PRINTF("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum); + if (dev->deregister != NULL ) dev->deregister(dev); /* Free up all the children.. */ - for(i = 0; i < USB_MAXCHILDREN; i++) + for (i = 0; i < USB_MAXCHILDREN; i++) { - if(dev->children[i] != NULL) + if (dev->children[i] != NULL ) { USB_PRINTF("USB %d, disconnect children %d\r\n", dev->usbnum, dev->children[i]->devnum); usb_disconnect(&dev->children[i]); @@ -914,14 +936,14 @@ void usb_disconnect(struct usb_device **pdev) } } /* Free up the device itself, including its device number */ - if(dev->devnum > 0) + if (dev->devnum > 0) { dev_index[dev->usbnum]--; memset(dev, 0, sizeof(struct usb_device)); dev->devnum = -1; } *pdev = NULL; - } + } } /* returns a pointer to the device with the index [index]. @@ -930,12 +952,11 @@ void usb_disconnect(struct usb_device **pdev) struct usb_device *usb_get_dev_index(int index, int index_bus) { struct usb_device *dev; - if((index_bus >= USB_MAX_BUS) || (index_bus < 0) - || (index >= USB_MAX_DEVICE) || (index < 0)) - return NULL; + if ((index_bus >= USB_MAX_BUS) || (index_bus < 0) + || (index >= USB_MAX_DEVICE) || (index < 0)) + return NULL ; dev = &usb_dev[(index_bus * USB_MAX_DEVICE) + index]; - if((controller_priv[index_bus] == NULL) || (dev->devnum == -1)) - return NULL; + if ((controller_priv[index_bus] == NULL )|| (dev->devnum == -1))return NULL; return dev; } @@ -946,17 +967,18 @@ struct usb_device *usb_alloc_new_device(int bus_index, void *priv) { int i, index = dev_index[bus_index]; struct usb_device *dev; - USB_PRINTF("USB %d new device %d\r\n", bus_index, index); - if(index >= USB_MAX_DEVICE) + USB_PRINTF("USB %d new device %d\r\n", bus_index, index); + if (index >= USB_MAX_DEVICE) { board_printf("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE); - return NULL; + return NULL ; } /* default Address is 0, real addresses start with 1 */ dev = &usb_dev[(bus_index * USB_MAX_DEVICE) + index]; dev->devnum = index + 1; dev->maxchild = 0; - for(i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL); + for (i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL ) + ; dev->parent = NULL; dev->priv_hcd = priv; dev->usbnum = bus_index; @@ -981,13 +1003,13 @@ int usb_new_device(struct usb_device *dev) struct usb_device *parent = dev->parent; unsigned short portstatus; #endif - if(dev == NULL) + if (dev == NULL ) return 1; /* We still haven't set the Address yet */ addr = dev->devnum; dev->devnum = 0; - tmpbuf = (unsigned char *)usb_malloc(USB_BUFSIZ); - if(tmpbuf == NULL) + tmpbuf = (unsigned char *) usb_malloc(USB_BUFSIZ); + if (tmpbuf == NULL ) { USB_PRINTF("usb_new_device: malloc failure\r\n"); return 1; @@ -998,7 +1020,7 @@ int usb_new_device(struct usb_device *dev) * both retrieve 64 bytes while reading the device descriptor * Several USB stick devices report ERR: CTL_TIMEOUT, caused by an * invalid header while reading 8 bytes as device descriptor. */ - dev->descriptor.bMaxPacketSize0 = 8; /* Start off at 8 bytes */ + dev->descriptor.bMaxPacketSize0 = 8; /* Start off at 8 bytes */ dev->maxpacketsize = PACKET_SIZE_8; dev->epmaxpacketin[0] = 8; dev->epmaxpacketout[0] = 8; @@ -1021,14 +1043,14 @@ int usb_new_device(struct usb_device *dev) * 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, or keeps on retransmitting the 8 byte header. */ - desc = (struct usb_device_descriptor *)tmpbuf; - dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */ + desc = (struct usb_device_descriptor *) tmpbuf; + dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */ /* Default to 64 byte max packet size */ dev->maxpacketsize = PACKET_SIZE_64; dev->epmaxpacketin[0] = 64; dev->epmaxpacketout[0] = 64; err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64); - if(err < 0) + if (err < 0) { USB_PRINTF("usb_new_device: usb_get_descriptor() failed\r\n"); usb_free(tmpbuf); @@ -1036,18 +1058,18 @@ int usb_new_device(struct usb_device *dev) } dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0; /* find the port number we're at */ - if(parent) + if (parent) { int j; - for(j = 0; j < parent->maxchild; j++) + for (j = 0; j < parent->maxchild; j++) { - if(parent->children[j] == dev) + if (parent->children[j] == dev) { port = j; break; } } - if(port < 0) + if (port < 0) { board_printf("usb_new_device: cannot locate device's port.\r\n"); usb_free(tmpbuf); @@ -1055,7 +1077,7 @@ int usb_new_device(struct usb_device *dev) } /* reset the port for the second time */ err = hub_port_reset(dev->parent, port, &portstatus); - if(err < 0) + if (err < 0) { board_printf("\r\nCouldn't reset port %i\r\n", port); usb_free(tmpbuf); @@ -1067,28 +1089,40 @@ int usb_new_device(struct usb_device *dev) dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; switch (dev->descriptor.bMaxPacketSize0) { - case 8: dev->maxpacketsize = PACKET_SIZE_8; break; - case 16: dev->maxpacketsize = PACKET_SIZE_16; break; - case 32: dev->maxpacketsize = PACKET_SIZE_32; break; - case 64: dev->maxpacketsize = PACKET_SIZE_64; break; + case 8: + dev->maxpacketsize = PACKET_SIZE_8; + break; + case 16: + dev->maxpacketsize = PACKET_SIZE_16; + break; + case 32: + dev->maxpacketsize = PACKET_SIZE_32; + break; + case 64: + dev->maxpacketsize = PACKET_SIZE_64; + break; } dev->devnum = addr; err = usb_set_address(dev); /* set address */ - if(err < 0) + if (err < 0) { - board_printf("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status); + board_printf("\r\nUSB device not accepting new address (error=%lX)\r\n", + dev->status); usb_free(tmpbuf); return 1; } - wait_ms(10); /* Let the SET_ADDRESS settle */ + wait_ms(10); /* Let the SET_ADDRESS settle */ tmp = sizeof(dev->descriptor); - err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, sizeof(dev->descriptor)); - if(err < tmp) + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, + sizeof(dev->descriptor)); + if (err < tmp) { - if(err < 0) + if (err < 0) board_printf("unable to get device descriptor (error=%d)\r\n", err); else - board_printf("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err); + board_printf( + "USB device descriptor short read (expected %i, got %i)\r\n", + tmp, err); usb_free(tmpbuf); return 1; } @@ -1102,27 +1136,28 @@ int usb_new_device(struct usb_device *dev) 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)) + if (usb_set_configuration(dev, dev->config.bConfigurationValue)) { - board_printf("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status); + board_printf( + "failed to set default configuration len %d, status %lX\r\n", + dev->act_len, dev->status); usb_free(tmpbuf); return -1; - } - USB_PRINTF("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n", - dev->descriptor.iManufacturer, dev->descriptor.iProduct, - dev->descriptor.iSerialNumber); + } USB_PRINTF("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n", + dev->descriptor.iManufacturer, dev->descriptor.iProduct, + dev->descriptor.iSerialNumber); memset(dev->mf, 0, sizeof(dev->mf)); memset(dev->prod, 0, sizeof(dev->prod)); memset(dev->serial, 0, sizeof(dev->serial)); - if(dev->descriptor.iManufacturer) - usb_string(dev, dev->descriptor.iManufacturer, dev->mf, sizeof(dev->mf)); - if(dev->descriptor.iProduct) + if (dev->descriptor.iManufacturer) + usb_string(dev, dev->descriptor.iManufacturer, dev->mf, + sizeof(dev->mf)); + if (dev->descriptor.iProduct) usb_string(dev, dev->descriptor.iProduct, dev->prod, sizeof(dev->prod)); - if(dev->descriptor.iSerialNumber) - usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, sizeof(dev->serial)); - USB_PRINTF("Manufacturer %s\r\n", dev->mf); - USB_PRINTF("Product %s\r\n", dev->prod); - USB_PRINTF("SerialNumber %s\r\n", dev->serial); + if (dev->descriptor.iSerialNumber) + usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, + sizeof(dev->serial)); + USB_PRINTF("Manufacturer %s\r\n", dev->mf); USB_PRINTF("Product %s\r\n", dev->prod); USB_PRINTF("SerialNumber %s\r\n", dev->serial); /* now prode if the device is a hub */ usb_hub_probe(dev, 0); usb_free(tmpbuf); @@ -1135,19 +1170,20 @@ void usb_scan_devices(void *priv) int i; struct usb_device *dev; /* first make all devices unknown */ - for(i = 0; i < USB_MAX_DEVICE; i++) + for (i = 0; i < USB_MAX_DEVICE; i++) { - memset(&usb_dev[(bus_index * USB_MAX_DEVICE) + i], 0, sizeof(struct usb_device)); + memset(&usb_dev[(bus_index * USB_MAX_DEVICE) + i], 0, + sizeof(struct usb_device)); usb_dev[(bus_index * USB_MAX_DEVICE) + i].devnum = -1; } dev_index[bus_index] = 0; /* device 0 is always present (root hub, so let it analyze) */ dev = usb_alloc_new_device(bus_index, priv); - if(usb_new_device(dev)) + if (usb_new_device(dev)) { Cconws("No USB Device found\r\n"); USB_PRINTF("No USB Device found\r\n"); - if(dev != NULL) + if (dev != NULL ) dev_index[bus_index]--; } else @@ -1158,14 +1194,14 @@ void usb_scan_devices(void *priv) #ifndef USB_POLL_HUB /* insert "driver" if possible */ #ifdef CONFIG_USB_KEYBOARD - if(drv_usb_kbd_init() < 0) - USB_PRINTF("No USB keyboard found\r\n"); + if (drv_usb_kbd_init() < 0) + USB_PRINTF("No USB keyboard found\r\n"); else Cconws("USB HID keyboard driver installed\r\n"); #endif /* CONFIG_USB_KEYBOARD */ #ifdef CONFIG_USB_MOUSE - if(drv_usb_mouse_init() < 0) - USB_PRINTF("No USB mouse found\r\n"); + if (drv_usb_mouse_init() < 0) + USB_PRINTF("No USB mouse found\r\n"); else Cconws("USB HID mouse driver installed\r\n"); #endif /* CONFIG_USB_MOUSE */ @@ -1196,38 +1232,41 @@ char usb_error_str[256]; int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, USB_DT_HUB << 8, 0, data, size, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_DESCRIPTOR, + USB_DIR_IN | USB_RT_HUB, USB_DT_HUB << 8, 0, data, size, + USB_CNTL_TIMEOUT); } int usb_clear_hub_feature(struct usb_device *dev, int feature) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_CLEAR_FEATURE, + USB_RT_HUB, feature, 0, NULL, 0, USB_CNTL_TIMEOUT); } int usb_clear_port_feature(struct usb_device *dev, int port, int feature) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_CLEAR_FEATURE, + USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); } int usb_set_port_feature(struct usb_device *dev, int port, int feature) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_FEATURE, + USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); } int usb_get_hub_status(struct usb_device *dev, void *data) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_STATUS, + USB_DIR_IN | USB_RT_HUB, 0, 0, data, sizeof(struct usb_hub_status), + USB_CNTL_TIMEOUT); } int usb_get_port_status(struct usb_device *dev, int port, void *data) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_STATUS, + USB_DIR_IN | USB_RT_PORT, 0, port, data, + sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); } static void usb_hub_power_on(struct usb_hub_device *hub) @@ -1252,31 +1291,32 @@ void usb_hub_reset(int bus_index) struct usb_hub_device *usb_hub_allocate(void) { - if(usb_hub_index[bus_index] < USB_MAX_HUB) + if (usb_hub_index[bus_index] < USB_MAX_HUB) return &hub_dev[bus_index][usb_hub_index[bus_index]++]; board_printf("ERROR: USB_MAX_HUB (%d) reached\r\n", USB_MAX_HUB); - return NULL; + return NULL ; } #define MAX_TRIES 5 static inline char *portspeed(int portstatus) { - if(portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) + if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) return "480 Mb/s"; - else if(portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) + else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) return "1.5 Mb/s"; else return "12 Mb/s"; } -static int hub_port_reset(struct usb_device *dev, int port, unsigned short *portstat) +static int hub_port_reset(struct usb_device *dev, int port, + unsigned short *portstat) { int tries; struct usb_port_status portsts; unsigned short portstatus, portchange; USB_HUB_PRINTF("hub_port_reset: resetting port %d...\r\n", port + 1); - 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); #ifdef USB_POLL_HUB @@ -1284,19 +1324,19 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port #else wait_ms(200); #endif - 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 status %lX\r\n", dev->status); return -1; } portstatus = le16_to_cpu(portsts.wPortStatus); portchange = le16_to_cpu(portsts.wPortChange); - USB_HUB_PRINTF("USB %d portstatus %x, change %x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus)); - USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE = %d\r\n", - (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0, (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)) + USB_HUB_PRINTF("USB %d portstatus %x, change %x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus)); USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE = %d\r\n", + (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0, (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)) return -1; - if(portstatus & USB_PORT_STAT_ENABLE) + if (portstatus & USB_PORT_STAT_ENABLE) break; #ifdef USB_POLL_HUB vTaskDelay((200*configTICK_RATE_HZ)/1000); @@ -1304,10 +1344,9 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port wait_ms(200); #endif } - if(tries == MAX_TRIES) + if (tries == MAX_TRIES) { - USB_HUB_PRINTF("USB %d, cannot enable port %i after %i retries, disabling port.\r\n", dev->usbnum, port + 1, MAX_TRIES); - USB_HUB_PRINTF("Maybe the USB cable is bad?\r\n"); + USB_HUB_PRINTF("USB %d, cannot enable port %i after %i retries, disabling port.\r\n", dev->usbnum, port + 1, MAX_TRIES); USB_HUB_PRINTF("Maybe the USB cable is bad?\r\n"); return -1; } usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET); @@ -1321,7 +1360,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) struct usb_port_status portsts; 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("USB %d get_port_status failed\r\n", dev->usbnum); return; @@ -1332,13 +1371,13 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) /* Clear the connection change status */ usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ - if(((!(portstatus & USB_PORT_STAT_CONNECTION)) - && (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) + if (((!(portstatus & USB_PORT_STAT_CONNECTION)) + && (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) { USB_HUB_PRINTF("USB %d port %i disconnected\r\n", dev->usbnum, port + 1); usb_disconnect(&dev->children[port]); /* Return now if nothing is connected */ - if(!(portstatus & USB_PORT_STAT_CONNECTION)) + if (!(portstatus & USB_PORT_STAT_CONNECTION)) return; } #ifdef USB_POLL_HUB @@ -1347,9 +1386,10 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) wait_ms(200); #endif /* Reset the port */ - if(hub_port_reset(dev, port, &portstatus) < 0) + if (hub_port_reset(dev, port, &portstatus) < 0) { - board_printf("USB %d cannot reset port %i!?\r\n", dev->usbnum, port + 1); + board_printf("USB %d cannot reset port %i!?\r\n", dev->usbnum, + port + 1); return; } #ifdef USB_POLL_HUB @@ -1359,16 +1399,16 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) #endif /* Allocate a new device struct for it */ usb = usb_alloc_new_device(dev->usbnum, dev->priv_hcd); - if(portstatus & USB_PORT_STAT_HIGH_SPEED) + if (portstatus & USB_PORT_STAT_HIGH_SPEED) usb->speed = USB_SPEED_HIGH; - else if(portstatus & USB_PORT_STAT_LOW_SPEED) + else if (portstatus & USB_PORT_STAT_LOW_SPEED) usb->speed = USB_SPEED_LOW; else usb->speed = USB_SPEED_FULL; dev->children[port] = usb; usb->parent = dev; /* Run it through the hoops (find a driver, etc) */ - if(usb_new_device(usb)) + if (usb_new_device(usb)) { /* Woops, disable the port */ USB_HUB_PRINTF("USB %d hub: disabling port %d\r\n", dev->usbnum, port + 1); @@ -1394,13 +1434,13 @@ static void usb_hub_events(struct usb_device *dev) { int i; struct usb_hub_device *hub = dev->hub; - if(hub == NULL) - return; - for(i = 0; i < dev->maxchild; i++) + if (hub == NULL ) + return; + for (i = 0; i < dev->maxchild; i++) { struct usb_port_status portsts; unsigned short portstatus, portchange; - if(usb_get_port_status(dev, i + 1, &portsts) < 0) + if (usb_get_port_status(dev, i + 1, &portsts) < 0) { USB_HUB_PRINTF("get_port_status failed\r\n"); continue; @@ -1408,36 +1448,38 @@ static void usb_hub_events(struct usb_device *dev) portstatus = le16_to_cpu(portsts.wPortStatus); portchange = le16_to_cpu(portsts.wPortChange); // USB_HUB_PRINTF("USB %d Port %d Status %X Change %X\r\n", dev->usbnum, i + 1, portstatus, portchange); - if(portchange & USB_PORT_STAT_C_CONNECTION) + if (portchange & USB_PORT_STAT_C_CONNECTION) { USB_HUB_PRINTF("USB %d port %d connection change\r\n", dev->usbnum, i + 1); usb_hub_port_connect_change(dev, i); } - if(portchange & USB_PORT_STAT_C_ENABLE) + if (portchange & USB_PORT_STAT_C_ENABLE) { USB_HUB_PRINTF("USB %d port %d enable change, status %x\r\n", dev->usbnum, i + 1, portstatus); usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE); /* EM interference sometimes causes bad shielded USB * devices to be shutdown by the hub, this hack enables * them again. Works at least with mouse driver */ - if(!(portstatus & USB_PORT_STAT_ENABLE) && (portstatus & USB_PORT_STAT_CONNECTION) && ((dev->children[i]))) + if (!(portstatus & USB_PORT_STAT_ENABLE) + && (portstatus & USB_PORT_STAT_CONNECTION) + && ((dev->children[i]))) { USB_HUB_PRINTF("USB %d already running port %i disabled by hub (EMI?), re-enabling...\r\n", dev->usbnum, i + 1); usb_hub_port_connect_change(dev, i); } } - if(portstatus & USB_PORT_STAT_SUSPEND) + if (portstatus & USB_PORT_STAT_SUSPEND) { USB_HUB_PRINTF("USB %d port %d suspend change\r\n", dev->usbnum, i + 1); usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND); } - if(portchange & USB_PORT_STAT_C_OVERCURRENT) + if (portchange & USB_PORT_STAT_C_OVERCURRENT) { USB_HUB_PRINTF("USB %d port %d over-current change\r\n", dev->usbnum, i + 1); usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT); usb_hub_power_on(hub); } - if(portchange & USB_PORT_STAT_C_RESET) + if (portchange & USB_PORT_STAT_C_RESET) { USB_HUB_PRINTF("USB %d port %d reset change\r\n", dev->usbnum, i + 1); usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET); @@ -1449,7 +1491,7 @@ static void usb_hub_events(struct usb_device *dev) void usb_poll_hub_task(void *pvParameters) { int index_bus = 0; - portTickType timeout = configTICK_RATE_HZ/10; + portTickType timeout = configTICK_RATE_HZ/10; if(pvParameters); while(1) { @@ -1473,10 +1515,10 @@ void usb_poll_hub_task(void *pvParameters) #ifdef CONFIG_USB_INTERRUPT_POLLING *vblsem = 0; #endif - for(i = 0; i < USB_MAX_BUS ; i++) + for(i = 0; i < USB_MAX_BUS; i++) { if(controller_priv[i] != NULL) - usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]); + usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]); } #ifdef CONFIG_USB_INTERRUPT_POLLING *vblsem = 1; @@ -1497,63 +1539,69 @@ int usb_hub_configure(struct usb_device *dev) /* "allocate" Hub device */ hub = usb_hub_allocate(); dev->hub = hub; - if(hub == NULL) + if (hub == NULL ) return -1; hub->pusb_dev = dev; - buffer = (unsigned char *)usb_malloc(USB_BUFSIZ); - if(buffer == NULL) + buffer = (unsigned char *) usb_malloc(USB_BUFSIZ); + if (buffer == NULL ) { USB_HUB_PRINTF("usb_hub_configure: malloc failure\r\n"); return -1; } /* Get the the hub descriptor */ - if(usb_get_hub_descriptor(dev, buffer, 4) < 0) + if (usb_get_hub_descriptor(dev, buffer, 4) < 0) { USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor, giving up %lX\r\n", dev->status); usb_free(buffer); return -1; - } - USB_HUB_PRINTF("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); - descriptor = (struct usb_hub_descriptor *)buffer; + } USB_HUB_PRINTF("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); + descriptor = (struct usb_hub_descriptor *) buffer; /* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */ i = descriptor->bLength; - if(i > USB_BUFSIZ) + if (i > USB_BUFSIZ) { USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor - too long: %d\r\n", descriptor->bLength); usb_free(buffer); return -1; } - if(usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) + 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\r\n", dev->status); usb_free(buffer); return -1; } - memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength); + memcpy((unsigned char *) &hub->desc, buffer, descriptor->bLength); /* adjust 16bit values */ - hub->desc.wHubCharacteristics = le16_to_cpu(descriptor->wHubCharacteristics); + hub->desc.wHubCharacteristics = le16_to_cpu( + descriptor->wHubCharacteristics); /* set the bitmap */ - bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0]; + bitmap = (unsigned char *) &hub->desc.DeviceRemovable[0]; /* devices not removable by default */ - memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8); - 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++) + memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); + 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++) + 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("USB %d, %d ports detected\r\n", dev->usbnum, dev->maxchild); - if(dev->maxchild >= 10) - dev->maxchild = 10; - switch(hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) + if (dev->maxchild >= 10) + dev->maxchild = 10; + switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) { - case 0x00: USB_HUB_PRINTF("ganged power switching\r\n"); break; - case 0x01: USB_HUB_PRINTF("individual port power switching\r\n"); break; - case 0x02: - case 0x03: USB_HUB_PRINTF("unknown reserved power switching mode\r\n"); break; + case 0x00: + USB_HUB_PRINTF("ganged power switching\r\n"); + break; + case 0x01: + USB_HUB_PRINTF("individual port power switching\r\n"); + break; + case 0x02: + case 0x03: + USB_HUB_PRINTF("unknown reserved power switching mode\r\n"); + break; } - if(hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND) + if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND) { USB_HUB_PRINTF("part of a compound device\r\n"); } @@ -1561,35 +1609,37 @@ int usb_hub_configure(struct usb_device *dev) { USB_HUB_PRINTF("standalone hub\r\n"); } - switch(hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) + switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) { - case 0x00: USB_HUB_PRINTF("global over-current protection\r\n"); break; - case 0x08: USB_HUB_PRINTF("individual port over-current protection\r\n"); break; - case 0x10: - case 0x18: USB_HUB_PRINTF("no over-current protection\r\n"); break; - } - USB_HUB_PRINTF("power on to power good time: %dms\r\n", descriptor->bPwrOn2PwrGood * 2); - USB_HUB_PRINTF("hub controller current requirement: %dmA\r\n", descriptor->bHubContrCurrent); - for(i = 0; i < dev->maxchild; i++) + case 0x00: + USB_HUB_PRINTF("global over-current protection\r\n"); + break; + case 0x08: + USB_HUB_PRINTF("individual port over-current protection\r\n"); + break; + case 0x10: + case 0x18: + USB_HUB_PRINTF("no over-current protection\r\n"); + break; + } USB_HUB_PRINTF("power on to power good time: %dms\r\n", descriptor->bPwrOn2PwrGood * 2); USB_HUB_PRINTF("hub controller current requirement: %dmA\r\n", descriptor->bHubContrCurrent); + for (i = 0; i < dev->maxchild; i++) { USB_HUB_PRINTF("USB %d port %d is%s removable\r\n", dev->usbnum, i + 1, hub->desc.DeviceRemovable[(i + 1) / 8] & (1 << ((i + 1) % 8)) ? " not" : ""); } - if(sizeof(struct usb_hub_status) > USB_BUFSIZ) + if (sizeof(struct usb_hub_status) > USB_BUFSIZ) { USB_HUB_PRINTF("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength); usb_free(buffer); return -1; } - if(usb_get_hub_status(dev, buffer) < 0) + if (usb_get_hub_status(dev, buffer) < 0) { USB_HUB_PRINTF("usb_hub_configure: failed to get Status %lX\r\n", dev->status); usb_free(buffer); return -1; } - hubsts = (struct usb_hub_status *)buffer; - USB_HUB_PRINTF("get_hub_status returned status %X, change %X\r\n", le16_to_cpu(hubsts->wHubStatus), le16_to_cpu(hubsts->wHubChange)); - USB_HUB_PRINTF("local power source is %s\r\n", (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good"); - USB_HUB_PRINTF("%sover-current condition exists\r\n", (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no "); + hubsts = (struct usb_hub_status *) buffer; + USB_HUB_PRINTF("get_hub_status returned status %X, change %X\r\n", le16_to_cpu(hubsts->wHubStatus), le16_to_cpu(hubsts->wHubChange)); USB_HUB_PRINTF("local power source is %s\r\n", (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good"); USB_HUB_PRINTF("%sover-current condition exists\r\n", (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no "); usb_hub_power_on(hub); #ifdef USB_POLL_HUB if(queue_poll_hub == NULL) @@ -1601,14 +1651,14 @@ int usb_hub_configure(struct usb_device *dev) if(xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS) { vQueueDelete(queue_poll_hub); - queue_poll_hub = NULL; + queue_poll_hub = NULL; } } vTaskDelay(configTICK_RATE_HZ); } if(queue_poll_hub == NULL) #endif - usb_hub_events(dev); + usb_hub_events(dev); usb_free(buffer); return 0; } @@ -1620,21 +1670,21 @@ int usb_hub_probe(struct usb_device *dev, int ifnum) int ret; iface = &dev->config.if_desc[ifnum]; /* Is it a hub? */ - if(iface->bInterfaceClass != USB_CLASS_HUB) + if (iface->bInterfaceClass != USB_CLASS_HUB) return 0; /* 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)) + if ((iface->bInterfaceSubClass != 0) && (iface->bInterfaceSubClass != 1)) return 0; /* Multiple endpoints? What kind of mutant ninja-hub is this? */ - if(iface->bNumEndpoints != 1) + if (iface->bNumEndpoints != 1) return 0; ep = &iface->ep_desc[0]; /* Output endpoint? Curiousier and curiousier.. */ - if(!(ep->bEndpointAddress & USB_DIR_IN)) + if (!(ep->bEndpointAddress & USB_DIR_IN)) return 0; /* If it's not an interrupt endpoint, we'd better punt! */ - if((ep->bmAttributes & 3) != 3) + if ((ep->bmAttributes & 3) != 3) return 0; /* We found a hub */ USB_HUB_PRINTF("USB %d hub found\r\n", dev->usbnum); diff --git a/sources/usb_kbd.c b/sources/usb_kbd.c index 249a50b..7c2688b 100644 --- a/sources/usb_kbd.c +++ b/sources/usb_kbd.c @@ -61,7 +61,6 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev); /* under TOS Repeat keys are build by timer C so infinite (0) or 1000 is a good value */ #define REPEAT_RATE 0 // 40 /* 40msec -> 25cps */ - #define MAX_VALUE_LOOKUP 0x90 #define MAX_VALUE_ATARI 0x75 @@ -116,33 +115,33 @@ static union { struct { - unsigned reserved1:3; - unsigned force_alt_shift:1; - unsigned right_shift_host:1; - unsigned left_shift_host:1; - unsigned alt_host:1; - unsigned ctrl_host:1; - unsigned key_forced:1; - unsigned reserved2:3; - unsigned altgr_usb:1; - unsigned shift_usb:1; - unsigned altgr_usb_break:1; - unsigned shift_usb_break:1; + unsigned reserved1 :3; + unsigned force_alt_shift :1; + unsigned right_shift_host :1; + unsigned left_shift_host :1; + unsigned alt_host :1; + unsigned ctrl_host :1; + unsigned key_forced :1; + unsigned reserved2 :3; + unsigned altgr_usb :1; + unsigned shift_usb :1; + unsigned altgr_usb_break :1; + unsigned shift_usb_break :1; } b; - unsigned short s; + unsigned short s; } flags; #ifdef USE_COUNTRYCODE 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)); +}__attribute__ ((packed)); static struct usb_hid_descriptor usb_kbd_hid_desc; #endif @@ -153,42 +152,42 @@ static int kbd_installed; static unsigned char usb_kbd_to_atari_scancode[] = { // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, // E F G H I J K L - 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, + 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, // M(,) N O P Q(A) R S T - 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, + 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, // U V W(Z) X Y Z(W) 1 2 - 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, + 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, // 3 4 5 6 7 8 9 0 - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, // RET ESC BACK TAB SPACE -()) = [(^) - 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x0D, 0x1A, + 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x0D, 0x1A, // ]($) \(*) EUR1 ;(M) ' ` ,(;) .(:) - 0x1B, 0x2B, 0x00, 0x27, 0x28, 0x5B, 0x33, 0x34, + 0x1B, 0x2B, 0x00, 0x27, 0x28, 0x5B, 0x33, 0x34, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x35, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, + 0x35, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x41, 0x42, 0x43, 0x44, 0x62, 0x61, 0x49, 0x4C, + 0x41, 0x42, 0x43, 0x44, 0x62, 0x61, 0x49, 0x4C, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x4F, 0x52, 0x47, 0x45, 0x53, 0x55, 0x46, 0x4D, + 0x4F, 0x52, 0x47, 0x45, 0x53, 0x55, 0x46, 0x4D, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x4B, 0x50, 0x48, 0x54, 0x65, 0x66, 0x4A, 0x4E, + 0x4B, 0x50, 0x48, 0x54, 0x65, 0x66, 0x4A, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, + 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, // KP8 KP9 KP0 KP. >< APP POWER KP= - 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, + 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x1D, 0x2A, 0x38, 0x56, 0x1D, 0x36, 0x38, 0x57 // virtual codes -}; + 0x1D, 0x2A, 0x38, 0x56, 0x1D, 0x36, 0x38, 0x57 // virtual codes + }; static unsigned char usb_kbd_to_atari_fr_modifier[] = { @@ -197,168 +196,164 @@ static unsigned char usb_kbd_to_atari_fr_modifier[] = /* bit 6: 1 for force CTRL */ /* bit 5: ALT, bit 4: SHIFT states for the AltGR table */ /* bit 3: ALT, bit 2: SHIFT states for the Shift table */ -/* bit 1: ALT, bit 0: SHIFT states for the Unshift table */ +/* bit 1: ALT, bit 0: SHIFT states for the Unshift table */ // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // E F G H I J K L - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // M(,) N O P Q(A) R S T - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // U V W(Z) X Y Z(W) 1 2 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, // 3 4 5 6 7 8 9 0 - 0x00, 0xB4, 0xA4, 0x94, 0x00, 0xA5, 0x84, 0xA4, + 0x00, 0xB4, 0xA4, 0x94, 0x00, 0xA5, 0x84, 0xA4, // RET ESC BACK TAB SPACE -()) = [(^) - 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xB4, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xB4, 0x00, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0x00, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x00, 0x00, 0x00, 0x95, 0x00, 0x95, 0x95, 0x00, + 0x00, 0x00, 0x00, 0x95, 0x00, 0x95, 0x95, 0x00, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // KP8 KP9 KP0 KP. >< APP POWER KP= - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x00, 0x00, 0x00, 0xEA, 0x00, 0x00, 0x00, 0xEA -}; + 0x00, 0x00, 0x00, 0xEA, 0x00, 0x00, 0x00, 0xEA }; -static unsigned char usb_kbd_to_atari_fr_unshift[] = +static unsigned char usb_kbd_to_atari_fr_unshift[] = { // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, // E F G H I J K L - 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, + 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, // M(,) N O P Q(A) R S T - 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, + 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, // U V W(Z) X Y Z(W) 1 2 - 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, + 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, // 3 4 5 6 7 8 9 0 - 0x04, 0x05, 0x06, 0x0D, 0x08, 0x0D, 0x0A, 0x0B, + 0x04, 0x05, 0x06, 0x0D, 0x08, 0x0D, 0x0A, 0x0B, // RET ESC BACK TAB SPACE -()) = [(^) - 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x35, 0x1A, + 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x35, 0x1A, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x1B, 0x1B, 0x00, 0x27, 0x28, 0x00, 0x33, 0x34, + 0x1B, 0x1B, 0x00, 0x27, 0x28, 0x00, 0x33, 0x34, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x09, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, + 0x09, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x41, 0x42, 0x43, 0x44, 0x62, 0x61, 0x62, 0x4C, + 0x41, 0x42, 0x43, 0x44, 0x62, 0x61, 0x62, 0x4C, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x4F, 0x52, 0x47, 0x45, 0x53, 0x47, 0x46, 0x4D, + 0x4F, 0x52, 0x47, 0x45, 0x53, 0x47, 0x46, 0x4D, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x4B, 0x50, 0x48, 0x00, 0x65, 0x66, 0x4A, 0x4E, + 0x4B, 0x50, 0x48, 0x00, 0x65, 0x66, 0x4A, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, + 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, // KP8 KP9 KP0 KP. >< APP KP= - 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, + 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F -}; + 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F }; -static unsigned char usb_kbd_to_atari_fr_shift[] = +static unsigned char usb_kbd_to_atari_fr_shift[] = { /* Hexa values, 00: unused => use the Unshift table */ /* FF: invalid => no scancode */ // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, // E F G H I J K L - 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, + 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, // M(,) N O P Q(A) R S T - 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, + 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, // U V W(Z) X Y Z(W) 1 2 - 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, + 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, // 3 4 5 6 7 8 9 0 - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, // RET ESC BACK TAB SPACE -()) = [(^) - 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x35, 0x1A, + 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x35, 0x1A, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x29, 0xFF, 0x00, 0x27, 0x28, 0x00, 0x33, 0x34, + 0x29, 0xFF, 0x00, 0x27, 0x28, 0x00, 0x33, 0x34, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x07, 0x3A, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x07, 0x3A, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x5A, 0x5B, 0x5C, 0x5D, 0x62, 0x61, 0x62, 0x4C, + 0x5A, 0x5B, 0x5C, 0x5D, 0x62, 0x61, 0x62, 0x4C, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x4F, 0x52, 0x47, 0x48, 0x53, 0x47, 0x50, 0x4D, + 0x4F, 0x52, 0x47, 0x48, 0x53, 0x47, 0x50, 0x4D, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x4B, 0x50, 0x48, 0x00, 0x65, 0x66, 0x4A, 0x4E, + 0x4B, 0x50, 0x48, 0x00, 0x65, 0x66, 0x4A, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, + 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, // KP8 KP9 KP0 KP. >< APP KP= - 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, + 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F -}; + 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F }; static unsigned char usb_kbd_to_atari_fr_altgr[] = { /* Hexa values, 00: unused => use the Unshift table */ /* FF: invalid => no scancode */ // A(Q) B C D - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // E F G H I J K L - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // M(,) N O P Q(A) R S T - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // U V W(Z) X Y Z(W) 1 2 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2B, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2B, // 3 4 5 6 7 8 9 0 - 0x2B, 0x1A, 0x1A, 0x2B, 0x29, 0x28, 0x1A, 0x2B, + 0x2B, 0x1A, 0x1A, 0x2B, 0x29, 0x28, 0x1A, 0x2B, // RET ESC BACK TAB SPACE -()) = [(^) - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1B, 0x1B, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1B, 0x1B, 0xFF, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //PAUSE INS HOME PgUp DEL END PgDn -> - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4E, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // KP8 KP9 KP0 KP. >< APP KP= - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // F13, F14, F15 F16 F17 F18 F19 F20 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x62, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x62, 0xFF, 0xFF, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0xFF, 0xFF, 0x61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //VolUp VolDn - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF -}; + 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF }; static unsigned char usb_kbd_to_atari_de_modifier[] = { @@ -367,194 +362,190 @@ static unsigned char usb_kbd_to_atari_de_modifier[] = /* bit 6: 1 for force CTRL */ /* bit 5: ALT, bit 4: SHIFT states for the AltGR table */ /* bit 3: ALT, bit 2: SHIFT states for the Shift table */ -/* bit 1: ALT, bit 0: SHIFT states for the Unshift table */ +/* bit 1: ALT, bit 0: SHIFT states for the Unshift table */ // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // E F G H I J K L - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // M(,) N O P Q(A) R S T - 0x00, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, // U V W(Z) X Y Z(W) 1 2 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 3 4 5 6 7 8 9 0 - 0x00, 0x00, 0x00, 0x00, 0xB4, 0xA4, 0xA4, 0xB4, + 0x00, 0x00, 0x00, 0x00, 0xB4, 0xA4, 0xA4, 0xB4, // RET ESC BACK TAB SPACE -()) = [(^) - 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x00, 0x80, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x00, 0x00, 0x00, 0x81, 0x00, 0x95, 0x81, 0x00, + 0x00, 0x00, 0x00, 0x81, 0x00, 0x95, 0x81, 0x00, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // KP8 KP9 KP0 KP. >< APP POWER KP= - 0x00, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x00, 0x00, 0x00, 0xEA, 0x00, 0x00, 0x00, 0xEA -}; + 0x00, 0x00, 0x00, 0xEA, 0x00, 0x00, 0x00, 0xEA }; static unsigned char usb_kbd_to_atari_de_unshift[] = { // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, // E F G H I J K L - 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, + 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, // M(,) N O P Q(A) R S T - 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, + 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, // U V W(Z) X Y Z(W) 1 2 - 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, + 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, // 3 4 5 6 7 8 9 0 - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, // RET ESC BACK TAB SPACE -()) = [(^) - 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x0D, 0x1A, + 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x0D, 0x1A, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x1B, 0x29, 0x00, 0x27, 0x28, 0x29, 0x33, 0x34, + 0x1B, 0x29, 0x00, 0x27, 0x28, 0x29, 0x33, 0x34, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x35, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, + 0x35, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x41, 0x42, 0x43, 0x44, 0x63, 0x64, 0x62, 0x50, + 0x41, 0x42, 0x43, 0x44, 0x63, 0x64, 0x62, 0x50, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x61, 0x52, 0x47, 0x48, 0x53, 0x47, 0x50, 0x4D, + 0x61, 0x52, 0x47, 0x48, 0x53, 0x47, 0x50, 0x4D, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x4B, 0x50, 0x48, 0x54, 0x65, 0x66, 0x4A, 0x4E, + 0x4B, 0x50, 0x48, 0x54, 0x65, 0x66, 0x4A, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, + 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, // KP8 KP9 KP0 KP. >< APP KP= - 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, + 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F -}; + 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F }; -static unsigned char usb_kbd_to_atari_de_shift[] = +static unsigned char usb_kbd_to_atari_de_shift[] = { /* Hexa values, 00: unused => use the Unshift table */ /* FF: invalid => no scancode */ // A(Q) B C D - 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x1E, 0x30, 0x2E, 0x20, // E F G H I J K L - 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, + 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, // M(,) N O P Q(A) R S T - 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, + 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14, // U V W(Z) X Y Z(W) 1 2 - 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, + 0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C, 0x02, 0x03, // 3 4 5 6 7 8 9 0 - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, // RET ESC BACK TAB SPACE -()) = [(^) - 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x0D, 0x1A, + 0x1C, 0x01, 0x0E, 0x0F, 0x39, 0x0C, 0x0D, 0x1A, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x1B, 0x0D, 0x00, 0x27, 0x28, 0x34, 0x33, 0x34, + 0x1B, 0x0D, 0x00, 0x27, 0x28, 0x34, 0x33, 0x34, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0x35, 0x3A, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x35, 0x3A, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0x5A, 0x5B, 0x5C, 0x5D, 0x63, 0x64, 0x62, 0x50, + 0x5A, 0x5B, 0x5C, 0x5D, 0x63, 0x64, 0x62, 0x50, //PAUSE INS HOME PgUp DEL END PgDn -> - 0x61, 0x52, 0x47, 0x48, 0x53, 0x47, 0x50, 0x4D, + 0x61, 0x52, 0x47, 0x48, 0x53, 0x47, 0x50, 0x4D, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0x4B, 0x50, 0x48, 0x54, 0x65, 0x66, 0x4A, 0x4E, + 0x4B, 0x50, 0x48, 0x54, 0x65, 0x66, 0x4A, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, + 0x72, 0x6D, 0x6E, 0x6F, 0x6A, 0x6B, 0x6C, 0x67, // KP8 KP9 KP0 KP. >< APP KP= - 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, + 0x68, 0x69, 0x70, 0x71, 0x60, 0x00, 0x00, 0x00, // F13, F14, F15 F16 F17 F18 F19 F20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x60, 0x00, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, //VolUp VolDn - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F -}; + 0x1D, 0x2A, 0x38, 0x0F, 0x1D, 0x36, 0x00, 0x0F }; static unsigned char usb_kbd_to_atari_de_altgr[] = { /* Hexa values, 00: unused => use the Unshift table */ /* FF: invalid => no scancode */ // A(Q) B C D - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // E F G H I J K L - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // M(,) N O P Q(A) R S T - 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0xFF, 0xFF, 0xFF, // U V W(Z) X Y Z(W) 1 2 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 3 4 5 6 7 8 9 0 - 0xFF, 0xFF, 0xFF, 0xFF, 0x27, 0x27, 0x28, 0x28, + 0xFF, 0xFF, 0xFF, 0xFF, 0x27, 0x27, 0x28, 0x28, // RET ESC BACK TAB SPACE -()) = [(^) - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0x2B, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0x2B, 0xFF, // ]($) \(*) ;(M) ' ` ,(;) .(:) - 0x2B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x2B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // /(!) CAPS F1 F2 F3 F4 F5 F6 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // F7 F8 F9 F10 F11 F12 PrtSc ScLoc - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //PAUSE INS HOME PgUp DEL END PgDn -> - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // <- DOWN UP NuLoc KP/ KP* KP- KP+ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4E, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4E, // ENT KP1 KP2 KP3 KP4 KP5 KP6 KP7 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // KP8 KP9 KP0 KP. >< APP KP= - 0xFF, 0xFF, 0xFF, 0xFF, 0x2B, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x2B, 0xFF, 0xFF, 0xFF, // F13, F14, F15 F16 F17 F18 F19 F20 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // F21 F22 F23 F24 EXEC HELP MENU SEL - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x62, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x62, 0xFF, 0xFF, // STOP AGAIN UNDO CUT COPY PASTE FIND MUTE - 0xFF, 0xFF, 0x61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //VolUp VolDn - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //LCTRL LSHFT LALT LGUI RCTRL RSHFT RALT RGUI - 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF -}; + 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF }; static COOKIE *get_cookie(long id) { - COOKIE *p= *(COOKIE **)0x5a0; - while(p) + COOKIE *p = *(COOKIE **) 0x5a0; + while (p) { - if(p->ident == id) - return(p); - if(!p->ident) - return((COOKIE *)0); + if (p->ident == id) + return (p); + if (!p->ident) + return ((COOKIE *) 0); p++; } - return((COOKIE *)0); + return ((COOKIE *) 0); } static void *memscan(void *addr, int c, int size) { - unsigned char *p = (unsigned char *)addr; - while(size) + unsigned char *p = (unsigned char *) addr; + while (size) { - if(*p == (char)c) - return(void *)p; + if (*p == (char) c) + return (void *) p; p++; size--; } - return(void *)p; + return (void *) p; } /* forward declaration */ @@ -564,12 +555,12 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum); int usb_kbd_deregister(struct usb_device *dev) { dev->irq_handle = NULL; - if(new != NULL) + if (new != NULL ) { usb_free(new); new = NULL; } - if(leds != NULL) + if (leds != NULL ) { usb_free(leds); leds = NULL; @@ -582,7 +573,7 @@ int usb_kbd_deregister(struct usb_device *dev) /* registering the keyboard */ int usb_kbd_register(struct usb_device *dev) { - if(!kbd_installed && (dev->devnum != -1) && (usb_kbd_probe(dev, 0) == 1)) + if (!kbd_installed && (dev->devnum != -1) && (usb_kbd_probe(dev, 0) == 1)) { /* Ok, we found a keyboard */ USB_KBD_PRINTF("USB KBD found (iorec: 0x%x, USB: %d, devnum: %d)\r\n", iorec, dev->usbnum, dev->devnum); num_lock = caps_lock = scroll_lock = old_modifier = 0; @@ -599,17 +590,17 @@ int usb_kbd_register(struct usb_device *dev) int drv_usb_kbd_init(void) { int i, j; - if(kbd_installed) + if (kbd_installed) return -1; /* scan all USB Devices */ - for(j = 0; j < USB_MAX_BUS; j++) + for (j = 0; j < USB_MAX_BUS; j++) { - for(i = 0; i < USB_MAX_DEVICE; i++) + for (i = 0; i < USB_MAX_DEVICE; i++) { struct usb_device *dev = usb_get_dev_index(i, j); /* get device */ - if(dev == NULL) + if (dev == NULL ) break; - if(usb_kbd_register(dev) > 0) + if (usb_kbd_register(dev) > 0) return 1; } } @@ -622,33 +613,34 @@ int drv_usb_kbd_init(void) */ /* set the LEDs. Since this is used in the irq routine, the control job - is issued with a timeout of 0. This means, that the job is queued without - waiting for job completion */ + is issued with a timeout of 0. This means, that the job is queued without + waiting for job completion */ static void usb_kbd_setled(struct usb_device *dev) { struct usb_interface_descriptor *iface = &dev->config.if_desc[0]; - unsigned char *pleds = (unsigned char *)(((unsigned long)leds + 3) & ~3); - if(scroll_lock != 0) + unsigned char *pleds = (unsigned char *) (((unsigned long) leds + 3) & ~3); + if (scroll_lock != 0) *pleds = 4; else *pleds = 0; - if(caps_lock != 0) + if (caps_lock != 0) *pleds |= 2; - if(num_lock != 0) + if (num_lock != 0) *pleds |= 1; - usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0x200, iface->bInterfaceNumber, pleds, 1, 0); + usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_REPORT, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0x200, + iface->bInterfaceNumber, pleds, 1, 0); } static void usb_kbd_send_code(unsigned char code) { - if((iorec != NULL) && (ikbdvec != NULL)) - call_ikbdvec(code, iorec, ikbdvec); + if ((iorec != NULL )&& (ikbdvec != NULL))call_ikbdvec(code, iorec, ikbdvec); } -/* Translate the scancode */ -static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int pressed) + /* Translate the scancode */ +static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, + int pressed) { unsigned char keycode = 0, atari_modifier = 0; #ifdef CONFIG_USB_INTERRUPT_POLLING @@ -657,11 +649,11 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int int type = USA; USB_KBD_PRINTF("USB KBD scancode: 0x%02x, modifier:0x%02x, pressed: %d\r\n", scancode, modifier, pressed); flags.b.force_alt_shift = 0; - if(scancode > MAX_VALUE_LOOKUP) + if (scancode > MAX_VALUE_LOOKUP) keycode = 0; else { - if(scancode == 0x8A) /* LEFT ALT */ + if (scancode == 0x8A) /* LEFT ALT */ keycode = 0x38; /* Alt Atari */ else { @@ -671,7 +663,7 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int unsigned char *modifier_table = NULL; unsigned long lang = USA; COOKIE *p = get_cookie('_AKP'); - if(p != NULL) + if (p != NULL ) lang = (p->v.l >> 8) & 0xFF; #ifdef USE_COUNTRYCODE switch(usb_kbd_hid_desc.bCountryCode) @@ -684,36 +676,37 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int case CC_ITA: lang = ITA; break; case CC_SWE: lang = SWE; break; case CC_SWF: lang = SWF; break; - case CC_SWG: lang = SWG; break; - } -#endif - switch(lang) - { - case FRA: - case SWF: - unshift_table = usb_kbd_to_atari_fr_unshift; - shift_table = usb_kbd_to_atari_fr_shift; - altgr_table = usb_kbd_to_atari_fr_altgr; - modifier_table = usb_kbd_to_atari_fr_modifier; - type = FRA; - break; - case FRG: - case SWG: - unshift_table = usb_kbd_to_atari_de_unshift; - shift_table = usb_kbd_to_atari_de_shift; - altgr_table = usb_kbd_to_atari_de_altgr; - modifier_table = usb_kbd_to_atari_de_modifier; - type = FRG; - break; - default: - unshift_table = usb_kbd_to_atari_scancode; - break; + case CC_SWG: lang = SWG; break; } - if(modifier != old_modifier) +#endif + switch (lang) { - if(((modifier & (1 << LEFT_SHIFT)) != 0) || ((modifier & (1 << RIGHT_SHIFT)) != 0)) + case FRA: + case SWF: + unshift_table = usb_kbd_to_atari_fr_unshift; + shift_table = usb_kbd_to_atari_fr_shift; + altgr_table = usb_kbd_to_atari_fr_altgr; + modifier_table = usb_kbd_to_atari_fr_modifier; + type = FRA; + break; + case FRG: + case SWG: + unshift_table = usb_kbd_to_atari_de_unshift; + shift_table = usb_kbd_to_atari_de_shift; + altgr_table = usb_kbd_to_atari_de_altgr; + modifier_table = usb_kbd_to_atari_de_modifier; + type = FRG; + break; + default: + unshift_table = usb_kbd_to_atari_scancode; + break; + } + if (modifier != old_modifier) + { + if (((modifier & (1 << LEFT_SHIFT)) != 0) + || ((modifier & (1 << RIGHT_SHIFT)) != 0)) { - if(!flags.b.shift_usb) + if (!flags.b.shift_usb) { flags.b.shift_usb = 1; flags.b.shift_usb_break = 1; @@ -721,9 +714,9 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int } else flags.b.shift_usb = 0; - if((modifier & (1 << RIGHT_ALT)) != 0) + if ((modifier & (1 << RIGHT_ALT)) != 0) { - if(!flags.b.altgr_usb) + if (!flags.b.altgr_usb) { flags.b.altgr_usb = 1; flags.b.altgr_usb_break = 1; @@ -733,74 +726,75 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int flags.b.altgr_usb = 0; old_modifier = modifier; } - else if(pressed) + else if (pressed) { - if(!flags.b.altgr_usb) + if (!flags.b.altgr_usb) flags.b.altgr_usb_break = 0; - if(!flags.b.shift_usb) + if (!flags.b.shift_usb) flags.b.shift_usb_break = 0; } keycode = unshift_table[scancode]; - if((modifier & (1 << LEFT_ALT)) == 0) + if ((modifier & (1 << LEFT_ALT)) == 0) { /* This modifier table can change host SHIFT & ALT states for each scancode, values - are in hexa : bit 7: 1 for a valid entry - bit 6: 1 for force CTRL - bit 5: ALT, bit 4: SHIFT states for the AltGR table - bit 3: ALT, bit 2: SHIFT states for the Shift table - bit 1: ALT, bit 0: SHIFT states for the Unshift table - */ - if(modifier_table != NULL) + are in hexa : bit 7: 1 for a valid entry + bit 6: 1 for force CTRL + bit 5: ALT, bit 4: SHIFT states for the AltGR table + bit 3: ALT, bit 2: SHIFT states for the Shift table + bit 1: ALT, bit 0: SHIFT states for the Unshift table + */ + if (modifier_table != NULL ) atari_modifier = modifier_table[scancode]; else atari_modifier = 0; - if((atari_modifier & (1 << 7)) != 0) + if ((atari_modifier & (1 << 7)) != 0) flags.b.force_alt_shift = 1; else atari_modifier = 0; - if(flags.b.altgr_usb_break) + if (flags.b.altgr_usb_break) { - if(altgr_table[scancode]) + if (altgr_table[scancode]) { keycode = altgr_table[scancode]; - if((atari_modifier & (1 << 6)) != 0) - atari_modifier = (atari_modifier >> 4) | (atari_modifier & (1 << 6)); + if ((atari_modifier & (1 << 6)) != 0) + atari_modifier = (atari_modifier >> 4) + | (atari_modifier & (1 << 6)); else atari_modifier >>= 4; } } - else if(flags.b.shift_usb_break) - { - if(shift_table[scancode]) + else if (flags.b.shift_usb_break) + { + if (shift_table[scancode]) { keycode = shift_table[scancode]; - if((atari_modifier & (1 << 6)) != 0) - atari_modifier = (atari_modifier >> 2) | (atari_modifier & (1 << 6)); + if ((atari_modifier & (1 << 6)) != 0) + atari_modifier = (atari_modifier >> 2) + | (atari_modifier & (1 << 6)); else atari_modifier >>= 2; - } + } } } } - } - USB_KBD_PRINTF("USB KBD atari-%s keycode:0x%02x, modifier:0x%02x, flags:0x%04x\r\n", (type == FRA) ? "fr" : (type == FRG) ? "de" : "us", keycode, atari_modifier, flags.s); - if(keycode == 0x1D) /* CTRL */ + } USB_KBD_PRINTF("USB KBD atari-%s keycode:0x%02x, modifier:0x%02x, flags:0x%04x\r\n", (type == FRA) ? "fr" : (type == FRG) ? "de" : "us", keycode, atari_modifier, flags.s); + if (keycode == 0x1D) /* CTRL */ { - if(pressed) + if (pressed) flags.b.ctrl_host = 1; else flags.b.ctrl_host = 0; } - if(keycode == 0x36) /* RSHIFT */ + if (keycode == 0x36) /* RSHIFT */ { - if(pressed) + if (pressed) flags.b.right_shift_host = 1; else flags.b.right_shift_host = 0; } - if(keycode == 0x2A) /* LSHIFT */ + if (keycode == 0x2A) /* LSHIFT */ { - if(pressed) + if (pressed) flags.b.left_shift_host = 1; else flags.b.left_shift_host = 0; @@ -808,84 +802,84 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int #ifdef CONFIG_USB_INTERRUPT_POLLING level = asm_set_ipl(7); /* mask interrupts for use call_ikbdvec() */ #endif - if(pressed && (flags.b.force_alt_shift)) + if (pressed && (flags.b.force_alt_shift)) { flags.b.key_forced = 1; - if(((atari_modifier & (1 << 6)) != 0) && flags.b.ctrl_host) + if (((atari_modifier & (1 << 6)) != 0) && flags.b.ctrl_host) usb_kbd_send_code(0x1D); /* CTRL */ - if((atari_modifier & (1 << 0)) == 0) + if ((atari_modifier & (1 << 0)) == 0) { - if(flags.b.left_shift_host) + if (flags.b.left_shift_host) usb_kbd_send_code(0xAA); /* !LSHIFT */ - if(flags.b.right_shift_host) + if (flags.b.right_shift_host) usb_kbd_send_code(0xB6); /* !RSHIFT */ } else { - if(!flags.b.left_shift_host) + if (!flags.b.left_shift_host) usb_kbd_send_code(0x2A); /* LSHIFT */ - if(!flags.b.right_shift_host && (keycode != 0x60)) /* < */ + if (!flags.b.right_shift_host && (keycode != 0x60)) /* < */ usb_kbd_send_code(0x36); /* RSHIFT */ } - if((atari_modifier & (1 << 1)) == 0) + if ((atari_modifier & (1 << 1)) == 0) { - if(flags.b.alt_host) + if (flags.b.alt_host) usb_kbd_send_code(0xB8); /* !ALT */ } else { - if(!flags.b.alt_host) + if (!flags.b.alt_host) usb_kbd_send_code(0x38); /* ALT */ } } - if((keycode !=0) && (keycode <= MAX_VALUE_ATARI)) + if ((keycode != 0) && (keycode <= MAX_VALUE_ATARI)) usb_kbd_send_code(pressed ? keycode : keycode | 0x80); - if(!pressed && (flags.b.force_alt_shift)) + if (!pressed && (flags.b.force_alt_shift)) { flags.b.key_forced = 0; - if(((atari_modifier & (1 << 6)) != 0) && flags.b.ctrl_host) + if (((atari_modifier & (1 << 6)) != 0) && flags.b.ctrl_host) usb_kbd_send_code(0x9D); /* !CTRL */ - if((atari_modifier & (1 << 0)) == 0) + if ((atari_modifier & (1 << 0)) == 0) { - if(flags.b.left_shift_host) + if (flags.b.left_shift_host) usb_kbd_send_code(0x2A); /* LSHIFT */ - if(flags.b.right_shift_host) + if (flags.b.right_shift_host) usb_kbd_send_code(0x36); /* RSHIFT */ } else { - if(!flags.b.left_shift_host) + if (!flags.b.left_shift_host) usb_kbd_send_code(0xAA); /* !LSHIFT */ - if(!flags.b.right_shift_host) + if (!flags.b.right_shift_host) usb_kbd_send_code(0xB6); /* !RSHIFT */ } - if((atari_modifier & (1 << 1)) == 0) + if ((atari_modifier & (1 << 1)) == 0) { - if(flags.b.alt_host) + if (flags.b.alt_host) usb_kbd_send_code(0x38); /* ALT */ } else { - if(!flags.b.alt_host) + if (!flags.b.alt_host) usb_kbd_send_code(0xB8); /* !ALT */ } } #ifdef CONFIG_USB_INTERRUPT_POLLING asm_set_ipl(level); #endif - if(pressed == 1) + if (pressed == 1) { - if(scancode == NUM_LOCK) + if (scancode == NUM_LOCK) { num_lock = ~num_lock; return 1; } - if(scancode == CAPS_LOCK) + if (scancode == CAPS_LOCK) { caps_lock = ~caps_lock; return 1; } - if(scancode == SCROLL_LOCK) + if (scancode == SCROLL_LOCK) { scroll_lock = ~scroll_lock; return 1; @@ -897,47 +891,55 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int /* Interrupt service routine */ static int usb_kbd_irq(struct usb_device *dev) { - int i,res; - if((dev->irq_status != 0) || (dev->irq_act_len != 8)) + int i, res; + if ((dev->irq_status != 0) || (dev->irq_act_len != 8)) { USB_KBD_PRINTF("USB KBD error %lX, len %d\r\n",dev->irq_status,dev->irq_act_len); return 1; } res = 0; - for(i = 2; i < 8; i++) + for (i = 2; i < 8; i++) { - if(old[i] > 3 && memscan(&new[2], old[i], 6) == &new[8]) + if (old[i] > 3 && memscan(&new[2], old[i], 6) == &new[8]) { res |= usb_kbd_translate(old[i], new[0], 0); old[0] = new[0]; } - if(new[i] > 3 && memscan(&old[2], new[i], 6) == &old[8]) + if (new[i] > 3 && memscan(&old[2], new[i], 6) == &old[8]) { res |= usb_kbd_translate(new[i], new[0], 1); old[0] = new[0]; } } - if(new[0] != old[0]) /* modifier change */ + if (new[0] != old[0]) /* modifier change */ { unsigned char modifier_change = new[0] ^ old[0]; - if(modifier_change & (1 << LEFT_CNTR)) - res |= usb_kbd_translate(0x88, new[0], (new[0] & (1 << LEFT_CNTR)) ? 1 : 0); - if(modifier_change & (1 << LEFT_SHIFT)) - res |= usb_kbd_translate(0x89, new[0], (new[0] & (1 << LEFT_SHIFT)) ? 1 : 0); - if(modifier_change & (1 << LEFT_ALT)) - res |= usb_kbd_translate(0x8A, new[0], (new[0] & (1 << LEFT_ALT)) ? 1 : 0); - if(modifier_change & (1 << LEFT_GUI)) - res |= usb_kbd_translate(0x8B, new[0], (new[0] & (1 << LEFT_GUI)) ? 1 : 0); - if(modifier_change & (1 << RIGHT_CNTR)) - res |= usb_kbd_translate(0x8C, new[0], (new[0] & (1 << RIGHT_CNTR)) ? 1 : 0); - if(modifier_change & (1 << RIGHT_SHIFT)) - res |= usb_kbd_translate(0x8D, new[0], (new[0] & (1 << RIGHT_SHIFT)) ? 1 : 0); - if(modifier_change & (1 << RIGHT_ALT)) - res |= usb_kbd_translate(0x8E, new[0], (new[0] & (1 << RIGHT_ALT)) ? 1 : 0); - if(modifier_change & (1 << RIGHT_GUI)) - res |= usb_kbd_translate(0x8F, new[0], (new[0] & (1 << RIGHT_GUI)) ? 1 : 0); + if (modifier_change & (1 << LEFT_CNTR)) + res |= usb_kbd_translate(0x88, new[0], + (new[0] & (1 << LEFT_CNTR)) ? 1 : 0); + if (modifier_change & (1 << LEFT_SHIFT)) + res |= usb_kbd_translate(0x89, new[0], + (new[0] & (1 << LEFT_SHIFT)) ? 1 : 0); + if (modifier_change & (1 << LEFT_ALT)) + res |= usb_kbd_translate(0x8A, new[0], + (new[0] & (1 << LEFT_ALT)) ? 1 : 0); + if (modifier_change & (1 << LEFT_GUI)) + res |= usb_kbd_translate(0x8B, new[0], + (new[0] & (1 << LEFT_GUI)) ? 1 : 0); + if (modifier_change & (1 << RIGHT_CNTR)) + res |= usb_kbd_translate(0x8C, new[0], + (new[0] & (1 << RIGHT_CNTR)) ? 1 : 0); + if (modifier_change & (1 << RIGHT_SHIFT)) + res |= usb_kbd_translate(0x8D, new[0], + (new[0] & (1 << RIGHT_SHIFT)) ? 1 : 0); + if (modifier_change & (1 << RIGHT_ALT)) + res |= usb_kbd_translate(0x8E, new[0], + (new[0] & (1 << RIGHT_ALT)) ? 1 : 0); + if (modifier_change & (1 << RIGHT_GUI)) + res |= usb_kbd_translate(0x8F, new[0], + (new[0] & (1 << RIGHT_GUI)) ? 1 : 0); } - if(res == 1) + if (res == 1) usb_kbd_setled(dev); memcpy(&old[0], &new[0], 8); return 1; /* install IRQ Handler again */ @@ -948,38 +950,37 @@ 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; - if(dev->descriptor.bNumConfigurations != 1) + int pipe, maxp; + if (dev->descriptor.bNumConfigurations != 1) return 0; iface = &dev->config.if_desc[ifnum]; - if(iface->bInterfaceClass != 3) + if (iface->bInterfaceClass != 3) return 0; - if(iface->bInterfaceSubClass != 1) + if (iface->bInterfaceSubClass != 1) return 0; - if(iface->bInterfaceProtocol != 1) + if (iface->bInterfaceProtocol != 1) return 0; - if(iface->bNumEndpoints != 1) + if (iface->bNumEndpoints != 1) return 0; ep = &iface->ep_desc[0]; - if(!(ep->bEndpointAddress & 0x80)) + if (!(ep->bEndpointAddress & 0x80)) return 0; - if((ep->bmAttributes & 3) != 3) + if ((ep->bmAttributes & 3) != 3) return 0; - leds = (unsigned char *)usb_malloc(8); - if(leds == NULL) + leds = (unsigned char *) usb_malloc(8); + if (leds == NULL ) return 0; - new = (unsigned char *)usb_malloc(8); - if(new == NULL) + new = (unsigned char *) usb_malloc(8); + if (new == NULL ) { usb_free(leds); new = NULL; return 0; - } - USB_KBD_PRINTF("USB KBD found set protocol...\r\n"); + } USB_KBD_PRINTF("USB KBD found set protocol...\r\n"); /* ok, we found a USB Keyboard, install it */ #ifdef USE_COUNTRYCODE if(usb_kbd_get_hid_desc(dev) < 0) - usb_kbd_hid_desc.bCountryCode = CC_NOT; + usb_kbd_hid_desc.bCountryCode = CC_NOT; #endif usb_set_protocol(dev, iface->bInterfaceNumber, 0); USB_KBD_PRINTF("USB KBD found set idle...\r\n"); @@ -1002,20 +1003,22 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) * into the data area. */ -struct hid_item { +struct hid_item +{ unsigned char format; unsigned char size; unsigned char type; unsigned char tag; - union { - unsigned char u_8; - char s_8; - unsigned short u_16; - short s_16; - unsigned long u_32; - long s_32; - unsigned char *longdata; - } data; + union + { + unsigned char u_8; + char s_8; + unsigned short u_16; + short s_16; + unsigned long u_32; + long s_32; + unsigned char *longdata; + }data; }; /* HID report item format */ @@ -1049,14 +1052,14 @@ static int fetch_item(unsigned char *start, unsigned char *end, struct hid_item { 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; @@ -1072,29 +1075,29 @@ static int fetch_item(unsigned char *start, unsigned char *end, struct hid_item switch(item->size) { case 0: - return item->size; + return item->size; case 1: - if((end - start) >= 1) - { - item->data.u_8 = *start++; - return item->size; - } - break; + if((end - start) >= 1) + { + item->data.u_8 = *start++; + return item->size; + } + break; case 2: - if((end - start) >= 2) - { - item->data.u_16 = le16_to_cpu(*(unsigned short *)start); - start+=2; - return item->size; - } + if((end - start) >= 2) + { + item->data.u_16 = le16_to_cpu(*(unsigned short *)start); + start+=2; + return item->size; + } case 3: - item->size++; - if((end - start) >= 4) - { - item->data.u_32 = le32_to_cpu(*(unsigned long *)start); - start+=4; - return item->size; - } + item->size++; + if((end - start) >= 4) + { + item->data.u_32 = le32_to_cpu(*(unsigned long *)start); + start+=4; + return item->size; + } } } } @@ -1179,53 +1182,53 @@ static void usb_kbd_show_item(struct hid_item *item) switch(item->type) { case HID_ITEM_TYPE_MAIN: - switch(item->tag) - { - case HID_MAIN_ITEM_TAG_INPUT: board_printf("Main Input"); break; - case HID_MAIN_ITEM_TAG_OUTPUT: board_printf("Main Output"); break; - case HID_MAIN_ITEM_TAG_FEATURE: board_printf("Main Feature"); break; - case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: board_printf("Main Begin Collection"); break; - case HID_MAIN_ITEM_TAG_END_COLLECTION: board_printf("Main End Collection"); break; - default: board_printf("Main reserved %d",item->tag); break; - } - break; + switch(item->tag) + { + case HID_MAIN_ITEM_TAG_INPUT: board_printf("Main Input"); break; + case HID_MAIN_ITEM_TAG_OUTPUT: board_printf("Main Output"); break; + case HID_MAIN_ITEM_TAG_FEATURE: board_printf("Main Feature"); break; + case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: board_printf("Main Begin Collection"); break; + case HID_MAIN_ITEM_TAG_END_COLLECTION: board_printf("Main End Collection"); break; + default: board_printf("Main reserved %d",item->tag); break; + } + break; case HID_ITEM_TYPE_GLOBAL: - switch(item->tag) - { - case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: board_printf("- Global Usage Page"); break; - case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: board_printf("- Global Logical Minimum"); break; - case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: board_printf("- Global Logical Maximum"); break; - case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: board_printf("- Global physical Minimum"); break; - case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: board_printf("- Global physical Maximum"); break; - case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: board_printf("- Global Unit Exponent"); break; - case HID_GLOBAL_ITEM_TAG_UNIT: board_printf("- Global Unit"); break; - case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: board_printf("- Global Report Size"); break; - case HID_GLOBAL_ITEM_TAG_REPORT_ID: board_printf("- Global Report ID"); break; - case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: board_printf("- Global Report Count"); break; - case HID_GLOBAL_ITEM_TAG_PUSH: board_printf("- Global Push"); break; - case HID_GLOBAL_ITEM_TAG_POP: board_printf("- Global Pop"); break; - default: board_printf("- Global reserved %d",item->tag); break; - } - break; + switch(item->tag) + { + case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: board_printf("- Global Usage Page"); break; + case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: board_printf("- Global Logical Minimum"); break; + case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: board_printf("- Global Logical Maximum"); break; + case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: board_printf("- Global physical Minimum"); break; + case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: board_printf("- Global physical Maximum"); break; + case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: board_printf("- Global Unit Exponent"); break; + case HID_GLOBAL_ITEM_TAG_UNIT: board_printf("- Global Unit"); break; + case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: board_printf("- Global Report Size"); break; + case HID_GLOBAL_ITEM_TAG_REPORT_ID: board_printf("- Global Report ID"); break; + case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: board_printf("- Global Report Count"); break; + case HID_GLOBAL_ITEM_TAG_PUSH: board_printf("- Global Push"); break; + case HID_GLOBAL_ITEM_TAG_POP: board_printf("- Global Pop"); break; + default: board_printf("- Global reserved %d",item->tag); break; + } + break; case HID_ITEM_TYPE_LOCAL: - switch(item->tag) - { - case HID_LOCAL_ITEM_TAG_USAGE: board_printf("-- Local Usage"); break; - case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: board_printf("-- Local Usage Minimum"); break; - case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: board_printf("-- Local Usage Maximum"); break; - case HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX: board_printf("-- Local Designator Index"); break; - case HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM: board_printf("-- Local Designator Minimum"); break; - case HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM: board_printf("-- Local Designator Maximum"); break; - case HID_LOCAL_ITEM_TAG_STRING_INDEX: board_printf("-- Local String Index"); break; - case HID_LOCAL_ITEM_TAG_STRING_MINIMUM: board_printf("-- Local String Minimum"); break; - case HID_LOCAL_ITEM_TAG_STRING_MAXIMUM: board_printf("-- Local String Maximum"); break; - case HID_LOCAL_ITEM_TAG_DELIMITER: board_printf("-- Local Delimiter"); break; - default: board_printf("-- Local reserved %d",item->tag); break; - } - break; + switch(item->tag) + { + case HID_LOCAL_ITEM_TAG_USAGE: board_printf("-- Local Usage"); break; + case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: board_printf("-- Local Usage Minimum"); break; + case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: board_printf("-- Local Usage Maximum"); break; + case HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX: board_printf("-- Local Designator Index"); break; + case HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM: board_printf("-- Local Designator Minimum"); break; + case HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM: board_printf("-- Local Designator Maximum"); break; + case HID_LOCAL_ITEM_TAG_STRING_INDEX: board_printf("-- Local String Index"); break; + case HID_LOCAL_ITEM_TAG_STRING_MINIMUM: board_printf("-- Local String Minimum"); break; + case HID_LOCAL_ITEM_TAG_STRING_MAXIMUM: board_printf("-- Local String Maximum"); break; + case HID_LOCAL_ITEM_TAG_DELIMITER: board_printf("-- Local Delimiter"); break; + default: board_printf("-- Local reserved %d",item->tag); break; + } + break; default: - board_printf("--- reserved %d",item->type); - break; + board_printf("--- reserved %d",item->type); + break; } board_printf(" "); switch(item->size) @@ -1250,7 +1253,7 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev) struct hid_item item; #endif if(buffer == NULL) - return -1; + return -1; if(usb_get_configuration_no(dev, &buffer[0], 0) == -1) { usb_free(buffer); @@ -1308,7 +1311,7 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev) i += index; i++; if(index >= 0) - usb_kbd_show_item(&item); + usb_kbd_show_item(&item); start += index; start++; } @@ -1321,8 +1324,8 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev) #endif /* USE_COUNTRYCODE */ /* - usb_get_report(dev, 0, 0, 1, &new[0], 8); -*/ + usb_get_report(dev, 0, 0, 1, &new[0], 8); + */ #endif /* CONFIG_USB_KEYBOARD */ #endif /* CONFIG_USB_UHCI || CONFIG_USB_OHCI || CONFIG_USB_EHCI */ diff --git a/sources/usb_mem.c b/sources/usb_mem.c index 4431b39..febd1a8 100644 --- a/sources/usb_mem.c +++ b/sources/usb_mem.c @@ -12,8 +12,6 @@ */ #include "config.h" -#include -#include #include #include "usb.h" @@ -182,6 +180,8 @@ static void freeit(MD *m, MPB *mp) } } +#define EFAULT -40 + int usb_free(void *addr) { int level;