Jetpack 5.0.2 i2c-mux-pca954x.c skip-mux-detect is not working

I am using a custom board based on the AGX Xavier.

Currently, I am trying to ignore i2c write execution by using the skip-mux-detect option in DT.

However, even when using the option, the i2c write still executes, printing ‘probe failed’.

When I checked the pca954x_probe function in the i2c-mux-pca954x.c code, I found the following sequence:

In Jetpack 4, it was as follows:

  1. goto pca954x_probe_skip_detect

  2. i2c_smbus_write_byte

  3. pca954x_probe_skip_detect:

I confirmed that starting with Jetpack 5, it has changed as follows:

  1. goto pca954x_probe_skip_detect
  2. pca954x_probe_skip_detect:
  3. pca954x_init
    1. i2c_smbus_write_byte

I am currently using this with the execution order changed, just like in Jetpack 4.

However, I have a few questions.

I am curious about the reason for changing the execution order in Jetpack 5 and whether this change was intentional.

Also, please confirm if there have been any related issues.

Jetpack 4.6.5

fskip = of_property_read_bool(client->dev.of_node,        
"skip_mux_detect");

if (fskip) {

    dev_info(&client->dev, "device detect skipped.\\n");

    goto pca954x_probe_skip_detect;

}



/\* Write the mux register at addr to verify

 \* that the mux is in fact present. This also

 \* initializes the mux to disconnected state.

 \*/

if (i2c_smbus_write_byte(client, 0) < 0) {

    dev_warn(&client->dev, "probe failed\\n");

    return -ENODEV;

}
pca954x_probe_skip_detect:
match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev);

if (match)

    data->chip = of_device_get_match_data(&client->dev);

else

    data->chip = &chips\[id->driver_data\];



data->last_chan = 0;           /\* force the first selection \*/



idle_disconnect_dt = of_node &&

    of_property_read_bool(of_node, "i2c-mux-idle-disconnect");

Jetpack 5.0.2

fskip = of_property_read_bool(client->dev.of_node,

        "skip_mux_detect");

if (fskip) {

    dev_info(&client->dev, "device detect skipped.\\n");

    goto pca954x_probe_skip_detect;

}
pca954x_probe_skip_detect:
data->chip = device_get_match_data(dev);

if (!data->chip)

    data->chip = &chips\[id->driver_data\];



data->last_chan = 0;           /\* force the first selection \*/



if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) {

    struct i2c_device_identity id;



    ret = i2c_get_device_id(client, &id);

    if (ret && ret != -EOPNOTSUPP)

        return ret;



    if (!ret &&

        (id.manufacturer_id != data->chip->id.manufacturer_id ||


         id.part_id != data->chip->id.part_id)) {

        dev_warn(dev, "unexpected device id %03x-%03x-%x\\n",

             id.manufacturer_id, id.part_id,

             id.die_revision);

        return -ENODEV;

    }

}



data->idle_state = MUX_IDLE_AS_IS;

if (device_property_read_u32(dev, "idle-state", &data->idle_state)) {

    if (device_property_read_bool(dev, "i2c-mux-idle-disconnect"))

        data->idle_state = MUX_IDLE_DISCONNECT;

}



/\*

 \* Write the mux register at addr to verify

 \* that the mux is in fact present. This also

 \* initializes the mux to a channel

 \* or disconnected state.

 \*/
ret = pca954x_init(client, data);

if (ret < 0) {

    dev_warn(dev, "probe failed\\n");

    goto fail_cleanup;

 }

I would like to suspect the change is cause by kernel regression.

Maybe confirm with vendor the the detail.

Thanks

Thank you for your reply. I would like to confirm if I have understood correctly. Are you saying that the change in execution order is more likely an unintended kernel regression error rather than an intentional design change, and that NVIDIA has not yet identified the exact cause?

If so, could you let me know if there is a way to obtain confirmation from the driver developer or vendor, or if there are any relevant bug tracking systems or patches available for us to check?

Yes, suppose it could be some kernel change cuase the behavior different.

Thanks

Is there no related patch? I am wondering if users have to modify it themselves.

Do you compare the pca954x driver is totally same?

Yes, I did not modify the i2c-mux-pca954x.c code initially provided by NVIDIA. What I am curious about is whether there was a behavioral change in the i2c-mux-pca954x code when upgrading from JP4 to JP5.

As a result, i2c_write was executed regardless of the skip-mux-detect option, causing a probe failed error. Upon verification, I confirmed that the pca954x_init function was added starting with JP5, and its execution location was changed.

I would like to know if NVIDIA experienced any related bugs, and if so, if a patch is available.

This driver is from upstream instead of from nvidia.

I mean do you compare these two version if any different?

The i2c-mux-pca954x.c driver itself is indeed from the upstream. However, the skip_mux_detect property is not present in the upstream and was added by NVIDIA via the downstream. I personally checked the mainline source code and confirmed that it is not there.

What I want to know is: Is this kernel regression (where skip_mux_detect goto becomes a no-op in JP4→JP5) already identified as a known bug by NVIDIA, or are there any related tracking or patches available?

OK,

Looks like it could be below change cause the behavior.

This modification for Jetson reference camera board. If your use case don’t like that you may need to customized it.

Thanks

commit 6bc0e3817cdd5adfae420a9058af8a67f5fa5626
Author: devang kubavat <dkubavat@nvidia.com>
Date:   Wed Jan 6 17:57:25 2021 +0530

    i2c: mux: pca954x: Add controls for camera boards

    - Add structs for platform mode and platform data
    - Add vcc/vcc-pullup regulator control
    - Add skip detection control
    - Add force start address control

    Bug 1856401
    Bug 200428906
    Bug 200417030

    Change-Id: Ic976cd42c9e5eee3de238f7090636258aa74b6fc
    Signed-off-by: Devang Kubavat <dkubavat@nvidia.com>
    (cherry picked from commit 708624e7a77e09c008ee4f707fb84de03e5c9e0b)
    Reviewed-on: http://git-master/r/1470617
    Reviewed-on: https://git-master.nvidia.com/r/1769839
    Reviewed-on: https://git-master.nvidia.com/r/c/linux-5.9/+/2466769
    Reviewed-by: Bitan Biswas <bbiswas@nvidia.com>
    Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
    Tested-by: Ashwini Purkar <apurkar@nvidia.com>
    Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 4ad665757dd8..14de5761c3f9 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -45,11 +45,30 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <dt-bindings/mux/mux.h>
+#include <linux/regulator/consumer.h>

 #define PCA954X_MAX_NCHANS 8

 #define PCA954X_IRQ_OFFSET 4

+/* Per channel initialisation data:
+ * @adap_id: bus number for the adapter. 0 = don't care
+ * @deselect_on_exit: set this entry to 1, if your H/W needs deselection
+ *                    of this channel after transaction.
+ *
+ */
+struct pca954x_platform_mode {
+   int     adap_id;
+   unsigned int    deselect_on_exit:1;
+   unsigned int    class;
+};
+
+/* Per mux/switch data, used with i2c_register_board_info */
+struct pca954x_platform_data {
+   struct pca954x_platform_mode *modes;
+   int num_modes;
+};
+
 enum pca_type {
    pca_9540,
    pca_9542,
@@ -88,6 +107,8 @@ struct pca954x {
    struct irq_domain *irq;
    unsigned int irq_mask;
    raw_spinlock_t lock;
+   struct regulator *vcc_reg;
+   struct regulator *pullup_reg;
 };

 /* Provide specs for the PCA954x types we know about */
@@ -416,11 +437,14 @@ static int pca954x_probe(struct i2c_client *client,
 {
    struct i2c_adapter *adap = client->adapter;
    struct device *dev = &client->dev;
+   struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev);
    struct gpio_desc *gpio;
    struct i2c_mux_core *muxc;
    struct pca954x *data;
-   int num;
+   int num, force, class;
    int ret;
+   bool fskip = false;
+   int force_bus = 0;

    if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
        return -ENODEV;
@@ -434,6 +458,40 @@ static int pca954x_probe(struct i2c_client *client,
    i2c_set_clientdata(client, muxc);
    data->client = client;

+   /* Get regulator pointer for pca954x vcc */
+   data->vcc_reg = devm_regulator_get(&client->dev, "vcc");
+   if (PTR_ERR(data->vcc_reg) == -EPROBE_DEFER)
+       data->vcc_reg = NULL;
+   else if (IS_ERR(data->vcc_reg)) {
+       ret = PTR_ERR(data->vcc_reg);
+       dev_err(&client->dev, "vcc regualtor get failed, %d\n", ret);
+       return ret;
+   }
+
+   /* Get regulator pointer for pca954x vcc-pullup */
+   data->pullup_reg = devm_regulator_get(&client->dev, "vcc-pullup");
+   if (IS_ERR(data->pullup_reg)) {
+       dev_info(&client->dev, "vcc-pullup regulator not found\n");
+       data->pullup_reg = NULL;
+   }
+
+   /* Enable vcc regulator for pca954x */
+   if (data->vcc_reg) {
+       ret = regulator_enable(data->vcc_reg);
+       if (ret < 0) {
+           dev_err(&client->dev, "failed to enable vcc\n");
+           return ret;
+       }
+   }
+   /* Enable vcc-pullup regulator for pca954x */
+   if (data->pullup_reg) {
+       ret = regulator_enable(data->pullup_reg);
+       if (ret < 0) {
+           dev_err(&client->dev, "failed to enable vcc-pullup\n");
+           return ret;
+       }
+   }
+
    /* Reset the mux if a reset GPIO is specified. */
    gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
    if (IS_ERR(gpio))
@@ -445,10 +503,33 @@ static int pca954x_probe(struct i2c_client *client,
        udelay(1);
    }

+
+   if (of_property_read_u32(client->dev.of_node, "force_bus_start",
+           &force_bus)) {
+       dev_info(&client->dev, "%s: could not read force bus number\n",
+           __func__);
+   } else {
+       if (force_bus > 0) {
+           dev_info(&client->dev,
+               "%s: forcing device bus number, start %i.\n",
+               __func__, force_bus);
+       }
+   }
+
+   fskip = of_property_read_bool(client->dev.of_node,
+           "skip_mux_detect");
+   if (fskip) {
+       dev_info(&client->dev, "device detect skipped.\n");
+       goto pca954x_probe_skip_detect;
+   }
+
+pca954x_probe_skip_detect:
    data->chip = device_get_match_data(dev);
    if (!data->chip)
        data->chip = &chips[id->driver_data];

+   data->last_chan = 0;           /* force the first selection */
+
    if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) {
        struct i2c_device_identity id;

@@ -490,7 +571,29 @@ static int pca954x_probe(struct i2c_client *client,

    /* Now create an adapter for each channel */
    for (num = 0; num < data->chip->nchans; num++) {
-       ret = i2c_mux_add_adapter(muxc, 0, num, 0);
+       bool idle_disconnect_pd = false;
+
+       force = 0;            /* dynamic adap number */
+       class = 0;            /* no class by default */
+       if (force_bus)
+           force = force_bus + num;
+
+       if (pdata) {
+           if (num < pdata->num_modes) {
+               /* force static number */
+               force = pdata->modes[num].adap_id;
+               class = pdata->modes[num].class;
+           } else
+               /* discard unconfigured channels */
+               break;
+           idle_disconnect_pd = pdata->modes[num].deselect_on_exit;
+       }
+       if (client->dev.of_node)
+           idle_disconnect_pd = true;
+
+       data->idle_state |= (idle_disconnect_pd ||
+                  data->idle_state) << num;
+       ret = i2c_mux_add_adapter(muxc, force, num, class);
        if (ret)
            goto fail_cleanup;
    }

Yes, that is correct. To use the skip_mux_detect option properly, the function execution order must be as follows:

+       goto pca954x_probe_skip_detect;
+   }
//////////////////////////////////
	ret = pca954x_init(client, data);
	if (ret < 0) {
		dev_warn(dev, "probe failed\n");
		goto fail_cleanup;
	}
////////////////////////
+pca954x_probe_skip_detect:
    data->chip = device_get_match_data(dev);
    if (!data->chip)
        data->chip = &chips[id->driver_data];

The code you sent operates as follows, causing a no-op issue:

+       goto pca954x_probe_skip_detect;
+   }
+
+pca954x_probe_skip_detect:
    data->chip = device_get_match_data(dev);
    if (!data->chip)
        data->chip = &chips[id->driver_data];
	    ...

//////////////////////
ret = pca954x_init(client, data);
if (ret < 0) {
		dev_warn(dev, "probe failed\n");
		goto fail_cleanup;
	}
/////////////////////

I will assume that this issue arose during the downstream process on NVIDIA’s end.

Thank you for your reply.

Upon verification, applying the changes as described above may result in a boot failure.

The reason for the failure is as follows:

pca954x_init() was executed before the call to data->chip = device_get_match_data().

When pca954x_regval() referenced data->chip->muxtype, data->chip was NULL, causing a crash during the probe.

  • Move the pca954x_init() call after the data->chip / data->idle_state settings.
  • Simplify the fskip branch from if (fskip) {…} else {…} to if (!fskip) {…}.

In other words, to use the skip_mux_detect attribute in JP5, the following modifications are required. The attribute application has been verified after implementation.

	// fix: pca954x_init() called before data->chip was set -> NULL deref on probe
	//  moved after device_get_match_data()/idle_state init, fskip branch simplified
	if (!fskip) 
	{
	    ret = pca954x_init(client, data);
    	if (ret < 0) {
        	dev_warn(dev, "probe failed\n");
        	goto fail_cleanup;
    	}
	}

	ret = pca954x_irq_setup(muxc);
	if (ret)
		goto fail_cleanup;

Thanks for the sharing