Device Tree Overlay for I2C device with interrupt

Hi,

I’m developing a HID device which uses I2C bus. I have connected this device to I2C-2 bus on the BeagleBone Black. I can read registers with i2cdump, so the I2C connection is fine.
My device signals changes with an interrupt. The interrupt pin is connected to GPIO_49 (P9_23) on the BBB. I need to write a kernel module and I have started with device tree overlay.

My dts file is:

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    part-number = "BB-I2C2-SLIDER";
    version = "00A0";

    fragment@0 {
        target = <&i2c2>;
        __overlay__ {
            slider: slider@68 {
                compatible = "ei,slider";
                #address-cells = <0x1>;
                #size-cells = <0>;
                reg = <0x68>;
                interrupt-parent = <&gpio2>; 
                interrupts = <49 1>; 
            };
        };
    };
};

The probe function in the kernel module is:

static int slider_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    struct slider_device *slider;
    int ret;

    slider = devm_kzalloc(&client->dev, sizeof(*slider), GFP_KERNEL);
    if (!slider)
        return -ENOMEM;

    slider->client = client;
    slider->irq = client->irq;

    ret = request_irq(slider->irq, slider_irq_handler, IRQF_TRIGGER_RISING, "slider_iqr", 0);
    if (ret) {
        dev_err(&client->dev, "Failed to request IRQ\n");
        return ret;
    }
    i2c_set_clientdata(client, slider);

    dev_info(&client->dev, "Slider device probed\n");
    return 0;
}

But when I try to load the module I got:

[   67.850464] ------------[ cut here ]------------
[   67.855431] WARNING: CPU: 0 PID: 1145 at kernel/irq/irqdomain.c:525 irq_domain_associate+0x16c/0x1e8
[   67.867662] error: hwirq 0x31 is too large for :ocp:interconnect@48000000:segment@100000:target-module@ac000:gpio@0
[   67.879774] Modules linked in: ei_i2cdriver(O+) pru_rproc irq_pruss_intc pm33xx pruss pvrsrvkm(O) ti_eqep counter c_can_platform c_can can_dev evdev wkup_m3_ipc uio_pdrv_genirq uio cpufreq_dt spidev
[   67.899421] CPU: 0 PID: 1145 Comm: insmod Tainted: G           O      5.10.168-ti-r71 #1bullseye
[   67.908261] Hardware name: Generic AM33XX (Flattened Device Tree)
[   67.914421] [<c0110e08>] (unwind_backtrace) from [<c010c058>] (show_stack+0x10/0x14)
[   67.922215] [<c010c058>] (show_stack) from [<c0eed268>] (dump_stack+0x88/0x9c)
[   67.929477] [<c0eed268>] (dump_stack) from [<c013b964>] (__warn+0x88/0x128)
[   67.936475] [<c013b964>] (__warn) from [<c0ee39a8>] (warn_slowpath_fmt+0x78/0xac)
[   67.944007] [<c0ee39a8>] (warn_slowpath_fmt) from [<c01b6ea0>] (irq_domain_associate+0x16c/0x1e8)
[   67.952928] [<c01b6ea0>] (irq_domain_associate) from [<c01b78c0>] (irq_create_mapping_affinity+0x148/0x1dc)
[   67.962717] [<c01b78c0>] (irq_create_mapping_affinity) from [<c01b8704>] (irq_create_fwspec_mapping+0x1f8/0x348)
[   67.972941] [<c01b8704>] (irq_create_fwspec_mapping) from [<c01b88a4>] (irq_create_of_mapping+0x50/0x78)
[   67.982470] [<c01b88a4>] (irq_create_of_mapping) from [<c0c8e290>] (of_irq_get+0x84/0xc0)
[   67.990698] [<c0c8e290>] (of_irq_get) from [<c0ba2228>] (i2c_device_probe+0x150/0x2d0)
[   67.998664] [<c0ba2228>] (i2c_device_probe) from [<c09e0040>] (really_probe+0xf8/0x4e4)
[   68.006711] [<c09e0040>] (really_probe) from [<c09e0868>] (driver_probe_device+0xf4/0x1c8)
[   68.015017] [<c09e0868>] (driver_probe_device) from [<c09e0c18>] (device_driver_attach+0xa8/0xb0)
[   68.023933] [<c09e0c18>] (device_driver_attach) from [<c09e0cc4>] (__driver_attach+0xa4/0x138)
[   68.032586] [<c09e0cc4>] (__driver_attach) from [<c09ddc28>] (bus_for_each_dev+0x74/0xc0)
[   68.040804] [<c09ddc28>] (bus_for_each_dev) from [<c09df274>] (bus_add_driver+0x114/0x208)
[   68.049109] [<c09df274>] (bus_add_driver) from [<c09e184c>] (driver_register+0x88/0x118)
[   68.057240] [<c09e184c>] (driver_register) from [<c0ba18f8>] (i2c_register_driver+0x40/0xc0)
[   68.065724] [<c0ba18f8>] (i2c_register_driver) from [<c0102170>] (do_one_initcall+0x40/0x2cc)
[   68.074300] [<c0102170>] (do_one_initcall) from [<c01f4f40>] (do_init_module+0x44/0x254)
[   68.082433] [<c01f4f40>] (do_init_module) from [<c01f7b40>] (sys_finit_module+0xbc/0x120)
[   68.090651] [<c01f7b40>] (sys_finit_module) from [<c0100060>] (ret_fast_syscall+0x0/0x54)
[   68.098865] Exception stack(0xc2869fa8 to 0xc2869ff0)
[   68.103943] 9fa0:                   00000000 00000002 00000003 004b62d0 00000000 00000001
[   68.112159] 9fc0: 00000000 00000002 8e8ff200 0000017b 012a41d0 00000000 00000002 be870c74
[   68.120374] 9fe0: be870a98 be870a88 004aeb0d b6d20932
[   68.132425] ---[ end trace 2367cdcb0efedf5e ]---
[   68.145408] slider 2-0068: Failed to request IRQ
[   68.158996] slider: probe of 2-0068 failed with error -22

There is no problem if I comment the request_irq function and the module works fine (of course without interrupt handler).
I believe the problem lays in the device tree description of the interrupt. I tried different options with a few other GPIOs, interrupt controllers and still haven’t found any solution. Does anyone know what I’m doing wrong?

Are you sure that is the correct node, just out of thin air it seems like it should be <&gic> or something. Its been a while since looking at that. Try going way upstream and see what node is being used in the base .dtsi. FYI, do this on a SD card. Its much easier to fix than trying to mount emmc.

are you sure? P9_23 is GPIO1_17…

                interrupt-parent = <&gpio1>; 
                interrupts = <17 1>; 

Regards,

1 Like

Oh… I knew it must be some obvious mistake! And it was very obvious! Thank you!