diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2014-05-28 03:44:41 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2014-06-01 16:22:38 -0400 |
commit | 386babf8e2f7dd483f88e5c0c4c761346b750185 (patch) | |
tree | 0698b4b6aaea1f9c5ce3a60b1387e8b65d222e65 | |
parent | 3f7de22eb28244fc79bc744d9f51d018da343962 (diff) |
i2c: rcar: refactor setting up msg
Setting up a read or write message is similar enough to be done in one
function. Also, move a helper function into the new function since it is
only used here.
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 | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 828b519146fc..42005ccd3254 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c | |||
@@ -155,11 +155,6 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv) | |||
155 | rcar_i2c_write(priv, ICMAR, 0); | 155 | rcar_i2c_write(priv, ICMAR, 0); |
156 | } | 156 | } |
157 | 157 | ||
158 | static void rcar_i2c_set_addr(struct rcar_i2c_priv *priv, u32 recv) | ||
159 | { | ||
160 | rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | recv); | ||
161 | } | ||
162 | |||
163 | /* | 158 | /* |
164 | * bus control functions | 159 | * bus control functions |
165 | */ | 160 | */ |
@@ -279,25 +274,14 @@ static void rcar_i2c_status_bit_clear(struct rcar_i2c_priv *priv, u32 bit) | |||
279 | rcar_i2c_write(priv, ICMSR, ~bit); | 274 | rcar_i2c_write(priv, ICMSR, ~bit); |
280 | } | 275 | } |
281 | 276 | ||
282 | /* | 277 | static int rcar_i2c_prepare_msg(struct rcar_i2c_priv *priv) |
283 | * recv/send functions | ||
284 | */ | ||
285 | static int rcar_i2c_recv(struct rcar_i2c_priv *priv) | ||
286 | { | 278 | { |
287 | rcar_i2c_set_addr(priv, 1); | 279 | int read = !!rcar_i2c_is_recv(priv); |
288 | rcar_i2c_status_clear(priv); | ||
289 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); | ||
290 | rcar_i2c_write(priv, ICMIER, RCAR_IRQ_RECV); | ||
291 | |||
292 | return 0; | ||
293 | } | ||
294 | 280 | ||
295 | static int rcar_i2c_send(struct rcar_i2c_priv *priv) | 281 | rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); |
296 | { | ||
297 | rcar_i2c_set_addr(priv, 0); | ||
298 | rcar_i2c_status_clear(priv); | 282 | rcar_i2c_status_clear(priv); |
299 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); | 283 | rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); |
300 | rcar_i2c_write(priv, ICMIER, RCAR_IRQ_SEND); | 284 | rcar_i2c_write(priv, ICMIER, read ? RCAR_IRQ_RECV : RCAR_IRQ_SEND); |
301 | 285 | ||
302 | return 0; | 286 | return 0; |
303 | } | 287 | } |
@@ -520,11 +504,7 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap, | |||
520 | if (priv->msg == &msgs[num - 1]) | 504 | if (priv->msg == &msgs[num - 1]) |
521 | rcar_i2c_flags_set(priv, ID_LAST_MSG); | 505 | rcar_i2c_flags_set(priv, ID_LAST_MSG); |
522 | 506 | ||
523 | /* start send/recv */ | 507 | ret = rcar_i2c_prepare_msg(priv); |
524 | if (rcar_i2c_is_recv(priv)) | ||
525 | ret = rcar_i2c_recv(priv); | ||
526 | else | ||
527 | ret = rcar_i2c_send(priv); | ||
528 | 508 | ||
529 | spin_unlock_irqrestore(&priv->lock, flags); | 509 | spin_unlock_irqrestore(&priv->lock, flags); |
530 | /*-------------- spin unlock -----------------*/ | 510 | /*-------------- spin unlock -----------------*/ |