您的位置:首页 > Web前端 > HTML5

17 H5里的i2c控制器驱动

2017-11-30 14:10 351 查看
i2c传输协议请参考: http://blog.csdn.net/jklinux/article/details/73920503

H5里共有4个i2c控制器。Soc里的控制器都是由芯片厂家负责驱动好的.



在内核源码里相关的配置:

make menuconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

-> Device Drivers
-> I2C support
I2C Hardware Bus support  --->
<*> Marvell mv64xxx I2C Controller


//全志H5的i2c控制器驱动用的是Marvell的i2c控制器驱动。 有点意思哈

控制器驱动源码在: drivers/i2c/busses/i2c-mv64xxx.c

里面是一个platform_driver, 意味着要么用platform_device或用设备树来提供相应的资源:

1000 static struct platform_driver mv64xxx_i2c_driver = {
1001     .probe  = mv64xxx_i2c_probe,
1002     .remove = mv64xxx_i2c_remove,
1003     .driver = {
1004         .name   = MV64XXX_I2C_CTLR_NAME,
1005         .pm     = mv64xxx_i2c_pm_ops,
1006         .of_match_table = mv64xxx_i2c_of_match_table,
1007     },
1008 };

747 static const struct of_device_id mv64xxx_i2c_of_match_table[] = {
748     { .compatible = "allwinner,sun4i-a10-i2c", .data = &mv64xxx_i2c_regs_sun4i},
749     { .compatible = "allwinner,sun6i-a31-i2c", .data = &mv64xxx_i2c_regs_sun4i},
750     { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
751     { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
752     { .compatible = "marvell,mv78230-a0-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
753     {}
754 };
755 MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table);


在设备树里的i2c控制器设备节点的compatible属性值应为”allwinner,sun4i-a10-i2c”或者”allwinner,sun6i-a31-i2c”.

设备树里i2c控制器的描述:

sunxi-h3-h5.dtsi:

657         i2c0: i2c@01c2ac00 {
658             compatible = "allwinner,sun6i-a31-i2c";
659             reg = <0x01c2ac00 0x400>;
660             interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
661             clocks = <&ccu CLK_BUS_I2C0>;
662             resets = <&ccu RST_BUS_I2C0>;
663             pinctrl-names = "default";
664             pinctrl-0 = <&i2c0_pins>;
665             status = "disabled";
666             #address-cells = <1>;
667             #size-cells = <0>;
668         };
669
670         i2c1: i2c@01c2b000 {
671             compatible = "allwinner,sun6i-a31-i2c";
672             reg = <0x01c2b000 0x400>;
673             interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
674             clocks = <&ccu CLK_BUS_I2C1>;
675             resets = <&ccu RST_BUS_I2C1>;
676             pinctrl-names = "default";
677             pinctrl-0 = <&i2c1_pins>;
678             status = "disabled";
679             #address-cells = <1>;
680             #size-cells = <0>;
681         };
682
683         i2c2: i2c@01c2b400 {
684             compatible = "allwinner,sun6i-a31-i2c";
685             reg = <0x01c2b400 0x400>;
686             interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
687             clocks = <&ccu CLK_BUS_I2C2>;
688             resets = <&ccu RST_BUS_I2C2>;
689             pinctrl-names = "default";
690             pinctrl-0 = <&i2c2_pins>;
691             status = "disabled";
692             #address-cells = <1>;
693             #size-cells = <0>;
694         };

392             i2c0_pins: i2c0 {
393                 pins = "PA11", "PA12";
394                 function = "i2c0";
395             };
396
397             i2c1_pins: i2c1 {
398                 pins = "PA18", "PA19";
399                 function = "i2c1";
400             };
401
402             i2c2_pins: i2c2 {
403                 pins = "PE12", "PE13";
404                 function = "i2c2";
405             };


确认i2c控制器是否驱动好, 因i2c控制器驱动是一个platform_driver, 可通过查看是否有platform_device与之匹配:

^_^ / # ls /sys/bus/platform/drivers/mv64xxx_i2c/
1c2ac00.i2c/  1c2b400.i2c/  uevent
1c2b000.i2c/  bind          unbind


也可以查看:

^_^ / # ls /sys/bus/i2c/devices/
0-0068/  i2c-0/   i2c-1/   i2c-2/


// i2c-x目录就是表示驱动好的控制器

还可以使用命令i2cdetect查看:

^_^ / # i2cdetect -l
i2c-1   i2c             mv64xxx_i2c adapter                     I2C adapter
i2c-2   i2c             mv64xxx_i2c adapter                     I2C adapter
i2c-0   i2c             mv64xxx_i2c adapter                     I2C adapter


^_^ / # ls /sys/class/i2c-adapter/*
/sys/class/i2c-adapter/i2c-0:
0-005c         device         new_device     subsystem
0-0068         i2c-dev        of_node        uevent
delete_device  name           power

/sys/class/i2c-adapter/i2c-1:
delete_device  i2c-dev        new_device     power          uevent
device         name           of_node        subsystem

/sys/class/i2c-adapter/i2c-2:
delete_device  i2c-dev        new_device     power          uevent
device         name           of_node        subsystem
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息