spi-gpio+mcp2510驱动移植

不啰嗦,上设备树代码:

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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值