Commit 42d9fe52 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

phase adjustment for 14MPx - in development

parent 576739fe
......@@ -111,8 +111,10 @@ struct sensor_t mt9f002 = {
.imageHeight = 3288, ///< nominal image height for final images
.clearWidth = 4608, ///< maximal clear image width
.clearHeight = 3288, ///< maximal clear image height;
.clearTop = 106, ///< top margin to the first clear pixel
.clearLeft = 114, ///< left margin to the first clear pixel
.clearTop = 32, ///< top margin to the first clear pixel
.clearLeft = 144, ///< left margin to the first clear pixel
//.clearTop = 106, ///< top margin to the first clear pixel
//.clearLeft = 114, ///< left margin to the first clear pixel
.arrayWidth = 4640, ///< total image array width (including black and boundary)
.arrayHeight = 3320, ///< total image array height (including black and boundary)
.minWidth = 2, ///< minimal WOI width
......@@ -126,9 +128,9 @@ struct sensor_t mt9f002 = {
.maxShutter = 0xfffff, ///< Maximal shutter duration (in lines)
.flips = 0, ///< bit mask bit 0 - flipX, 1 - flipY
.flips = 3, ///< bit mask bit 0 - flipX, 1 - flipY
.init_flips = 0, ///< normal orientation flips bit mask bit 0 - flipX, 1 - flipY
.bayer = 0, ///< bayer shift for flips==0
.bayer = 2, ///< bayer shift for flips==0
.dcmHor = 0xff, ///< 1,2,3,4,5,6,7,8 (doc show [0,6] - change to 0x7f
.dcmVert = 0xff, ///< 1,2,3,4,5,6,7,8
.binHor = 0xff, ///< 1,2,4 0xb{0,1,3}
......@@ -233,7 +235,7 @@ int mt9f002_pgm_detectsensor (int sensor_port, ///< sensor port
struct sensor_t * psensor; // current sensor
x393_sensio_ctl_t sensio_ctl = {.d32=0};
//unsigned short * sensor_multi_regs;
struct sensor_port_config_t pcfg;
struct sensor_port_config_t *pcfg;
const char *name;
x393_i2c_device_t * dc;
......@@ -255,10 +257,12 @@ int mt9f002_pgm_detectsensor (int sensor_port, ///< sensor port
psensor= &mt9f002;
// temporary solution
pcfg = pSensorPortConfig[sensor_port];
name = get_name_by_code(pcfg.mux,DETECT_SENSOR);
pcfg = &pSensorPortConfig[sensor_port];
name = get_name_by_code(pcfg->sensor[0],DETECT_SENSOR);
dc = xi2c_dev_get(name);
psensor->i2c_addr = dc->slave7;
if (dc) {
psensor->i2c_addr = dc->slave7;
}
// set control lines
sensio_ctl.mrst = 1;
......@@ -280,7 +284,6 @@ int mt9f002_pgm_detectsensor (int sensor_port, ///< sensor port
//udelay(50); // is it needed?
X3X3_I2C_RCV2(sensor_port, psensor->i2c_addr, P_REG_MT9F002_MODEL_ID, &i2c_read_dataw);
dev_dbg(g_dev_ptr,"Read i2c (port = %d, sa7=0x%lx, reg=0x%x) chip ID=%x\n",sensor_port, psensor->i2c_addr, P_REG_MT9F002_MODEL_ID, i2c_read_dataw);
if ((i2c_read_dataw ^ MT9F002_PARTID)==0) {
......@@ -324,6 +327,65 @@ int mt9f002_pgm_detectsensor (int sensor_port, ///< sensor port
//NOTE 353: hardware i2c is turned off (not needed in 393)
}
int mt9f002_phases_read_flags(int sensor_port,int shift){
int res = 0;
x393_status_sens_io_t status;
x393_sensio_tim2_t reset_flags = {.d32=0};
// reset flags
set_x393_sensio_tim2(reset_flags,sensor_port);
// read flags
status = x393_sensio_status(sensor_port);
switch(shift){
case 0: res = status.barrel_0;break;
case 1: res = status.barrel_1;break;
case 2: res = status.barrel_2;break;
case 3: res = status.barrel_3;break;
}
return res;
}
int mt9f002_adjust_cable_phase(int sensor_port){
// insert phase adjustment here - find middle
// status: x393_status_sens_io_t status = x393_sensio_status(port) - read barrel - bits[21:14]
// set lane phase example: write_sensor_i2c 0 1 0 0x31c08db6 = P_REG_MT9F002_HISPI_TIMING
//
// for port 0:
// reset lanes_alive bits by writing to set_x393_sensio_tim2(port) - reg:0x40e or set_x393_sensio_tim3(port) reg:0x40f
// data: 0x40e x393_sensio_tim2_t D3?-[31:24],D2?-[23:16],D1?-[15:8],D0?-[7:0] - higher 5 bits - which D is which?!
// hact: 0x40f x393_sensio_tim3_t [7:0]
int phase = 0x8000;
int i,j;
int status;
// read it first ?
x393_status_ctrl_t status_ctrl = {.d32 = 0};
// enable status updates
status_ctrl.mode = 0x3;
set_x393_sensio_status_cntrl(status_ctrl, sensor_port);
// 4 data lanes, prior knowledge
for(i=0;i<4;i++){
// 16 values: 8 for CLK phase 0 position CLK, 8 - for CLK phase 4 position
for(j=0;j<16;j++){
status = mt9f002_phases_read_flags(sensor_port,i);
}
}
// disable status updates
status_ctrl.mode = 0x0;
set_x393_sensio_status_cntrl(status_ctrl, sensor_port);
return 0;
}
/** Reset and initialize sensor
* resets sensor, reads sensor registers, schedules "secret" manufacturer's corrections to the registers (stops/re-enables hardware i2c - 353 only)
* i2c is supposed to be already programmed */
......@@ -353,14 +415,19 @@ int mt9f002_pgm_initsensor (int sensor_port, ///< sensor port
data = mt9f002_inits[2*i+1];
page = pSensorPortConfig[sensor_port].haddr2rec[0][haddr];
// write immediately
dev_dbg(g_dev_ptr,"{%d} Immediately writing 0x%04x to register 0x%02x%02x\n",sensor_port,data,haddr,laddr);
dev_dbg(g_dev_ptr,"{%d} init sensor: writing 0x%04x to register 0x%02x%02x\n",sensor_port,data,haddr,laddr);
write_xi2c_reg16(sensor_port,page,laddr,data);
}
// sensor is supposed to be streaming by now
mt9f002_adjust_cable_phase(sensor_port);
// init register shadows here
return 0;
}
}
// SysFS interface to mt9f002
......
......@@ -785,7 +785,7 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port
unsigned short * sensor_multi_regs;
// temporary
struct sensor_port_config_t pcfg;
struct sensor_port_config_t *pcfg;
const char *name;
x393_i2c_device_t * dc;
......@@ -800,12 +800,6 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port
// try MT9P001 first
psensor= &mt9p001;
// temporary solution
pcfg = pSensorPortConfig[sensor_port];
name = get_name_by_code(pcfg.mux,DETECT_SENSOR);
dc = xi2c_dev_get(name);
psensor->i2c_addr = dc->slave7;
// set control lines
sensio_ctl.mrst = 1;
sensio_ctl.mrst_set = 1;
......@@ -853,6 +847,15 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port
}
// MDD1(dev_dbg(g_dev_ptr,"sensor=0x%x, sensor_subtype=0x%x\n", (int)sensor, (int)sensor_subtype));
if (sensor_subtype ==0) return 0; // no sensor found
// temporary solution
pcfg = &pSensorPortConfig[sensor_port];
name = get_name_by_code(pcfg->sensor[0],DETECT_SENSOR);
dc = xi2c_dev_get(name);
if (dc){
psensor->i2c_addr = dc->slave7;
}
// Sensor recognized, go on
// memcpy(&sensor, psensor, sizeof(mt9p001)); // copy sensor definitions
memcpy(sensor, psensor, sizeof(mt9p001)); // copy sensor definitions
......
......@@ -1454,6 +1454,8 @@ int pgm_sensorin (int sensor_port, ///< sensor port number (0..3
int margins;
x393_mcntrl_frame_start_dly_t start_dly ={.d32=0};
int sens = get_detected_sensor_code(sensor_port, -1);
dev_dbg(g_dev_ptr,"{%d} frame16=%d\n",sensor_port,frame16);
MDP(DBGB_PSFN, sensor_port,"frame16=%d\n",frame16)
if (frame16 >= PARS_FRAMES) return -1; // wrong frame
......@@ -1480,16 +1482,32 @@ int pgm_sensorin (int sensor_port, ///< sensor port number (0..3
thispars->pars[P_SHIFTL]));
#endif
}
// STRIKE HERE
// Writing WOI width for internally generated HACT
if (thispars->pars[P_FRAMESYNC_DLY] & 0x10000) { /// set enforced HACT length, if 0 - use HACT from sensor
sensio_width.sensor_width = thispars->pars[P_ACTUAL_WIDTH]+(2 * margins);
}
// fix for MT9F002
if ((sens & SENSOR_MASK) == SENSOR_MT9F002){
sensio_width.sensor_width = 2;
}
X393_SEQ_SEND1 (sensor_port, frame16, x393_sensio_width, sensio_width);
pr_info("{%d} X393_SEQ_SEND1(0x%x, 0x%x, x393_sensio_width, 0x%x)\n",
sensor_port, sensor_port, frame16, sensio_width.d32);
dev_dbg(g_dev_ptr,"{%d} X393_SEQ_SEND1(0x%x, 0x%x, x393_sensio_width, 0x%x)\n",
sensor_port, sensor_port, frame16, sensio_width.d32);
MDP(DBGB_PADD, sensor_port,"X393_SEQ_SEND1(0x%x, 0x%x, x393_sensio_width, 0x%x)\n",
sensor_port, frame16, sensio_width.d32)
// END OF STRIKE HERE
// Program number of scan lines to acquire
// Is PhotoFinish mode enabled? // **************** TODO: use ACTUAL_HEIGHT (and update it) not WOI_HEIGHT
if (((thispars->pars[P_PF_HEIGHT] & 0xffff)>0) && (thispars->pars[P_PF_HEIGHT]<=thispars->pars[P_ACTUAL_HEIGHT])){
......@@ -1529,6 +1547,7 @@ int pgm_sensorin (int sensor_port, ///< sensor port number (0..3
// Change Bayer for gamma/histograms?
if (bayer_modified) {
pr_info("OH NO, setting BAYER!!!");
bayer = thispars->pars[P_BAYER] ^ flips ^ sensor->bayer ^ 3; // 3 added for NC393;
setFramePar(sensor_port, thispars, P_COMP_BAYER | FRAMEPAIR_FORCE_PROC, bayer);
gamma_ctl.bayer = bayer; // 3 added for NC393
......@@ -1542,13 +1561,14 @@ int pgm_sensorin (int sensor_port, ///< sensor port number (0..3
MDP(DBGB_PADD, sensor_port,"X393_SEQ_SEND1(0x%x, 0x%x, x393_sens_gamma_ctrl, 0x%x)\n",sensor_port, frame16, gamma_ctl.d32)
}
// this is VACT delay, important period of time
if (FRAMEPAR_MODIFIED(P_MEMSENSOR_DLY) && ((start_dly.start_dly = thispars->pars[P_MEMSENSOR_DLY]))){
X393_SEQ_SEND1 (sensor_port, frame16, x393_sens_mcntrl_scanline_start_delay, start_dly);
pr_info("{%d} Setting sensor-to-memory frame sync delay to %d (0x%x)\n",sensor_port, start_dly.start_dly,start_dly.start_dly);
dev_dbg(g_dev_ptr,"{%d} Setting sensor-to-memory frame sync delay to %d (0x%x)\n",sensor_port, start_dly.start_dly,start_dly.start_dly);
MDP(DBGB_PADD, sensor_port,"Setting sensor-to-memory frame sync delay to %d (0x%x)\n", start_dly.start_dly,start_dly.start_dly)
}
#if 0
typedef union {
......@@ -2042,7 +2062,7 @@ int pgm_memsensor (int sensor_port, ///< sensor port number (
}
width_bursts = (width_marg >> 4) + ((width_marg & 0xf) ? 1 : 0);
pr_debug("PGM_MEMSENSOR: sport=%d width_burts=%d width_marg=%d height_marg=%d left_margin=%d top_margin=%d\n",
pr_info("PGM_MEMSENSOR: sport=%d width_burts=%d width_marg=%d height_marg=%d left_margin=%d top_margin=%d\n",
sensor_port,
width_bursts,
width_marg,
......
......@@ -1217,7 +1217,7 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use
int port, subchn;
x393_i2c_device_t *class_mux, *class_sensor;
x393_i2c_device_t dev_sensor;
struct sensor_port_config_t pcfg;
struct sensor_port_config_t *pcfg;
const char *name;
const char *name10359;
......@@ -1227,17 +1227,17 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use
i2c_page_alloc_init(port); // reset all pages allocation
pcfg = pSensorPortConfig[port];
pcfg = &pSensorPortConfig[port];
// pcfg.mux==0 equals 'DETECT'
//mux = (pcfg.mux!=SENSOR_NONE)&&(pcfg.mux!=0);
mux = (pcfg.mux!=SENSOR_NONE);
mux = (pcfg->mux!=SENSOR_NONE);
// 'write' recs for mux
if (mux){
// returns 'mux10359', need 'el10359'
name = get_name_by_code(pcfg.mux,DETECT_MUX);
name = get_name_by_code(pcfg->mux,DETECT_MUX);
// get reference name 'mux10359'
name10359 = get_name_by_code(SENSOR_MUX_10359,DETECT_MUX);
......@@ -1260,9 +1260,9 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use
// 'write' recs for sensors
for(subchn=0;subchn<4;subchn++){
if (pcfg.sensor[subchn]!=SENSOR_NONE){
if (pcfg->sensor[subchn]!=SENSOR_NONE){
name = get_name_by_code(pcfg.sensor[subchn],DETECT_SENSOR);
name = get_name_by_code(pcfg->sensor[subchn],DETECT_SENSOR);
class_sensor = xi2c_dev_get(name);
// copy reference data
......@@ -1278,7 +1278,7 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use
// 'read' recs for sensors,
// TODO: request the # from fpga, do not use LEGACY_READ_PAGE2, check read functions
name = get_name_by_code(pcfg.sensor[0],1);
name = get_name_by_code(pcfg->sensor[0],1);
class_sensor = xi2c_dev_get(name);
memcpy(&dev_sensor, class_sensor, sizeof(x393_i2c_device_t));
i2c_page_register(port, LEGACY_READ_PAGE2);
......
......@@ -361,9 +361,15 @@ int setup_sensor_memory (int num_sensor, ///< sensor port number (0..3)
window_width_height.height = window_height;
window_left_top.left = window_left;
window_left_top.top = window_top;
dev_dbg(g_dev_ptr,"{%d} setup_sensor_memory frame16=%d, command=%d\n",num_sensor,frame16, (int) x393cmd);
dev_dbg(g_dev_ptr,"sa=0x%08x sa_inc=0x%08x lfn=0x%08x fw=0x%08x wh=0x%08x lt=0x%08x\n",
window_frame_sa.d32,window_frame_sa_inc.d32, window_last_frame_num.d32, window_full_width.d32,window_width_height.d32,window_left_top.d32);
pr_info("{%d} setup_sensor_memory frame16=%d, command=%d\n",num_sensor,frame16, (int) x393cmd);
pr_info("sa=0x%08x sa_inc=0x%08x lfn=0x%08x fw=0x%08x wh=0x%08x lt=0x%08x\n",
window_frame_sa.d32,window_frame_sa_inc.d32, window_last_frame_num.d32, window_full_width.d32,window_width_height.d32,window_left_top.d32);
MDP(DBGB_VM,num_sensor,"frame16=%d, command=%d\n", frame16, (int) x393cmd)
MDP(DBGB_VM,num_sensor,"sa=0x%08x sa_inc=0x%08x lfn=0x%08x fw=0x%08x wh=0x%08x lt=0x%08x\n",
window_frame_sa.d32,window_frame_sa_inc.d32, window_last_frame_num.d32, window_full_width.d32,window_width_height.d32,window_left_top.d32)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment