XilinxProcessorIPLib/drivers/mipicsiss/examples/xmipi_vck_example/mipi_cfg.c
int SetupCameraSensor(void) {
	int Status;
	u32 Index, MaxIndex;
	SensorIicAddr = SENSOR_ADDR;
	struct regval_list *sensor_cfg = NULL;

	/* If no camera present then return */
	if (Pipeline_Cfg.CameraPresent == FALSE) {
		xil_printf("%s - No camera present\r\n", __func__);
		return XST_SUCCESS;
	}

	/* Validate Pipeline Configuration */
	if ((Pipeline_Cfg.VideoMode == XVIDC_VM_3840x2160_30_P)
			&& (Pipeline_Cfg.ActiveLanes != 4)) {
		xil_printf("4K supports only 4 Lane configuration\r\n");
		return XST_FAILURE;
	}

	if ((Pipeline_Cfg.VideoMode == XVIDC_VM_1920x1080_60_P)
			&& (Pipeline_Cfg.ActiveLanes == 1)) {
		xil_printf("1080p doesn't support 1 Lane configuration\r\n");
		return XST_FAILURE;
	}

	Status = XIic_SetAddress(&IicSensor, XII_ADDR_TO_SEND_TYPE,
					SensorIicAddr);

	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Select the sensor configuration based on resolution and lane */
	switch (Pipeline_Cfg.VideoMode) {

		case XVIDC_VM_1280x720_60_P:
			MaxIndex = length_imx274_config_720p_60fps_regs;
			sensor_cfg = imx274_config_720p_60fps_regs;
			break;

		case XVIDC_VM_1920x1080_30_P:
			MaxIndex = length_imx274_config_1080p_60fps_regs;
			sensor_cfg = imx274_config_1080p_60fps_regs;
			break;

		case XVIDC_VM_1920x1080_60_P:
			MaxIndex = length_imx274_config_1080p_60fps_regs;
			sensor_cfg = imx274_config_1080p_60fps_regs;
			break;

		case XVIDC_VM_3840x2160_30_P:
			MaxIndex = length_imx274_config_4K_30fps_regs;
			sensor_cfg = imx274_config_4K_30fps_regs;
			break;

		case XVIDC_VM_3840x2160_60_P:
			MaxIndex = length_imx274_config_4K_60fps_regs;
			sensor_cfg = imx274_config_4K_60fps_regs;
			break;


		default:
			return XST_FAILURE;
			break;

	}

	/* Program sensor */
	for (Index = 0; Index < (MaxIndex - 0); Index++) {

		WriteBuffer[0] = sensor_cfg[Index].Address >> 8;
		WriteBuffer[1] = sensor_cfg[Index].Address;
		WriteBuffer[2] = sensor_cfg[Index].Data;
		Status = SensorWriteData(3);
		if (Status == XST_SUCCESS) {
			ReadBuffer[0] = 0;
			Status = SensorReadData(ReadBuffer, 1);
			if(WriteBuffer[2] != ReadBuffer[0])
			 xil_printf("index %d Ref %d Read %d\n",Index,WriteBuffer[2],ReadBuffer[0]);
			usleep(100);

		} else {
			xil_printf("Error in Writing entry status = %x \r\n",
					Status);
			break;
		}
	}
	if (Index != (MaxIndex - 0)) {
		/* all registers are written into */
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 * This function setup Camera sensor programming wrt resolution selected
 *
 * @return	XST_SUCCESS if successful else XST_FAILURE.
 *
 * @note	None.
 *
 *****************************************************************************/
This function setup Camera sensor programming wrt resolution selected
@return      XST_SUCCESS if successful else XST_FAILURE.

@note        None.
This function setup Camera sensor programming wrt resolution selected @return XST_SUCCESS if successful else XST_FAILURE . @note None .
int SetupCameraSensor(void) {
	int Status;
	u32 Index, MaxIndex;
	SensorIicAddr = SENSOR_ADDR;
	struct regval_list *sensor_cfg = NULL;
	if (Pipeline_Cfg.CameraPresent == FALSE) {
		xil_printf("%s - No camera present\r\n", __func__);
		return XST_SUCCESS;
	}
	if ((Pipeline_Cfg.VideoMode == XVIDC_VM_3840x2160_30_P)
			&& (Pipeline_Cfg.ActiveLanes != 4)) {
		xil_printf("4K supports only 4 Lane configuration\r\n");
		return XST_FAILURE;
	}
	if ((Pipeline_Cfg.VideoMode == XVIDC_VM_1920x1080_60_P)
			&& (Pipeline_Cfg.ActiveLanes == 1)) {
		xil_printf("1080p doesn't support 1 Lane configuration\r\n");
		return XST_FAILURE;
	}
	Status = XIic_SetAddress(&IicSensor, XII_ADDR_TO_SEND_TYPE,
					SensorIicAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	switch (Pipeline_Cfg.VideoMode) {
		case XVIDC_VM_1280x720_60_P:
			MaxIndex = length_imx274_config_720p_60fps_regs;
			sensor_cfg = imx274_config_720p_60fps_regs;
			break;
		case XVIDC_VM_1920x1080_30_P:
			MaxIndex = length_imx274_config_1080p_60fps_regs;
			sensor_cfg = imx274_config_1080p_60fps_regs;
			break;
		case XVIDC_VM_1920x1080_60_P:
			MaxIndex = length_imx274_config_1080p_60fps_regs;
			sensor_cfg = imx274_config_1080p_60fps_regs;
			break;
		case XVIDC_VM_3840x2160_30_P:
			MaxIndex = length_imx274_config_4K_30fps_regs;
			sensor_cfg = imx274_config_4K_30fps_regs;
			break;
		case XVIDC_VM_3840x2160_60_P:
			MaxIndex = length_imx274_config_4K_60fps_regs;
			sensor_cfg = imx274_config_4K_60fps_regs;
			break;
		default:
			return XST_FAILURE;
			break;
	}
	for (Index = 0; Index < (MaxIndex - 0); Index++) {
		WriteBuffer[0] = sensor_cfg[Index].Address >> 8;
		WriteBuffer[1] = sensor_cfg[Index].Address;
		WriteBuffer[2] = sensor_cfg[Index].Data;
		Status = SensorWriteData(3);
		if (Status == XST_SUCCESS) {
			ReadBuffer[0] = 0;
			Status = SensorReadData(ReadBuffer, 1);
			if(WriteBuffer[2] != ReadBuffer[0])
			 xil_printf("index %d Ref %d Read %d\n",Index,WriteBuffer[2],ReadBuffer[0]);
			usleep(100);
		} else {
			xil_printf("Error in Writing entry status = %x \r\n",
					Status);
			break;
		}
	}
	if (Index != (MaxIndex - 0)) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int SetupCameraSensor ( void ) { int Status ; u32 Index , MaxIndex ; SensorIicAddr = SENSOR_ADDR ; struct regval_list * sensor_cfg = NULL ; if ( Pipeline_Cfg . CameraPresent == FALSE ) { xil_printf ( " \r \n " , __func__ ) ; return XST_SUCCESS ; } if ( ( Pipeline_Cfg . VideoMode == XVIDC_VM_3840x2160_30_P ) && ( Pipeline_Cfg . ActiveLanes != 4 ) ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } if ( ( Pipeline_Cfg . VideoMode == XVIDC_VM_1920x1080_60_P ) && ( Pipeline_Cfg . ActiveLanes == 1 ) ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } Status = XIic_SetAddress ( & IicSensor , XII_ADDR_TO_SEND_TYPE , SensorIicAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } switch ( Pipeline_Cfg . VideoMode ) { case XVIDC_VM_1280x720_60_P : MaxIndex = length_imx274_config_720p_60fps_regs ; sensor_cfg = imx274_config_720p_60fps_regs ; break ; case XVIDC_VM_1920x1080_30_P : MaxIndex = length_imx274_config_1080p_60fps_regs ; sensor_cfg = imx274_config_1080p_60fps_regs ; break ; case XVIDC_VM_1920x1080_60_P : MaxIndex = length_imx274_config_1080p_60fps_regs ; sensor_cfg = imx274_config_1080p_60fps_regs ; break ; case XVIDC_VM_3840x2160_30_P : MaxIndex = length_imx274_config_4K_30fps_regs ; sensor_cfg = imx274_config_4K_30fps_regs ; break ; case XVIDC_VM_3840x2160_60_P : MaxIndex = length_imx274_config_4K_60fps_regs ; sensor_cfg = imx274_config_4K_60fps_regs ; break ; default : return XST_FAILURE ; break ; } for ( Index = 0 ; Index < ( MaxIndex - 0 ) ; Index ++ ) { WriteBuffer [ 0 ] = sensor_cfg [ Index ] . Address >> 8 ; WriteBuffer [ 1 ] = sensor_cfg [ Index ] . Address ; WriteBuffer [ 2 ] = sensor_cfg [ Index ] . Data ; Status = SensorWriteData ( 3 ) ; if ( Status == XST_SUCCESS ) { ReadBuffer [ 0 ] = 0 ; Status = SensorReadData ( ReadBuffer , 1 ) ; if ( WriteBuffer [ 2 ] != ReadBuffer [ 0 ] ) xil_printf ( " \n " , Index , WriteBuffer [ 2 ] , ReadBuffer [ 0 ] ) ; usleep ( 100 ) ; } else { xil_printf ( " \r \n " , Status ) ; break ; } } if ( Index != ( MaxIndex - 0 ) ) { return XST_FAILURE ; } return XST_SUCCESS ; }
This function setup Camera sensor programming wrt resolution selected
 @return      XST_SUCCESS if successful else XST_FAILURE.
This function setup Camera sensor programming wrt resolution selected @return XST_SUCCESS if successful else XST_FAILURE .
/* If no camera present then return */ /* Validate Pipeline Configuration */ /* Select the sensor configuration based on resolution and lane */ /* Program sensor */ /* all registers are written into */