您尚未登录。

楼主 # 2023-03-02 10:04:55

744219909
会员
注册时间: 2022-07-29
已发帖子: 31
积分: 124

关于荔枝派nano中将I2C添加到设备树

在按照《linux驱动入门》书中添加I2C到设备树发现nano里并没有
sys/devices/platform/soc/1c27000.i2c/i2c-0/0-0050/
I2C-0这一目录,本书甚至给出代码

&i2c0 {
  clock-frequency = <100000>; //时钟设置为 100KHz
  status = "okay";
  at24c02: at24c02@50 {
  compatible = "test,at24c0x";
  reg = <0x50>;
  };
};

这样一般笔带,随后我只能开船畅游百度。
第一天无果
第二天我试图在原有的内核中找线索,我在arch/arm/boot/dts/sun4i-a10.dtsi中找到这么一串代码

i2c0: i2c@1c2ac00 {
			compatible = "allwinner,sun4i-a10-i2c";
			reg = <0x01c2ac00 0x400>;
			interrupts = <7>;
			clocks = <&ccu CLK_APB1_I2C0>;
			pinctrl-names = "default";
			pinctrl-0 = <&i2c0_pins>;
			status = "disabled";
			#address-cells = <1>;
			#size-cells = <0>;
		};

将其拷贝粘贴debug,神奇的一幕发现了
ls sys/devices/platform/soc/1c27000.i2c/i2c-0/0-0050
已经生成了i2c-0

/ # insmod /home/zr/i2c.ko 
[  144.167822] i2c: loading out-of-tree module taints kernel.
/ # ls sys/devices/platform/soc/1c27000.i2c/i2c-0/0-0050/of_node/
compatible  name        reg
/ # ls sys/devices/platform/soc/1c27000.i2c/i2c-0/0-0050/
at24c02     modalias    of_node/    subsystem/
driver/     name        power/      uevent

究其原因是因为compatible属性没有适配,将compatible填写成sun4i-a10-i2c就可以了。
这是我的设备树
dtsi

i2c0: i2c@1c27000 {
				compatible = "allwinner,sun4i-a10-i2c";
				reg = <0x01c27000 0x400>;
				interrupts = <7>;
				clocks = <&ccu CLK_BUS_I2C0>;
				resets = <&ccu RST_BUS_I2C0>;
				pinctrl-names = "default";
				pinctrl-0 = <&i2c0_pins>;
				status = "okay";
				#address-cells = <1>;
				#size-cells = <0>;
		 };

dts

&i2c0 {
			clock-frequency = <100000>; //时钟设置为 100KHz
			pinctrl-names = "default";
			pinctrl-0 = <&i2c0_pins>;
			status = "okay";
			at24c02@50 {
				compatible = "test,at24c0x";
				reg = <0x50>;
			};
		};

下面继续调试i2c

最近编辑记录 744219909 (2023-03-02 10:08:19)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn