【问题标题】:Add SPI slave device in linux 4.9 device tree for raspbery pi在 linux 4.9 设备树中为树莓派添加 SPI 从设备
【发布时间】:2017-11-26 11:13:22
【问题描述】:

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

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

&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>;
    };
};

我的驱动代码看起来像

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 =>

[  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 中。 由于未找到匹配的设备,因此未调用 Probe。

驱动的probe是如何调用的,如何在设备树中添加spi设备

任何帮助将不胜感激。

【问题讨论】:

  • 您的 SPI 主机只为片选定义了两个引脚,即使您想访问三个 SPI 从机。
  • spi1 有 3 个 CE 引脚。或者您可以使用 spi0 并禁用其中一个 spidev 设备来窃取您设备的 CE 引脚。这取决于您在 40 路接头上使用的引脚。最好使用 DT 覆盖而不是修改基本 DT 文件。

标签: raspberry-pi driver linux-device-driver


【解决方案1】:

1) 您需要在以下属性数组中添加 CS GPIO,如下所示: cs-gpios = , ,

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

【讨论】:

  • cs-gpios = , ,
  • 并且需要在您的驱动程序中使用 reg = = 为什么是 3?
  • IIRC SPI CE 选择为 0 索引。所以这里是 reg =
【解决方案2】:

感谢您的意见。 现在我已经用新设备替换了 spi0 设备。 驱动程序探针被调用

【讨论】:

  • 你能告诉我这是什么意思吗 - 现在我已经用新设备替换了 spi0 设备。
猜你喜欢
  • 1970-01-01
  • 2018-11-16
  • 1970-01-01
  • 1970-01-01
  • 2019-02-14
  • 2014-12-05
  • 2021-07-15
  • 2019-02-14
  • 1970-01-01
相关资源
最近更新 更多