Skip to contentSkip to conversation

: Supporting PIO mode of operation in i2c_msg->flags

RFC Vaibhav Hiremath 3 participants 8 messages May 25, 2015 – Jun 16, 2015 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

This is rather an old issue, for which I have also done custom & hacky solution in the past.

Please let me know if there is already an some other method or accepted workaround to this issue. Also, let me know if you have any suggestions on this patch, I would be happy to work on it.

Problem Statement:
------------------
In certain embedded platforms, the board power on/off is managed by PMIC IC, which in most of the cases is over I2C bus.
So during shutdown/reboot you may have to do I2C transactions to access PMIC, which may sleep if I2C bus driver is not functioning in PIO by default.

This is unexpected, to sleep after you disable the interrupts.

For example,

During reboot/shutdown, the execution call reaches to,

void machine_power_off(void)

{
        local_irq_disable();
        smp_send_stop();
        if (pm_power_off)
                pm_power_off();
}

pm_power_off will try to do I2C transaction to access PMIC, which may sleep/schedule.

Current implementation:
--------------------

Everyone probably does have their own custom implementation for this. Or some other mechanism to achieve this (may be hardware support).

Proposal:
---------

If I am not missing any other way of handling this situation, below proposal should be clean and acceptable (I hope so :) )

Add flags to choose PIO mode, for I2C transactions, and the default would be to non-PIO mode.

struct i2c_msg flags :

#define I2C_M_PIO 0x0800

And also add respective functionality flags

#define I2C_FUNC_PIO 0x10000000 /* Driver should support PIO mode*/

In the bus driver,

Inside master_xfer() callback we will check whether the intended i2c transaction is meant to be processed in PIO mode, if yes, then we will call PIO api, else as usual non-pio api should serve.

static int xxx_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)

{
	...

/* We can also check i2c_check_functionality(adap,I2C_FUNC_PIO) */

	if (msg->flags & I2C_M_PIO) {
		/* PIO mode operation */
	} else {
		/* non-pio mode of operation */
	}


	...


        return ret;
}

Feedback/comments are always welcome.

Thanks,
Vaibhav

#1 lore raw
Quoted 93 lines · Vaibhav Hiremath

Hi,

This is rather an old issue, for which I have also done custom & hacky solution in the past.

Please let me know if there is already an some other method or accepted workaround to this issue. Also, let me know if you have any suggestions on this patch, I would be happy to work on it.

Problem Statement:
------------------
In certain embedded platforms, the board power on/off is managed by PMIC IC, which in most of the cases is over I2C bus.
So during shutdown/reboot you may have to do I2C transactions to access PMIC, which may sleep if I2C bus driver is not functioning in PIO by default.

This is unexpected, to sleep after you disable the interrupts.

For example,

During reboot/shutdown, the execution call reaches to,

void machine_power_off(void)

{
         local_irq_disable();
         smp_send_stop();
         if (pm_power_off)
                 pm_power_off();
}

pm_power_off will try to do I2C transaction to access PMIC, which may sleep/schedule.

Current implementation:
--------------------

Everyone probably does have their own custom implementation for this. Or some other mechanism to achieve this (may be hardware support).

Proposal:
---------

If I am not missing any other way of handling this situation, below proposal should be clean and acceptable (I hope so :) )

Add flags to choose PIO mode, for I2C transactions, and the default would be to non-PIO mode.

struct i2c_msg flags :

#define I2C_M_PIO 0x0800

And also add respective functionality flags

#define I2C_FUNC_PIO 0x10000000 /* Driver should support PIO mode*/

In the bus driver,

Inside master_xfer() callback we will check whether the intended i2c transaction is meant to be processed in PIO mode, if yes, then we will call PIO api, else as usual non-pio api should serve.

static int xxx_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)

{
     ...

/* We can also check i2c_check_functionality(adap,I2C_FUNC_PIO) */

     if (msg->flags & I2C_M_PIO) {
         /* PIO mode operation */
     } else {
         /* non-pio mode of operation */
     }


     ...


         return ret;
}
Quoted 4 lines

Feedback/comments are always welcome.

Thanks,
Vaibhav

Any comments on the RFC?

Also,
+ linux-arm & Wolfram Sang

Thanks,
Vaibhav

#2 lore raw
Quoted 98 lines · Vaibhav Hiremath
Quoted 95 lines · Vaibhav Hiremath

Hi,

This is rather an old issue, for which I have also done custom & hacky solution in the past.

Please let me know if there is already an some other method or accepted workaround to this issue. Also, let me know if you have any suggestions on this patch, I would be happy to work on it.

Problem Statement:
------------------
In certain embedded platforms, the board power on/off is managed by PMIC IC, which in most of the cases is over I2C bus.
So during shutdown/reboot you may have to do I2C transactions to access PMIC, which may sleep if I2C bus driver is not functioning in PIO by default.

This is unexpected, to sleep after you disable the interrupts.

For example,

During reboot/shutdown, the execution call reaches to,

void machine_power_off(void)

{
         local_irq_disable();
         smp_send_stop();
         if (pm_power_off)
                 pm_power_off();
}

pm_power_off will try to do I2C transaction to access PMIC, which may sleep/schedule.

Current implementation:
--------------------

Everyone probably does have their own custom implementation for this. Or some other mechanism to achieve this (may be hardware support).

Proposal:
---------

If I am not missing any other way of handling this situation, below proposal should be clean and acceptable (I hope so :) )

Add flags to choose PIO mode, for I2C transactions, and the default would be to non-PIO mode.

struct i2c_msg flags :

#define I2C_M_PIO 0x0800

And also add respective functionality flags

#define I2C_FUNC_PIO 0x10000000 /* Driver should support PIO mode*/

In the bus driver,

Inside master_xfer() callback we will check whether the intended i2c transaction is meant to be processed in PIO mode, if yes, then we will call PIO api, else as usual non-pio api should serve.

static int xxx_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)

{
     ...

/* We can also check i2c_check_functionality(adap,I2C_FUNC_PIO) */

     if (msg->flags & I2C_M_PIO) {
         /* PIO mode operation */
     } else {
         /* non-pio mode of operation */
     }


     ...


         return ret;
}

Feedback/comments are always welcome.

Quoted 9 lines
Quoted 2 lines

Thanks,
Vaibhav

Any comments on the RFC?

Also,
+ linux-arm & Wolfram Sang

Wolfram,

Any comment on this RFC?

Thanks,
Vaibhav

#4 lore raw
In reply to a message not in the archive
Quoted 5 lines

Current implementation:
--------------------

Everyone probably does have their own custom implementation for this. Or some other mechanism to achieve this (may be hardware support).

Do you have examples? It is easier to look at code.

Quoted 6 lines

/* We can also check i2c_check_functionality(adap,I2C_FUNC_PIO) */

	if (msg->flags & I2C_M_PIO) {
		/* PIO mode operation */
	} else {
		/* non-pio mode of operation */
	}

I'd rather let the core decide. Like introduce a master_xfer_nosleep callback and let the core use the standard or the nosleep one. We'd need the same for smbus as well.

This leads to the question if we need a M_FLAG or expose the *_nosleep functions directly?

And I wonder about the demand for it. There are a number of SoCs with designated I2C cores for the PMIC which do automated transfers.

#5 lore raw
Quoted 8 lines · Wolfram Sang
Quoted 5 lines

Current implementation:
--------------------

Everyone probably does have their own custom implementation for this. Or some other mechanism to achieve this (may be hardware support).

Do you have examples? It is easier to look at code.

As I mentioned in the "Problem Statement",

I2C interface for PMIC may need to be used at the end of poweroff sequence where you cannot afford to sleep/schedule, as interrupt has been disabled.

Earlier I was working on OMAP platform, where I remember we had implemented something for such requirement, but as I am not in TI anymore, I can not access the internal code.

Let me check whether I can share the current marvell codebase outside.

Quoted 7 lines
Quoted 6 lines

/* We can also check i2c_check_functionality(adap,I2C_FUNC_PIO) */

	if (msg->flags & I2C_M_PIO) {
		/* PIO mode operation */
	} else {
		/* non-pio mode of operation */
	}
Quoted 7 lines

I'd rather let the core decide. Like introduce a master_xfer_nosleep callback and let the core use the standard or the nosleep one. We'd need the same for smbus as well.

This leads to the question if we need a M_FLAG or expose the *_nosleep functions directly?

I thought of it, but did not convince myself after looking at the usage of this. This function would be used only when interrupt is disabled.

Quoted 3 lines

And I wonder about the demand for it. There are a number of SoCs with designated I2C cores for the PMIC which do automated transfers.

This is exactly the same reason I did not propose it as a core change. as I feel that the use of this is very minimal and with M_FLAG driver can very well handle it.

Thanks,
Vaibhav

#7 lore raw
In reply to a message not in the archive
Quoted 45 lines · Vaibhav Hiremath
Quoted 8 lines · Wolfram Sang
Quoted 5 lines

Current implementation:
--------------------

Everyone probably does have their own custom implementation for this. Or some other mechanism to achieve this (may be hardware support).

Do you have examples? It is easier to look at code.

As I mentioned in the "Problem Statement",

I2C interface for PMIC may need to be used at the end of poweroff sequence where you cannot afford to sleep/schedule, as interrupt has been disabled.

Earlier I was working on OMAP platform, where I remember we had implemented something for such requirement, but as I am not in TI anymore, I can not access the internal code.

Let me check whether I can share the current marvell codebase outside.

Quoted 7 lines
Quoted 6 lines

/* We can also check i2c_check_functionality(adap,I2C_FUNC_PIO) */

    if (msg->flags & I2C_M_PIO) {
        /* PIO mode operation */
    } else {
        /* non-pio mode of operation */
    }
Quoted 7 lines

I'd rather let the core decide. Like introduce a master_xfer_nosleep callback and let the core use the standard or the nosleep one. We'd need the same for smbus as well.

This leads to the question if we need a M_FLAG or expose the *_nosleep functions directly?

I thought of it, but did not convince myself after looking at the usage of this. This function would be used only when interrupt is disabled.

Quoted 8 lines
Quoted 3 lines

And I wonder about the demand for it. There are a number of SoCs with designated I2C cores for the PMIC which do automated transfers.

This is exactly the same reason I did not propose it as a core change. as I feel that the use of this is very minimal and with M_FLAG driver can very well handle it.

Wolfram,

Any update on this?

If we could close on this, I can quickly change the code and submit the patch for review.

Thanks,
Vaibhav

#10 lore raw
Quoted 7 lines · Wolfram Sang
Quoted 2 lines

Any update on this?

Not yet.

a) there was no code to look at

Actually its simple question, whether we can call i2c_transfer in pm_power_off fn, where interupts are disabled and i2c_transfer fn may sleep.

Just to illustrate my point,
I just quickly created something for you. Correct me if I am wrong here.

pm_power_off Usecase:
=====

File: arch/arm64/kernel/process.c

void machine_power_off(void)

{
        local_irq_disable();
        smp_send_stop();
        if (pm_power_off)
                pm_power_off();
}

Dummy pm_power_off Implementation:
=====

drivers/i2c/busses/i2c-pxa.c +4 -1
index 03b70f8..e364a2a 100644
@@ -1170,7 +1170,10 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
        i2c_pxa_enable(i2c, true);
 
        for (i = adap->retries; i >= 0; i--) {
-               ret = i2c_pxa_do_xfer(i2c, msgs, num);
+               if (msgs[0].flags & I2C_M_PIO)
+                       ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
+               else
+                       ret = i2c_pxa_do_xfer(i2c, msgs, num);
                if (ret != I2C_RETRY)
                        goto out;
 
drivers/mfd/88pm800.c +50 -0

62 lines not on this page · raw message

include/uapi/linux/i2c.h +0 -0
index 0e949cb..22fda83 100644
@@ -76,6 +76,7 @@ struct i2c_msg {
 #define I2C_M_IGNORE_NAK       0x1000  /* if I2C_FUNC_PROTOCOL_MANGLING */
 #define I2C_M_NO_RD_ACK                0x0800  /* if 

I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_RECV_LEN 0x0400 /* length will be first
received byte */

+#define I2C_M_PIO              0x0200  /* pio mode of transaction */
        __u16 len;              /* msg length                           */
        __u8 *buf;              /* pointer to msg data                  */

};