Changeset 6003:7f0e74d54fdb in roaraudio


Ignore:
Timestamp:
04/06/14 17:40:08 (5 years ago)
Author:
phi
Branch:
default
Message:

added support for block transpfer mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/driver_i2cdmx.c

    r6000 r6003  
    141141} 
    142142 
     143static inline int __i2c_read_block(struct driver_i2cdmx * self, size_t off, uint8_t * value); 
     144static inline int __i2c_write_block(struct driver_i2cdmx * self, size_t off, const uint8_t * value) { 
     145 union i2c_smbus_data data; 
     146 struct i2c_smbus_ioctl_data args = {.read_write = I2C_SMBUS_WRITE, .command = off, .size = I2C_SMBUS_I2C_BLOCK_BROKEN, .data = &data}; 
     147 struct roar_vio_sysio_ioctl ctl = {.cmd = I2C_SMBUS, .argp = &args}; 
     148 size_t i; 
     149 
     150 for (i = 0; i < sizeof(data.block); i++) 
     151  data.block[i] = 0xAF; 
     152 
     153 data.block[0] = I2C_SMBUS_BLOCK_MAX; 
     154 
     155 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) 
     156  data.block[i+1] = value[i]; 
     157 
     158 return roar_vio_ctl(&(self->vio), ROAR_VIO_CTL_SYSIO_IOCTL, &ctl); 
     159} 
     160 
    143161static inline int __i2c_command(struct driver_i2cdmx * self, uint8_t command) { 
    144162 int16_t ret; 
     
    318336} 
    319337 
     338static int __i2c_write_channel_block(struct driver_i2cdmx * self, size_t channel, const uint8_t * value) { 
     339 size_t bank, offset; 
     340 
     341 bank = channel/32; 
     342 offset = bank*32; 
     343 
     344 if ( __i2c_write(self, ADDR_BANK, bank) == -1 ) 
     345  return -1; 
     346 
     347 return __i2c_write_block(self, ADDR_DATA+channel-offset, value); 
     348} 
     349 
    320350static ssize_t        __vio_read    (struct roar_vio_calls * vio, void *buf, size_t count) { 
    321351 struct driver_i2cdmx * self; 
     
    346376 struct driver_i2cdmx * self; 
    347377 size_t i; 
    348  size_t endaddr; 
     378// size_t endaddr; 
     379 size_t todo; 
     380 size_t len; 
    349381 
    350382 if ( vio == NULL ) { 
     
    363395  return -1; 
    364396 
     397/* 
    365398 for (i = self->startaddr, endaddr = self->startaddr + self->len; i < endaddr; i++) 
    366399  if ( __i2c_write_channel(self, i, ((uint8_t*)buf)[i]) == -1 ) 
    367400   return -1; 
     401 */ 
     402 
     403 i = self->startaddr; 
     404 todo = self->len; 
     405 while (todo) { 
     406  if ( todo >= I2C_SMBUS_BLOCK_MAX ) { 
     407   if ( __i2c_write_channel_block(self, i, &(((const uint8_t*)buf)[i])) == -1 ) 
     408    return -1; 
     409   i += I2C_SMBUS_BLOCK_MAX; 
     410   todo -= I2C_SMBUS_BLOCK_MAX; 
     411  } else { 
     412   if ( __i2c_write_channel(self, i, ((uint8_t*)buf)[i]) == -1 ) 
     413    return -1; 
     414   i++; 
     415   todo--; 
     416  } 
     417 } 
    368418#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
    369419 memcpy(self->txtransfer+6, buf, sizeof(self->txtransfer)-6); 
Note: See TracChangeset for help on using the changeset viewer.