power: smb349-charger: wait for pm_ops to complete before reading i2c
Trying to read from the i2c bus before the dev_pm_ops resume function is
complete can cause errors on the i2c bus because the pm operations are not
complete. Fix this by adding a completion to the smb349-charger's stat
irq and only handle the irq after the dev_pm_ops resume is complete in the
driver.
Ensure that there is no outstanding waiting stat irq handler by adding a
irq_waiting flag and setting it in the stat irq handler before going to
sleep when waiting for the completion. If this flag is set, then in the
suspend_noirq function cancel the suspend to handle the stat interrupt.
The kernel threads that the irq is using are of a higher priority than
the user threads that suspend is initiated from, and are guaranteed to
terminate or sleep before suspend_noirq is called by the kernel.
The mutex takes care of the race between the irq and the suspend handler.
There is a possibility that the i2c bus might get suspended while executing
the STAT IRQ handler causing the subsequent i2c calls to fail. To avoid
this serialize the suspend and irq handler.
This guarantees that:
1. No stat irq handlers can be suspended in a incomplete state
so that USB detection fails.
2. No I2C communication will be called after the SMB and I2C
driver's suspend pm operation.
Change-Id: Id44a424958a389d1875be1b6b6daf3af141fcc70
Signed-off-by:
Xiaozhe Shi <xiaozhes@codeaurora.org>
Loading
Please register or sign in to comment