为什么I2C_SMBUS_BLOCK_MAX限制为32个字节? [英] Why I2C_SMBUS_BLOCK_MAX is limited to 32 bytes?

查看:315
本文介绍了为什么I2C_SMBUS_BLOCK_MAX限制为32个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Raspberry Pi作为开发套件通过I2C总线配置SAA6752HS芯片(MPEG-2编码器)。直到我不得不在芯片的地址0xC2上写之前,这简直是小菜一碟。对于此任务,我必须使用I2C命令,该命令期望有效载荷大小为189字节。因此,我偶然发现了I2C驱动程序内部的32字节限制,该限制由/usr/include/linux/i2c.h中的I2C_SMBUS_BLOCK_MAX定义。不能强制使用不同的最大极限值。 I2C库周围的所有内容最终都进入函数i2c_smbus_access,并且任何超过32个字节的请求都会使ioctl返回-1。到目前为止,我还不知道如何调试它。

I'm trying to configure a SAA6752HS chip (a MPEG-2 encoder) through I2C bus using a Raspberry Pi as a development kit. It was a piece of cake until I had to write at the address 0xC2 of the chip. For this task, I have to use an I2C command that expects a payload of size 189 bytes. So then I stumbled upon a 32 bytes limitation inside the I2C driver, defined by I2C_SMBUS_BLOCK_MAX, in /usr/include/linux/i2c.h. It is not possible to force different values of max limit. Everything around I2C lib end up into the function i2c_smbus_access and any request with more then 32 bytes makes ioctl returns -1. I have no idea how to debug it so far.

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);
}

考虑到有设备,我不明白为什么会有这样的限制需要超过32字节的有效负载数据才能工作(SAA6752HS是这样的示例)。

I can't understand why there is such limitation, considering that there are devices that require more than 32 bytes of payload data to work (SAA6752HS is such an example).

有没有一种方法可以克服这种限制而无需重写新的驱动程序?

Are there a way to overcome such limitation without rewrite a new driver?

请先谢谢您。

推荐答案

以下是Linux i2c界面的文档: https://www.kernel.org/doc/Documentation/i2c/dev-interface

Here's the documentation for the Linux i2c interface: https://www.kernel.org/doc/Documentation/i2c/dev-interface

在最简单的级别上,您可以使用 ioctl(I2C_SLAVE)设置从站地址,并使用 write 系统调用编写命令。像这样的东西:

At the simplest level you can use ioctl(I2C_SLAVE) to set the slave address and the write system call to write the command. Something like:

i2c_write(int file, int address, int subaddress, int size, char *data) {
    char buf[size + 1];               // note: variable length array
    ioctl(file, I2C_SLAVE, address);  // real code would need to check for an error
    buf[0] = subaddress;              // need to send everything in one call to write
    memcpy(buf + 1, data, size);      // so copy subaddress and data to a buffer 
    write(file, buf, size + 1); 
}

这篇关于为什么I2C_SMBUS_BLOCK_MAX限制为32个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆