按照楼主的帖子,我用的licheepi zero 成功挂载了mcp2515,设置波特率,up等操作都是正常的,但是,用cansend数据后,用ifconfig 查看 can0的tx没有增加,不知道楼主有碰到类似的情况吗
我是这种情况,就离谱
]]>哈, 你这样改只是让 mp2515 有了时钟, 暂时跑起来了,后面可能会有未知的坑,目前调试 can 的时候可以这么做,后面量产的时候一定记得改回来。
看你说的会有坑,有点怕,我又查了些资料。
https://searchcode.com/codesearch/view/47347027/
linux /Documentation/devicetree/bindings/clock/clock-bindings.txt
76: clock-ranges: Empty property indicating that child nodes can inherit named
clocks from this node. Useful for bus nodes to provide a
clock to their children.
这意思是不是刚好符合我这情况?
]]>dock这个设备树文件里这样写,就可以了。
&spi0{
status = "okay";
clock-ranges;
can@0{
status = "okay";
compatible = "microchip,mcp2515";
reg = <0>;
spi-max-frequency = <5000000>;
interrupt-parent = <&pio>;
interrupts = < 4 21 IRQ_TYPE_EDGE_FALLING>;
};
};
Oceanic 5205 5inMFD has MCP2515 CAN device connected via SPI1.
- via SPI1 bus
- vdd supplied by 5V supply along with PL2 enable pin
- xceiver supply same as vdd
- can oscillator connected at 20MHz
- PB2 gpio as interrupt pin
- PD6 gpio as RX_BUF1_CAN0
- PD7 gpio as RX_BUF0_CAN0
Tested-by: Tamas Papp <tamas@osukl.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
.../sun50i-a64-oceanic-5205-5inmfd.dts | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-oceanic-5205-5inmfd.dts b/arch/arm64/boot/dts/allwinner/sun50i-a64-oceanic-5205-5inmfd.dts
index f0cd6587f619..22535a297f51 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-oceanic-5205-5inmfd.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-oceanic-5205-5inmfd.dts
@@ -21,6 +21,24 @@
chosen {
stdout-path = "serial0:115200n8";
};
+
+ can_osc: can-osc {
+ compatible = "fixed-clock";
+ #clock-cells = <0>;
+ clock-frequency = <20000000>;
+ };
+
+ reg_can_v5v: reg-can-v5v {
+ compatible = "regulator-fixed";
+ regulator-name = "reg-can-v5v";
+ regulator-min-microvolt = <5000000>;
+ regulator-max-microvolt = <5000000>;
+ regulator-boot-on;
+ enable-active-high;
+ gpio = <&r_pio 0 2 GPIO_ACTIVE_HIGH>; /* CAN_3V3_EN: PL2 */
+ status = "okay";
+ };
+
};
&ehci0 {
@@ -77,6 +95,31 @@
status = "okay";
};
+&pio {
+ can_pins: can-pins {
+ pins = "PD6", /* RX_BUF1_CAN0 */
+ "PD7"; /* RX_BUF0_CAN0 */
+ function = "gpio_in";
+ };
+};
+
+&spi1 {
+ status = "okay";
+
+ can@0 {
+ compatible = "microchip,mcp2515";
+ reg = <0>;
+ spi-max-frequency = <10000000>;
+ pinctrl-names = "default";
+ pinctrl-0 = <&can_pins>;
+ interrupt-parent = <&pio>;
+ interrupts = <1 2 IRQ_TYPE_EDGE_FALLING>; /* INT_CAN0: PB2 */
+ clocks = <&can_osc>;
+ vdd-supply = <®_can_v5v>;
+ xceiver-supply = <®_can_v5v>;
+ };
+};
+
&uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pb_pins>;
--
2.18.0.321.gffc6fa0e3
https://github.com/armbian/sunxi-DT-overlays/blob/master/examples/spi-mcp251x.dts
can0_osc_fixed: can0_osc_fixed {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <8000000>;
};
mcp2515 {
reg = <0>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
pinctrl-0 = <&can0_pin_irq>;
spi-max-frequency = <10000000>;
interrupt-parent = <&pio>;
interrupts = <0 7 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */
clocks = <&can0_osc_fixed>;
status = "okay";
};
Example:
can0: can@1 {
compatible = "microchip,mcp2515";
reg = <1>;
clocks = <&clk24m>;
interrupt-parent = <&gpio4>;
interrupts = <13 0x2>;
vdd-supply = <®5v0>;
xceiver-supply = <®5v0>;
};
貌似你的设备树缺时钟源。
]]>感觉不应该是 !np 这个地方问题, 如果是这里问题, 应该早发现了。
同感, 这里是 Linux 驱动部分的核心代码, 按理不应该会这里出错。
https://github.com/torvalds/linux/blob/v4.13/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.14/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.15/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.16/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.17/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.18/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.19/drivers/clk/clkdev.c
https://github.com/torvalds/linux/blob/v4.20/drivers/clk/clkdev.c
这里全部都一样。
]]> /* Walk up the tree of devices looking for a clock that matches */
while (np) {
int index = 0;
/*
* For named clocks, first look up the name in the
* "clock-names" property. If it cannot be found, then
* index will be an error code, and of_clk_get() will fail.
*/
if (name)
index = of_property_match_string(np, "clock-names", name);
clk = __of_clk_get(np, index, dev_id, name);
if (!IS_ERR(clk)) {
break;
} else if (name && index >= 0) {
if (PTR_ERR(clk) != -EPROBE_DEFER)
pr_err("ERROR: could not get clock %pOF:%s(%i)\n",
np, name ? name : "", index);
return clk;
}
/*
* No matching clock found on this node. If the parent node
* has a "clock-ranges" property, then we can try one of its
* clocks.
*/
np = np->parent;
if (np && !of_get_property(np, "clock-ranges", NULL))
break;
}
return clk;
}
发现while循环的末尾有个判断可能写错了。
np = np->parent;
if (np && !of_get_property(np, "clock-ranges", NULL))
break;
应该是
np = np->parent;
if (!np && !of_get_property(np, "clock-ranges", NULL))
break;
改了后,我的can设备就出现了。
[ 181.937474] mcp251x spi0.0 can0: MCP2515 successfully initialized.
# ifconfig -a
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
好开心啊!!!
]]>