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

device tree添加spi设备节点不成功的问题 么得钱钱 2024-02-21 17:14:02 82

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

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 点赞 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
么得钱钱
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区