最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What is the proper way for sending custom commands to Linux I2C driver? - Stack Overflow

programmeradmin3浏览0评论

I would like to:

  • initiate complex I2C transfer sequences with parameters
  • read results
  • do it from user space C code and/or command line/scripts

I2C driver (like other platform drivers), does not give us a way to implement custom IOCTL or read/write callbacks. "struct i2c_driver" has few callbacks like probe/remove, but no read/write/ioctl. There is "command" callback - "a ioctl like command that can be used to perform specific functions" but it is marked as "deprecated" in .html

IOCTL to I2C device, such as I2C_RDWR, are handled by drivers/i2c/i2c-dev.c and are not passed to my driver.

I can create sysfs subdirectory with multiple attributes for my I2C device, but that would violate the convention that there should be only one value per attribute (but I need multiple) and it should not be used to perform transfers (/).

May be I should use sysfs Binary Attributes? For example, NVMEM subsystem, used by drivers/misc/eeprom/at24.c, exposes entire EEPROM as a binary sysfs file for random reading/writing. May be I can use "loff_t pos" parameter for ssize_t (*read)(struct kobject *kobj, char *buffer, loff_t pos, size_t size); in struct bin_attribute to pass parameter(s), execute transfer and then print the result? Would it violate some convention?

Or I can create debugfs, which does not appear to have such strict limitations, but it sounds wrong to use debugfs for the core device functionality.

Or should I create a traditional chardev in parallel to I2C one?

Any other options? What is the best one?

Note: my question appears to be similar to accessing i2c platform device from userspace program, but that was specific to EEPROM.

发布评论

评论列表(0)

  1. 暂无评论