Skip to content

Commit 171408c

Browse files
Jingchang LuWolfram Sang
authored andcommitted
i2c: imx: add INT flag and IEN bit operatation codes
This add bits operation macro that differ between SoCs. Interrupt flags clear operation in I2SR differ between SoCs: write zero to clear(w0c) INT flag on i.MX, but write one to clear(w1c) INT flag on Vybrid. I2C module enable operation in I2CR also differ between SoCs: set I2CR_IEN bit enable the module on i.MX, but clear I2CR_IEN bit enable the module on Vybrid. Signed-off-by: Jingchang Lu <[email protected]> Reviewed-by: Sascha Hauer <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 8cc7331 commit 171408c

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

drivers/i2c/busses/i2c-imx.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@
9595
#define I2CR_IIEN 0x40
9696
#define I2CR_IEN 0x80
9797

98+
/* register bits different operating codes definition:
99+
* 1) I2SR: Interrupt flags clear operation differ between SoCs:
100+
* - write zero to clear(w0c) INT flag on i.MX,
101+
* - but write one to clear(w1c) INT flag on Vybrid.
102+
* 2) I2CR: I2C module enable operation also differ between SoCs:
103+
* - set I2CR_IEN bit enable the module on i.MX,
104+
* - but clear I2CR_IEN bit enable the module on Vybrid.
105+
*/
106+
#define I2SR_CLR_OPCODE_W0C 0x0
107+
#define I2SR_CLR_OPCODE_W1C (I2SR_IAL | I2SR_IIF)
108+
#define I2CR_IEN_OPCODE_0 0x0
109+
#define I2CR_IEN_OPCODE_1 I2CR_IEN
110+
111+
#define IMX_I2SR_CLR_OPCODE I2SR_CLR_OPCODE_W0C
112+
#define IMX_I2CR_IEN_OPCODE I2CR_IEN_OPCODE_1
113+
98114
/** Variables ******************************************************************
99115
*******************************************************************************/
100116

@@ -242,8 +258,8 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
242258
clk_prepare_enable(i2c_imx->clk);
243259
imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR);
244260
/* Enable I2C controller */
245-
imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
246-
imx_i2c_write_reg(I2CR_IEN, i2c_imx, IMX_I2C_I2CR);
261+
imx_i2c_write_reg(IMX_I2SR_CLR_OPCODE, i2c_imx, IMX_I2C_I2SR);
262+
imx_i2c_write_reg(IMX_I2CR_IEN_OPCODE, i2c_imx, IMX_I2C_I2CR);
247263

248264
/* Wait controller to be stable */
249265
udelay(50);
@@ -287,7 +303,7 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
287303
}
288304

289305
/* Disable I2C controller */
290-
imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
306+
imx_i2c_write_reg(IMX_I2CR_IEN_OPCODE ^ I2CR_IEN, i2c_imx, IMX_I2C_I2CR);
291307
clk_disable_unprepare(i2c_imx->clk);
292308
}
293309

@@ -339,6 +355,7 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
339355
/* save status register */
340356
i2c_imx->i2csr = temp;
341357
temp &= ~I2SR_IIF;
358+
temp |= (IMX_I2SR_CLR_OPCODE & I2SR_IIF);
342359
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
343360
wake_up(&i2c_imx->queue);
344361
return IRQ_HANDLED;
@@ -596,8 +613,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
596613
i2c_imx_set_clk(i2c_imx, bitrate);
597614

598615
/* Set up chip registers to defaults */
599-
imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
600-
imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
616+
imx_i2c_write_reg(IMX_I2CR_IEN_OPCODE ^ I2CR_IEN, i2c_imx, IMX_I2C_I2CR);
617+
imx_i2c_write_reg(IMX_I2SR_CLR_OPCODE, i2c_imx, IMX_I2C_I2SR);
601618

602619
/* Add I2C adapter */
603620
ret = i2c_add_numbered_adapter(&i2c_imx->adapter);

0 commit comments

Comments
 (0)