在Linux 4.9设备树中添加SPI从设备进行树莓派 [英] Add SPI slave device in linux 4.9 device tree for raspbery pi

查看:2038
本文介绍了在Linux 4.9设备树中添加SPI从设备进行树莓派的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing mcp3008 driver without use of iio for learnings. At this stage i want driver's probe to be called.

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

I have appended my code in 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>;
    };
};

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

And my driver code looks like

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

It is not able to register and create spi device 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中. 因为找不到匹配的设备,所以未调用探针.

spi_bcm2835 and spi_bcm2835aux are added to system. And as I noticed, module is added in /sys/bus/spi/drivers after inserting it. Probe is not called because matching device is not found.

如何调用驱动程序的探针,以及如何在设备树中添加spi设备

How driver's probe is called, and how to add spi device in device tree

我们将不胜感激.

推荐答案

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

1) You need to add CS GPIO in array of following property as shown bellow : cs-gpios = <&gpio 8 1>, <&gpio 7 1> ,

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

2) And need use reg = <3> in your driver

这篇关于在Linux 4.9设备树中添加SPI从设备进行树莓派的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆