libpayload: remove uhci_reg_maskX
[coreboot.git] / payloads / libpayload / drivers / usb / uhci.c
index 1f80c6a3c699486be2f4d562007515eaccced2d7..b964ee7a0b168245ce4ea2830ef27de981de8c42 100644 (file)
@@ -50,14 +50,14 @@ static u8* uhci_poll_intr_queue (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
 
@@ -80,21 +80,21 @@ td_dump (td_t *td)
                        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
@@ -112,7 +112,7 @@ uhci_reset (hci_t *controller)
        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);
@@ -120,7 +120,8 @@ uhci_reset (hci_t *controller)
        /* 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);
 }
@@ -134,11 +135,11 @@ uhci_init (pcidev_t addr)
        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;
@@ -168,7 +169,7 @@ uhci_init (pcidev_t addr)
 
        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));
@@ -182,7 +183,7 @@ uhci_init (pcidev_t addr)
           */
        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));
@@ -194,7 +195,7 @@ uhci_init (pcidev_t addr)
            ! 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);
@@ -240,7 +241,8 @@ uhci_shutdown (hci_t *controller)
        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);
@@ -253,13 +255,15 @@ uhci_shutdown (hci_t *controller)
 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))
@@ -274,7 +278,8 @@ wait_for_completed_qh (hci_t *controller, qh_t *qh)
                        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) ==
@@ -367,7 +372,7 @@ uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen
        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;
        }
@@ -443,7 +448,7 @@ uhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize)
 {
        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;
@@ -486,7 +491,7 @@ uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming
        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;
@@ -494,7 +499,7 @@ uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming
 
        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;
@@ -636,24 +641,3 @@ uhci_reg_read8 (hci_t *ctrl, usbreg reg)
 {
        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);
-}