Skip to content

Commit da33aa0

Browse files
wangbaolin719Wolfram Sang
authored andcommitted
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>
1 parent 23a2772 commit da33aa0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎drivers/i2c/busses/i2c-sprd.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct sprd_i2c {
8686
u32 count;
8787
int irq;
8888
int err;
89+
bool is_suspended;
8990
};
9091

9192
static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count)
@@ -283,6 +284,9 @@ static int sprd_i2c_master_xfer(struct i2c_adapter *i2c_adap,
283284
struct sprd_i2c *i2c_dev = i2c_adap->algo_data;
284285
int im, ret;
285286

287+
if (i2c_dev->is_suspended)
288+
return -EBUSY;
289+
286290
ret = pm_runtime_get_sync(i2c_dev->dev);
287291
if (ret < 0)
288292
return ret;
@@ -586,11 +590,23 @@ static int sprd_i2c_remove(struct platform_device *pdev)
586590

587591
static int __maybe_unused sprd_i2c_suspend_noirq(struct device *pdev)
588592
{
593+
struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev);
594+
595+
i2c_lock_adapter(&i2c_dev->adap);
596+
i2c_dev->is_suspended = true;
597+
i2c_unlock_adapter(&i2c_dev->adap);
598+
589599
return pm_runtime_force_suspend(pdev);
590600
}
591601

592602
static int __maybe_unused sprd_i2c_resume_noirq(struct device *pdev)
593603
{
604+
struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev);
605+
606+
i2c_lock_adapter(&i2c_dev->adap);
607+
i2c_dev->is_suspended = false;
608+
i2c_unlock_adapter(&i2c_dev->adap);
609+
594610
return pm_runtime_force_resume(pdev);
595611
}
596612

0 commit comments

Comments
 (0)