Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Erwan LE RAY <erwan.leray@foss.st.com>, linux-serial@vger.kernel.org
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jean Philippe Romain <jean-philippe.romain@foss.st.com>,
	Valentin Caron <valentin.caron@foss.st.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH 2/2] serial: stm32: Use TC interrupt to deassert GPIO RTS in RS485 mode
Date: Thu, 5 May 2022 03:02:23 +0200	[thread overview]
Message-ID: <5adb61a1-7959-cab3-2be6-ab7555ed7876@denx.de> (raw)
In-Reply-To: <57896136-5e08-b9fe-2e3e-0eff4388e064@foss.st.com>

On 5/4/22 17:54, Erwan LE RAY wrote:

Hi,

[...]

>>>> diff --git a/drivers/tty/serial/stm32-usart.c 
>>>> b/drivers/tty/serial/stm32-usart.c
>>>> index 224f359c6051e..764415b8e8f03 100644
>>>> --- a/drivers/tty/serial/stm32-usart.c
>>>> +++ b/drivers/tty/serial/stm32-usart.c
>>>> @@ -417,6 +417,14 @@ static void 
>>>> stm32_usart_tx_interrupt_enable(struct uart_port *port)
>>>>           stm32_usart_set_bits(port, ofs->cr1, USART_CR1_TXEIE);
>>>>   }
>>>> +static void stm32_usart_tc_interrupt_enable(struct uart_port *port)
>>>> +{
>>>> +    struct stm32_port *stm32_port = to_stm32_port(port);
>>>> +    const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
>>>> +
>>>> +    stm32_usart_set_bits(port, ofs->cr1, USART_CR1_TCIE);
>>>> +}
>>>> +
>>> I don't see the added value of this helper (only 1 instruction used 1 
>>> time), and other Interrupt Enabled bits are already set/unset in 
>>> others functions of this driver.
>>> To keep an homogeneous code in the driver, could you please remove 
>>> this helper and set TCIE directly when you need it ?
>>
>> Should I also remove stm32_usart_tx_interrupt_enable() / 
>> stm32_usart_tx_interrupt_disable() , which does the same thing for 
>> other bits in the interrupt register ?
>>
> In stm32_usart_tx_interrupt_enable() / 
> stm32_usart_tx_interrupt_disable() case, 2 bits are configured 
> differently under a condition, and stm32_usart_tx_interrupt_disable() is 
> called 4 times in the driver. The factorization is triggered by the 
> multiple calls to this code.

stm32_usart_tc_interrupt_{en,dis}able() is called 3 times after 2/2, so 
having 3 copies of the same code sprinkled across the driver seems iffy 
at best. Also, stm32_usart_tc_interrupt_{en,dis}able() handles the 
register offset ($ofs variable), that would also have to be duplicated 
all over the driver. I don't like that, it would make the code harder to 
read.

> In your proposal, the helper is executing a single instruction

The helper first has to figure out the register offset from this $ofs 
table which is at least two instructions, and then does register RMW 
which are at least three instructions on arm32.

>, and is 
> called only once

Thrice in total.

> , reason why I suggested to enable / disable the TCIE 
> directly in your new functions stm32_usart_tc_interrupt_enable() / 
> stm32_usart_tc_interrupt_disable().
> 
>> That sounds to me like making the code harder to read, not easier.
Seems we have a coding style preference stall here.

      reply	other threads:[~2022-05-05  1:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-30 16:28 [PATCH 1/2] serial: stm32: Factor out GPIO RTS toggling into separate function Marek Vasut
2022-04-30 16:28 ` [PATCH 2/2] serial: stm32: Use TC interrupt to deassert GPIO RTS in RS485 mode Marek Vasut
2022-05-02  8:44   ` Erwan LE RAY
2022-05-02 11:13     ` Marek Vasut
2022-05-04 15:54       ` Erwan LE RAY
2022-05-05  1:02         ` Marek Vasut [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5adb61a1-7959-cab3-2be6-ab7555ed7876@denx.de \
    --to=marex@denx.de \
    --cc=alexandre.torgue@foss.st.com \
    --cc=erwan.leray@foss.st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jean-philippe.romain@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=valentin.caron@foss.st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox