/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
/* High/full/low speed bus transaction times (Section 5.11.3 USB Specification Rev 2.0)*/
#include <iostypes.h>
#include <ios.h>
#include <iop.h>
#include <ioslibc.h>

#include "ehci.h"
#include "ehci_regs.h"
#include "ehci_core.h"
#include "usb20.h"
#include "ehci_types.h"

u32 
calcBusTransTime_ns(u32 speed, u32 dir, u32 type, u32 bytes)
{
  u32 rv = 0;
  switch (speed) {
      case EHCI_SPD_HI:
          if (USB20_ENDPT_ATTR_ISO == type) {
              rv = 2083L*(38*8*1000 + 3167 + 8L*7*bytes*1000/6)/1000000L
                  + HOST_DELAY;
          } else {
              rv = 2083L*(55*8*1000 + 3167 + 8L*7*bytes*1000/6)/1000000L
                  + HOST_DELAY;
          }
          goto done;
      case EHCI_SPD_FULL:
          rv = 8354L *(3167L + 8L*7*bytes*1000/6)/100000L + HOST_DELAY;
          if (USB20_ENDPT_ATTR_ISO == type) {
              rv += (QTD_TOKEN_PID_IN == dir)? 7268L: 6265L;
          } else {
              rv += 9107L;
          }
          goto done;
      case EHCI_SPD_LOW:
          rv = (QTD_TOKEN_PID_IN == dir)? 64060L: 64107L 
                 + 2 *HUB_LS_SETUP 
                 + ((QTD_TOKEN_PID_IN == dir)? 
                         67667L:66700L) * (3167L + 8L*7*bytes*1000/6)/100000L
                 + HOST_DELAY;
          goto done;
  }
done:
  return rv; /* us */
}
