diff mbox series

[5/9] spi: spi-sun6i: sun6i_spi_drain_fifo(): introduce sun6i_spi_get_rx_fifo_count() and make use of it

Message ID 20200706071801.558394-6-mkl@pengutronix.de (mailing list archive)
State Superseded
Headers show
Series spi: spi-sun6i: One fix and some improvements | expand

Commit Message

Marc Kleine-Budde July 6, 2020, 7:17 a.m. UTC
This patch introduces the function sun6i_spi_get_rx_fifo_count(), similar to
the existing sun6i_spi_get_tx_fifo_count(), to make the sun6i_spi_drain_fifo()
function a bit easier to read.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/spi/spi-sun6i.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Maxime Ripard July 6, 2020, 12:36 p.m. UTC | #1
On Mon, Jul 06, 2020 at 09:17:57AM +0200, Marc Kleine-Budde wrote:
> This patch introduces the function sun6i_spi_get_rx_fifo_count(), similar to
> the existing sun6i_spi_get_tx_fifo_count(), to make the sun6i_spi_drain_fifo()
> function a bit easier to read.
> 
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/spi/spi-sun6i.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
> index 882492774986..f70d14229483 100644
> --- a/drivers/spi/spi-sun6i.c
> +++ b/drivers/spi/spi-sun6i.c
> @@ -106,6 +106,15 @@ static inline void sun6i_spi_write(struct sun6i_spi *sspi, u32 reg, u32 value)
>  	writel(value, sspi->base_addr + reg);
>  }
>  
> +static inline u32 sun6i_spi_get_rx_fifo_count(struct sun6i_spi *sspi)
> +{
> +	u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
> +
> +	reg >>= SUN6I_FIFO_STA_RF_CNT_BITS;
> +
> +	return reg & SUN6I_FIFO_STA_RF_CNT_MASK;
> +}
> +

I guess we could just use FIELD_GET here?

Looks good otherwise, thanks!
Maxime
Marc Kleine-Budde July 6, 2020, 12:37 p.m. UTC | #2
On 7/6/20 2:36 PM, Maxime Ripard wrote:
> On Mon, Jul 06, 2020 at 09:17:57AM +0200, Marc Kleine-Budde wrote:
>> This patch introduces the function sun6i_spi_get_rx_fifo_count(), similar to
>> the existing sun6i_spi_get_tx_fifo_count(), to make the sun6i_spi_drain_fifo()
>> function a bit easier to read.
>>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> ---
>>  drivers/spi/spi-sun6i.c | 15 +++++++++++----
>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
>> index 882492774986..f70d14229483 100644
>> --- a/drivers/spi/spi-sun6i.c
>> +++ b/drivers/spi/spi-sun6i.c
>> @@ -106,6 +106,15 @@ static inline void sun6i_spi_write(struct sun6i_spi *sspi, u32 reg, u32 value)
>>  	writel(value, sspi->base_addr + reg);
>>  }
>>  
>> +static inline u32 sun6i_spi_get_rx_fifo_count(struct sun6i_spi *sspi)
>> +{
>> +	u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
>> +
>> +	reg >>= SUN6I_FIFO_STA_RF_CNT_BITS;
>> +
>> +	return reg & SUN6I_FIFO_STA_RF_CNT_MASK;
>> +}
>> +
> 
> I guess we could just use FIELD_GET here?
> 
> Looks good otherwise, thanks!

Will change in v2.

Marc
diff mbox series

Patch

diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
index 882492774986..f70d14229483 100644
--- a/drivers/spi/spi-sun6i.c
+++ b/drivers/spi/spi-sun6i.c
@@ -106,6 +106,15 @@  static inline void sun6i_spi_write(struct sun6i_spi *sspi, u32 reg, u32 value)
 	writel(value, sspi->base_addr + reg);
 }
 
+static inline u32 sun6i_spi_get_rx_fifo_count(struct sun6i_spi *sspi)
+{
+	u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
+
+	reg >>= SUN6I_FIFO_STA_RF_CNT_BITS;
+
+	return reg & SUN6I_FIFO_STA_RF_CNT_MASK;
+}
+
 static inline u32 sun6i_spi_get_tx_fifo_count(struct sun6i_spi *sspi)
 {
 	u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
@@ -133,13 +142,11 @@  static inline void sun6i_spi_disable_interrupt(struct sun6i_spi *sspi, u32 mask)
 
 static inline void sun6i_spi_drain_fifo(struct sun6i_spi *sspi, int len)
 {
-	u32 reg, cnt;
+	u32 cnt;
 	u8 byte;
 
 	/* See how much data is available */
-	reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
-	reg &= SUN6I_FIFO_STA_RF_CNT_MASK;
-	cnt = reg >> SUN6I_FIFO_STA_RF_CNT_BITS;
+	cnt = sun6i_spi_get_rx_fifo_count(sspi);
 
 	if (len > cnt)
 		len = cnt;