/notes/linux/imx6ull-char-device-dts

Linux Driver//16 分钟

基于 i.MX6ULL 的字符设备驱动与设备树节点解析

从 compatible 字符串到 platform_driver 的 probe 流程,以及 device-tree overlay 在 bring-up 阶段的妙用。

i.MX6ULL设备树platform_bus

设备树节点

&ecspi1 {
    mydev: my-device@0 {
        compatible = "mycorp,mydev-v1";
        reg = <0>;
        spi-max-frequency = <40000000>;
        interrupt-parent = <&gpio1>;
        interrupts = <4 IRQ_TYPE_EDGE_FALLING>;
    };
};

platform_driver 流程

内核在解析设备树后,会为每个节点生成一个 platform_device。驱动用 of_device_idcompatible 字段匹配:

static const struct of_device_id mydev_dt_ids[] = {
    { .compatible = "mycorp,mydev-v1" },
    { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, mydev_dt_ids);

probe 里做什么

  • 解析 GPIO / 中断 / DMA 通道;
  • 注册字符设备;
  • 创建 /sys/class/... 属性。

结论

理解设备树 → platform_bus → probe 的链路,是写 Linux 驱动的必修课。