diff mbox

[linux,dev-4.7,v3,1/2] drivers/fsi: Move common read/write code into shared utility

Message ID 20170223195837.82098-2-cbostic@linux.vnet.ibm.com
State Superseded, archived
Headers show

Commit Message

Christopher Bostic Feb. 23, 2017, 7:58 p.m. UTC
Move common code shared between fsi_master_gpio_read/write into
send utility.

Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>

---

v2 - Separate this patch from a collection of other changes in the
     v1 related patch.
---
 drivers/fsi/fsi-master-gpio.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

Comments

Eddie James Feb. 23, 2017, 8:57 p.m. UTC | #1
Looks good.

Acked-by: Eddie James <eajames@linux.vnet.ibm.com>

On 02/23/2017 01:58 PM, Christopher Bostic wrote:
> Move common code shared between fsi_master_gpio_read/write into
> send utility.
>
> Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
>
> ---
>
> v2 - Separate this patch from a collection of other changes in the
>       v1 related patch.
> ---
>   drivers/fsi/fsi-master-gpio.c | 38 ++++++++++++++++++--------------------
>   1 file changed, 18 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c
> index 8c8a8f4..b6feec1 100644
> --- a/drivers/fsi/fsi-master-gpio.c
> +++ b/drivers/fsi/fsi-master-gpio.c
> @@ -354,26 +354,33 @@ static void build_abs_ar_command(struct fsi_gpio_msg *cmd, uint64_t mode,
>   	cmd->msg >>= (64 - cmd->bits);
>   }
>
> +static int send_command(struct fsi_master_gpio *master,
> +			struct fsi_gpio_msg *cmd, uint8_t expected,
> +			size_t size, void *val)
> +{
> +	unsigned long flags;
> +	int rc;
> +
> +	spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
> +	serial_out(master, cmd);
> +	echo_delay(master);
> +	rc = poll_for_response(master, expected, size, val);
> +	spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
> +
> +	return rc;
> +}
> +
>   static int fsi_master_gpio_read(struct fsi_master *_master, int link,
>   		uint8_t slave, uint32_t addr, void *val, size_t size)
>   {
>   	struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
>   	struct fsi_gpio_msg cmd;
> -	int rc;
> -	unsigned long flags;
>
>   	if (link != 0)
>   		return -ENODEV;
>
>   	build_abs_ar_command(&cmd, FSI_GPIO_CMD_READ, slave, addr, size, NULL);
> -
> -	spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
> -	serial_out(master, &cmd);
> -	echo_delay(master);
> -	rc = poll_for_response(master, FSI_GPIO_RESP_ACKD, size, val);
> -	spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
> -
> -	return rc;
> +	return send_command(master, &cmd, FSI_GPIO_RESP_ACKD, size, val);
>   }
>
>   static int fsi_master_gpio_write(struct fsi_master *_master, int link,
> @@ -381,21 +388,12 @@ static int fsi_master_gpio_write(struct fsi_master *_master, int link,
>   {
>   	struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
>   	struct fsi_gpio_msg cmd;
> -	int rc;
> -	unsigned long flags;
>
>   	if (link != 0)
>   		return -ENODEV;
>
>   	build_abs_ar_command(&cmd, FSI_GPIO_CMD_WRITE, slave, addr, size, val);
> -
> -	spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
> -	serial_out(master, &cmd);
> -	echo_delay(master);
> -	rc = poll_for_response(master, FSI_GPIO_RESP_ACK, size, NULL);
> -	spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
> -
> -	return rc;
> +	return send_command(master, &cmd, FSI_GPIO_RESP_ACK, size, NULL);
>   }
>
>   /*
Joel Stanley Feb. 24, 2017, 12:33 a.m. UTC | #2
Hi Eddie,

On Fri, Feb 24, 2017 at 7:27 AM, Eddie James <eajames@linux.vnet.ibm.com> wrote:
> Looks good.
>
> Acked-by: Eddie James <eajames@linux.vnet.ibm.com>

Please don't top post on the mailing list.

Cheers,

Joel

>
>
> On 02/23/2017 01:58 PM, Christopher Bostic wrote:
>>
>> Move common code shared between fsi_master_gpio_read/write into
>> send utility.
>>
>> Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
>>
>> ---
>>
>> v2 - Separate this patch from a collection of other changes in the
>>       v1 related patch.
>> ---
>>   drivers/fsi/fsi-master-gpio.c | 38
>> ++++++++++++++++++--------------------
>>   1 file changed, 18 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c
>> index 8c8a8f4..b6feec1 100644
>> --- a/drivers/fsi/fsi-master-gpio.c
>> +++ b/drivers/fsi/fsi-master-gpio.c
>> @@ -354,26 +354,33 @@ static void build_abs_ar_command(struct fsi_gpio_msg
>> *cmd, uint64_t mode,
>>         cmd->msg >>= (64 - cmd->bits);
>>   }
>>
>> +static int send_command(struct fsi_master_gpio *master,
>> +                       struct fsi_gpio_msg *cmd, uint8_t expected,
>> +                       size_t size, void *val)
>> +{
>> +       unsigned long flags;
>> +       int rc;
>> +
>> +       spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
>> +       serial_out(master, cmd);
>> +       echo_delay(master);
>> +       rc = poll_for_response(master, expected, size, val);
>> +       spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
>> +
>> +       return rc;
>> +}
>> +
>>   static int fsi_master_gpio_read(struct fsi_master *_master, int link,
>>                 uint8_t slave, uint32_t addr, void *val, size_t size)
>>   {
>>         struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
>>         struct fsi_gpio_msg cmd;
>> -       int rc;
>> -       unsigned long flags;
>>
>>         if (link != 0)
>>                 return -ENODEV;
>>
>>         build_abs_ar_command(&cmd, FSI_GPIO_CMD_READ, slave, addr, size,
>> NULL);
>> -
>> -       spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
>> -       serial_out(master, &cmd);
>> -       echo_delay(master);
>> -       rc = poll_for_response(master, FSI_GPIO_RESP_ACKD, size, val);
>> -       spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
>> -
>> -       return rc;
>> +       return send_command(master, &cmd, FSI_GPIO_RESP_ACKD, size, val);
>>   }
>>
>>   static int fsi_master_gpio_write(struct fsi_master *_master, int link,
>> @@ -381,21 +388,12 @@ static int fsi_master_gpio_write(struct fsi_master
>> *_master, int link,
>>   {
>>         struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
>>         struct fsi_gpio_msg cmd;
>> -       int rc;
>> -       unsigned long flags;
>>
>>         if (link != 0)
>>                 return -ENODEV;
>>
>>         build_abs_ar_command(&cmd, FSI_GPIO_CMD_WRITE, slave, addr, size,
>> val);
>> -
>> -       spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
>> -       serial_out(master, &cmd);
>> -       echo_delay(master);
>> -       rc = poll_for_response(master, FSI_GPIO_RESP_ACK, size, NULL);
>> -       spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
>> -
>> -       return rc;
>> +       return send_command(master, &cmd, FSI_GPIO_RESP_ACK, size, NULL);
>>   }
>>
>>   /*
>
>
Joel Stanley Feb. 24, 2017, 12:34 a.m. UTC | #3
Hi Chris,

On Fri, Feb 24, 2017 at 6:28 AM, Christopher Bostic
<cbostic@linux.vnet.ibm.com> wrote:
> Move common code shared between fsi_master_gpio_read/write into
> send utility.
>
> Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
>
> ---
>
> v2 - Separate this patch from a collection of other changes in the
>      v1 related patch.

This patch is unchanged from when I acked the previous revision. You
should include the tags from your reviewers when you re-send.

Reviewed-by: Joel Stanley <joel@jms.id.au>

Cheers,

Joel

> ---
>  drivers/fsi/fsi-master-gpio.c | 38 ++++++++++++++++++--------------------
>  1 file changed, 18 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c
> index 8c8a8f4..b6feec1 100644
> --- a/drivers/fsi/fsi-master-gpio.c
> +++ b/drivers/fsi/fsi-master-gpio.c
> @@ -354,26 +354,33 @@ static void build_abs_ar_command(struct fsi_gpio_msg *cmd, uint64_t mode,
>         cmd->msg >>= (64 - cmd->bits);
>  }
>
> +static int send_command(struct fsi_master_gpio *master,
> +                       struct fsi_gpio_msg *cmd, uint8_t expected,
> +                       size_t size, void *val)
> +{
> +       unsigned long flags;
> +       int rc;
> +
> +       spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
> +       serial_out(master, cmd);
> +       echo_delay(master);
> +       rc = poll_for_response(master, expected, size, val);
> +       spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
> +
> +       return rc;
> +}
> +
>  static int fsi_master_gpio_read(struct fsi_master *_master, int link,
>                 uint8_t slave, uint32_t addr, void *val, size_t size)
>  {
>         struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
>         struct fsi_gpio_msg cmd;
> -       int rc;
> -       unsigned long flags;
>
>         if (link != 0)
>                 return -ENODEV;
>
>         build_abs_ar_command(&cmd, FSI_GPIO_CMD_READ, slave, addr, size, NULL);
> -
> -       spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
> -       serial_out(master, &cmd);
> -       echo_delay(master);
> -       rc = poll_for_response(master, FSI_GPIO_RESP_ACKD, size, val);
> -       spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
> -
> -       return rc;
> +       return send_command(master, &cmd, FSI_GPIO_RESP_ACKD, size, val);
>  }
>
>  static int fsi_master_gpio_write(struct fsi_master *_master, int link,
> @@ -381,21 +388,12 @@ static int fsi_master_gpio_write(struct fsi_master *_master, int link,
>  {
>         struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
>         struct fsi_gpio_msg cmd;
> -       int rc;
> -       unsigned long flags;
>
>         if (link != 0)
>                 return -ENODEV;
>
>         build_abs_ar_command(&cmd, FSI_GPIO_CMD_WRITE, slave, addr, size, val);
> -
> -       spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
> -       serial_out(master, &cmd);
> -       echo_delay(master);
> -       rc = poll_for_response(master, FSI_GPIO_RESP_ACK, size, NULL);
> -       spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
> -
> -       return rc;
> +       return send_command(master, &cmd, FSI_GPIO_RESP_ACK, size, NULL);
>  }
>
>  /*
> --
> 1.8.2.2
>
diff mbox

Patch

diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c
index 8c8a8f4..b6feec1 100644
--- a/drivers/fsi/fsi-master-gpio.c
+++ b/drivers/fsi/fsi-master-gpio.c
@@ -354,26 +354,33 @@  static void build_abs_ar_command(struct fsi_gpio_msg *cmd, uint64_t mode,
 	cmd->msg >>= (64 - cmd->bits);
 }
 
+static int send_command(struct fsi_master_gpio *master,
+			struct fsi_gpio_msg *cmd, uint8_t expected,
+			size_t size, void *val)
+{
+	unsigned long flags;
+	int rc;
+
+	spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
+	serial_out(master, cmd);
+	echo_delay(master);
+	rc = poll_for_response(master, expected, size, val);
+	spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
+
+	return rc;
+}
+
 static int fsi_master_gpio_read(struct fsi_master *_master, int link,
 		uint8_t slave, uint32_t addr, void *val, size_t size)
 {
 	struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
 	struct fsi_gpio_msg cmd;
-	int rc;
-	unsigned long flags;
 
 	if (link != 0)
 		return -ENODEV;
 
 	build_abs_ar_command(&cmd, FSI_GPIO_CMD_READ, slave, addr, size, NULL);
-
-	spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
-	serial_out(master, &cmd);
-	echo_delay(master);
-	rc = poll_for_response(master, FSI_GPIO_RESP_ACKD, size, val);
-	spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
-
-	return rc;
+	return send_command(master, &cmd, FSI_GPIO_RESP_ACKD, size, val);
 }
 
 static int fsi_master_gpio_write(struct fsi_master *_master, int link,
@@ -381,21 +388,12 @@  static int fsi_master_gpio_write(struct fsi_master *_master, int link,
 {
 	struct fsi_master_gpio *master = to_fsi_master_gpio(_master);
 	struct fsi_gpio_msg cmd;
-	int rc;
-	unsigned long flags;
 
 	if (link != 0)
 		return -ENODEV;
 
 	build_abs_ar_command(&cmd, FSI_GPIO_CMD_WRITE, slave, addr, size, val);
-
-	spin_lock_irqsave(&fsi_gpio_cmd_lock, flags);
-	serial_out(master, &cmd);
-	echo_delay(master);
-	rc = poll_for_response(master, FSI_GPIO_RESP_ACK, size, NULL);
-	spin_unlock_irqrestore(&fsi_gpio_cmd_lock, flags);
-
-	return rc;
+	return send_command(master, &cmd, FSI_GPIO_RESP_ACK, size, NULL);
 }
 
 /*