MK27
Posts: 6
Joined: Sun Jan 12, 2014 4:17 pm

Unable to use I2C0 with > 3.17.7 kernel

Sat Oct 24, 2015 12:47 pm

This is presumably unreproducible for others, but I thought I'd ask anyway in case anyone here has an idea about what might (have) cause(d) the problem.

The Pi in question is a B from a few years ago, I believe made by RS. I've soldered pins onto what is usually referred to as the P5 header but is labelled P6 on my board.

Using the latest kernel (4.1.11+) and firmware (from https://github.com/raspberrypi/firmware), and this in `config.txt`:

Code: Select all

    dtparam=i2c=on
    dtparam=i2c0=on
Niether `/dev/i2c-0` nor `/dev/i2c-1` are available. The following does not work either:

- Removing the `i2c0` line to just enable i2c-1.
- Disabling device tree (`device_tree=`) and using the old method of inserting the i2c-dev module.

I'm sure at some point device tree did work with a stock kernel, at least for i2c-1. However, it is i2c-0 that's important to me.

The last kernel that will work (same firmware) is 3.17.7; I compiled this with the I2C module built-in and currently it boots with both `/dev/i2c-1` and `/dev/i2c-0` listed, although the later doesn't really work: `i2cdetect 0` will probe, but show nothing connected until I enable the alt functions.

Code: Select all

#include <bcm2835.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void on () {
        bcm2835_gpio_fsel(0, BCM2835_GPIO_FSEL_INPT);
        bcm2835_gpio_fsel(1, BCM2835_GPIO_FSEL_INPT);

        bcm2835_gpio_fsel(28, BCM2835_GPIO_FSEL_ALT0);
        bcm2835_gpio_set_pud(28, BCM2835_GPIO_PUD_UP);

        bcm2835_gpio_fsel(29, BCM2835_GPIO_FSEL_ALT0);
        bcm2835_gpio_set_pud(29, BCM2835_GPIO_PUD_UP);
}

int main (void) {
        bcm2835_init();
        on();
        bcm2835_close();
        return 0;
}
After which everything is fine. Using the same configuration (I did not do anything special WRT I2C other than building the module in) on a 3.18 or subsequent kernel fails.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Unable to use I2C0 with > 3.17.7 kernel

Sat Oct 24, 2015 12:52 pm

Use device tree. Device tree will automatically load i2c_bcm2708. You will need to manually load i2c_dev, perhaps by adding the line i2c-dev to /etc/modules.

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Unable to use I2C0 with > 3.17.7 kernel

Sat Oct 24, 2015 12:55 pm

joan wrote:Use device tree. Device tree will automatically load i2c_bcm2708. You will need to manually load i2c_dev, perhaps by adding the line i2c-dev to /etc/modules.
That piece is somewhat broken in the current 4.1.11+ kernel. I'm having to modprobe i2c-bcm2708 on my system with an i2c RTC.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

MK27
Posts: 6
Joined: Sun Jan 12, 2014 4:17 pm

Re: Unable to use I2C0 with > 3.17.7 kernel

Sat Oct 24, 2015 1:40 pm

joan wrote:Use device tree. Device tree will automatically load i2c_bcm2708. You will need to manually load i2c_dev, perhaps by adding the line i2c-dev to /etc/modules.
Cheers. I was sure I had tried this -- `modprobe i2c-dev` all by itself does not work, and as per Dougie's comment i2c_bcm2708 is not loaded automagically.

But in any case that works, at least with stock 4.1.11+.

MK27
Posts: 6
Joined: Sun Jan 12, 2014 4:17 pm

Re: Unable to use I2C0 with > 3.17.7 kernel

Sat Oct 24, 2015 1:52 pm

Ouch -- now here's a tricky thing.

What I'd tried before wasn't `modprobe i2c_bcm2708`, it was `modprobe i2c_bcm2835`.

The stock kernel doesn't have this (at least, not as a .ko) and will return an error. But in my custom config I had it set that way (the option is I2C_BCM2835).

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Unable to use I2C0 with > 3.17.7 kernel

Sat Oct 24, 2015 2:20 pm

If I were building a custom kernel it would have spidev and all the I2C stuff built in, not as loadable modules (I'd keep things like the RTC drivers as modules). I've never fathomed why the RPF kernel builders didn't do that stuff.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Interfacing (DSI, CSI, I2C, etc.)”