@@ -47,7 +47,7 @@
#define QUP_STATE_MASK 3
#define QUP_STATE_VALID BIT(2)
-#define QUP_I2C_MAST_GEN BIT(4)
+#define QUP_I2C_MAST_GEN (QUP_STATE_VALID | BIT(4))
#define QUP_OPERATIONAL_RESET 0x000ff0
#define QUP_I2C_STATUS_RESET 0xfffffc
@@ -190,43 +190,40 @@ done:
return IRQ_HANDLED;
}
-static int
-qup_i2c_poll_state(struct qup_i2c_dev *qup, u32 req_state, bool only_valid)
+static int __qup_i2c_poll_state(struct qup_i2c_dev *qup, u32 mask, u32 value)
{
int retries = 0;
u32 state;
do {
state = readl(qup->base + QUP_STATE);
-
- /*
- * If only valid bit needs to be checked, requested state is
- * 'don't care'
- */
- if (state & QUP_STATE_VALID) {
- if (only_valid)
- return 0;
- if ((req_state & QUP_I2C_MAST_GEN)
- && (state & QUP_I2C_MAST_GEN))
- return 0;
- if ((state & QUP_STATE_MASK) == req_state)
- return 0;
- }
-
+ if ((state & mask) == value)
+ return 0;
udelay(1);
} while (retries++ != QUP_MAX_QUP_STATE_RETRIES);
return -ETIMEDOUT;
}
+static int qup_i2c_poll_state_bit(struct qup_i2c_dev *qup, u32 mask)
+{
+ return __qup_i2c_poll_state(qup, mask, mask);
+}
+
+static int qup_i2c_poll_state(struct qup_i2c_dev *qup, u32 state)
+{
+ return __qup_i2c_poll_state(qup, QUP_STATE_VALID | QUP_STATE_MASK,
+ QUP_STATE_VALID | state);
+}
+
static int qup_i2c_change_state(struct qup_i2c_dev *qup, u32 state)
{
- if (qup_i2c_poll_state(qup, 0, true) != 0)
+ if (qup_i2c_poll_state_bit(qup, QUP_STATE_VALID) != 0)
return -EIO;
writel(state, qup->base + QUP_STATE);
- if (qup_i2c_poll_state(qup, state, false) != 0)
+ if (qup_i2c_poll_state(qup, state) != 0)
return -EIO;
return 0;
}
@@ -616,7 +613,7 @@ qup_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
goto out;
writel(1, qup->base + QUP_SW_RESET);
- ret = qup_i2c_poll_state(qup, QUP_RESET_STATE, false);
+ ret = qup_i2c_poll_state(qup, QUP_RESET_STATE);
if (ret) {
dev_err(qup->dev, "cannot goto reset state\n");
goto out;
@@ -633,7 +630,7 @@ qup_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
writel(0, qup->base + QUP_I2C_CLK_CTL);
writel(QUP_I2C_STATUS_RESET, qup->base + QUP_I2C_STATUS);
- if (qup_i2c_poll_state(qup, QUP_I2C_MAST_GEN, false) != 0) {
+ if (qup_i2c_poll_state_bit(qup, QUP_I2C_MAST_GEN) != 0) {
ret = -EIO;
goto out;
}
@@ -730,7 +727,7 @@ static int qup_i2c_probe(struct platform_device *pdev)
* so we reset the core before registering for interrupts.
*/
writel(1, qup->base + QUP_SW_RESET);
- ret = qup_i2c_poll_state(qup, 0, true);
+ ret = qup_i2c_poll_state(qup, QUP_STATE_VALID);
if (ret)
goto fail;