首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在linux 4.9设备树中为raspbery pi添加SPI从设备

在linux 4.9设备树中为raspbery pi添加SPI从设备
EN

Stack Overflow用户
提问于 2017-06-23 09:49:15
回答 2查看 2.1K关注 1票数 1

我正在编写mcp3008驱动程序,不使用iio进行学习。在这个阶段,我希望调用驱动程序的探测器。

我将代码附加到了DT arch/arm/boot/dts/bcm2708-rpi-b.dts中

代码语言:javascript
复制
&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
    cs-gpios = <&gpio 8 1>, <&gpio 7 1>;

    spidev0: spidev@0{
            compatible = "spidev";
            reg = <0>;      /* CE0 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
    };

    spidev1: spidev@1{
            compatible = "spidev";
            reg = <1>;      /* CE1 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
    };

    /* new device for mcp3008 */  
    aartyaa_3008{
            compatible = "aartyaa_mcp3008";
            reg = <0>;
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <1600000>;
    };
};

我的驱动程序代码看起来像这样

代码语言:javascript
复制
static int mcp3008_probe(struct spi_device *spi)
{
    int ret = 0;
    struct mcp3008 *mcp = NULL;
    const struct mcp3008_chip_info *chip_info;

    dev_dbg(&spi->dev, "aaartyaa came in probe, master dev = %s\n",
                     dev_name(&spi->master->dev));

    .
    .
    .
    .

}

static const struct of_device_id mcp3008_of_ids[] = {
    {
            .compatible = "aartyaa_mcp3008",
    },

    { },
};

MODULE_DEVICE_TABLE(of, mcp3008_of_ids);

static const struct spi_device_id mcp3008_ids[] = {
    {"aartyaa_mcp3008", MCP3008},
    {},
};

MODULE_DEVICE_TABLE(spi, mcp3008_ids);

static struct spi_driver mcp3008_driver = {
    .driver = {
            .name = "aartyaa_mcp3008",
            .of_match_table = of_match_ptr(mcp3008_of_ids),
    },
    .id_table = mcp3008_ids,
    .probe = mcp3008_probe,
    //.remove = devm_mcp3008_device_release,
};

module_spi_driver(mcp3008_driver);

无法注册和创建spi设备dmesg =>

代码语言:javascript
复制
[  213.352758] spi-bcm2835 20204000.spi: chipselect 0 already in use
[  213.352781] spi_master spi0: spi_device register error /soc/spi@7e204000/aartyaa_3008
[  213.352799] spi_master spi0: Failed to create SPI device for /soc/spi@7e204000/aartyaa_3008

将spi_bcm2835和spi_bcm2835aux添加到系统中。正如我注意到的,模块在插入后被添加到/sys/bus/spi/drivers中。未调用探测,因为找不到匹配的设备。

driver的probe如何调用,以及如何在设备树中添加spi设备

任何帮助都将被感激和感谢。

EN

回答 2

Stack Overflow用户

发布于 2019-06-12 01:26:16

1)需要在如下属性的数组中添加CS GPIO :cs-gpio= <&gpio 8 1>,<&gpio 7 1>,

2)并且需要在您的驱动程序中使用reg = <3>

票数 1
EN

Stack Overflow用户

发布于 2017-06-25 03:36:14

我很感谢你的意见。目前,我已经用新的spi0设备替换了它。正在调用驱动程序探测器

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44711842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档