spi-gpio+mcp2510驱动移植

本文详细介绍了SPI-GPIO设备树的配置方法,包括必要的属性设置如compatible、#address-cells、ranges、gpio-sck等,以及如何配置mcp2515 CAN控制器和时钟选项。通过实例展示了设备树的正确编写方式。

不啰嗦,上设备树代码:

spi {
                compatible = "spi-gpio";
                #address-cells = <0x1>;
                //ranges;
                #size-cells = <0>;
                gpio-sck = <&gpio2 18 0>;
                gpio-miso = <&gpio2 17 0>;
                gpio-mosi = <&gpio2 1 0>;
                cs-gpios = <&gpio7 12 0>;
                num-chipselects = <1>;

                /* clients */
                can0: can@1 {
                        compatible = "microchip,mcp2515";
                        reg = <0>;
                        //clocks = <&clks 24>;
                        clocks = <&clk16m>;
                        interrupt-parent = <&gpio1>;
                        interrupts = <30 0x2>;
                        spi-max-frequency = <10000000>;
                        status = "okay";
                        //vdd-supply = <&reg5v0>;
                        //xceiver-supply = <&reg5v0>;
                };

        };


内核设备树文档内容为:

SPI-GPIO devicetree bindings

Required properties:

 - compatible: should be set to "spi-gpio"
 - #address-cells: should be set to <0x1>
 - ranges
 - gpio-sck: GPIO spec for the SCK line to use
 - gpio-miso: GPIO spec for the MISO line to use
 - gpio-mosi: GPIO spec for the MOSI line to use
 - cs-gpios: GPIOs to use for chipselect lines.
             Not needed if num-chipselects = <0>.
 - num-chipselects: Number of chipselect lines. Should be <0> if a single device
                    with no chip select is connected.

Example:

    spi {
        compatible = "spi-gpio";
        #address-cells = <0x1>;
        ranges;

        gpio-sck = <&gpio 95 0>;
        gpio-miso = <&gpio 98 0>;
        gpio-mosi = <&gpio 97 0>;
        cs-gpios = <&gpio 125 0>;
        num-chipselects = <1>;

        /* clients */
    };


注释了ranges;选项,并没了解深层次原因,待补充,我也是参考设备树里面别的厂家写的代码改的,慢慢再深入吧。 
然后,配置内核,选上spi-gpio驱动选项即可。 
mcp2510驱动类似,主要是clocks这一项不会写,还是参考了别人写的,添加了一个时钟,成功运行。

clocks {
       /* Fixed crystal dedicated to mcp251x */
       clk16m: clk@1 {
                compatible = "fixed-clock";
                reg = <1>;
                #clock-cells = <0>;
                clock-frequency = <16000000>;
                clock-output-names = "clk16m";
       };
    };

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值