removed TOS dependencies with (some shaky) replacements to make everything compile without TOS headers

This commit is contained in:
Markus Fröschle
2013-04-21 05:13:32 +00:00
parent 9b9caf98e4
commit a822d3f8f5
5 changed files with 881 additions and 819 deletions

View File

@@ -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-

View File

@@ -26,10 +26,10 @@
#ifndef _USB_H_
#define _USB_H_
#include <mint/osbind.h>
#include <mint/sysvars.h>
#include <stdlib.h>
#include <string.h>
#include <bas_printf.h>
#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
*/

View File

@@ -72,7 +72,8 @@ extern unsigned long usb_1st_disk_drive;
#define USB_BUFSIZ 512
struct hci {
struct hci
{
/* ------- common part -------- */
long handle; /* PCI BIOS */
const struct pci_device_id *ent;
@@ -101,7 +102,8 @@ 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
@@ -131,7 +133,8 @@ int usb_init(long handle, const struct pci_device_id *ent)
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);
usb_dev = (struct usb_device *) usb_malloc(
sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE);
if (usb_dev == NULL )
{
usb_started = 0;
@@ -155,7 +158,7 @@ int usb_init(long handle, const struct pci_device_id *ent)
}
usb_hub_reset(bus_index);
/* init low_level USB */
Cconws("USB: ");
xprintf("USB: ");
switch (ent->class)
{
#ifdef CONFIG_USB_UHCI
@@ -173,7 +176,9 @@ int usb_init(long handle, const struct pci_device_id *ent)
res = ehci_usb_lowlevel_init(handle, ent, &priv);
break;
#endif
default: res = -1; break;
default:
res = -1;
break;
}
if (!res)
{
@@ -186,7 +191,7 @@ int usb_init(long handle, const struct pci_device_id *ent)
usb_started = 0;
return -1; /* out of memoy */
}
Cconws("Scanning bus for devices... ");
xprintf("Scanning bus for devices... ");
controller_priv[bus_index] = (struct hci *) priv;
controller_priv[bus_index]->usbnum = bus_index;
usb_scan_devices(priv);
@@ -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;
}
@@ -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,7 +311,8 @@ 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)
@@ -338,9 +344,8 @@ 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))
@@ -397,7 +402,8 @@ 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)
@@ -438,7 +444,6 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len,
return -1;
}
/*-------------------------------------------------------------------
* Max Packet stuff
*/
@@ -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;
@@ -527,7 +534,8 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
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]);
@@ -542,12 +550,14 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
switch (head->bDescriptorType)
{
case USB_DT_INTERFACE:
if(((struct usb_interface_descriptor *)&buffer[index])->bInterfaceNumber != curr_if_num)
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]);
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;
@@ -562,8 +572,10 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
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));
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:
@@ -573,8 +585,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
{
ch = (unsigned char *) head;
for (i = 0; i < head->bLength; i++)
USB_PRINTF(" %02X", *ch++);
USB_PRINTF("\r\n");
USB_PRINTF(" %02X", *ch++); USB_PRINTF("\r\n");
}
break;
}
@@ -594,7 +605,8 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
int result;
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)
return result;
@@ -611,18 +623,20 @@ 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;
@@ -632,9 +646,11 @@ int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int
if (result < 9)
{
if (result < 0)
board_printf("unable to get descriptor, error %lX\r\n", dev->status);
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);
@@ -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;
}
@@ -689,8 +706,9 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
*/
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);
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,7 +723,8 @@ 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);
USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0,
USB_CNTL_TIMEOUT);
if (res == 0)
{
dev->toggle[0] = 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,9 +750,9 @@ 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);
}
/********************************************************************
@@ -742,9 +761,9 @@ int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id)
int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
unsigned char id, void *buf, int size)
{
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
USB_REQ_GET_REPORT, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
(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,23 +772,26 @@ 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)
{
/* 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);
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;
}
@@ -792,7 +814,8 @@ static void usb_try_string_workarounds(unsigned char *buf, int *length)
}
}
static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned int index, unsigned char *buf)
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
@@ -899,8 +922,7 @@ void usb_disconnect(struct usb_device **pdev)
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);
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.. */
@@ -934,8 +956,7 @@ struct usb_device *usb_get_dev_index(int index, int index_bus)
|| (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;
}
@@ -956,7 +977,8 @@ struct usb_device *usb_alloc_new_device(int bus_index, void *priv)
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;
@@ -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)
{
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 */
tmp = sizeof(dev->descriptor);
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, sizeof(dev->descriptor));
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor,
sizeof(dev->descriptor));
if (err < tmp)
{
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;
}
@@ -1104,25 +1138,26 @@ int usb_new_device(struct usb_device *dev)
/* we set the default configuration here */
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",
} 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));
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);
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);
@@ -1137,7 +1172,8 @@ void usb_scan_devices(void *priv)
/* first make all devices unknown */
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;
@@ -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)
@@ -1270,7 +1309,8 @@ static inline char *portspeed(int portstatus)
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;
@@ -1291,10 +1331,10 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port
}
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",
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))
if ((portchange & USB_PORT_STAT_C_CONNECTION)
|| !(portstatus & USB_PORT_STAT_CONNECTION))
return -1;
if (portstatus & USB_PORT_STAT_ENABLE)
break;
@@ -1306,8 +1346,7 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port
}
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);
@@ -1349,7 +1388,8 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
/* Reset the port */
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
@@ -1420,7 +1460,9 @@ static void usb_hub_events(struct usb_device *dev)
/* 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);
@@ -1512,8 +1554,7 @@ int usb_hub_configure(struct usb_device *dev)
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]);
} 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;
@@ -1531,7 +1572,8 @@ int usb_hub_configure(struct usb_device *dev)
}
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];
/* devices not removable by default */
@@ -1548,10 +1590,16 @@ int usb_hub_configure(struct usb_device *dev)
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 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 0x03:
USB_HUB_PRINTF("unknown reserved power switching mode\r\n");
break;
}
if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
{
@@ -1563,13 +1611,17 @@ int usb_hub_configure(struct usb_device *dev)
}
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 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);
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" : "");
@@ -1587,9 +1639,7 @@ int usb_hub_configure(struct usb_device *dev)
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 ");
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)

View File

@@ -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
@@ -233,8 +232,7 @@ static unsigned char usb_kbd_to_atari_fr_modifier[] =
//VolUp VolDn
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[] =
{
@@ -273,8 +271,7 @@ static unsigned char usb_kbd_to_atari_fr_unshift[] =
//VolUp VolDn
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[] =
{
@@ -315,8 +312,7 @@ static unsigned char usb_kbd_to_atari_fr_shift[] =
//VolUp VolDn
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[] =
{
@@ -357,8 +353,7 @@ static unsigned char usb_kbd_to_atari_fr_altgr[] =
//VolUp VolDn
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[] =
{
@@ -403,8 +398,7 @@ static unsigned char usb_kbd_to_atari_de_modifier[] =
//VolUp VolDn
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[] =
{
@@ -443,8 +437,7 @@ static unsigned char usb_kbd_to_atari_de_unshift[] =
//VolUp VolDn
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[] =
{
@@ -485,8 +478,7 @@ static unsigned char usb_kbd_to_atari_de_shift[] =
//VolUp VolDn
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[] =
{
@@ -527,8 +519,7 @@ static unsigned char usb_kbd_to_atari_de_altgr[] =
//VolUp VolDn
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)
{
@@ -637,18 +628,19 @@ static void usb_kbd_setled(struct usb_device *dev)
*pleds |= 2;
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)
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
@@ -711,7 +703,8 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int
}
if (modifier != old_modifier)
{
if(((modifier & (1 << LEFT_SHIFT)) != 0) || ((modifier & (1 << RIGHT_SHIFT)) != 0))
if (((modifier & (1 << LEFT_SHIFT)) != 0)
|| ((modifier & (1 << RIGHT_SHIFT)) != 0))
{
if (!flags.b.shift_usb)
{
@@ -764,7 +757,8 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int
{
keycode = altgr_table[scancode];
if ((atari_modifier & (1 << 6)) != 0)
atari_modifier = (atari_modifier >> 4) | (atari_modifier & (1 << 6));
atari_modifier = (atari_modifier >> 4)
| (atari_modifier & (1 << 6));
else
atari_modifier >>= 4;
}
@@ -775,15 +769,15 @@ static int usb_kbd_translate(unsigned char scancode, unsigned char modifier, int
{
keycode = shift_table[scancode];
if ((atari_modifier & (1 << 6)) != 0)
atari_modifier = (atari_modifier >> 2) | (atari_modifier & (1 << 6));
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);
} 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)
@@ -921,21 +915,29 @@ static int usb_kbd_irq(struct usb_device *dev)
{
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);
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);
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);
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);
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);
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);
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);
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);
res |= usb_kbd_translate(0x8F, new[0],
(new[0] & (1 << RIGHT_GUI)) ? 1 : 0);
}
if (res == 1)
usb_kbd_setled(dev);
@@ -974,8 +976,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
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)
@@ -1002,12 +1003,14 @@ 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 {
union
{
unsigned char u_8;
char s_8;
unsigned short u_16;

View File

@@ -12,8 +12,6 @@
*/
#include "config.h"
#include <mint/errno.h>
#include <mint/osbind.h>
#include <string.h>
#include "usb.h"
@@ -182,6 +180,8 @@ static void freeit(MD *m, MPB *mp)
}
}
#define EFAULT -40
int usb_free(void *addr)
{
int level;