Commit 53ff55a4 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

Fixed mux board programming sensors via broadcast address. Testing

parent 3db94829
...@@ -436,10 +436,7 @@ static int par2addr_fill(const unsigned short *par2addr, u32 *table){ ...@@ -436,10 +436,7 @@ static int par2addr_fill(const unsigned short *par2addr, u32 *table){
* the specified sensor * the specified sensor
* @return 0 * @return 0
*/ */
static int par2addr_init(void){ int detect_sensors_par2addr_init(int port,int sub_chn){
int port;
int sub_chn;
const unsigned short *par2addr; const unsigned short *par2addr;
const unsigned short *pages; const unsigned short *pages;
...@@ -453,23 +450,43 @@ static int par2addr_init(void){ ...@@ -453,23 +450,43 @@ static int par2addr_init(void){
}; };
*/ */
switch (sensorPortConfig[port].sensor[sub_chn]) {
case SENSOR_MT9P006:
// get sensor table
par2addr = mt9x001_par2addr;
pages = mt9x001_pages;
break;
case SENSOR_MT9F002:
// get sensor table
par2addr = mt9f002_par2addr;
pages = mt9f002_pages;
break;
}
if (par2addr){
// convert to key-value
par2addr_fill(par2addr,sensorPortConfig[port].par2addr[sub_chn]);
// save pointer to static LUT
sensorPortConfig[port].pages_ptr[sub_chn] = pages;
}
/*
// all .mux and .sensor are already filled out // all .mux and .sensor are already filled out
for (port = 0; port < SENSOR_PORTS; port++){ for (portx = 0; portx < SENSOR_PORTS; portx++){
// that's from device tree, fpga is not programmed yet // that's from device tree, fpga is not programmed yet
dev_dbg(g_dev_ptr,"port: %d mux: %d sensors: %d %d %d %d\n", dev_dbg(g_dev_ptr,"port: %d mux: %d sensors: %d %d %d %d\n",
port, portx,
sensorPortConfig[port].mux, sensorPortConfig[portx].mux,
sensorPortConfig[port].sensor[0], sensorPortConfig[portx].sensor[0],
sensorPortConfig[port].sensor[1], sensorPortConfig[portx].sensor[1],
sensorPortConfig[port].sensor[2], sensorPortConfig[portx].sensor[2],
sensorPortConfig[port].sensor[3] sensorPortConfig[portx].sensor[3]
); );
// sub_chn = 3 is never used // sub_chn = 3 is never used
for (sub_chn = 0; sub_chn < 4; sub_chn++){ for (sub_chn = 0; sub_chn < 4; sub_chn++){
//sensorPortConfig[port].sensor[sub_chn]; //sensorPortConfig[port].sensor[sub_chn];
switch (sensorPortConfig[port].sensor[sub_chn]) { switch (sensorPortConfig[portx].sensor[sub_chn]) {
case SENSOR_MT9P006: case SENSOR_MT9P006:
// get sensor table // get sensor table
par2addr = mt9x001_par2addr; par2addr = mt9x001_par2addr;
...@@ -483,12 +500,13 @@ static int par2addr_init(void){ ...@@ -483,12 +500,13 @@ static int par2addr_init(void){
} }
if (par2addr){ if (par2addr){
// convert to key-value // convert to key-value
par2addr_fill(par2addr,sensorPortConfig[port].par2addr[sub_chn]); par2addr_fill(par2addr,sensorPortConfig[portx].par2addr[sub_chn]);
// save pointer to static LUT // save pointer to static LUT
sensorPortConfig[port].pages_ptr[sub_chn] = pages; sensorPortConfig[portx].pages_ptr[sub_chn] = pages;
} }
} }
} }
*/
return 0; return 0;
} }
...@@ -515,7 +533,8 @@ static int par2addr_init(void){ ...@@ -515,7 +533,8 @@ static int par2addr_init(void){
detect_sensors_init_of(pdev); detect_sensors_init_of(pdev);
par2addr_init(); // move this fucntion to a later stage, right before fpga pages get allocated (pgm_functions.c)
//detect_sensors_par2addr_init();
// dev_dbg(dev, "Registering character device with name "DEV393_NAME(DEV393_DETECT_SENSORS)); // dev_dbg(dev, "Registering character device with name "DEV393_NAME(DEV393_DETECT_SENSORS));
// res = register_chrdev(DETECT_SENSORS_MAJOR, DEV393_NAME(DEV393_DETECT_SENSORS), &detect_sensors_fops); // res = register_chrdev(DETECT_SENSORS_MAJOR, DEV393_NAME(DEV393_DETECT_SENSORS), &detect_sensors_fops);
......
...@@ -47,6 +47,7 @@ typedef enum {NONE,PARALLEL12,HISPI4} sens_iface_t; ///< Sensor port interface t ...@@ -47,6 +47,7 @@ typedef enum {NONE,PARALLEL12,HISPI4} sens_iface_t; ///< Sensor port interface t
int get_code_by_name(const char * name, int type); int get_code_by_name(const char * name, int type);
const char * get_name_by_code(int code, int type); const char * get_name_by_code(int code, int type);
sens_iface_t get_iface_by_code(int code, int type); sens_iface_t get_iface_by_code(int code, int type);
int detect_sensors_par2addr_init(int port, int sub_chn);
int get_detected_mux_code(int port); int get_detected_mux_code(int port);
int set_broadcast_address(int port,int value); int set_broadcast_address(int port,int value);
......
...@@ -806,6 +806,7 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port ...@@ -806,6 +806,7 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port
dc = xi2c_dev_get(name); dc = xi2c_dev_get(name);
if (dc){ if (dc){
dev_dbg(g_dev_ptr,"{%d} setting i2c_addr to 0x%02x\n",sensor_port,dc->slave7); dev_dbg(g_dev_ptr,"{%d} setting i2c_addr to 0x%02x\n",sensor_port,dc->slave7);
//pr_info("{%d} Setting i2c_addr to 0x%02x\n",sensor_port,dc->slave7);
psensor->i2c_addr = dc->slave7; psensor->i2c_addr = dc->slave7;
} }
...@@ -827,8 +828,10 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port ...@@ -827,8 +828,10 @@ int mt9x001_pgm_detectsensor (int sensor_port, ///< sensor port
udelay(50); // is it needed? udelay(50); // is it needed?
X3X3_I2C_RCV2(sensor_port, psensor->i2c_addr, P_MT9X001_CHIPVER, &i2c_read_dataw); X3X3_I2C_RCV2(sensor_port, psensor->i2c_addr, P_MT9X001_CHIPVER, &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_MT9X001_CHIPVER, 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_MT9X001_CHIPVER, i2c_read_dataw);
//pr_info("Read i2c (port = %d, sa7=0x%lx, reg=0x%x) chip ID=%x\n",sensor_port, psensor->i2c_addr, P_MT9X001_CHIPVER, i2c_read_dataw);
if (((i2c_read_dataw ^ MT9P001_PARTID) & MT9X001_PARTIDMASK)==0) { if (((i2c_read_dataw ^ MT9P001_PARTID) & MT9X001_PARTIDMASK)==0) {
dev_dbg(g_dev_ptr,"Found MT9P001 2592x1944 sensor, chip ID=%x\n",i2c_read_dataw); dev_dbg(g_dev_ptr,"Found MT9P001 2592x1944 sensor, chip ID=%x\n",i2c_read_dataw);
//pr_info("Found MT9P001 2592x1944 sensor, chip ID=%x\n",i2c_read_dataw);
sensor_subtype=MT9P_TYP; //1; sensor_subtype=MT9P_TYP; //1;
} }
// dev_dbg(g_dev_ptr,"sensor id= 0x%x\n",i2c_read_data[0]); // dev_dbg(g_dev_ptr,"sensor id= 0x%x\n",i2c_read_data[0]);
......
...@@ -754,19 +754,19 @@ if (GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE)) { ...@@ -754,19 +754,19 @@ if (GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE)) {
dev_dbg(g_dev_ptr,"selected=%x, thispars->pars[P_MULTI_SELECTED]=%x composite=%x sequence=%x\n", selected, (int) thispars->pars[P_MULTI_SELECTED], composite, sequence); dev_dbg(g_dev_ptr,"selected=%x, thispars->pars[P_MULTI_SELECTED]=%x composite=%x sequence=%x\n", selected, (int) thispars->pars[P_MULTI_SELECTED], composite, sequence);
if ((ww-1) != thispars->pars[P_SENSOR_REGS+P_MT9X001_WIDTH]) { if ((ww-1) != thispars->pars[P_SENSOR_REGS+P_MT9X001_WIDTH]) {
SET_SENSOR_MBPAR(sensor_port, frame16, sensor->i2c_addr, P_MT9X001_WIDTH, ww-1); SET_SENSOR_MBPAR_LUT(sensor_port, frame16, P_MT9X001_WIDTH, ww-1);
dev_dbg(g_dev_ptr,"SET_SENSOR_MBPAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_WIDTH, (int) ww-1); dev_dbg(g_dev_ptr,"SET_SENSOR_MBPAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_WIDTH, (int) ww-1);
} }
// Program binning/decimation (also common but some older sensors) // Program binning/decimation (also common but some older sensors)
if((styp == MT9T_TYP) || (styp == MT9P_TYP)) { // 3MPix and 5MPix sensors if((styp == MT9T_TYP) || (styp == MT9P_TYP)) { // 3MPix and 5MPix sensors
v= (thispars->pars[P_SENSOR_REGS+P_MT9X001_RAM] & 0xff88) | ((bv - 1) << 4) | (dv - 1) ; v= (thispars->pars[P_SENSOR_REGS+P_MT9X001_RAM] & 0xff88) | ((bv - 1) << 4) | (dv - 1) ;
if (v != thispars->pars[P_SENSOR_REGS+P_MT9X001_RAM]) { if (v != thispars->pars[P_SENSOR_REGS+P_MT9X001_RAM]) {
SET_SENSOR_PAR(sensor_port, frame16,sensor->i2c_addr, P_MT9X001_RAM, v); SET_SENSOR_PAR_LUT(sensor_port, frame16, P_MT9X001_RAM, v);
dev_dbg(g_dev_ptr,"SET_SENSOR_PAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_RAM, (int) v); dev_dbg(g_dev_ptr,"SET_SENSOR_PAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_RAM, (int) v);
} }
v=(thispars->pars[P_SENSOR_REGS+P_MT9X001_CAM] & 0xff88) | ((bh - 1) << 4) | (dh - 1); v=(thispars->pars[P_SENSOR_REGS+P_MT9X001_CAM] & 0xff88) | ((bh - 1) << 4) | (dh - 1);
if (v != thispars->pars[P_SENSOR_REGS+P_MT9X001_CAM]) { if (v != thispars->pars[P_SENSOR_REGS+P_MT9X001_CAM]) {
SET_SENSOR_PAR(sensor_port, frame16,sensor->i2c_addr, P_MT9X001_CAM, v); SET_SENSOR_PAR_LUT(sensor_port, frame16, P_MT9X001_CAM, v);
dev_dbg(g_dev_ptr,"SET_SENSOR_PAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_CAM, (int) v); dev_dbg(g_dev_ptr,"SET_SENSOR_PAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_CAM, (int) v);
} }
} else { // 1.3 and 2 MPix sensors } else { // 1.3 and 2 MPix sensors
...@@ -776,7 +776,7 @@ if (GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE)) { ...@@ -776,7 +776,7 @@ if (GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE)) {
((dh == 8) ? (1 << 4) : 0) | // Column skip 8 ((dh == 8) ? (1 << 4) : 0) | // Column skip 8
((dv == 8) ? (1 << 5) : 0) ; // Row skip 8 ((dv == 8) ? (1 << 5) : 0) ; // Row skip 8
if (v != thispars->pars[P_SENSOR_REGS+P_MT9X001_RMODE1]) { if (v != thispars->pars[P_SENSOR_REGS+P_MT9X001_RMODE1]) {
SET_SENSOR_MBPAR(sensor_port,frame16,sensor->i2c_addr, P_MT9X001_RMODE1, v); SET_SENSOR_MBPAR_LUT(sensor_port,frame16, P_MT9X001_RMODE1, v);
dev_dbg(g_dev_ptr,"SET_SENSOR_MBPAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_RMODE1, (int) v); dev_dbg(g_dev_ptr,"SET_SENSOR_MBPAR(0x%x,0x%x, 0x%x, 0x%x)\n", frame16, (int) sensor->i2c_addr, (int) P_MT9X001_RMODE1, (int) v);
} }
} }
...@@ -788,24 +788,24 @@ if (GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE)) { ...@@ -788,24 +788,24 @@ if (GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE)) {
wt=sensor_wt(wois[(P_MULTI_TOP1- P_MULTI_WOI)+SENSOR_IN_SEQ(i,sequence)], wh, sFlipY[i], dv, thispars->pars[P_OVERSIZE], sensor); wt=sensor_wt(wois[(P_MULTI_TOP1- P_MULTI_WOI)+SENSOR_IN_SEQ(i,sequence)], wh, sFlipY[i], dv, thispars->pars[P_OVERSIZE], sensor);
// program sensor height // program sensor height
SET_SENSOR_MIBPAR_COND(sensor_port,frame16,sensor->i2c_addr, i, P_MT9X001_HEIGHT, wh-1); SET_SENSOR_MIBPAR_COND_LUT(sensor_port,frame16, i, P_MT9X001_HEIGHT, wh-1);
// Program sensor left margin // Program sensor left margin
SET_SENSOR_MIBPAR_COND(sensor_port,frame16,sensor->i2c_addr, i, P_MT9X001_COLSTART, wl); SET_SENSOR_MIBPAR_COND_LUT(sensor_port,frame16, i, P_MT9X001_COLSTART, wl);
// Program sensor top margin // Program sensor top margin
SET_SENSOR_MIBPAR_COND(sensor_port,frame16,sensor->i2c_addr, i, P_MT9X001_ROWSTART, wt); SET_SENSOR_MIBPAR_COND_LUT(sensor_port,frame16, i, P_MT9X001_ROWSTART, wt);
if((styp == MT9T_TYP) || (styp == MT9P_TYP)) { // 3MPix and 5MPix sensors if((styp == MT9T_TYP) || (styp == MT9P_TYP)) { // 3MPix and 5MPix sensors
v= (thispars->pars[P_SENSOR_REGS+P_MT9X001_RMODE2] & 0x3fff) | // preserve other bits from shadows v= (thispars->pars[P_SENSOR_REGS+P_MT9X001_RMODE2] & 0x3fff) | // preserve other bits from shadows
(sFlipX[i] ? (1 << 14) : 0) | // FLIPH - will control just alternative rows (sFlipX[i] ? (1 << 14) : 0) | // FLIPH - will control just alternative rows
(sFlipY[i] ? (1 << 15) : 0) ; // FLIPV (sFlipY[i] ? (1 << 15) : 0) ; // FLIPV
SET_SENSOR_MIBPAR_COND(sensor_port,frame16,sensor->i2c_addr, i, P_MT9X001_RMODE2, v); SET_SENSOR_MIBPAR_COND_LUT(sensor_port,frame16, i, P_MT9X001_RMODE2, v);
} else { // 1.3 and 2 MPix sensors } else { // 1.3 and 2 MPix sensors
v= (thispars->pars[P_SENSOR_REGS+P_MT9X001_RMODE2] & 0x3fe7) | // preserve other bits from shadows v= (thispars->pars[P_SENSOR_REGS+P_MT9X001_RMODE2] & 0x3fe7) | // preserve other bits from shadows
((dh == 2) ? (1 << 3) : 0) | // Column skip 2 ((dh == 2) ? (1 << 3) : 0) | // Column skip 2
((dv == 2) ? (1 << 4) : 0) | // Row skip 2 ((dv == 2) ? (1 << 4) : 0) | // Row skip 2
(sFlipX[i] ? (1 << 14) : 0) | // FLIPH - will control just alternative rows (sFlipX[i] ? (1 << 14) : 0) | // FLIPH - will control just alternative rows
(sFlipY[i] ? (1 << 15) : 0) ; // FLIPV (sFlipY[i] ? (1 << 15) : 0) ; // FLIPV
SET_SENSOR_MIBPAR_COND(sensor_port,frame16,sensor->i2c_addr, i, P_MT9X001_RMODE2, v); SET_SENSOR_MIBPAR_COND_LUT(sensor_port,frame16, i, P_MT9X001_RMODE2, v);
} }
} }
if (!(GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE))) { // try after sensors if (!(GLOBALPARS(sensor_port, G_MULTI_CFG) & (1 <<G_MULTI_CFG_BEFORE))) { // try after sensors
...@@ -1120,6 +1120,7 @@ int multisensor_pgm_detectsensor (int sensor_port, ///< sensor p ...@@ -1120,6 +1120,7 @@ int multisensor_pgm_detectsensor (int sensor_port, ///< sensor p
&sensor_id[i], &sensor_id[i],
2); 2);
#else #else
// do not forget when updated read macro
rslt= X3X3_I2C_RCV2 (sensor_port, rslt= X3X3_I2C_RCV2 (sensor_port,
MT9P001_I2C_ADDR + ((i+1) * I2C359_INC), MT9P001_I2C_ADDR + ((i+1) * I2C359_INC),
P_MT9X001_CHIPVER, P_MT9X001_CHIPVER,
......
...@@ -100,10 +100,10 @@ extern struct sensor_port_config_t *pSensorPortConfig; ...@@ -100,10 +100,10 @@ extern struct sensor_port_config_t *pSensorPortConfig;
* @param data value to set (16 bits) * @param data value to set (16 bits)
*/ */
#define SET_SENSOR_PAR_LUT(port,frame,reg,data) {\ #define SET_SENSOR_PAR_LUT(port,frame,reg,data) {\
int _I = pSensorPortConfig[(port)].broadcast_addr;\
int _ADDR = pSensorPortConfig[(port)].par2addr[_I][(reg)];\
pars_to_update[nupdate ].num= P_SENSOR_REGS+(reg);\ pars_to_update[nupdate ].num= P_SENSOR_REGS+(reg);\
pars_to_update[nupdate++].val=(data);\ pars_to_update[nupdate++].val=(data);\
int _I = 0;\
int _ADDR = pSensorPortConfig[(port)].par2addr[_I][(reg)];\
if (!(_ADDR&0xffff0000)) {\ if (!(_ADDR&0xffff0000)) {\
X3X3_I2C_SEND2_LUT((port),(frame), _I, _ADDR, (data));\ X3X3_I2C_SEND2_LUT((port),(frame), _I, _ADDR, (data));\
}\ }\
......
...@@ -1225,6 +1225,7 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use ...@@ -1225,6 +1225,7 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use
const char *name10359; const char *name10359;
bool mux; bool mux;
bool broadcast_set = false;
dev_dbg(g_dev_ptr,"register_i2c_sensor()\n"); dev_dbg(g_dev_ptr,"register_i2c_sensor()\n");
...@@ -1260,20 +1261,45 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use ...@@ -1260,20 +1261,45 @@ int register_i2c_sensor(int ports_mask) ///< bitmask of the sensor ports to use
// TODO: request a line# from fpga table and register it (not class_mux->slave7) // TODO: request a line# from fpga table and register it (not class_mux->slave7)
i2c_page_register(port, class_mux->slave7); i2c_page_register(port, class_mux->slave7);
set_xi2c_wrc(class_mux, port, class_mux->slave7, 0); set_xi2c_wrc(class_mux, port, class_mux->slave7, 0);
}
// 'write' recs for sensors // 'write' recs for sensors
for(subchn=0;subchn<4;subchn++){ for(subchn=0;subchn<4;subchn++){
if (pcfg->sensor[subchn]!=SENSOR_NONE){
// set the 1st found sensor type to broadcast
if (!broadcast_set){
broadcast_set = true;
pcfg->sensor[pcfg->broadcast_addr] = pcfg->sensor[subchn];
}
// init par2addr and other tables for sensors
detect_sensors_par2addr_init(port,subchn);
name = get_name_by_code(pcfg->sensor[subchn],DETECT_SENSOR);
class_sensor = xi2c_dev_get(name);
// copy reference data
memcpy(&dev_sensor, class_sensor, sizeof(x393_i2c_device_t));
if (subchn==pcfg->broadcast_addr){
dev_sensor.slave7 = class_sensor->slave7;
}else{
// i2c address increment rule for MUX ports
dev_sensor.slave7 = class_sensor->slave7 + I2C359_INC * (subchn+1);
}
// register line#s for available sensors (w or w/o mux)
fpga_register_i2c_pages(port,subchn,dev_sensor);
}
}
}else{
// single sensor this port, subchn is 0
subchn = 0;
if (pcfg->sensor[subchn]!=SENSOR_NONE){ if (pcfg->sensor[subchn]!=SENSOR_NONE){
detect_sensors_par2addr_init(port,subchn);
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); class_sensor = xi2c_dev_get(name);
// copy reference data
memcpy(&dev_sensor, class_sensor, sizeof(x393_i2c_device_t)); memcpy(&dev_sensor, class_sensor, sizeof(x393_i2c_device_t));
// i2c address rule for MUX ports dev_sensor.slave7 = class_sensor->slave7;
dev_sensor.slave7 = class_sensor->slave7 + I2C359_INC * subchn;
// register line#s for available sensors (w or w/o mux)
fpga_register_i2c_pages(port,subchn,dev_sensor); fpga_register_i2c_pages(port,subchn,dev_sensor);
} }
} }
......
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