/******************************************************************************/
/*                       Copyright 2001 Broadcom Corporation                  */
/*                                                                            */
/* This material is the confidential trade secret and proprietary information */
/* of Broadcom Corp.  It may not be reproduced, used, sold or transferred to  */
/* any third party without the prior written consent of Broadcom Corp.        */
/* All rights reserved.                                                       */
/******************************************************************************/
/*   FileName        : bcm_transfer.c                                         */
/*   Purpose         : Basic memory map implementation for transfer layer     */
/*   Limitations     : None                                                   */
/*   Author          : Emmanuel Hanssens                                      */
/*   Creation Date   : 26-Nov-2001                                            */
/*   History         : Compiled by CVS                                        */
/******************************************************************************/
/*   $Id: bcm_transfer.c,v 1.15 2004/11/18 15:34:04 hanssens Exp $  */
/******************************************************************************/

#include <stdio.h>
#include "bcm_transfer.h"
#include <FW_lt/FW_lt_api.h> // add by Chein-Chung Lo

/* {{{ transferDriverInit */
void transferDriverInit(void)
{
  /* nothing to do */
}
/* }}} */

/* {{{ transferReq */
void transferReq(uint32 dev_address, access_t access, uint32 address, 
                 uint8 *data, uint32 size) 
{
#ifndef BCM_DONT_USE_MEMCPY_FOR_TRANSFER
//	uint32 i;
	uint8 *mem_addr = (uint8 *) (dev_address + address);
//	printf("dev_address:%x\n", (unsigned int)dev_address);
//	printf("address:%x\n", (unsigned int)address);
//	printf("size:%d \n", (unsigned int)size);

  if (access == BCM_READ)
  {
    //memcpy((void *) data, (void *) mem_addr, size);
//	printf("read\n");
	FW_ReadLT(data, (unsigned int)mem_addr, size);
/*
	if(size < 100)
	{
		for(i = 0; i < size; i++)
		{
			printf("%x ", *(data + i));
		}
		printf("\n\n\n\n");
	}
	else
	{
		for(i = 0; i < 32; i++)
		{
			printf("%x ", *(data + i));
		}
		printf("\n\n\n\n");
	}
*/
  }
  else
  {
    //memcpy((void *) mem_addr, (void *) data, size);
//	printf("write\n");
/*
	if(size < 100)
	{
		for(i = 0; i < size; i++)
		{
			printf("%x ", *(data + i));
		}
		printf("\n\n\n\n");
	}
	else
	{
		for(i = 0; i < 32; i++)
		{
			printf("%x ", *(data + i));
		}
		printf("\n\n\n\n");
	}
*/
	FW_WriteLT(data, (unsigned int)mem_addr, size);

  }
#else
  uint32 i;
  
  if (access == BCM_READ)
    for( i=0 ; i<size ; i++)
      *(data++) = *(mem_addr++);

  else /* access == BCM_WRITE */
    for( i=0 ; i<size ; i++)
      *(mem_addr++) = *(data++);
#endif
}
/* }}} */

/* {{{ transferResetBCM6410 */
void transferResetBCM6410(uint16 devId)
{
  /* provide here customer way to reset the BCM6410 device */  
}
/* }}} */

/* {{{ transferClose */
void transferClose(void)
{
  /* nothing to do */
}
/* }}} */
