Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: sprd: Prevent i2c accesses after suspend is called

Add one flag to indicate if the i2c controller has been in suspend state,
which can prevent i2c accesses after i2c controller is suspended following
system suspend.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Baolin Wang and committed by
Wolfram Sang
da33aa03 23a27722

+16
+16
drivers/i2c/busses/i2c-sprd.c
··· 86 86 u32 count; 87 87 int irq; 88 88 int err; 89 + bool is_suspended; 89 90 }; 90 91 91 92 static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count) ··· 283 282 { 284 283 struct sprd_i2c *i2c_dev = i2c_adap->algo_data; 285 284 int im, ret; 285 + 286 + if (i2c_dev->is_suspended) 287 + return -EBUSY; 286 288 287 289 ret = pm_runtime_get_sync(i2c_dev->dev); 288 290 if (ret < 0) ··· 590 586 591 587 static int __maybe_unused sprd_i2c_suspend_noirq(struct device *pdev) 592 588 { 589 + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 590 + 591 + i2c_lock_adapter(&i2c_dev->adap); 592 + i2c_dev->is_suspended = true; 593 + i2c_unlock_adapter(&i2c_dev->adap); 594 + 593 595 return pm_runtime_force_suspend(pdev); 594 596 } 595 597 596 598 static int __maybe_unused sprd_i2c_resume_noirq(struct device *pdev) 597 599 { 600 + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 601 + 602 + i2c_lock_adapter(&i2c_dev->adap); 603 + i2c_dev->is_suspended = false; 604 + i2c_unlock_adapter(&i2c_dev->adap); 605 + 598 606 return pm_runtime_force_resume(pdev); 599 607 } 600 608