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

在设备树中新添加了一个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属性的长度和大小

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值