Commit 8c5660bb authored by Lucas De Marchi's avatar Lucas De Marchi Committed by Wolfram Sang

i2c: designware: add common functions for locking

These are used in 2 places and will be needed in more.
Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Acked-by: default avatarJarkko Nikula <jarkko.nikula@linux.intel.com>
Tested-by: default avatarChristian Ruppert <christian.ruppert@alitech.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 2702ea7d
...@@ -292,6 +292,28 @@ static unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev) ...@@ -292,6 +292,28 @@ static unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev)
return dev->get_clk_rate_khz(dev); return dev->get_clk_rate_khz(dev);
} }
static int i2c_dw_acquire_lock(struct dw_i2c_dev *dev)
{
int ret;
if (!dev->acquire_lock)
return 0;
ret = dev->acquire_lock(dev);
if (!ret)
return 0;
dev_err(dev->dev, "couldn't acquire bus ownership\n");
return ret;
}
static void i2c_dw_release_lock(struct dw_i2c_dev *dev)
{
if (dev->release_lock)
dev->release_lock(dev);
}
/** /**
* i2c_dw_init() - initialize the designware i2c master hardware * i2c_dw_init() - initialize the designware i2c master hardware
* @dev: device private data * @dev: device private data
...@@ -307,13 +329,9 @@ int i2c_dw_init(struct dw_i2c_dev *dev) ...@@ -307,13 +329,9 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
u32 sda_falling_time, scl_falling_time; u32 sda_falling_time, scl_falling_time;
int ret; int ret;
if (dev->acquire_lock) { ret = i2c_dw_acquire_lock(dev);
ret = dev->acquire_lock(dev); if (ret)
if (ret) { return ret;
dev_err(dev->dev, "couldn't acquire bus ownership\n");
return ret;
}
}
reg = dw_readl(dev, DW_IC_COMP_TYPE); reg = dw_readl(dev, DW_IC_COMP_TYPE);
if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) { if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
...@@ -325,8 +343,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev) ...@@ -325,8 +343,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
} else if (reg != DW_IC_COMP_TYPE_VALUE) { } else if (reg != DW_IC_COMP_TYPE_VALUE) {
dev_err(dev->dev, "Unknown Synopsys component type: " dev_err(dev->dev, "Unknown Synopsys component type: "
"0x%08x\n", reg); "0x%08x\n", reg);
if (dev->release_lock) i2c_dw_release_lock(dev);
dev->release_lock(dev);
return -ENODEV; return -ENODEV;
} }
...@@ -415,8 +432,8 @@ int i2c_dw_init(struct dw_i2c_dev *dev) ...@@ -415,8 +432,8 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
/* configure the i2c master */ /* configure the i2c master */
dw_writel(dev, dev->master_cfg , DW_IC_CON); dw_writel(dev, dev->master_cfg , DW_IC_CON);
if (dev->release_lock) i2c_dw_release_lock(dev);
dev->release_lock(dev);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(i2c_dw_init); EXPORT_SYMBOL_GPL(i2c_dw_init);
...@@ -679,13 +696,9 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ...@@ -679,13 +696,9 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
dev->abort_source = 0; dev->abort_source = 0;
dev->rx_outstanding = 0; dev->rx_outstanding = 0;
if (dev->acquire_lock) { ret = i2c_dw_acquire_lock(dev);
ret = dev->acquire_lock(dev); if (ret)
if (ret) { goto done_nolock;
dev_err(dev->dev, "couldn't acquire bus ownership\n");
goto done_nolock;
}
}
ret = i2c_dw_wait_bus_not_busy(dev); ret = i2c_dw_wait_bus_not_busy(dev);
if (ret < 0) if (ret < 0)
...@@ -732,8 +745,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ...@@ -732,8 +745,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
ret = -EIO; ret = -EIO;
done: done:
if (dev->release_lock) i2c_dw_release_lock(dev);
dev->release_lock(dev);
done_nolock: done_nolock:
pm_runtime_mark_last_busy(dev->dev); pm_runtime_mark_last_busy(dev->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment