Example #1
0
void i2c_stop(i2c_connection conn) {
  struct i2c_state *c = (struct i2c_state *) conn;
  dprintf(("stop mcs %lx\n", HWREG(c->base + I2C_O_MCS)));
  if (I2CMasterBusBusy(c->base)) {
    i2c_command(c, I2C_MASTER_CMD_BURST_SEND_FINISH);
  }
}
Example #2
0
File: i2c_gvc.c Project: 7LK/McWRT
/*#---------------------------------------------------------------------------
 *#
 *# FUNCTION NAME: i2c_writeread
 *#
 *# DESCRIPTION  :
 *#
 *# PARAMETERS   :
 *#
 *# RETURN       :
 *#
 *#---------------------------------------------------------------------------
 */
int i2c_writeread( unsigned char  slave
                 , unsigned char* wbuf
                 , unsigned char  wlen
                 , unsigned char* rbuf
                 , unsigned char  rlen
                 )
{
    return ( i2c_command( slave, wbuf, wlen, rbuf, rlen ) );
}   /* i2c_writeread */
Example #3
0
uint8_t i2c_read_byte(i2c_connection conn, enum i2c_ack_type ack_type) {
  struct i2c_state *c = (struct i2c_state *) conn;
  if (c->first) {
    /* First byte is buffered since the time of start. */
    c->first = 0;
  } else {
    i2c_command(c, ack_type == I2C_ACK ? I2C_MASTER_CMD_BURST_RECEIVE_CONT
                                       : I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
  }
  return (uint8_t) I2CMasterDataGet(c->base);
}
Example #4
0
enum i2c_ack_type i2c_start(i2c_connection conn, uint16_t addr,
                            enum i2c_rw mode) {
  struct i2c_state *c = (struct i2c_state *) conn;
  /* CC3200 does not support 10 bit addresses. */
  if (addr > 0x7F) return I2C_ERR;
  MAP_I2CMasterSlaveAddrSet(c->base, addr, (mode == I2C_READ));
  c->first = 1;
  if (mode == I2C_WRITE) {
    /* Start condition is set only with data to send. */
    return I2C_ACK;
  } else {
    c->first = 1;
    return i2c_command(c, I2C_MASTER_CMD_BURST_RECEIVE_START);
  }
}
Example #5
0
File: i2c_gvc.c Project: 7LK/McWRT
/*#---------------------------------------------------------------------------
 *#
 *# FUNCTION NAME: i2c_ioctl
 *#
 *# DESCRIPTION  : Main device API: ioctl's to write/read
 *#                to/from i2c registers
 *#
 *# PARAMETERS   : *inode: reference to inode
 *#                *filp : reference to file pointer
 *#                cmd   : command to be executed during the ioctl call
 *#                arg   : pointer to a structure with the data???
 *#
 *# RETURN       : result of the ioctl call
 *#
 *#---------------------------------------------------------------------------
 */
static int i2c_ioctl( struct inode *inode
                    , struct file *file
                    , unsigned int cmd
                    , unsigned long arg
                    )
{
    /* the acme ioctls */
    I2C_DATA i2cdata;
    int RetVal = EI2CNOERRORS;

    if ( _IOC_TYPE( cmd ) != ETRAXI2C_IOCTYPE )
    {
        return ( -EINVAL );
    }

    switch ( _IOC_NR( cmd ) )
    {
    case I2C_WRITEREG:
        /* write to an i2c slave */
        RetVal = i2c_writereg( I2C_ARGSLAVE( arg )
                             , I2C_ARGREG( arg )
                             , I2C_ARGVALUE( arg )
                             );
        break;

    case I2C_READREG:
        RetVal = i2c_readreg( I2C_ARGSLAVE( arg ), I2C_ARGREG( arg ) );
        break;

    /* New functions added by GVC */
    case I2C_READ:
        copy_from_user( (char*)&i2cdata, (char*)arg, sizeof( I2C_DATA ) );
        {
            int RetryCntr = MAXRETRIES;

            do
            {
                RetVal = i2c_command( i2cdata.slave
                                    , NULL
                                    , 0
                                    , i2cdata.rbuf
                                    , i2cdata.rlen
                                    );
             } while ( ( EI2CNOERRORS != RetVal )
                     &&( --RetryCntr )
                     );
        }
        copy_to_user( (char*)arg, (char*)&i2cdata, sizeof( I2C_DATA ) );
        break;

    case I2C_WRITE:
        copy_from_user( (char*)&i2cdata, (char*)arg, sizeof( I2C_DATA ) );
        {
            int RetryCntr = MAXRETRIES;

            do
            {
                RetVal = i2c_command( i2cdata.slave
                                    , i2cdata.wbuf
                                    , i2cdata.wlen
                                    , NULL
                                    , 0
                                    );
             } while ( ( EI2CNOERRORS != RetVal )
                     &&( --RetryCntr )
                     );
        }
        break;

    case I2C_WRITEREAD:
        copy_from_user( (char*)&i2cdata, (char*)arg, sizeof( I2C_DATA ) );
        {
            int RetryCntr = MAXRETRIES;

            do
            {
                RetVal = i2c_command( i2cdata.slave
                                    , i2cdata.wbuf
                                    , i2cdata.wlen
                                    , i2cdata.rbuf
                                    , i2cdata.rlen
                                    );
             } while ( ( EI2CNOERRORS != RetVal )
                     &&( --RetryCntr )
                     );
        }
        copy_to_user( (char*)arg, (char*)&i2cdata, sizeof( I2C_DATA ) );
        break;

    default:
        RetVal = -EINVAL;
    }

    return ( -RetVal );
}   /* i2c_ioctl */
Example #6
0
File: i2c_gvc.c Project: 7LK/McWRT
/*#---------------------------------------------------------------------------
 *#
 *# FUNCTION NAME: i2c_write
 *#
 *# DESCRIPTION  :
 *#
 *# PARAMETERS   :
 *#
 *# RETURN       :
 *#
 *#---------------------------------------------------------------------------
 */
int i2c_write( unsigned char slave, unsigned char* wbuf, unsigned char wlen )
{
    return ( i2c_command( slave, wbuf, wlen, NULL, 0 ) );
}   /* i2c_write */
Example #7
0
File: i2c_gvc.c Project: 7LK/McWRT
/*#---------------------------------------------------------------------------
 *#
 *# FUNCTION NAME: i2c_read
 *#
 *# DESCRIPTION  :
 *#
 *# PARAMETERS   :
 *#
 *# RETURN       :
 *#
 *#---------------------------------------------------------------------------
 */
int i2c_read( unsigned char slave, unsigned char* rbuf, unsigned char rlen )
{
    return ( i2c_command( slave, NULL, 0, rbuf, rlen ) );
}   /* i2c_read */