]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
i2c: rcar: refactor setup of a msg
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 19 Nov 2015 15:56:45 +0000 (16:56 +0100)
committerWolfram Sang <wsa@the-dreams.de>
Mon, 30 Nov 2015 13:21:07 +0000 (14:21 +0100)
We want to reuse this function later.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/busses/i2c-rcar.c

index 0f2dc74ab8bcc147770a66f66e02988da9e56f57..4bd3099865b4858b214d2db7d250019ba6d25547 100644 (file)
@@ -106,7 +106,8 @@ enum rcar_i2c_type {
 struct rcar_i2c_priv {
        void __iomem *io;
        struct i2c_adapter adap;
-       struct i2c_msg  *msg;
+       struct i2c_msg *msg;
+       int msgs_left;
        struct clk *clk;
 
        wait_queue_head_t wait;
@@ -255,6 +256,11 @@ static void rcar_i2c_prepare_msg(struct rcar_i2c_priv *priv)
 {
        int read = !!rcar_i2c_is_recv(priv);
 
+       priv->pos = 0;
+       priv->flags = 0;
+       if (priv->msgs_left == 1)
+               rcar_i2c_flags_set(priv, ID_LAST_MSG);
+
        rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read);
        rcar_i2c_write(priv, ICMSR, 0);
        rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START);
@@ -499,11 +505,8 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
                }
 
                /* init each data */
-               priv->msg       = &msgs[i];
-               priv->pos       = 0;
-               priv->flags     = 0;
-               if (i == num - 1)
-                       rcar_i2c_flags_set(priv, ID_LAST_MSG);
+               priv->msg = &msgs[i];
+               priv->msgs_left = num - i;
 
                rcar_i2c_prepare_msg(priv);