os/linux-2.6-tag--devboard-R2_10-4/arch/cris/arch-v32/drivers/elphel/cxi2c.c File Reference

#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/autoconf.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/delay.h>
#include <asm/uaccess.h>
#include <asm/elphel/c313a.h>
#include "fpgactrl.h"
#include "x3x3.h"
#include "cc3x3.h"
#include "cci2c.h"

Include dependency graph for cxi2c.c:

Go to the source code of this file.

Defines

#define D(x)
#define CLOCK_LOW_TIME   8
#define CLOCK_HIGH_TIME   8
#define START_CONDITION_HOLD_TIME   8
#define STOP_CONDITION_HOLD_TIME   8
#define ENABLE_OUTPUT   0x01
#define ENABLE_INPUT   0x00
#define I2C_CLOCK_HIGH   1
#define I2C_CLOCK_LOW   0
#define I2C_DATA_HIGH   1
#define I2C_DATA_LOW   0
#define i2c_delay(usecs)   udelay(usecs)
#define I2C_DELAY_SCALE   1
#define SCL1_0   0x1
#define SCL1_OFF   0x3
#define SDA1_0   0x4
#define SDA1_OFF   0xc
#define SCL1_1   0x2
#define SDA1_1   0x8
#define X3X3_I2C_DRIVER_NAME   "Elphel (R) model 353 i2c character device driver"
#define I2CBUFSIZE   8196

Functions

void i2c_disable (int n)
void i2c_dir_out (int n)
void i2c_dir_in (int n)
void i2c_scl_0 (int n)
void i2c_scl_1 (int n)
void i2c_sda (int n, int d)
int i2c_getbit (int n)
 filtering noise/interference by repeating measurement 7 times and using the majority
int i2c_getscl (int n)
int i2c_diagnose (int n)
int i2c_start (int n)
 generate i2c start condition and test bus
int i2c_restart (int n)
int i2c_stop (int n)
int i2c_outbyte (int n, unsigned char d)
unsigned char i2c_inbyte (int n, int more)
void i2c_sendack (int n, int ackn)
int i2c_delays (unsigned long delays)
void il_ccamCRAnd (unsigned long d)
void il_ccamCROr (unsigned long d)
void il_ccamCRAndOr (unsigned long d_and, unsigned long d_or)
void i2c_sda_weak (int n, int d)
void i2c_sda_strong (int n, int d)
int i2c_writeData (int n, unsigned char theSlave, unsigned char *theData, int size, int stop)
int i2c_readData (int n, unsigned char theSlave, unsigned char *theData, int size, int start)
int i2c_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
static int xi2c_open (struct inode *inode, struct file *filp)
 ++++++++++++++++++++++++++++++++++++ open() ++++++++++++++++++++++++++++++++++++++++++++++++++++++
static int xi2c_release (struct inode *inode, struct file *filp)
 ++++++++++++++++++++++++++++++++++++ release() ++++++++++++++++++++++++++++++++++++++++++++++++++++++
static loff_t xi2c_lseek (struct file *file, loff_t offset, int orig)
 ++++++++++++++++++++++++++++++++++++ lseek() ++++++++++++++++++++++++++++++++++++++++++++++++++++++
static ssize_t xi2c_write (struct file *file, const char *buf, size_t count, loff_t *off)
 ++++++++++++++++++++++++++++++++++++ write() ++++++++++++++++++++++++++++++++++++++++++++++++++++++
static ssize_t xi2c_read (struct file *file, char *buf, size_t count, loff_t *off)
 ++++++++++++++++++++++++++++++++++++ read() ++++++++++++++++++++++++++++++++++++++++++++++++++++++
static int __init xi2c_init (void)
 module_init (xi2c_init)
 MODULE_LICENSE ("GPL")
 MODULE_AUTHOR ("Andrey Filippov <andrey@elphel.com>.")
 MODULE_DESCRIPTION (X3X3_I2C_DRIVER_NAME)

Variables

volatile unsigned long ccam_cr_shadow
static struct i2c_timing_t bitdelays [X3X3_I2C_CHANNELS]
 TODO: Make delays independent for 2 channels?
int _353_io_board_present
static unsigned char i2c_enable [X3X3_I2C_CHANNELS *128]
static unsigned char i2cbuf_all [X3X3_I2C_CHANNELS+1 *I2CBUFSIZE]
static loff_t sizes [X3X3_I2C_MAXMINOR+1]
 no buffers for control files
static int burst_sizes [X3X3_I2C_MAXMINOR+1]
static loff_t inuse [X3X3_I2C_CHANNELS]
 fix for PHP read (always 8192)
static struct file_operations xi2c_fops


Define Documentation

#define CLOCK_HIGH_TIME   8

Definition at line 85 of file cxi2c.c.

#define CLOCK_LOW_TIME   8

Definition at line 84 of file cxi2c.c.

#define D ( x   ) 

******************************************************************************** ! FILE NAME : cxi2c.c ! DESCRIPTION: I2c driver for FPGA communicating to sensors, software implementation ! Copyright (C) 2002-2007 Elphel, Inc. ! -----------------------------------------------------------------------------** ! ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation, either version 3 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** !

Log
cxi2c.c,v
! Revision 1.7 2008/04/11 23:16:51 elphel ! removed unneeded local_irq_disable() after local_irq_save_flags() ! ! Revision 1.6 2008/03/16 01:25:15 elphel ! increased default delays fro I2c bus 1 (EEPROM was not fast enough) ! ! Revision 1.5 2008/02/18 20:02:34 elphel ! added option to specify number of bytes to be actually written from device per read command (PHP feature fix) ! ! Revision 1.4 2008/02/12 21:53:20 elphel ! Modified I2c to support multiple buses, added raw access (no address registers) and per-slave protection bitmasks ! ! Revision 1.3 2008/02/11 04:52:18 elphel ! Modified I2C operations, added second bus to work with the 10369 (and future) board(s) ! ! Revision 1.2 2007/10/16 23:18:31 elphel ! added filtering I2C lines, r/w control of the I2C bit delays !

Definition at line 71 of file cxi2c.c.

#define ENABLE_INPUT   0x00

Definition at line 89 of file cxi2c.c.

#define ENABLE_OUTPUT   0x01

Definition at line 88 of file cxi2c.c.

#define I2C_CLOCK_HIGH   1

Definition at line 90 of file cxi2c.c.

#define I2C_CLOCK_LOW   0

Definition at line 91 of file cxi2c.c.

#define I2C_DATA_HIGH   1

Definition at line 92 of file cxi2c.c.

#define I2C_DATA_LOW   0

Definition at line 93 of file cxi2c.c.

#define i2c_delay ( usecs   )     udelay(usecs)

Definition at line 102 of file cxi2c.c.

#define I2C_DELAY_SCALE   1

Definition at line 103 of file cxi2c.c.

Referenced by i2c_inbyte(), i2c_outbyte(), i2c_restart(), i2c_start(), and i2c_stop().

#define I2CBUFSIZE   8196

Definition at line 556 of file cxi2c.c.

Referenced by xi2c_read(), and xi2c_write().

#define SCL1_0   0x1

Definition at line 177 of file cxi2c.c.

Referenced by i2c_scl_0().

#define SCL1_1   0x2

Definition at line 186 of file cxi2c.c.

Referenced by i2c_scl_1().

#define SCL1_OFF   0x3

Definition at line 178 of file cxi2c.c.

#define SDA1_0   0x4

Definition at line 179 of file cxi2c.c.

Referenced by i2c_sda_strong(), and i2c_sda_weak().

#define SDA1_1   0x8

Definition at line 187 of file cxi2c.c.

Referenced by i2c_sda_strong().

#define SDA1_OFF   0xc

Definition at line 180 of file cxi2c.c.

Referenced by i2c_sda_weak().

#define START_CONDITION_HOLD_TIME   8

Definition at line 86 of file cxi2c.c.

#define STOP_CONDITION_HOLD_TIME   8

Definition at line 87 of file cxi2c.c.

#define X3X3_I2C_DRIVER_NAME   "Elphel (R) model 353 i2c character device driver"

Definition at line 552 of file cxi2c.c.

Referenced by xi2c_init().


Function Documentation

int i2c_delays ( unsigned long  delays  ) 

Definition at line 154 of file cxi2c.c.

References bitdelays.

Referenced by i2c_ioctl().

int i2c_diagnose ( int  n  ) 

void i2c_dir_in ( int  n  ) 

void i2c_dir_out ( int  n  ) 

void i2c_disable ( int  n  ) 

int i2c_getbit ( int  n  ) 

filtering noise/interference by repeating measurement 7 times and using the majority

Definition at line 201 of file cxi2c.c.

References bitdelays, i2c_timing_t::filter_sda, X313_PIOR, and X313_SR.

Referenced by i2c_inbyte(), i2c_outbyte(), and i2c_start().

int i2c_getscl ( int  n  ) 

Definition at line 208 of file cxi2c.c.

References bitdelays, i2c_timing_t::filter_scl, X313_PIOR, and X313_SR.

unsigned char i2c_inbyte ( int  n,
int  more 
)

Definition at line 372 of file cxi2c.c.

References bitdelays, D, I2C_DELAY_SCALE, i2c_getbit(), i2c_scl_0(), i2c_scl_1(), i2c_sda_strong(), i2c_sda_weak(), local_irq_restore, local_irq_save, i2c_timing_t::master2slave, printk, i2c_timing_t::scl_high, i2c_timing_t::scl_low, i2c_timing_t::slave2master, and x3x3_DELAY.

Referenced by i2c_readData().

int i2c_ioctl ( struct inode *  inode,
struct file *  file,
unsigned int  cmd,
unsigned long  arg 
)

Definition at line 469 of file cxi2c.c.

References _353_io_board_present, CMOSCAM_IOCTYPE, D, data, error(), I2C_16_ARGREG, I2C_16_ARGSLAVE, I2C_16_ARGVALUE, I2C_16_ARGVALUE_H, I2C_16_ARGVALUE_L, I2C_16_READREG, I2C_16_WRITEREG, I2C_ARGBUS, I2C_ARGREG, I2C_ARGSLAVE, I2C_ARGVALUE, i2c_delays(), I2C_DELAYS, i2c_readData(), I2C_READREG, i2c_writeData(), I2C_WRITEREG, IO_EXT_BOARD_PRESENT, and printk.

Referenced by cmoscam_ioctl().

int i2c_outbyte ( int  n,
unsigned char  d 
)

Definition at line 338 of file cxi2c.c.

References bitdelays, D, I2C_DELAY_SCALE, i2c_getbit(), i2c_scl_0(), i2c_scl_1(), i2c_sda_strong(), i2c_sda_weak(), local_irq_restore, local_irq_save, i2c_timing_t::master2slave, printk, i2c_timing_t::scl_high, i2c_timing_t::scl_low, i2c_timing_t::slave2master, x, and x3x3_DELAY.

Referenced by i2c_readData(), and i2c_writeData().

int i2c_readData ( int  n,
unsigned char  theSlave,
unsigned char *  theData,
int  size,
int  start 
)

Definition at line 444 of file cxi2c.c.

References D, ERR_I2C_BSY, error(), i2c_inbyte(), i2c_outbyte(), i2c_restart(), i2c_start(), i2c_stop(), and printk.

Referenced by i2c_ioctl(), init_mt9x001(), readSensorReg(), readSensorReg16(), and xi2c_read().

int i2c_restart ( int  n  ) 

Definition at line 317 of file cxi2c.c.

References bitdelays, D, I2C_DELAY_SCALE, i2c_scl_0(), i2c_scl_1(), i2c_sda_strong(), i2c_sda_weak(), local_irq_restore, local_irq_save, printk, i2c_timing_t::scl_high, i2c_timing_t::scl_low, i2c_timing_t::slave2master, and x3x3_DELAY.

Referenced by i2c_readData().

void i2c_scl_0 ( int  n  ) 

Definition at line 229 of file cxi2c.c.

References il_ccamCRAndOr(), port_csp0_addr, SCL1_0, and X313_BITS.

Referenced by i2c_inbyte(), i2c_outbyte(), i2c_restart(), and i2c_start().

void i2c_scl_1 ( int  n  ) 

Definition at line 235 of file cxi2c.c.

References il_ccamCROr(), port_csp0_addr, SCL1_1, and X313_BITS.

Referenced by i2c_inbyte(), i2c_outbyte(), i2c_restart(), i2c_start(), and i2c_stop().

void i2c_sda ( int  n,
int  d 
)

void i2c_sda_strong ( int  n,
int  d 
)

Definition at line 253 of file cxi2c.c.

References il_ccamCRAndOr(), il_ccamCROr(), port_csp0_addr, SDA1_0, SDA1_1, and X313_BITS.

Referenced by i2c_inbyte(), i2c_outbyte(), i2c_restart(), and i2c_stop().

void i2c_sda_weak ( int  n,
int  d 
)

Definition at line 243 of file cxi2c.c.

References il_ccamCRAndOr(), port_csp0_addr, SDA1_0, SDA1_OFF, and X313_BITS.

Referenced by i2c_inbyte(), i2c_outbyte(), i2c_restart(), i2c_start(), and i2c_stop().

void i2c_sendack ( int  n,
int  ackn 
)

int i2c_start ( int  n  ) 

generate i2c start condition and test bus

Definition at line 265 of file cxi2c.c.

References bitdelays, D, ERR_I2C_SDA_ST0, I2C_DELAY_SCALE, i2c_getbit(), i2c_scl_0(), i2c_scl_1(), i2c_sda_weak(), local_irq_restore, local_irq_save, printk, i2c_timing_t::scl_high, i2c_timing_t::scl_low, and x3x3_DELAY.

Referenced by i2c_readData(), and i2c_writeData().

int i2c_stop ( int  n  ) 

Definition at line 298 of file cxi2c.c.

References bitdelays, D, I2C_DELAY_SCALE, i2c_scl_1(), i2c_sda_strong(), i2c_sda_weak(), local_irq_restore, local_irq_save, printk, i2c_timing_t::scl_high, i2c_timing_t::scl_low, i2c_timing_t::slave2master, and x3x3_DELAY.

Referenced by i2c_readData(), and i2c_writeData().

int i2c_writeData ( int  n,
unsigned char  theSlave,
unsigned char *  theData,
int  size,
int  stop 
)

Definition at line 414 of file cxi2c.c.

References D, ERR_I2C_BSY, ERR_I2C_NACK, error(), i2c_outbyte(), i2c_start(), i2c_stop(), and printk.

Referenced by i2c_ioctl(), init_mt9x001(), readSensorReg(), readSensorReg16(), writeSensorReg(), writeSensorReg16(), writeSensorRegFF(), xi2c_read(), and xi2c_write().

void il_ccamCRAnd ( unsigned long  d  )  [inline]

Definition at line 216 of file cxi2c.c.

References ccam_cr_shadow, port_csp0_addr, and X313_WA_WCTL.

void il_ccamCRAndOr ( unsigned long  d_and,
unsigned long  d_or 
) [inline]

Definition at line 224 of file cxi2c.c.

References ccam_cr_shadow, port_csp0_addr, and X313_WA_WCTL.

Referenced by i2c_scl_0(), i2c_sda_strong(), and i2c_sda_weak().

void il_ccamCROr ( unsigned long  d  )  [inline]

Definition at line 220 of file cxi2c.c.

References ccam_cr_shadow, port_csp0_addr, and X313_WA_WCTL.

Referenced by i2c_scl_1(), and i2c_sda_strong().

MODULE_AUTHOR ( "Andrey Filippov <andrey@elphel.com>."   ) 

MODULE_DESCRIPTION ( X3X3_I2C_DRIVER_NAME   ) 

module_init ( xi2c_init   ) 

MODULE_LICENSE ( "GPL"   ) 

static int __init xi2c_init ( void   )  [static]

Definition at line 1004 of file cxi2c.c.

References bitdelays, i2c_timing_t::filter_scl, i2c_timing_t::filter_sda, i2c_enable, inuse, KERN_ERR, i2c_timing_t::master2slave, printk, i2c_timing_t::scl_high, i2c_timing_t::scl_low, sizes, i2c_timing_t::slave2master, X3X3_I2C, X3X3_I2C1_16_AINC, X3X3_I2C1_8_AINC, X3X3_I2C1_RAW, X3X3_I2C_16_AINC, X3X3_I2C_8_AINC, X3X3_I2C_CHANNELS, X3X3_I2C_CTRL, X3X3_I2C_DRIVER_NAME, X3X3_I2C_ENABLE, X3X3_I2C_ENABLE_16, X3X3_I2C_ENABLE_8, X3X3_I2C_ENABLE_RAW, X3X3_I2C_ENABLE_RD, X3X3_I2C_ENABLE_WR, X3X3_I2C_RAW, and xi2c_fops.

static loff_t xi2c_lseek ( struct file *  file,
loff_t  offset,
int  orig 
) [static]

++++++++++++++++++++++++++++++++++++ lseek() ++++++++++++++++++++++++++++++++++++++++++++++++++++++

overload

Number of bytes to read in a single (read) if 8192 is passed (odd for 16-bits will be fixed during read itself

Definition at line 672 of file cxi2c.c.

References burst_sizes, int, sizes, X3X3_I2C1_16_AINC, X3X3_I2C1_RAW, X3X3_I2C_16_AINC, and X3X3_I2C_RAW.

int xi2c_open ( struct inode *  inode,
struct file *  filp 
) [static]

++++++++++++++++++++++++++++++++++++ open() ++++++++++++++++++++++++++++++++++++++++++++++++++++++

fix for PHP read (always 8192) -> 1 byte/read

fix for PHP read (always 8192) -> 2 bytes/read

Definition at line 585 of file cxi2c.c.

References bitdelays, burst_sizes, bus, D, i2c_enable, inuse, pd, printk, sizes, X3X3_I2C1_16_AINC, X3X3_I2C1_8_AINC, X3X3_I2C1_RAW, X3X3_I2C_16_AINC, X3X3_I2C_8_AINC, X3X3_I2C_CTRL, X3X3_I2C_ENABLE, and X3X3_I2C_RAW.

ssize_t xi2c_read ( struct file *  file,
char *  buf,
size_t  count,
loff_t *  off 
) [static]

++++++++++++++++++++++++++++++++++++ read() ++++++++++++++++++++++++++++++++++++++++++++++++++++++

PHP "feature" fix

PHP "feature" fix

Verify if this slave is enabled for the I2C operation requested

do not increment pointer for raw accesses

Definition at line 729 of file cxi2c.c.

References bitdelays, burst_sizes, bus, D, error(), i2c_enable, i2c_readData(), i2c_writeData(), i2cbuf_all, I2CBUFSIZE, int, printk, sizes, X3X3_I2C1_16_AINC, X3X3_I2C1_8_AINC, X3X3_I2C1_RAW, X3X3_I2C_16_AINC, X3X3_I2C_8_AINC, X3X3_I2C_CTRL, X3X3_I2C_ENABLE, X3X3_I2C_ENABLE_16, X3X3_I2C_ENABLE_8, X3X3_I2C_ENABLE_RAW, X3X3_I2C_ENABLE_RD, and X3X3_I2C_RAW.

static int xi2c_release ( struct inode *  inode,
struct file *  filp 
) [static]

++++++++++++++++++++++++++++++++++++ release() ++++++++++++++++++++++++++++++++++++++++++++++++++++++

Definition at line 645 of file cxi2c.c.

References bus, D, inuse, printk, X3X3_I2C1_16_AINC, X3X3_I2C1_8_AINC, X3X3_I2C1_RAW, X3X3_I2C_16_AINC, X3X3_I2C_8_AINC, X3X3_I2C_CHANNELS, X3X3_I2C_CTRL, X3X3_I2C_ENABLE, and X3X3_I2C_RAW.

static ssize_t xi2c_write ( struct file *  file,
const char *  buf,
size_t  count,
loff_t *  off 
) [static]

++++++++++++++++++++++++++++++++++++ write() ++++++++++++++++++++++++++++++++++++++++++++++++++++++

Verify if this slave is enabled for the I2C operation requested

only for control files that write directly to static arrays, no buffering

do not increment pointer for raw accesses

Definition at line 871 of file cxi2c.c.

References bitdelays, bus, D, error(), i2c_enable, i2c_writeData(), i2cbuf_all, I2CBUFSIZE, int, printk, sizes, X3X3_I2C1_16_AINC, X3X3_I2C1_8_AINC, X3X3_I2C1_RAW, X3X3_I2C_16_AINC, X3X3_I2C_8_AINC, X3X3_I2C_CTRL, X3X3_I2C_ENABLE, X3X3_I2C_ENABLE_16, X3X3_I2C_ENABLE_8, X3X3_I2C_ENABLE_RAW, X3X3_I2C_ENABLE_WR, and X3X3_I2C_RAW.


Variable Documentation

int _353_io_board_present

Definition at line 85 of file io.c.

Referenced by _353_configure(), and i2c_ioctl().

struct i2c_timing_t bitdelays[X3X3_I2C_CHANNELS] [static]

TODO: Make delays independent for 2 channels?

Definition at line 124 of file cxi2c.c.

Referenced by i2c_delays(), i2c_getbit(), i2c_getscl(), i2c_inbyte(), i2c_outbyte(), i2c_restart(), i2c_start(), i2c_stop(), xi2c_init(), xi2c_open(), xi2c_read(), and xi2c_write().

int burst_sizes[X3X3_I2C_MAXMINOR+1] [static]

Definition at line 562 of file cxi2c.c.

Referenced by xi2c_lseek(), xi2c_open(), and xi2c_read().

volatile unsigned long ccam_cr_shadow

Definition at line 802 of file cc353.c.

unsigned char i2c_enable[X3X3_I2C_CHANNELS *128] [static]

Definition at line 558 of file cxi2c.c.

Referenced by xi2c_init(), xi2c_open(), xi2c_read(), and xi2c_write().

unsigned char i2cbuf_all[X3X3_I2C_CHANNELS+1 *I2CBUFSIZE] [static]

Definition at line 560 of file cxi2c.c.

Referenced by xi2c_read(), and xi2c_write().

loff_t inuse[X3X3_I2C_CHANNELS] [static]

fix for PHP read (always 8192)

Definition at line 563 of file cxi2c.c.

Referenced by xi2c_init(), xi2c_open(), and xi2c_release().

loff_t sizes[X3X3_I2C_MAXMINOR+1] [static]

no buffers for control files

Definition at line 561 of file cxi2c.c.

struct file_operations xi2c_fops [static]

Initial value:

 {
        owner:    THIS_MODULE,
        open:     xi2c_open,
        release:  xi2c_release,
        read:     xi2c_read,
        write:    xi2c_write,
        llseek:   xi2c_lseek
}

Definition at line 574 of file cxi2c.c.

Referenced by xi2c_init().


Generated on Thu Aug 7 16:20:14 2008 for elphel by  doxygen 1.5.1