Setting I2C Clock Stretch Timeout and Baudrate with i2c-dev

Open
#4,336 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, linux

Research direction

Start by reading i2c-bcm2835.c and the i2c-dev interface, then inspect how the BSC.CLKT register and TOUT value currently control clock stretching. Consider how the proposed I2C_CLOCK_TIMEOUT and I2C_BAUDRATE ioctls would fit the existing interfaces and update the driver. Done means both settings can be changed at application level with the requested ranges and behavior.

Written by the indexing model from the issue text.

Description

This idea came to my mind after spending several days fighting against an I2C clock stretch timeout issue.

Currently the I2C Clock Stretch Timeout is set to 35ms in i2c-bcm2835.c which is not sufficient for applications requiring a very long processing time (e.g. several seconds). Besides even the max value (65535 i2c clock cycles) is not sufficient in some cases, as it's "only" 655ms @ 100kbits : in that case the only workaround is to disable it by setting it to 0.

I found a way to fix it (by directly addressing the BSC.CLKT register and setting TOUT to 0 to disable the clock stretch timeout), but thought it would be much simpler to do it at higher level using ioctl commands.

In the same idea, it would be nice to set the I2C baudrate at application level using ioctl , instead of doing it in boot/config.txt

Here is my proposal:

  • add 1 new parameter I2C_CLOCK_TIMEOUT in i2c-dev to set the clock stretch timeout - value between 0 to 65535
  • add 1 new parameter I2C_BAUDRATE in i2c-dev to set the I2C baudrate
  • update i2c-bcm2835 accordingly

What do you think?
Please note I'm discovering the raspberry (and linux in general) so I may be missed some obvious reasons that prevent to do these changes.

Dominant language
C
Stars
13.2k
Forks
5.5k
Avg merge
2d 21h
Merged PRs (30d)
21

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/linux

All issues in raspberrypi/linux

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.