如何让 linux 驱动程序在 linux 内核加载后检测并使用设备?

How to make a linux driver detect and use a device after linux kernel has already loaded?

我在 i2c-0 总线上使用地址为 0x3f 的系统监视器设备。该设备在设备树中配置有 pmbus 驱动程序。

问题是,加载 linux 内核时,此 'Sysmon' 设备未通电。因此,当我在总线 0 上执行 i2cdetect 时,我们会在预期的 0x3f 处看到“--”。现在,当我使用 UI 为 Sysmon 供电时,linux 添加了设备,我们在 运行 i2cdetect 上看到了“3f”。

现在,我希望 pmbus 驱动程序检测到此设备并将其更改为 'UU',以便我可以在 sysfs 中看到所有 pmbus 属性。

我可以从用户空间进行吗?如何进行?如果不是,你能建议我如何解决这个问题吗?

如果我使用硬件强制为设备供电然后加载 linux,pmbus 驱动程序会检测到该设备并保留它。但是我不允许强制为设备供电。

设备树:

   i2c@ff020000 

   {

        compatible = "cdns,i2c-r1p14", "cdns,i2c-r1p10";
        status = "okay";
        interrupt-parent = <0x4>;
        interrupts = <0x0 0x11 0x4>;
        reg = <0x0 0xff020000 0x0 0x1000>;
        #address-cells = <0x1>;
        #size-cells = <0x0>;
        power-domains = <0x15>;
        clocks = <0x3 0x3d>;
        clock-frequency = <0x186a0>;
        pinctrl-names = "default", "gpio";
        pinctrl-0 = <0x16>;
        pinctrl-1 = <0x17>;
        scl-gpios = <0x18 0x4a 0x0>;
        sda-gpios = <0x18 0x4b 0x0>;

        fpga1sysmon0@3f {
            compatible = "general,pmbus";
            reg = <0x3f>;
        };

PS:我是初学者,这是我在 Stack Overflow 上的第一个问题。如有任何错误,请多多包涵。

如何在 /etc/init.d/rcS(假设您使用的是 busybox init)或 systemd /etc/rc.local.

中启用 sysmon

以下将在地址 0x60 加载 LTC2978 的驱动程序 在 I2C 总线 #1 上:

$ modprobe pmbus
$ echo ltc2978 0x60 > /sys/bus/i2c/devices/i2c-1/new_device

你可以把它放在

/etc/init.d/rcS/etc/rc.local

另见 https://www.kernel.org/doc/Documentation/hwmon/pmbus