Tool/software: Linux
Hi,
the usb hub 2517 supports only smbus block read/write.
i am using below application, but write/read not happning.
/*
* Simple I2C example
*
* Copyright 2017 Joel Stanley <joel@jms.id.au>
*
* 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 2 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <err.h>
#include <errno.h>
#include <linux/types.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
int size, union i2c_smbus_data *data)
{
struct i2c_smbus_ioctl_data args;
args.read_write = read_write;
args.command = command;
args.size = size;
args.data = data;
return ioctl(file,I2C_SMBUS,&args);
}
static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
{
union i2c_smbus_data data;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_BYTE_DATA,&data))
return -1;
else
return 0x0FF & data.byte;
}
static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
__u8 *values)
{
union i2c_smbus_data data;
int i;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_BLOCK_DATA,&data))
return -1;
else {
for (i = 1; i <= data.block[0]; i++)
values[i-1] = data.block[i];
return data.block[0];
}
}
static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
__u8 length, __u8 *values)
{
union i2c_smbus_data data;
int i;
if (length > 32)
length = 32;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_BLOCK_DATA, &data);
}
int main(int argc, char **argv)
{
uint8_t data=0x00, addr = 0x00,reg = 0x00;
__u8 read_data[32]={0x00},write_data[32]={0x00},offset=0;
const char *path = argv[1];
int file, rc,i=0,r_w=0;
if (argc == 1)
errx(-1, "path [i2c address] [register]");
if (argc > 2)
addr = strtoul(argv[2], NULL, 0);
if (argc > 3)
reg = strtoul(argv[3], NULL, 0);
file = open(path, O_RDWR);
if (file < 0)
err(errno, "Tried to open '%s'", path);
rc = ioctl(file, I2C_SLAVE, addr);
if (rc < 0)
{
printf("slave not detected\n");
close(file);
return 0;
}
printf("please enter 0/1 for read/write \n");
scanf("%d",&r_w);
if(r_w==1)
{
for(i=0;i<32;i++)
{
write_data[i] = (__u8)i;
}
rc=i2c_smbus_write_block_data(file,reg,8,write_data);
if(rc<0)
printf("write failed\n");
}
//data = i2c_smbus_read_byte_data(file, reg);
//printf("%s: device 0x%02x at address 0x%02x: 0x%02x\n", path, addr, reg, data);
else
{
rc=i2c_smbus_read_block_data(file, reg, read_data);
//rc=i2c_smbus_read_byte_data(file,reg);
if(rc<0)
{
printf("read failed\n");
}
else
{
// printf("Value returned from read%x\n",rc);
for(i=0;i<32;i++)
printf("%x ",read_data[i]);
printf("\n");
}
}
close(file);
}
///opt/sdk_ti/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc /opt/sdk_ti/hub_config.c -o hub_block_read_2c
//www.linux-mag.com/.../