spi-gpio+mcp2510驱动移植

来源:互联网 发布:三知四会一联通 编辑:程序博客网 时间:2024/06/17 14:06

不啰嗦,上设备树代码:

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 bindingsRequired 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";       };    };
原创粉丝点击