Commit 35f01d22 authored by Andrey Filippov's avatar Andrey Filippov

Updating multi10359, documenting

parent a9dd5e60
......@@ -75,7 +75,6 @@ typedef struct {
int calc_pll_params (unsigned int f, t_pll_params * pars); // f -in Hz
int setCYField (int sensor_port, int addr, int mask, int value); /// bus==1 - FPGA (sensor bus through 10359), 0 - CPU bus
int setClockFreq(int nclock, int freq); // freq now in Hz
int calc_pll_params (unsigned int f, t_pll_params * pars) { // f -in Hz
// t_pll_params pars;
......@@ -176,6 +175,7 @@ int setCYField (int sensor_port, int reg_addr, int mask, int value) {
sensor_port, reg_addr, mask, value,reg_data);
return error;
}
return 0;
}
int x393_getClockFreq(int sensor_port, int nclock) {
......
......@@ -115,7 +115,7 @@
#endif
/**
* \def FRAMEPARS_DRIVER_NAME driver name to display
* driver name to display
*/
#define FRAMEPARS_DRIVER_NAME "Elphel (R) Model 393 Frame Parameters device driver"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -34,6 +34,7 @@
#include <asm/uaccess.h>
#include "x393.h"
#include "sensor_i2c.h"
#include <elphel/c313a.h> // PARS_FRAMES_MASK
//------------------
......@@ -85,8 +86,10 @@ void i2c_page_alloc_init(void)
for (i = 0; i < sizeof(sysfs_page)/sizeof(sysfs_page[0]); i++) sysfs_page[i] = -1;
}
/** Reserve i2c page (1 of 256) for a sensor port
* @param chn sensor port number (0..3)
* @return allocated page number or -ENOMEM if all pages are already used
*/
int i2c_page_alloc(int chn)
{
......@@ -109,6 +112,31 @@ int i2c_page_alloc(int chn)
}
EXPORT_SYMBOL_GPL(i2c_page_alloc);
/** Register specific page, can be used with legacy software to register page equal to slave address,
* and use 0xff for reading. Works with 1byhte addresses and 16-bit data */
int i2c_page_register(int chn, ///< Sensor port
int page) ///< page to register (for legacy software, use 7-bit slave address
///< @return 0 on success, -ENOMEM if page is already registered
{
int g = page >> 5;
int b = page & 0x1f;
u32 * fb = free_i2c_pages + ((chn << 3) + g);
spin_lock(&lock);
if (unlikely(!(*fb & (1 << (31-b))))) {
spin_unlock(&lock);
return -ENOMEM; // page is already registered
}
*fb &= (1 << (31-b));
if (unlikely(*fb == 0)){
free_i2c_groups[chn] &= ~(1 << (31 - g));
}
spin_unlock(&lock);
return 0;
}
EXPORT_SYMBOL_GPL(i2c_page_register);
/** Free i2c page
* @param chn sensor port number (0..3)
* @param page i2c configuration page to release
......@@ -355,6 +383,45 @@ void write_xi2c_reg16 (int chn, ///< sensor port
}
EXPORT_SYMBOL_GPL(write_xi2c_reg16);
/** Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode */
void write_xi2c_reg16_rel (int chn, ///< sensor port
int page, ///< index in the table (8 bits)
int frame, ///< relative frame number modulo PARS_FRAMES
int addr, ///< low byte of the register address (high is in the table), 8 bits
u32 data) ///< 16 or 8-bit data (LSB aligned)
{
u32 dw = ((page & 0xff) << 24) | ((addr & 0xff) << 16) | (data & 0xffff);
x393_sensi2c_rel (dw, chn, frame & PARS_FRAMES_MASK);
}
EXPORT_SYMBOL_GPL(write_xi2c_reg16_rel);
/** Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode */
void write_xi2c_reg16_abs (int chn, ///< sensor port
int page, ///< index in the table (8 bits)
int frame, ///< absolute frame number modulo PARS_FRAMES
int addr, ///< low byte of the register address (high is in the table), 8 bits
u32 data) ///< 16 or 8-bit data (LSB aligned)
{
u32 dw = ((page & 0xff) << 24) | ((addr & 0xff) << 16) | (data & 0xffff);
x393_sensi2c_abs (dw, chn, frame & PARS_FRAMES_MASK);
}
EXPORT_SYMBOL_GPL(write_xi2c_reg16_abs);
/** Compatibility with the legacy code: frame <0 - ASAP, >=0 - absolute
* Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode */
void write_xi2c_reg16_abs_asap (int chn, ///< sensor port
int page, ///< index in the table (8 bits)
int frame, ///< absolute frame number modulo PARS_FRAMES
int addr, ///< low byte of the register address (high is in the table), 8 bits
u32 data) ///< 16 or 8-bit data (LSB aligned)
{
u32 dw = ((page & 0xff) << 24) | ((addr & 0xff) << 16) | (data & 0xffff);
if (frame<0) x393_sensi2c_abs (dw, chn, 0);
else x393_sensi2c_abs (dw, chn, frame & PARS_FRAMES_MASK);
}
EXPORT_SYMBOL_GPL(write_xi2c_reg16_abs);
/** Initiate sensor i2c read in immediate mode (data itself has to be read from FIFO with read_xi2c_fifo)
* Use slave address from provided class structure.
*/
......
......@@ -14,7 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#ifndef SENSOR_I2C.H
#define SENSOR_I2C.H
/** I2C device description to be used with i2c sequencer*/
typedef struct{
char name[32]; ///< Device class name (up to 31 characters)
......@@ -29,14 +30,30 @@ typedef struct{
* @param chn sensor port number (0..3) */
int i2c_page_alloc(int chn);
/* Register specific page, can be used with legacy software to register page equal to slave address,
* and use 0xff for reading. Works with 1byhte addresses and 16-bit data */
int i2c_page_register(int chn, // Sensor port
int page); // page to register (for legacy software, use 7-bit slave address
// @return 0 on success, -ENOMEM if page is already registered
/* Free i2c page */
void i2c_page_free(int chn, int page);
/* Find device list entry by device class name */
x393_i2c_device_t * xi2c_dev_get(const char * name); // Device class name as string
/* Set i2c table entry to raw data (will just overwrite tbl_mode = 2)*/
void set_xi2c_raw(int chn,
int page, // index in lookup table
u32 data); // Bit delay - number of mclk periods in 1/4 of the SCL period
/* Set i2c table entry for write operation */
void set_xi2c_wr(int chn, // sensor port
int page, // index in lookup table
int sa7, // slave address (7 bit)
int rah, // High byte of the i2c register address
int num_bytes, // Number of bytes to write (1..10)
int bit_delay); // Bit delay - number of mclk periods in 1/4 of the SCL period
/*
* Set i2c table entry for write operation using known devices
* Get device with xi2c_dev_get(), copy and modify, if needed to
......@@ -78,6 +95,28 @@ void write_xi2c_reg16 (int chn,
int addr, // low 8 bits
u32 data); // 16 or 8-bit data (LSB aligned)
/* Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode */
void write_xi2c_reg16_rel (int chn, // sensor port
int page, // index in the table (8 bits)
int frame, // relative frame number modulo PARS_FRAMES
int addr, // low byte of the register address (high is in the table), 8 bits
u32 data); ///< 16 or 8-bit data (LSB aligned)
/* Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode */
void write_xi2c_reg16_abs (int chn, // sensor port
int page, // index in the table (8 bits)
int frame, // absolute frame number modulo PARS_FRAMES
int addr, // low byte of the register address (high is in the table), 8 bits
u32 data); //16 or 8-bit data (LSB aligned)
/* Compatibility with the legacy code: frame <0 - ASAP, >=0 - absolute
* Write sensor 16 bit (or 8 bit as programmed in the table) data in immediate mode */
void write_xi2c_reg16_abs_asap (int chn, // sensor port
int page, // index in the table (8 bits)
int frame, // absolute frame number modulo PARS_FRAMES
int addr, // low byte of the register address (high is in the table), 8 bits
u32 data); // 16 or 8-bit data (LSB aligned)
/* Initiate sensor i2c read in immediate mode (data itself has to be read from FIFO with read_xi2c_fifo)
* Use slave address from provided class structure. */
void read_xi2c (x393_i2c_device_t * dc, // device class
......@@ -110,3 +149,4 @@ int x393_xi2c_read_reg( const char * cname, // device class name
int sa7_offs, // slave address (7-bit) offset from the class defined slave address
int reg_addr, // register address (width is defined by class)
int * datap); // pointer to a data receiver (read data width is defined by class)
#endif
......@@ -71,8 +71,6 @@
//xi2craw_aux c 134 6
//xi2cenable c 134 7
#define FPGA_DCM_STEP 22 // ps/step
#define FPGA_DCM_RANGE 250 // maximal phase correction (+/-) ?
/* camera sequencer states */
//Obsolete
#define CAMSEQ_OFF 0 // off, not programmed (Video mode off on Zoran sensors)
......@@ -123,6 +121,10 @@
#endif
#define FPGA_DCM_STEP 22 // ps/step
#define FPGA_DCM_RANGE 250 // maximal phase correction (+/-) ?
/* supported ioctl _IOC_NR's */
#ifndef I2C_WRITEARG
#define I2C_WRITEARG(bus, slave, reg, value) (((bus) << 24) | ((slave) << 16) | ((reg) << 8) | (value))
......@@ -593,15 +595,22 @@
#endif
#define P_MAX_PAR_ROUNDUP ROUND_UP (P_MAX_PAR , (PAGE_SIZE/8)) ///< half page in DWORDs
#ifdef NC353 // to hide old code
#ifdef SAFE_CHECK
#define MULTIREG(x,n) ((((n)>=0) && ((n)<MAX_SENSORS) && ((x) >0) && ((x) < P_MAX_PAR) && (multiSensIndex[x] > 0))? (multiSensIndex[x]+(n)) : 0)
#else
#define MULTIREG(x,n) ((multiSensIndex[x] > 0)? (multiSensIndex[x]+(n)) : 0) // unsafe
#endif
#define MULTIRVRSREG(x) (multiSensRvrsIndex[x])
#else
#ifdef SAFE_CHECK
#define MULTIREG(p,x,n) ((((n)>=0) && ((n)<MAX_SENSORS) && ((x) >0) && ((x) < P_MAX_PAR) && (amultiSensIndex[p][x] > 0))? (amultiSensIndex[p][x]+(n)) : 0)
#else
#define MULTIREG(p,x,n) ((amultiSensIndex[p][x] > 0)? (amultiSensIndex[p][x]+(n)) : 0) // unsafe
#endif
#define MULTIRVRSREG(p,x) (amultiSensRvrsIndex[p][x])
#endif
///amultiSensRvrsIndex
//#define P_MAX_PAR 511 /// maximal # of used parameter
//#define P_MAX_GPAR 1023 // maximal # of global parameter
//#define P_MAX_GPAR 2047 /// maximal # of global parameter - TODO: change name to NUM_GPAR and make it 2048
......@@ -1603,10 +1612,11 @@ struct sensorproc_t {
/// functions return <0 on error (and do nothing)
/// first 32 functions are called directly when appropriate bit is set, next 32 - sensor specific that are called
/// by corresponding one with (number-32) if not NULL. Sensor initilaization should set up those functions
int (*pgm_func[64]) (struct sensor_t * sensor, /// pointer to sensor parameters
struct framepars_t * framepars, /// pointer to structure with array of current frame parameters
struct framepars_t * prevpars, /// pointer to structure with array of previous frame parameters
int frame8); /// frame to program (latency applied), -1 - ASAP
int (*pgm_func[64]) (int sensor_port, ///< sensor port number (0..3)
struct sensor_t * sensor, ///< pointer to sensor parameters
struct framepars_t * framepars, ///< pointer to structure with array of current frame parameters
struct framepars_t * prevpars, ///< pointer to structure with array of previous frame parameters
int frame16); ///< frame to program (latency applied), -1 - ASAP
};
......
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