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

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

问题描述

我正在尝试使用 Raspberry Pi 作为开发套件,通过 I2C 总线配置 SAA6752HS 芯片(MPEG-2 编码器).直到我不得不在芯片的地址 0xC2 写入之前,这都是小菜一碟.对于这个任务,我必须使用一个 I2C 命令,它需要一个大小为 189 字节的有效负载.然后我偶然发现了 I2C 驱动程序内部的 32 字节限制,由 I2C_SMBUS_BLOCK_MAX 定义,位于/usr/include/linux/i2c.h.不可能强制使用不同的最大限制值.围绕 I2C lib 的所有内容最终都会进入函数 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天全站免登陆