页次: 1
对比了一下启动信息。
我的板子,多了一个错误,这是什么意思?
倒数第二行。
[ 1.462903] EXT4-fs (mmcblk0p2): couldn't mount as ext2 due to feature incompatibilities
[ 1.492842] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 1.501154] VFS: Mounted root (ext4 filesystem) on device 179:2.
[ 1.510055] devtmpfs: mounted
[ 1.514355] Freeing unused kernel memory: 1024K
[ 1.575119] musb-hdrc musb-hdrc.1.auto: VBUS_ERROR in b_idle (80, <SessEnd), retry #0, port1 00000100
[ 1.652464] EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered
哈, 你这样改只是让 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.
这意思是不是刚好符合我这情况?
谢谢各位了!晕哥说这代码是核心代码,那基本上是不可能出错的,看了那个语句的后半断,会查找父设备里的有没一个"clock-ranges"这样的属性,如果有就会使用父设备返回父设备的clk,我就给加上了,现在不改代码,can设备也出现了。水平有限,我主要搞单片机的,这个设备树还不理解,楼上给的,我不知道在荔枝上怎么配置,我就不试了。先看看这个can设备是不是能用了,如果可以我就先这样吧,再次谢谢各位!@ALL
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>;
};
};
终于有进展了。
我跟踪到这个函数内部:(位于drivers/clk/clkdev.c)
static struct clk *__of_clk_get_by_name(struct device_node *np,
const char *dev_id,
const char *name)
{
struct clk *clk = ERR_PTR(-ENOENT);
/* 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)
好开心啊!!!
外接的模块是一个mcp2515的can芯片,在它驱动里的probe里需要获取clk,但我调试看了下,一直获取不到。
它调用的函数是clk = devm_clk_get(&spi->dev, NULL)
我代码跟踪感觉这个函数最终会调用
clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id);
这个函数,dev_id 是从spi->dev.init_name中获取的,我打印了下为NULL, con_id 也为NULL(第一个函数传进去的)
所以我用了"spi","mod","ahb"作为devm_clk_get()这个函数的第二个参数来调试,依然获取不到。
这是设备树里的配置
官方的那个头里的配置
spi0: spi@1c68000 {
compatible = "allwinner,sun8i-h3-spi";
reg = <0x01c68000 0x1000>;
interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_SPI0>, <&ccu CLK_SPI0>;
clock-names = "ahb", "mod";
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins>;
resets = <&ccu RST_BUS_SPI0>;
status = "disabled";
#address-cells = <1>;
#size-cells = <0>;
};
我自己的配置
&spi0{
status = "okay";
can@0{
status = "okay";
compatible = "microchip,mcp2515";
reg = <0>;
spi-max-frequency = <5000000>;
interrupt-parent = <&pio>;
interrupts = < 4 21 IRQ_TYPE_EDGE_FALLING>;
};
};
页次: 1