Access PMIC with I2C on user space

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Access PMIC with I2C on user space

6,705 Views
linhdong
Contributor II

Hello,

 

I'm trying to test I2C interface of PMIC on user space by read ID but it can't access. I don't know why?

I'm using PF0100 with address is 0x08 , ID is 0x10 , register ID is 0x00.

root@imx6_custom:/home# ./i2c_test
PMIC Test
Can't access i2c device
: Device or resource busy

Does It locked slave address from kernel? Do you have any way to read ID of PMIC on user space though I2C interface?

 

Thanks !

Original Attachment has been moved to: i2c_test.c.zip

Tags (3)
11 Replies

3,628 Views
igorpadykov
NXP Employee
NXP Employee

Hi linh

please check

SGTL5000 access/set PEQ from Linux userspace 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

3,628 Views
pastrana
Contributor III

Hi!

I think that I have the same problem... I posted here: pmic-user-space I do not know how I can change the state of the regulators once they have been started. As you can see in the next picture, I have only read permission, the all path was:

""/sys/devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0008/regulator/regulator.5""

Selection_005.png

As ypu can see in the picture, I cannot change the state for example.

Any idea??

Thanks for your time,

Regards,

Javier

0 Kudos

3,628 Views
vinodmaverickr0
Contributor IV

Have you tried with echo command

echo <value> > /sys/devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0008/regulator/regulator.5/*

0 Kudos

3,628 Views
pastrana
Contributor III

Hi,

Yes, I am. Firstly I have tried to use "cat" in order to see the values, in the next picture you can see:

Selection_002.png

Regarding the "echo", I can do it for example in:

"/sys/devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0008/regulator/regulator.5/power/control/"

By default it is in "auto" mode, but I can change it to "on" mode. As you can see in the next picture:

Selection_006.png

I saw in this documentation ABI/testing which "commands" we can use, the problem is that I do not have all of the files that are defined there. For example, I cannot manage the state, you can see it in the next picture:

Selection_007.png

Thanks a lot,

Javier

My device tree:

&i2c2 {
    clock-frequency = <100000>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_i2c2>;
    status = "okay";
    pmic: pfuze3000@08 {
        compatible = "fsl,pfuze3000";
        reg = <0x08>;
        regulators {
            sw1a_reg: sw1a {
                regulator-name = "sw1a";
                regulator-compatible = "sw1a";
                regulator-min-microvolt = <700000>;
                regulator-max-microvolt = <3300000>;
                regulator-boot-on;
                regulator-always-on;
                regulator-allow-set-load;
                regulator-ramp-delay = <6250>;
                /* Regulator should be on in suspend state */
                regulator-state-mem {
                    regulator-on-in-suspend;
                };
            };
            /* use sw1c_reg to align with pfuze100/pfuze200 */
            sw1c_reg: sw1b {
                regulator-name = "sw1b";
                regulator-compatible = "sw1b";        
                regulator-min-microvolt = <700000>;
                regulator-max-microvolt = <1475000>;
                regulator-boot-on;
                regulator-always-on;
                regulator-ramp-delay = <6250>;
                /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
            sw2_reg: sw2 {
                regulator-name = "sw2";
                regulator-compatible = "sw2";
                regulator-min-microvolt = <1500000>;
                regulator-max-microvolt = <1850000>;
                regulator-boot-on;
                regulator-always-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
            sw3a_reg: sw3 {
                regulator-name = "sw3";
                regulator-compatible = "sw3";
                regulator-min-microvolt = <900000>;
                regulator-max-microvolt = <1650000>;
                regulator-boot-on;
                regulator-always-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
            swbst_reg: swbst {
                regulator-name = "swbst";
                regulator-compatible = "swbst";
                regulator-min-microvolt = <5000000>;
                regulator-max-microvolt = <5150000>;
                        regulator-boot-on;
                        regulator-always-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
            snvs_reg: vsnvs {
                regulator-name = "vsnvs";
                regulator-compatible = "vsnvs";
                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <3000000>;
                regulator-boot-on;
                regulator-always-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                };
            };
            vref_reg: vrefddr {
                regulator-name = "vrefddr";
                regulator-boot-on;
                regulator-always-on;
            };
            vgen1_reg: vldo1 {
                regulator-name = "vldo1";
                regulator-compatible = "vldo1";
                regulator-min-microvolt = <1800000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
                        /* Regulator should be on in suspend state */
                        regulator-state-mem {
                            regulator-on-in-suspend;
                        };
            };
            vgen2_reg: vldo2 {
                regulator-name = "vldo2";
                regulator-min-microvolt = <800000>;
                regulator-max-microvolt = <1550000>;
            };
            vgen3_reg: vccsd {
                regulator-name = "vccsd";
                regulator-compatible = "vccsd";
                regulator-min-microvolt = <2850000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
            vgen4_reg: v33 {
                regulator-name = "v33";
                regulator-compatible = "v33";
                regulator-min-microvolt = <2850000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
            vgen5_reg: vldo3 {
                regulator-name = "vldo3";
                regulator-min-microvolt = <1800000>;
                regulator-max-microvolt = <3300000>;
            };
            vgen6_reg: vldo4 {
                regulator-name = "vldo4";
                regulator-compatible = "vldo4";
                regulator-min-microvolt = <1800000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
                        /* Regulator should be off in suspend state */
                        regulator-state-mem {
                            regulator-off-in-suspend;
                        };
            };
        };
    };
};

0 Kudos

3,628 Views
vinodmaverickr0
Contributor IV

Hi Javier,

It looks strange. Before proceeding further can you just perform a small task.

Try to change the state of any other regulator(As I can see there are about 6 regulator in your dts file). And if you are not able to change the state of any of them(out of 6); then just comment  "regulator-always-on"  in one of the regulator setting (Assuming it is stopping to change the state of regulator), then give one more try.

KEEP YOUR FINGERS CROSSED :smileyhappy:

With Regrads,

Vinod 

0 Kudos

3,628 Views
pastrana
Contributor III

Now I saw this documentation, UserGuidePmic. And I am more confused... Have we do it using the /sysfs interface or with a consumer driver interface??

Could it be possible that sysfs interface is only for read operations and if you want to change dynamically the regulators states do you have to use a consumer driver??

Application Interface

This section provides the details of the application interface for the PMIC regulator driver. Client device drivers are the ones which use PMIC regulator drivers to enable/ disable and/or regulate output voltage/current. Specifically, a client driver uses:

  • Consumer driver interface: This uses a similar API to the kernel clock interface in that consumer drivers can get and put a regulator (like they can with clocks) and get/set voltage, current limit, enable and disable. This allows consumer complete control over their supply voltage and current limit.
  • Sysfs interface: The linux voltage regulator framework also exports a lot of useful voltage/current/opmode data to userspace via sysfs. This could be used to help monitor device power consumption and status.

Thanks again!

Regards,

Javier

0 Kudos

3,628 Views
vinodmaverickr0
Contributor IV

Hi Javier,

It is possible that sysfs can be for read only access; that depend upon your device attribute setting (). Yes there is userspace consumer driver is already available in mainline kernel

drivers/regulator/userspace-consumer.c

You can put some print in the this driver in below function to verify the calling:


static ssize_t reg_show_state(struct device *dev, struct device_attribute *attr, char *buf);

static ssize_t reg_set_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);

3,628 Views
pastrana
Contributor III

Hi Vinod,

Thanks for your help. Finally I achieved it. I posted the solution in this other post of NXP:

You have to use the consumer-driver in order to write the status. But , the userspace-sonsumer.c needs changes to work.

Regards,

Javier

0 Kudos

3,628 Views
vinodmaverickr0
Contributor IV

Hi Javier,

Thanks for the update. Nice to hear that you are able to achieve it.

Regards,

Vinod

3,628 Views
pastrana
Contributor III

Hi Vinod,

Thanks a lot for your answer! But I did not achieve it.. I saw you the results.

I cannot change the status of any regulator, I tried different configurations, but it could not be possible.

This is the Device Tree of my PFUCE that I was working:

vinod kumar wrote:

&i2c2 {
    clock-frequency = <100000>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_i2c2>;
    status = "okay";
    pmic: pfuze3000@08 {
        compatible = "fsl,pfuze3000";
        reg = <0x08>;
        regulators {
            sw1a_reg: sw1a {
                regulator-name = "sw1a";
                regulator-min-microvolt = <700000>;
                regulator-max-microvolt = <3300000>;
                regulator-boot-on;
                regulator-always-on;
                regulator-allow-set-load;
                regulator-ramp-delay = <6250>;
            };
            /* use sw1c_reg to align with pfuze100/pfuze200 */
            sw1c_reg: sw1b {
                regulator-name = "sw1b";
                regulator-min-microvolt = <700000>;
                regulator-max-microvolt = <1475000>;
                regulator-boot-on;
                regulator-always-on;
                regulator-ramp-delay = <6250>;
            };
            sw2_reg: sw2 {
                regulator-name = "sw2";
                regulator-min-microvolt = <1500000>;
                regulator-max-microvolt = <1850000>;
                regulator-boot-on;
                regulator-always-on;
            };
            sw3a_reg: sw3 {
                regulator-name = "sw3";
                regulator-min-microvolt = <900000>;
                regulator-max-microvolt = <1650000>;
                regulator-boot-on;
                regulator-always-on;
            };
            swbst_reg: swbst {
                regulator-name = "swbst";
                regulator-min-microvolt = <5000000>;
                regulator-max-microvolt = <5150000>;
                        regulator-boot-on;
                        regulator-always-on;
            };
            snvs_reg: vsnvs {
                regulator-name = "vsnvs";
                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <3000000>;
                regulator-boot-on;
                regulator-always-on;
            };
            vref_reg: vrefddr {
                regulator-name = "vrefddr";
                regulator-boot-on;
                regulator-always-on;
            };
            vgen1_reg: vldo1 {
                regulator-name = "vldo1";
                regulator-min-microvolt = <1800000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
                regulator-vmmc-supply = <&vgen1_reg>;
            };
            vgen2_reg: vldo2 {
                regulator-name = "vldo2";
                regulator-min-microvolt = <800000>;
                regulator-max-microvolt = <1550000>;
            };
            vgen3_reg: vccsd {
                regulator-name = "vccsd";
                regulator-min-microvolt = <2850000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
            };
            vgen4_reg: v33 {
                regulator-name = "v33";
                regulator-min-microvolt = <2850000>;
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
                regulator-boot-on;
            };
            vgen5_reg: vldo3 {
                regulator-name = "vldo3";
                regulator-min-microvolt = <1800000>;
                regulator-max-microvolt = <3300000>;
                regulator-boot-on;
            };
            vgen6_reg: vldo4 {
                regulator-name = "vldo4";
                regulator-min-microvolt = <1800000>;
                regulator-max-microvolt = <3300000>;
                regulator-boot-on;
                regulator-vmmc-supply = <&vgen6_reg>; // I tried with vmmc-supply - Same result
            };
        };
    };
};

The results that I achieved are:

Selection_009.png

The results of SW1B and SW3 attract my attention, because I did not found the "state" file in order to check their state. Maybe this problem is related with the other.

I am checking all this information in the path "/sys/class/regulator/regular.*/

I do not know how I have to continue... Any idea?

Thanks again for your support,

Regards,

Javier

0 Kudos

3,628 Views
linhdong
Contributor II

Hi igorpadykov,

Thanks so much for your suggest. I tried with i2cget and it can do good my require.

This is log as my expect :

root@imx6_custom:~# ./i2cget -f -y 1 0x08 0x00 b
0x10

(0x10 is ID of PMIC chip )

0 Kudos