/**   i2c_tests_npa56x4.c
 **
 **   This module includes all the low-level i2c tests for the TNPA-56x4
 ** AMC card.
 **
 ** Created by Ted Schmitz, June 12, 2008
 **
 **/
#include <common.h>

#include "diag_mon/errcodes.h"
#include "ll_bist.h"
#include "diag_mon/ascii_functions.h"
#include "ll_post_types.h"
#include "ll_post_utils.h"
#include "io_drivers_npa_56x4.h"

/*****************************************************************************
 **                        I2c Acknowledge Test
 **
 **   This function verifies all i2c devices on the unit are capable of 
 ** responding to a select.
 **
 ** INPUT - Nothing
 **
 ** OUTPUT - Nothing
 **
 ** RETURN - Nothing
 **
 ****************************************************************************/
void i2c_dev_ack_test(void)
{
  unsigned char buf[10];        /* scratch buf for reading i2c devs */
  int results;                  /* results of various sys calls */
  struct errhand_info eh;       /* err info structure */

  /* Read one byte of data from the Maxim temperature sensor */
  results = bist_read_i2c_device(buf, TEMP_SENSOR_I2C_ADRS, 0, 1, 
                                 ENABLE_ERROR_MSGS);

  /* report an error if temp sensor did not respond */
  if (results == PROBLEM_DETECTED)
    {
      eh.call_type = EH_ERR_CODE_FRU;
      eh.error_stop = ES0250;
      eh.sup_error_stop = SES0000;
      eh.severity = SLEVEL_FATAL;
      eh.data_exp[0] = (u64) 0;
      eh.data_rec[0] = (u64) 0;
      eh.fail_adrs = TEMP_SENSOR_I2C_ADRS;
      eh.disp_size = DISP_SIZE_2B;
      eh.void_ptr = 0;
      eh.fru_list[0] = mb;
      eh.fru_list[1] = 0xFF;

      /* report the error to the BIST system */
      error_handler(&eh);
      return;

    }

  /* Read one byte of data from the SEEPROM */
  results = bist_read_i2c_device(buf, SEEPROM_I2C_ADRS, 0, 1, 
                                 ENABLE_ERROR_MSGS);

  /* report an error if SEEPROM did not respond */
  if (results == PROBLEM_DETECTED)
    {
      eh.call_type = EH_ERR_CODE_FRU;
      eh.error_stop = ES0260;
      eh.sup_error_stop = SES0000;
      eh.severity = SLEVEL_FATAL;
      eh.data_exp[0] = (u64) 0;
      eh.data_rec[0] = (u64) 0;
      eh.fail_adrs = SEEPROM_I2C_ADRS;
      eh.disp_size = DISP_SIZE_2B;
      eh.void_ptr = 0;
      eh.fru_list[0] = mb;
      eh.fru_list[1] = 0xFF;

      /* report the error to the BIST system */
      error_handler(&eh);
      return;
    }

}

/*****************************************************************************
 **                        I2c Device Detect
 **
 **   This prints all the i2c addresses that respond to a select.
 **
 ** NOTE:  This function actually did find all the i2c devices on the
 **        TNPA-5644 amc card.
 **
 ** INPUT - Nothing
 **
 ** OUTPUT - Nothing
 **
 ** RETURN - Nothing
 **
 ****************************************************************************/
void i2c_dev_detect(void)
{
  unsigned char buf[10];
  unsigned char i;
  int results;

  printf("\ni2c addresses that respond to a select...\n");

  for (i = 0; i < 0xFE; i+=2)
    {
    results = bist_read_i2c_device(buf, i, 0, 1, DISABLE_ERROR_MSGS);
    if (results == NO_PROBLEM_DETECTED)
      printf("%02X\n",i);
    }

  printf("...Done\n");

}



