diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2014-05-28 03:44:38 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2014-06-01 16:22:25 -0400 |
commit | 4f443a8a611d0cb3c40e95e0d90e9d7e4740eda6 (patch) | |
tree | 04b14006cf7a7d7209dd714af30375b796567f7c | |
parent | 93e953d3785fa6fc7fda4b64bd38d003f1dcb1d2 (diff) |
i2c: rcar: refactor bus state machine
Remove the seperate functions and use designated constants. As readable
but less overhead.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r-- | drivers/i2c/busses/i2c-rcar.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 5a3e8a12e8d5..eadaca0ef4be 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c | |||
@@ -79,11 +79,9 @@ | |||
79 | #define MATE (1 << 0) /* address sent irq en */ | 79 | #define MATE (1 << 0) /* address sent irq en */ |
80 | 80 | ||
81 | 81 | ||
82 | enum { | 82 | #define RCAR_BUS_PHASE_START (MDBS | MIE | ESG) |
83 | RCAR_BUS_PHASE_ADDR, | 83 | #define RCAR_BUS_PHASE_DATA (MDBS | MIE) |
84 | RCAR_BUS_PHASE_DATA, | 84 | #define RCAR_BUS_PHASE_STOP (MDBS | MIE | FSB) |
85 | RCAR_BUS_PHASE_STOP, | ||
86 | }; | ||
87 | 85 | ||
88 | enum { | 86 | enum { |
89 | RCAR_IRQ_CLOSE, | 87 | RCAR_IRQ_CLOSE, |
@@ -204,21 +202,6 @@ static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) | |||
204 | return -EBUSY; | 202 | return -EBUSY; |
205 | } | 203 | } |
206 | 204 | ||
207 | static void rcar_i2c_bus_phase(struct rcar_i2c_priv *priv, int phase) | ||
208 | { | ||
209 | switch (phase) { | ||
210 | case RCAR_BUS_PHASE_ADDR: | ||
211 | rcar_i2c_write(priv, ICMCR, MDBS | MIE | ESG); | ||
212 | break; | ||
213 | case RCAR_BUS_PHASE_DATA: | ||
214 | rcar_i2c_write(priv, ICMCR, MDBS | MIE); | ||
215 | break; | ||
216 | case RCAR_BUS_PHASE_STOP: | ||
217 | rcar_i2c_write(priv, ICMCR, MDBS | MIE | FSB); | ||
218 | break; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | /* | 205 | /* |
223 | * clock function | 206 | * clock function |
224 | */ | 207 | */ |
@@ -328,7 +311,7 @@ static int rcar_i2c_recv(struct rcar_i2c_priv *priv) | |||
328 | { | 311 | { |
329 | rcar_i2c_set_addr(priv, 1); | 312 | rcar_i2c_set_addr(priv, 1); |
330 | rcar_i2c_status_clear(priv); | 313 | rcar_i2c_status_clear(priv); |
331 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_ADDR); | 314 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); |
332 | rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_RECV); | 315 | rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_RECV); |
333 | 316 | ||
334 | return 0; | 317 | return 0; |
@@ -347,7 +330,7 @@ static int rcar_i2c_send(struct rcar_i2c_priv *priv) | |||
347 | 330 | ||
348 | rcar_i2c_set_addr(priv, 0); | 331 | rcar_i2c_set_addr(priv, 0); |
349 | rcar_i2c_status_clear(priv); | 332 | rcar_i2c_status_clear(priv); |
350 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_ADDR); | 333 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); |
351 | rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_SEND); | 334 | rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_SEND); |
352 | 335 | ||
353 | return 0; | 336 | return 0; |
@@ -376,7 +359,7 @@ static int rcar_i2c_irq_send(struct rcar_i2c_priv *priv, u32 msr) | |||
376 | * goto data phase. | 359 | * goto data phase. |
377 | */ | 360 | */ |
378 | if (msr & MAT) | 361 | if (msr & MAT) |
379 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_DATA); | 362 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); |
380 | 363 | ||
381 | if (priv->pos < msg->len) { | 364 | if (priv->pos < msg->len) { |
382 | /* | 365 | /* |
@@ -404,7 +387,7 @@ static int rcar_i2c_irq_send(struct rcar_i2c_priv *priv, u32 msr) | |||
404 | * prepare stop condition here. | 387 | * prepare stop condition here. |
405 | * ID_DONE will be set on STOP irq. | 388 | * ID_DONE will be set on STOP irq. |
406 | */ | 389 | */ |
407 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_STOP); | 390 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); |
408 | else | 391 | else |
409 | /* | 392 | /* |
410 | * If current msg is _NOT_ last msg, | 393 | * If current msg is _NOT_ last msg, |
@@ -452,9 +435,9 @@ static int rcar_i2c_irq_recv(struct rcar_i2c_priv *priv, u32 msr) | |||
452 | * otherwise, go to DATA phase. | 435 | * otherwise, go to DATA phase. |
453 | */ | 436 | */ |
454 | if (priv->pos + 1 >= msg->len) | 437 | if (priv->pos + 1 >= msg->len) |
455 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_STOP); | 438 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); |
456 | else | 439 | else |
457 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_DATA); | 440 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); |
458 | 441 | ||
459 | rcar_i2c_recv_restart(priv); | 442 | rcar_i2c_recv_restart(priv); |
460 | 443 | ||
@@ -502,7 +485,7 @@ static irqreturn_t rcar_i2c_irq(int irq, void *ptr) | |||
502 | dev_dbg(dev, "Nack\n"); | 485 | dev_dbg(dev, "Nack\n"); |
503 | 486 | ||
504 | /* go to stop phase */ | 487 | /* go to stop phase */ |
505 | rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_STOP); | 488 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); |
506 | rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_STOP); | 489 | rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_STOP); |
507 | rcar_i2c_flags_set(priv, ID_NACK); | 490 | rcar_i2c_flags_set(priv, ID_NACK); |
508 | goto out; | 491 | goto out; |