[email protected] { compatible = “gcore,touchscreen”; spi max freque...">

当前位置:网站首页>Device tree failed to add SPI device node

Device tree failed to add SPI device node

2022-06-22 07:26:00 Neilo_ chen

A new... Is added to the device tree spi The equipment nodes are as follows :
&spi1 {
[email protected] {
compatible = “gcore,touchscreen”;
spi-max-frequency = <1000000>;
spi-cpha = <1>;
spi-cpol = <1>;
};
};
It doesn't look like a problem , But in the system /sys/bus/spi/devices/ The device is not found in the directory ?

reason :
By analyzing the code , If I don't read reg attribute , Add device error !

of_register_spi_device(struct spi_master *master, struct device_node *nc)
{
    
        struct spi_device *spi;
        int rc;
        u32 value;

        /* Alloc an spi_device */
        spi = spi_alloc_device(master);
        if (!spi) {
    
                dev_err(&master->dev, "spi_device alloc error for %s\n",
                        nc->full_name);
                rc = -ENOMEM;
                goto err_out;
        }

        /* Select device driver */
        rc = of_modalias_node(nc, spi->modalias,
                                sizeof(spi->modalias));
        if (rc < 0) {
    
                dev_err(&master->dev, "cannot find modalias for %s\n",
                        nc->full_name);
                goto err_out;
        }

        /* Device address */
rc = of_property_read_u32(nc, "reg", &value);
        if (rc) {
    
                dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n",
                        nc->full_name, rc);
                goto err_out;
        }
        spi->chip_select = value;

        /* Mode (clock phase/polarity/etc.) */
        if (of_find_property(nc, "spi-cpha", NULL))
                spi->mode |= SPI_CPHA;
        if (of_find_property(nc, "spi-cpol", NULL))
                spi->mode |= SPI_CPOL;
        if (of_find_property(nc, "spi-cs-high", NULL))
                spi->mode |= SPI_CS_HIGH;
        if (of_find_property(nc, "spi-3wire", NULL))
                spi->mode |= SPI_3WIRE;
        if (of_find_property(nc, "spi-lsb-first", NULL))
                spi->mode |= SPI_LSB_FIRST;
...

add to reg attribute ,/bus/spi/devices/ You can see
&spi1 {
#address-cells = <1>;
#size-cells = <0>;
[email protected] {
compatible = “gcore,touchscreen”;
spi-max-frequency = <1000000>;
reg = <1>;
spi-cpha = <1>;
spi-cpol = <1>;
};
};

Note that the #address-cells = <1>; #size-cells = <0>;
To reset reg Length and size of attributes

原网站

版权声明
本文为[Neilo_ chen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220536067574.html