From 84bb1bb6130f1745ecc19a0210d06e2fe7a1635f Mon Sep 17 00:00:00 2001
From: "Suren A. Chilingaryan" <csa@dside.dyndns.org>
Date: Fri, 19 Oct 2012 03:36:45 +0200
Subject: Detect firmware version during initialization

---
 ipecamera/ipecamera.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/ipecamera/ipecamera.c b/ipecamera/ipecamera.c
index f8136d4..acd423f 100644
--- a/ipecamera/ipecamera.c
+++ b/ipecamera/ipecamera.c
@@ -88,8 +88,10 @@ pcilib_context_t *ipecamera_init(pcilib_t *pcilib) {
     ipecamera_t *ctx = malloc(sizeof(ipecamera_t));
 
     if (ctx) {
-	memset(ctx, 0, sizeof(ipecamera_t));
+	pcilib_register_value_t value;
 	
+	memset(ctx, 0, sizeof(ipecamera_t));
+
 	ctx->buffer_size = IPECAMERA_DEFAULT_BUFFER_SIZE;
 	ctx->dim.bpp = sizeof(ipecamera_pixel_t) * 8;
 
@@ -113,6 +115,17 @@ pcilib_context_t *ipecamera_init(pcilib_t *pcilib) {
 	FIND_REG(max_frames_reg, "fpga", "ddr_max_frames");
 	FIND_REG(num_frames_reg, "fpga", "ddr_num_frames");
 
+
+	GET_REG(firmware_version_reg, value);
+	switch (value) {
+	 case 4:
+	 case 5:
+	    ctx->firmware = value;
+	    break;
+	 default:
+    	    pcilib_error("Unsupported version of firmware (%lu)", value);
+	}
+
 	ctx->rdma = PCILIB_DMA_ENGINE_INVALID;
 	ctx->wdma = PCILIB_DMA_ENGINE_INVALID;
 
@@ -263,17 +276,6 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
 	return PCILIB_ERROR_INVALID_REQUEST;
     }
 
-
-    GET_REG(firmware_version_reg, value);
-    switch (value) {
-     case 4:
-     case 5:
-	ctx->firmware = value;
-	break;
-     default:
-        pcilib_error("Unsupported version of firmware (%lu)", value);
-    }
-
 	// Allow readout and clean the FRAME_REQUEST mode if set for some reason
     SET_REG(control_reg, IPECAMERA_IDLE|IPECAMERA_READOUT_FLAG);
     usleep(IPECAMERA_SLEEP_TIME);
-- 
cgit v1.2.3