Search code examples
linuxlinux-device-driverembedded-linuxxilinxi2c

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


I am using a System Monitor device at address 0x3f on i2c-0 bus. This device is configured with the pmbus driver in the device tree.

The problem is that, this 'Sysmon' device is not powered when the linux kernel is loaded. Therefore, when I do a i2cdetect on bus 0 we see '--' at 0x3f which is expected. Now, when I power the Sysmon using my UI, the device is added by linux and we see a '3f' on running the i2cdetect.

Now, I want the pmbus driver to detect this device and change it to 'UU' so that I can see all the pmbus attributes in sysfs.

Can I do it from userspace and how? If no, can you suggest how can I tackle this.

If I force power the device using hardware and then load linux, the pmbus driver detects this device and reserves it. But I'm not allowed to force power the device.

Device Tree:

   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: I'm a beginner and this is my 1st question on Stack Overflow. Please bear with me for any mistakes I've made.


Solution

  • what about enabling the sysmon in /etc/init.d/rcS (assuming you are using busybox init) or in systemd /etc/rc.local.

    the following will load the driver for an LTC2978 at address 0x60 on I2C bus #1:

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

    you can put that in

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

    see also https://www.kernel.org/doc/Documentation/hwmon/pmbus