device tree添加spi设备节点不成功的问题

  • Post author:
  • Post category:其他


在设备树中新添加了一个spi设备节点如下:

&spi1 {


gcore_touch@0 {


compatible = “gcore,touchscreen”;

spi-max-frequency = <1000000>;

spi-cpha = <1>;

spi-cpol = <1>;

};

};

看起来没什么问题,但是在系统/sys/bus/spi/devices/目录下却没有看到该设备?

原因:

通过分析代码,如果没有读到reg属性,添加设备错误!

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;
...

添加reg属性,/bus/spi/devices/就可以看到了

&spi1 {


#address-cells = <1>;

#size-cells = <0>;

gcore_touch@0 {


compatible = “gcore,touchscreen”;

spi-max-frequency = <1000000>;

reg = <1>;

spi-cpha = <1>;

spi-cpol = <1>;

};

};

注意还需要使用 #address-cells = <1>; #size-cells = <0>;

来重新设定reg属性的长度和大小



版权声明:本文为cjianeng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。