/*
 *               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.
 *
 */
/* Initialization of USB PHY per ATI's recommendations. */
#include <types.h>
#include <iop.h>
#include <ioslibc.h>
#include <sys.h>
#include "sys_int.h"

#define IREF_91 2 /* 91% */
#define IREF_95 3 /* 95% */
#define IREF_100 4 /* 100% */
#define IREF_105 5 /* 105% */

#define USB_CMN_PHY_DEFAULT 0x2014
#define IREF_SETTING(iref_val, discondet_val) \
    ((USB_CMN_PHY_DEFAULT) | ((iref_val & IREF_MASK)<< IREF_SHIFT) \
             | (((discondet_val & DISCONDET_MASK) << DISCONDET_SHIFT)))
#define CAL_SETTING(iref_val) \
    (0x20000| (((5*(iref_val & IREF_MASK) - 4) & CAL_MASK) << CAL_SHIFT))

typedef struct {
    u8 iref;
    u8 ddet;
} PHYConfig;

static PHYConfig __phyConfigs[] = {
      { IREF_91, 0 }  /* chipid_major = 0 - Hollywood ES 1.x */
    , { IREF_100, 0 }  /* chipid_major = 1 - Hollywood ES 2.x */
    , { IREF_105, 0xf }  /* chipid_major >=2 - Bollywood */
};

void
init_USBPHY(u32 chipid_major)
{
    u32 ctrlVal, calVal;
    u32 idxmax = sizeof(__phyConfigs)/sizeof(PHYConfig) - 1;

    chipid_major = (chipid_major > idxmax)? idxmax : chipid_major;
    ctrlVal = IREF_SETTING(__phyConfigs[chipid_major].iref,
                           __phyConfigs[chipid_major].ddet);
    calVal = CAL_SETTING(__phyConfigs[chipid_major].iref);
    busWrt32(USB_PHYADJ_CTRL_REG, ctrlVal);
    busWrt32(USB_PHYCMN_CAL_REG, calVal);
}
