Question about SC16IS752 device tree.

From: Zhou Yanjie
Date: Mon May 09 2022 - 14:08:41 EST


Hi folks,

I encountered a problem when using the SC16IS752 to expand the serial port.
I connected two Bluetooth modules to the two serial ports extended by the
SC16IS752. The device tree is as follows:

&ssi0 {
    status = "okay";

    num-cs = <2>;

    pinctrl-names = "default";
    pinctrl-0 = <&pins_ssi0>;

    sc16is752: expander@0 {
        compatible = "nxp,sc16is752";
        reg = <0>; /* CE0 */

        spi-rx-bus-width = <1>;
        spi-tx-bus-width = <1>;
        spi-max-frequency = <6000000>;

        clocks = <&exclk_sc16is752>;

        interrupt-parent = <&gpb>;
        interrupts = <18 IRQ_TYPE_EDGE_FALLING>;

        gpio-controller;
        #gpio-cells = <2>;

        bluetooth@0 {
            compatible = "brcm,bcm43438-bt";
            max-speed = <1000000>;

            device-wakeup-gpios = <&gpc 26 GPIO_ACTIVE_HIGH>;
            reset-gpios = <&gpb 17 GPIO_ACTIVE_LOW>;
        };

        bluetooth@1 {
            compatible = "brcm,bcm43438-bt";

            device-wakeup-gpios = <&gpc 28 GPIO_ACTIVE_HIGH>;
            reset-gpios = <&gpb 19 GPIO_ACTIVE_LOW>;
        };
    };
};



There are the following error messages after startup:

[    0.548417] serial serial0-0: controller busy
[    0.553572] serial serial0-0: failure adding device. status -EBUSY
[    0.559764] serial serial0: tty port ttySC0 registered
[    0.565545] spi0.0: ttySC1 at I/O 0x1 (irq = 18, base_baud = 3000000) is a SC16IS752
[    0.573987] serial serial1-0: controller busy
[    0.578351] serial serial1-0: failure adding device. status -EBUSY
[    0.585003] serial serial1: tty port ttySC1 registered

And only the module connected to the first serial port (ttySC0) can work normally.



If I change the device tree to:

&ssi0 {
    status = "okay";

    num-cs = <2>;

    pinctrl-names = "default";
    pinctrl-0 = <&pins_ssi0>;

    sc16is752: expander@0 {
        compatible = "nxp,sc16is752";
        reg = <0>; /* CE0 */

        spi-rx-bus-width = <1>;
        spi-tx-bus-width = <1>;
        spi-max-frequency = <6000000>;

        clocks = <&exclk_sc16is752>;

        interrupt-parent = <&gpb>;
        interrupts = <18 IRQ_TYPE_EDGE_FALLING>;

        gpio-controller;
        #gpio-cells = <2>;

        bluetooth@0 {
            compatible = "brcm,bcm43438-bt";
            max-speed = <1000000>;

            device-wakeup-gpios = <&gpc 26 GPIO_ACTIVE_HIGH>;
            reset-gpios = <&gpb 17 GPIO_ACTIVE_LOW>;
        };
    };
};

Then there will be no error message, and the module connected to the first
serial port (ttySC0) can also work normally.



After tracing, the problem seems to be in "serdev_device_add()" (line 111) of
"drivers/tty/serdev/core.c":

int serdev_device_add(struct serdev_device *serdev)
{
    struct serdev_controller *ctrl = serdev->ctrl;
    struct device *parent = serdev->dev.parent;
    int err;

    dev_set_name(&serdev->dev, "%s-%d", dev_name(parent), serdev->nr);

    /* Only a single slave device is currently supported. */
    if (ctrl->serdev) {
        dev_err(&serdev->dev, "controller busy\n");
        return -EBUSY;
    }
    ctrl->serdev = serdev;

    err = device_add(&serdev->dev);
    if (err < 0) {
        dev_err(&serdev->dev, "Can't add %s, status %pe\n",
            dev_name(&serdev->dev), ERR_PTR(err));
        goto err_clear_serdev;
    }

    dev_dbg(&serdev->dev, "device %s registered\n", dev_name(&serdev->dev));

    return 0;

err_clear_serdev:
    ctrl->serdev = NULL;
    return err;
}
EXPORT_SYMBOL_GPL(serdev_device_add);



Is there any way to correctly describe the device mounted on the second
serial port (ttySC1) in the device tree? Or how do I need to modify the
"drivers/tty/serdev/core.c" to make the SC16IS752 still work properly
with two child nodes mounted?

Thanks and beset regards!