Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access to I2C_SLAVE_FORCE #1

Closed
wants to merge 2 commits into from

Conversation

fordsfords
Copy link

Hello. Thank you very much for writing this library! I hope you accept this pull request.

Short version: I added an optional parameter to init() and open() to tell the device select function to use "I2C_SLAVE_FORCE" instead of "I2C_SLAVE". Existing code should be unaffected. Test code is included.

Long version:

I have a C.H.I.P board (see https://getchip.com) and wanted to be able to access the power controller (AXP209) on bus 0. However, this library, and the original smbus library it was based on, says that the device is busy. This is presumably because the kernel is using it.

Imagine my surprise when the i2c command-line tools are able to access it just fine. A bit of research shows why: i2c command-line tools use I2C_SLAVE_FORCE, while the libraries use "I2C_SLAVE".

I can understand why the library would not use _FORCE: it is dangerous. The kernel keeps track of the state of the device, and if you change that state out from under the kernel, bad things can happen, up to and including panicking the kernel.

I can also understand why the i2c tools use _FORCE: if an administrator, who presumably knows what he is doing, needs to diddle something, he needs a tool to do it. Fortunately, the administrator needs root access to do it.

But so does a python programmer. I.e. adding the ability to use _FORCE with this library doesn't make the overall system any more vulnerable or dangerous. Since python is a widely-used language by administrators, I think the library should grant the same access as the command-line tools.

So I added the "dangerous" flag to both init() and open(). :-) It is an optional parameter, so existing code should not be affected. I called it "dangerous" instead of "force" because in the future we may find other restrictions which are generally a good idea to enforce, but want a bypass for those who like to live on the edge.

Since I don't have an RPi, I couldn't run the test code. So I wrote an additional test program which works on C.H.I.P. That program demonstrates its use.

Steve

Added dangerous flag to open.  Also added test program (for NTC’s CHIP).
@xtacocorex
Copy link

I don't believe there are any i2c devices owned by the kernel on the Raspberry Pi unless you explicitly add an RTC.

@fordsfords
Copy link
Author

Ping?

@ladyada
Copy link
Member

ladyada commented May 4, 2021

hiya thanks - this is very cool hacking :) closing this as we cannot merge because for our user we recommend to please disable the kernel interface... its really not a good idea to prod I2C chips that the kernel is going to be using at random times.

@ladyada ladyada closed this May 4, 2021
@adafruit adafruit locked as resolved and limited conversation to collaborators May 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants