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/driver_numbers.h>
#include <asm/elphel/c313a.h>
#include "fpgactrl.h"
#include "x3x3.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 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)
 NOTE: what the hell is it doing here?
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

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 107 of file cxi2c.c.

#define CLOCK_LOW_TIME   8

Definition at line 106 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.1.1.1 2008/11/27 20:04:00 elphel ! ! ! Revision 1.7 2008/09/20 00:29:49 elphel ! moved driver major/minor numbers to a single file - include/asm-cris/elphel/driver_numbers.h ! ! Revision 1.6 2008/09/12 00:23:58 elphel ! removed cc353.c, cc353.h ! ! Revision 1.5 2008/09/05 23:20:26 elphel ! just a snapshot ! ! Revision 1.4 2008/08/25 19:07:23 elphel ! just a snapshot ! ! Revision 1.3 2008/07/27 04:27:49 elphel ! next snapshot ! ! Revision 1.2 2008/06/19 02:17:36 elphel ! continuing work - just a snapshot ! ! 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 93 of file cxi2c.c.

#define ENABLE_INPUT   0x00

Definition at line 111 of file cxi2c.c.

#define ENABLE_OUTPUT   0x01

Definition at line 110 of file cxi2c.c.

#define I2C_CLOCK_HIGH   1

Definition at line 112 of file cxi2c.c.

#define I2C_CLOCK_LOW   0

Definition at line 113 of file cxi2c.c.

#define I2C_DATA_HIGH   1

Definition at line 114 of file cxi2c.c.

#define I2C_DATA_LOW   0

Definition at line 115 of file cxi2c.c.

#define i2c_delay ( usecs   )     udelay(usecs)

Definition at line 124 of file cxi2c.c.

#define I2C_DELAY_SCALE   1

Definition at line 125 of file cxi2c.c.

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

#define I2CBUFSIZE   8196

Definition at line 579 of file cxi2c.c.

Referenced by xi2c_read(), and xi2c_write().

#define SCL1_0   0x1

Definition at line 207 of file cxi2c.c.

Referenced by i2c_scl_0().

#define SCL1_1   0x2

Definition at line 216 of file cxi2c.c.

Referenced by i2c_scl_1().

#define SCL1_OFF   0x3

Definition at line 208 of file cxi2c.c.

#define SDA1_0   0x4

Definition at line 209 of file cxi2c.c.

Referenced by i2c_sda_strong(), and i2c_sda_weak().

#define SDA1_1   0x8

Definition at line 217 of file cxi2c.c.

Referenced by i2c_sda_strong().

#define SDA1_OFF   0xc

Definition at line 210 of file cxi2c.c.

Referenced by i2c_sda_weak().

#define START_CONDITION_HOLD_TIME   8

Definition at line 108 of file cxi2c.c.

#define STOP_CONDITION_HOLD_TIME   8

Definition at line 109 of file cxi2c.c.

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

Definition at line 575 of file cxi2c.c.

Referenced by xi2c_init().


Function Documentation

int i2c_delays ( unsigned long  delays  ) 

Definition at line 176 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 231 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 238 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 395 of file cxi2c.c.

References bitdelays, D, flags, 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 
)

NOTE: what the hell is it doing here?

Definition at line 492 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.

int i2c_outbyte ( int  n,
unsigned char  d 
)

Definition at line 361 of file cxi2c.c.

References bitdelays, D, flags, 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 467 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(), mt9x001_pgm_detectsensor(), mt9x001_pgm_initsensor(), and xi2c_read().

int i2c_restart ( int  n  ) 

Definition at line 340 of file cxi2c.c.

References bitdelays, D, flags, 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 246 of file cxi2c.c.

References port_csp0_addr, SCL1_0, X313_I2C_CMD, X313_WA_IOPINS, and X3X3_I2C_SCL_0_BITS.

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

void i2c_scl_1 ( int  n  ) 

Definition at line 255 of file cxi2c.c.

References port_csp0_addr, SCL1_1, X313_I2C_CMD, X313_WA_IOPINS, and X3X3_I2C_SCL_1_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 274 of file cxi2c.c.

References port_csp0_addr, SDA1_0, SDA1_1, X313_I2C_CMD, X313_WA_IOPINS, X3X3_I2C_SDA_0_BITS, and X3X3_I2C_SDA_1_BITS.

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

void i2c_sda_weak ( int  n,
int  d 
)

Definition at line 262 of file cxi2c.c.

References port_csp0_addr, SDA1_0, SDA1_OFF, X313_I2C_CMD, X313_WA_IOPINS, X3X3_I2C_SDA_0_BITS, and X3X3_I2C_SDA_Z_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 288 of file cxi2c.c.

References bitdelays, D, ERR_I2C_SDA_ST0, flags, 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 321 of file cxi2c.c.

References bitdelays, D, flags, 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 437 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(), mt9x001_pgm_detectsensor(), mt9x001_pgm_initsensor(), xi2c_read(), and xi2c_write().

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 1027 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_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_MAJOR, 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 695 of file cxi2c.c.

References burst_sizes, int, SEEK_CUR, SEEK_END, SEEK_SET, 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 608 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 752 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 668 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 894 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 146 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 585 of file cxi2c.c.

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

unsigned char i2c_enable[X3X3_I2C_CHANNELS *128] [static]

Definition at line 581 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 583 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 586 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 584 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 597 of file cxi2c.c.

Referenced by xi2c_init().


Generated on Fri Nov 28 00:07:42 2008 for elphel by  doxygen 1.5.1