0

My scenario is the following: From an out-of-tree kernel module A, I want to create a new I²C device B when some event happens in A. From what I understand from the kernel I²C documentation, I would then expect that ->probe() function of the driver associated with the newly created I²C B to be called by the kernel, but that does not happen.

Module A code snippet:

static struct i2c_board_info board_info[] = {
    {
        I2C_BOARD_INFO("device_B", 0x70),
    },
};

// Create new I2C device when event happens
i2c_client = i2c_new_client_device(client->adapter, (struct i2c_board_info const *)&board_info);

Module B code snippet:

static int device_B_probe(struct i2c_client *client)
{
    pr_info("Probe called");
    return 0;
}

static const struct of_device_id device_B_of_match[] = {
    { .compatible = "device_B", },
    { }
};
MODULE_DEVICE_TABLE(of, device_B_of_match);

static const struct i2c_device_id device_B_id[] = {
    { "device_B", 0 },
    { }
};
MODULE_DEVICE_TABLE(i2c, device_B_id);

static struct i2c_driver device_B_driver = {
    .driver = {
        .name   = "device_B_name",
        .of_match_table = device_B_of_match,
    },
    .probe_new  = device_B_probe,
    .id_table   = device_B_id,
};
module_i2c_driver(device_B_driver);

Any ideas what could be wrong? There are no entries for device B in the device tree. I tried changing modules to in-tree modules but it makes no difference.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • There are two problematic places in the code. **1)** It's not clear what are you trying to supply as a second parameter to `i2c_new_client_device()`. It takes pointer to board info, and looks like you forgot the index in the array, i.e. `i2c_new_client_device(client->adapter, &board_info[0])` (note that you don't need to cast). – 0andriy Sep 09 '22 at 19:40
  • **2)** The output of the messages has to be flushed, which is done when either kernel has released the module or when the message contains `\n`. Try `pr_info("Probe called\n");`. – 0andriy Sep 09 '22 at 19:41
  • The problem is fixed. The name in the I2C_BOARD_INFO struct did not quite match the name in the .compatible member. – Ulrich Sørensen Sep 15 '22 at 14:06

0 Answers0