aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorPaul Osmialowski <p.osmialowsk@samsung.com>2015-01-19 11:03:33 -0500
committerWolfram Sang <wsa@the-dreams.de>2015-01-23 23:43:45 -0500
commit34e81ad5f0b60007c95995eb7803da7e00c6c611 (patch)
tree1a1db92fad52fa30a10451ede89b3b206c1c9b2a /drivers/i2c
parent2541f7f4c14e2198ed8d8c61c854b86cae238cf1 (diff)
i2c: s3c2410: fix ABBA deadlock by keeping clock prepared
This patch solves deadlock between clock prepare mutex and regmap mutex reported by Tomasz Figa in [1] by implementing solution from [2]: "always leave the clock of the i2c controller in a prepared state". [1] https://lkml.org/lkml/2014/7/2/171 [2] https://lkml.org/lkml/2014/7/2/207 On each i2c transfer handled by s3c24xx_i2c_xfer(), clk_prepare_enable() was called, which calls clk_prepare() then clk_enable(). clk_prepare() takes prepare_lock mutex before proceeding. Note that i2c transfer functions are invoked from many places in kernel, typically with some other additional lock held. It may happen that function on CPU1 (e.g. regmap_update_bits()) has taken a mutex (i.e. regmap lock mutex) then it attempts i2c communication in order to proceed (so it needs to obtain clock related prepare_lock mutex during transfer preparation stage due to clk_prepare() call). At the same time other task on CPU0 wants to operate on clock (e.g. to (un)prepare clock for some other reason) so it has taken prepare_lock mutex. CPU0: CPU1: clk_disable_unused() regulator_disable() clk_prepare_lock() map->lock(map->lock_arg) regmap_read() s3c24xx_i2c_xfer() map->lock(map->lock_arg) clk_prepare_lock() Implemented solution from [2] leaves i2c clock prepared. Preparation is done in s3c24xx_i2c_probe() function. Without this patch, it is immediately unprepared by clk_disable_unprepare() call. I've replaced this call with clk_disable() and I've added clk_unprepare() call in s3c24xx_i2c_remove(). The s3c24xx_i2c_xfer() function now uses clk_enable() instead of clk_prepare_enable() (and clk_disable() instead of clk_unprepare_disable()). Signed-off-by: Paul Osmialowski <p.osmialowsk@samsung.com> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Cc: stable@kernel.org
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index bff20a589621..958c8db4ec30 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -785,14 +785,16 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
785 int ret; 785 int ret;
786 786
787 pm_runtime_get_sync(&adap->dev); 787 pm_runtime_get_sync(&adap->dev);
788 clk_prepare_enable(i2c->clk); 788 ret = clk_enable(i2c->clk);
789 if (ret)
790 return ret;
789 791
790 for (retry = 0; retry < adap->retries; retry++) { 792 for (retry = 0; retry < adap->retries; retry++) {
791 793
792 ret = s3c24xx_i2c_doxfer(i2c, msgs, num); 794 ret = s3c24xx_i2c_doxfer(i2c, msgs, num);
793 795
794 if (ret != -EAGAIN) { 796 if (ret != -EAGAIN) {
795 clk_disable_unprepare(i2c->clk); 797 clk_disable(i2c->clk);
796 pm_runtime_put(&adap->dev); 798 pm_runtime_put(&adap->dev);
797 return ret; 799 return ret;
798 } 800 }
@@ -802,7 +804,7 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
802 udelay(100); 804 udelay(100);
803 } 805 }
804 806
805 clk_disable_unprepare(i2c->clk); 807 clk_disable(i2c->clk);
806 pm_runtime_put(&adap->dev); 808 pm_runtime_put(&adap->dev);
807 return -EREMOTEIO; 809 return -EREMOTEIO;
808} 810}
@@ -1197,7 +1199,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1197 1199
1198 clk_prepare_enable(i2c->clk); 1200 clk_prepare_enable(i2c->clk);
1199 ret = s3c24xx_i2c_init(i2c); 1201 ret = s3c24xx_i2c_init(i2c);
1200 clk_disable_unprepare(i2c->clk); 1202 clk_disable(i2c->clk);
1201 if (ret != 0) { 1203 if (ret != 0) {
1202 dev_err(&pdev->dev, "I2C controller init failed\n"); 1204 dev_err(&pdev->dev, "I2C controller init failed\n");
1203 return ret; 1205 return ret;
@@ -1210,6 +1212,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1210 i2c->irq = ret = platform_get_irq(pdev, 0); 1212 i2c->irq = ret = platform_get_irq(pdev, 0);
1211 if (ret <= 0) { 1213 if (ret <= 0) {
1212 dev_err(&pdev->dev, "cannot find IRQ\n"); 1214 dev_err(&pdev->dev, "cannot find IRQ\n");
1215 clk_unprepare(i2c->clk);
1213 return ret; 1216 return ret;
1214 } 1217 }
1215 1218
@@ -1218,6 +1221,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1218 1221
1219 if (ret != 0) { 1222 if (ret != 0) {
1220 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); 1223 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
1224 clk_unprepare(i2c->clk);
1221 return ret; 1225 return ret;
1222 } 1226 }
1223 } 1227 }
@@ -1225,6 +1229,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1225 ret = s3c24xx_i2c_register_cpufreq(i2c); 1229 ret = s3c24xx_i2c_register_cpufreq(i2c);
1226 if (ret < 0) { 1230 if (ret < 0) {
1227 dev_err(&pdev->dev, "failed to register cpufreq notifier\n"); 1231 dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
1232 clk_unprepare(i2c->clk);
1228 return ret; 1233 return ret;
1229 } 1234 }
1230 1235
@@ -1241,6 +1246,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1241 if (ret < 0) { 1246 if (ret < 0) {
1242 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 1247 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
1243 s3c24xx_i2c_deregister_cpufreq(i2c); 1248 s3c24xx_i2c_deregister_cpufreq(i2c);
1249 clk_unprepare(i2c->clk);
1244 return ret; 1250 return ret;
1245 } 1251 }
1246 1252
@@ -1262,6 +1268,8 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev)
1262{ 1268{
1263 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 1269 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
1264 1270
1271 clk_unprepare(i2c->clk);
1272
1265 pm_runtime_disable(&i2c->adap.dev); 1273 pm_runtime_disable(&i2c->adap.dev);
1266 pm_runtime_disable(&pdev->dev); 1274 pm_runtime_disable(&pdev->dev);
1267 1275
@@ -1293,13 +1301,16 @@ static int s3c24xx_i2c_resume_noirq(struct device *dev)
1293{ 1301{
1294 struct platform_device *pdev = to_platform_device(dev); 1302 struct platform_device *pdev = to_platform_device(dev);
1295 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 1303 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
1304 int ret;
1296 1305
1297 if (!IS_ERR(i2c->sysreg)) 1306 if (!IS_ERR(i2c->sysreg))
1298 regmap_write(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, i2c->sys_i2c_cfg); 1307 regmap_write(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, i2c->sys_i2c_cfg);
1299 1308
1300 clk_prepare_enable(i2c->clk); 1309 ret = clk_enable(i2c->clk);
1310 if (ret)
1311 return ret;
1301 s3c24xx_i2c_init(i2c); 1312 s3c24xx_i2c_init(i2c);
1302 clk_disable_unprepare(i2c->clk); 1313 clk_disable(i2c->clk);
1303 i2c->suspended = 0; 1314 i2c->suspended = 0;
1304 1315
1305 return 0; 1316 return 0;