2

I have two I2C devices I want to connect to my Linux device. A temperature sensor, TMP117, worked fine by writing it to the /sys/bus/i2c/devices/i2c-x/new_device. In addition, I want to add an accelerometer, ADXL343. However, when using the same method as with the TMP117, I receive an error in dmesg that the GPIO for the interrupt is not found. This also affects a GPIO extender, which requires the interrupt signal for my application.

Is it possible to dynamically add I2C devices with additional signals, such as interrupts?

2 Answers 2

2

As you can read, Linux offers 4 methods for instantiating I2C devices.

Since the sysfs interface offers only 2 attribute files (new_device and delete_device) and the new_device takes 2 parameters only (the name of the I2C device and the address of the I2C device), I am afraid that you just cannot fiddle the IRQ from userland.

However, since the i2c_board_info structure makes provision for some IRQ setting I suggest you prefer declaring the I2C device by bus number as described in Method 1a (cf first link) enabling you to precisely define the structure like in the example given:

static struct i2c_board_info h4_i2c_board_info[] __initdata = {
    {
        I2C_BOARD_INFO("isp1301_omap", 0x2d),
        .irq        = OMAP_GPIO_IRQ(125),
    },
...
};
2
  • Okay, so if I understand this correctly: 1. I create a i2c_board_info struct containing the information for my device. 2. I pass this struct into the i2c_new_client_device function. Would I then be able to compile and run this program? And then the device should be available to me? Commented Jan 18, 2023 at 13:17
  • 1
    Wow... yet another hidden nugget of wisdom in the kernel documentation! Thanks for this :) Commented Mar 10 at 23:19
1

From https://www.kernel.org/doc/Documentation/i2c/instantiating-devices follows, that you can only pass an I²C address as parameter. So, how would the kernel know on which GPIO line that interrupt line is connected?

So, complex drivers that encompass more hardware than just an I²C device cannot be used this way.

The "correct" way would probably writing a devicetree entry (1b from above document) if you know where the hardware sits at boot time (or even if you don't – nowadays, you can modify the devicetree at runtime). If that's not an option, you'd need to write a kernel module.

However, good news: Michael Hennerich of ADI (nice guy, buy him a coffee if you meet him) has written the adxl34x driver (included in upstream linux), so this really just boils down to telling your kernel (again, via devicetree) at which address to find your ADXL34x on the I²C bus, and on which interrupt lines to listen to.

2
  • Thanks, it's an intel platform, so it is using ACPI. Adding the device to the ACPI namespace is beyond my knowledge. Commented Jan 18, 2023 at 12:52
  • read the document I linked to – it has a section about ACPI, which refers you to specific documentation on how to do it on ACPI. Commented Jan 18, 2023 at 12:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.