i2c: designware: Move register access detection to common code
Move register access detection out from master and slave HW initialization code to common code. Motivation for this is to have register access configured before HW initialization and remove duplicated code. This allows to do further separation between probe time initialization and runtime reinitialization code. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
6e6bcc0d30
commit
3aca0bd6f4
|
@ -94,6 +94,40 @@ void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* i2c_dw_set_reg_access() - Set register access flags
|
||||
* @dev: device private data
|
||||
*
|
||||
* Autodetects needed register access mode and sets access flags accordingly.
|
||||
* This must be called before doing any other register access.
|
||||
*/
|
||||
int i2c_dw_set_reg_access(struct dw_i2c_dev *dev)
|
||||
{
|
||||
u32 reg;
|
||||
int ret;
|
||||
|
||||
ret = i2c_dw_acquire_lock(dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
reg = dw_readl(dev, DW_IC_COMP_TYPE);
|
||||
i2c_dw_release_lock(dev);
|
||||
|
||||
if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
|
||||
/* Configure register endianess access */
|
||||
dev->flags |= ACCESS_SWAP;
|
||||
} else if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
|
||||
/* Configure register access mode 16bit */
|
||||
dev->flags |= ACCESS_16BIT;
|
||||
} else if (reg != DW_IC_COMP_TYPE_VALUE) {
|
||||
dev_err(dev->dev,
|
||||
"Unknown Synopsys component type: 0x%08x\n", reg);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -295,6 +295,7 @@ struct dw_i2c_dev {
|
|||
|
||||
u32 dw_readl(struct dw_i2c_dev *dev, int offset);
|
||||
void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset);
|
||||
int i2c_dw_set_reg_access(struct dw_i2c_dev *dev);
|
||||
u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
|
||||
u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset);
|
||||
unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev);
|
||||
|
|
|
@ -64,20 +64,6 @@ static int i2c_dw_init_master(struct dw_i2c_dev *dev)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
reg = dw_readl(dev, DW_IC_COMP_TYPE);
|
||||
if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
|
||||
/* Configure register endianess access */
|
||||
dev->flags |= ACCESS_SWAP;
|
||||
} else if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
|
||||
/* Configure register access mode 16bit */
|
||||
dev->flags |= ACCESS_16BIT;
|
||||
} else if (reg != DW_IC_COMP_TYPE_VALUE) {
|
||||
dev_err(dev->dev,
|
||||
"Unknown Synopsys component type: 0x%08x\n", reg);
|
||||
i2c_dw_release_lock(dev);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1);
|
||||
|
||||
/* Disable the adapter */
|
||||
|
@ -681,6 +667,10 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
|
|||
dev->disable = i2c_dw_disable;
|
||||
dev->disable_int = i2c_dw_disable_int;
|
||||
|
||||
ret = i2c_dw_set_reg_access(dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = dev->init(dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
|
|
@ -58,20 +58,6 @@ static int i2c_dw_init_slave(struct dw_i2c_dev *dev)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
reg = dw_readl(dev, DW_IC_COMP_TYPE);
|
||||
if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
|
||||
/* Configure register endianness access. */
|
||||
dev->flags |= ACCESS_SWAP;
|
||||
} else if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
|
||||
/* Configure register access mode 16bit. */
|
||||
dev->flags |= ACCESS_16BIT;
|
||||
} else if (reg != DW_IC_COMP_TYPE_VALUE) {
|
||||
dev_err(dev->dev,
|
||||
"Unknown Synopsys component type: 0x%08x\n", reg);
|
||||
i2c_dw_release_lock(dev);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Disable the adapter. */
|
||||
__i2c_dw_disable(dev);
|
||||
|
||||
|
@ -297,6 +283,10 @@ int i2c_dw_probe_slave(struct dw_i2c_dev *dev)
|
|||
dev->disable = i2c_dw_disable;
|
||||
dev->disable_int = i2c_dw_disable_int;
|
||||
|
||||
ret = i2c_dw_set_reg_access(dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = dev->init(dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue