//#define USB_DEBUG
+#include <arch/virtual.h>
#include <usb/usb.h>
#include "uhci.h"
-#include <arch/virtual.h>
+#include "uhci_private.h"
static void uhci_start (hci_t *controller);
static void uhci_stop (hci_t *controller);
static void uhci_reset (hci_t *controller);
static void uhci_shutdown (hci_t *controller);
static int uhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize);
-static int uhci_control (usbdev_t *dev, pid_t dir, int drlen, void *devreq,
+static int uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq,
int dalen, u8 *data);
static void* uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming);
static void uhci_destroy_intr_queue (endpoint_t *ep, void *queue);
static void
uhci_dump (hci_t *controller)
{
- printf ("dump:\nUSBCMD: %x\n", uhci_reg_read16 (controller, USBCMD));
- printf ("USBSTS: %x\n", uhci_reg_read16 (controller, USBSTS));
- printf ("USBINTR: %x\n", uhci_reg_read16 (controller, USBINTR));
- printf ("FRNUM: %x\n", uhci_reg_read16 (controller, FRNUM));
- printf ("FLBASEADD: %x\n", uhci_reg_read32 (controller, FLBASEADD));
- printf ("SOFMOD: %x\n", uhci_reg_read8 (controller, SOFMOD));
- printf ("PORTSC1: %x\n", uhci_reg_read16 (controller, PORTSC1));
- printf ("PORTSC2: %x\n", uhci_reg_read16 (controller, PORTSC2));
+ debug ("dump:\nUSBCMD: %x\n", uhci_reg_read16 (controller, USBCMD));
+ debug ("USBSTS: %x\n", uhci_reg_read16 (controller, USBSTS));
+ debug ("USBINTR: %x\n", uhci_reg_read16 (controller, USBINTR));
+ debug ("FRNUM: %x\n", uhci_reg_read16 (controller, FRNUM));
+ debug ("FLBASEADD: %x\n", uhci_reg_read32 (controller, FLBASEADD));
+ debug ("SOFMOD: %x\n", uhci_reg_read8 (controller, SOFMOD));
+ debug ("PORTSC1: %x\n", uhci_reg_read16 (controller, PORTSC1));
+ debug ("PORTSC2: %x\n", uhci_reg_read16 (controller, PORTSC2));
}
#endif
td_dump (td_t *td)
{
char td_value[3];
- char *td_type;
+ const char *td_type;
switch (td->pid) {
- case SETUP:
+ case UHCI_SETUP:
td_type="SETUP";
break;
- case IN:
+ case UHCI_IN:
td_type="IN";
break;
- case OUT:
+ case UHCI_OUT:
td_type="OUT";
break;
default:
sprintf(td_value, "%x", td->pid);
td_type=td_value;
}
- printf ("%s packet (at %lx) to %x.%x failed\n", td_type,
+ debug ("%s packet (at %lx) to %x.%x failed\n", td_type,
virt_to_phys (td), td->dev_addr, td->endp);
- printf ("td (counter at %x) returns: ", td->counter);
- printf (" bitstuff err: %x, ", td->status_bitstuff_err);
- printf (" CRC err: %x, ", td->status_crc_err);
- printf (" NAK rcvd: %x, ", td->status_nakrcvd);
- printf (" Babble: %x, ", td->status_babble);
- printf (" Data Buffer err: %x, ", td->status_databuf_err);
- printf (" Stalled: %x, ", td->status_stalled);
- printf (" Active: %x\n", td->status_active);
+ debug ("td (counter at %x) returns: ", td->counter);
+ debug (" bitstuff err: %x, ", td->status_bitstuff_err);
+ debug (" CRC err: %x, ", td->status_crc_err);
+ debug (" NAK rcvd: %x, ", td->status_nakrcvd);
+ debug (" Babble: %x, ", td->status_babble);
+ debug (" Data Buffer err: %x, ", td->status_databuf_err);
+ debug (" Stalled: %x, ", td->status_stalled);
+ debug (" Active: %x\n", td->status_active);
if (td->status_babble)
- printf (" Babble because of %s\n",
+ debug (" Babble because of %s\n",
td->status_bitstuff_err ? "host" : "device");
if (td->status_active)
- printf (" still active - timeout?\n");
+ debug (" still active - timeout?\n");
}
static void
uhci_reg_write32 (controller, FLBASEADD,
(u32) virt_to_phys (UHCI_INST (controller)->
framelistptr));
- //printf ("framelist at %p\n",UHCI_INST(controller)->framelistptr);
+ //debug ("framelist at %p\n",UHCI_INST(controller)->framelistptr);
/* disable irqs */
uhci_reg_write16 (controller, USBINTR, 0);
/* reset framelist index */
uhci_reg_write16 (controller, FRNUM, 0);
- uhci_reg_mask16 (controller, USBCMD, ~0, 0xc0); // max packets, configure flag
+ uhci_reg_write16(controller, USBCMD,
+ uhci_reg_read16(controller, USBCMD) | 0xc0); // max packets, configure flag
uhci_start (controller);
}
hci_t *controller = new_controller ();
if (!controller)
- usb_fatal("Could not create USB controller instance.\n");
+ fatal("Could not create USB controller instance.\n");
controller->instance = malloc (sizeof (uhci_t));
if(!controller->instance)
- usb_fatal("Not enough memory creating USB controller instance.\n");
+ fatal("Not enough memory creating USB controller instance.\n");
controller->start = uhci_start;
controller->stop = uhci_stop;
UHCI_INST (controller)->framelistptr = memalign (0x1000, 1024 * sizeof (flistp_t *)); /* 4kb aligned to 4kb */
if (! UHCI_INST (controller)->framelistptr)
- usb_fatal("Not enough memory for USB frame list pointer.\n");
+ fatal("Not enough memory for USB frame list pointer.\n");
memset (UHCI_INST (controller)->framelistptr, 0,
1024 * sizeof (flistp_t));
*/
td_t *antiberserk = memalign(16, sizeof(td_t));
if (!antiberserk)
- usb_fatal("Not enough memory for chipset workaround.\n");
+ fatal("Not enough memory for chipset workaround.\n");
memset(antiberserk, 0, sizeof(td_t));
UHCI_INST (controller)->qh_prei = memalign (16, sizeof (qh_t));
! UHCI_INST (controller)->qh_intr ||
! UHCI_INST (controller)->qh_data ||
! UHCI_INST (controller)->qh_last)
- usb_fatal ("Not enough memory for USB controller queues.\n");
+ fatal("Not enough memory for USB controller queues.\n");
UHCI_INST (controller)->qh_prei->headlinkptr.ptr =
virt_to_phys (UHCI_INST (controller)->qh_intr);
detach_controller (controller);
UHCI_INST (controller)->roothub->destroy (UHCI_INST (controller)->
roothub);
- uhci_reg_mask16 (controller, USBCMD, 0, 0); // stop work
+ uhci_reg_write16(controller, USBCMD,
+ uhci_reg_read16(controller, USBCMD) & 0); // stop work
free (UHCI_INST (controller)->framelistptr);
free (UHCI_INST (controller)->qh_prei);
free (UHCI_INST (controller)->qh_intr);
static void
uhci_start (hci_t *controller)
{
- uhci_reg_mask16 (controller, USBCMD, ~0, 1); // start work on schedule
+ uhci_reg_write16(controller, USBCMD,
+ uhci_reg_read16(controller, USBCMD) | 1); // start work on schedule
}
static void
uhci_stop (hci_t *controller)
{
- uhci_reg_mask16 (controller, USBCMD, ~1, 0); // stop work on schedule
+ uhci_reg_write16(controller, USBCMD,
+ uhci_reg_read16(controller, USBCMD) & ~1); // stop work on schedule
}
#define GET_TD(x) ((void*)(((unsigned int)(x))&~0xf))
current = GET_TD (qh->elementlinkptr.ptr);
timeout = 1000000;
}
- uhci_reg_mask16 (controller, USBSTS, ~0, 0); // clear resettable registers
+ uhci_reg_write16(controller, USBSTS,
+ uhci_reg_read16(controller, USBSTS) | 0); // clear resettable registers
udelay (30);
}
return (GET_TD (qh->elementlinkptr.ptr) ==
}
static int
-uhci_control (usbdev_t *dev, pid_t dir, int drlen, void *devreq, int dalen,
+uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen,
unsigned char *data)
{
int endp = 0; /* this is control: always 0 */
tds[count].depth_first = 1;
tds[count].terminate = 1;
- tds[0].pid = SETUP;
+ tds[0].pid = UHCI_SETUP;
tds[0].dev_addr = dev->address;
tds[0].endp = endp;
tds[0].maxlen = maxlen (drlen);
int toggle = 1;
for (i = 1; i < count; i++) {
- tds[i].pid = dir;
+ switch (dir) {
+ case SETUP: tds[i].pid = UHCI_SETUP; break;
+ case IN: tds[i].pid = UHCI_IN; break;
+ case OUT: tds[i].pid = UHCI_OUT; break;
+ }
tds[i].dev_addr = dev->address;
tds[i].endp = endp;
tds[i].maxlen = maxlen (min (mlen, dalen));
data += mlen;
}
- tds[count].pid = (dir == OUT) ? IN : OUT;
+ tds[count].pid = (dir == OUT) ? UHCI_IN : UHCI_OUT;
tds[count].dev_addr = dev->address;
tds[count].endp = endp;
tds[count].maxlen = maxlen (0);
if (td == 0) {
result = 0;
} else {
- printf ("control packet, req %x\n", req);
+ debug ("control packet, req %x\n", req);
td_dump (td);
result = 1;
}
fill_schedule (td_t *td, endpoint_t *ep, int length, unsigned char *data,
int *toggle)
{
- td->pid = ep->direction;
+ switch (ep->direction) {
+ case IN: td->pid = UHCI_IN; break;
+ case OUT: td->pid = UHCI_OUT; break;
+ case SETUP: td->pid = UHCI_SETUP; break;
+ }
td->dev_addr = ep->dev->address;
td->endp = ep->endpoint & 0xf;
td->maxlen = maxlen (length);
{
int maxpsize = ep->maxpacketsize;
if (maxpsize == 0)
- usb_fatal ("MaxPacketSize == 0!!!");
+ fatal("MaxPacketSize == 0!!!");
int numpackets = (size + maxpsize - 1 + finalize) / maxpsize;
if (numpackets == 0)
return 0;
qh_t *qh = memalign(16, sizeof(qh_t));
if (!data || !tds || !qh)
- usb_fatal ("Not enough memory to create USB intr queue prerequisites.\n");
+ fatal("Not enough memory to create USB intr queue prerequisites.\n");
qh->elementlinkptr.ptr = virt_to_phys(tds);
qh->elementlinkptr.queue_head = 0;
intr_q *q = malloc(sizeof(intr_q));
if (!q)
- usb_fatal ("Not enough memory to create USB intr queue.\n");
+ fatal("Not enough memory to create USB intr queue.\n");
q->qh = qh;
q->tds = tds;
q->data = data;
tds[i].queue_head = 0;
tds[i].depth_first = 0;
- tds[i].pid = ep->direction;
+ switch (ep->direction) {
+ case IN: tds[i].pid = UHCI_IN; break;
+ case OUT: tds[i].pid = UHCI_OUT; break;
+ case SETUP: tds[i].pid = UHCI_SETUP; break;
+ }
tds[i].dev_addr = ep->dev->address;
tds[i].endp = ep->endpoint & 0xf;
tds[i].maxlen = maxlen (reqsize);
{
return inb (ctrl->reg_base + reg);
}
-
-void
-uhci_reg_mask32 (hci_t *ctrl, usbreg reg, u32 andmask, u32 ormask)
-{
- uhci_reg_write32 (ctrl, reg,
- (uhci_reg_read32 (ctrl, reg) & andmask) | ormask);
-}
-
-void
-uhci_reg_mask16 (hci_t *ctrl, usbreg reg, u16 andmask, u16 ormask)
-{
- uhci_reg_write16 (ctrl, reg,
- (uhci_reg_read16 (ctrl, reg) & andmask) | ormask);
-}
-
-void
-uhci_reg_mask8 (hci_t *ctrl, usbreg reg, u8 andmask, u8 ormask)
-{
- uhci_reg_write8 (ctrl, reg,
- (uhci_reg_read8 (ctrl, reg) & andmask) | ormask);
-}