Re: [PATCH v5 4/8] serial: max310x: wait for TX to drain before powering down in shutdown

From: Tapio Reijonen

Date: Sun Oct 04 2026 - 06:57:00 EST


Hi Hugo,

On 10/2/26 18:01, Hugo Villeneuve wrote:
> I meant only these two lines:
> to_max310x_port(port)->one_char_duration_us =
> DIV_ROUND_UP(USEC_PER_SEC * frame_bits, baud);
Understood - but as of v6 even those cannot move below the call: the
helper can arm the after-send hold itself (the mid-transfer takeover
fix), and that hold is computed from the character time, so it must be
current before the call. I will extend the comment above the pair so
it says why both values are cached first.

> Its unfortunate that you trimmed some parts of the original email so
> we
> no longer see the relevant code...
>
> But maybe you should reword/improve your comments then?

Fair point on both counts. v6 will state the reason in the comment
itself: the tty layer's wait-until-sent is bounded by closing_wait,
which can be configured to none, and hangup reaches shutdown() with no
wait at all, so shutdown() cannot assume the FIFO is empty.

> So at 115200, this could mean 128 reads each ~90-100 us?
>
> Could using the interrupt to detect tx empty could improve
> efficiency and reduce load on I2C/SPI bus?

Yes, 128 reads is the worst case - but they are spread over the ~11 ms
the remaining data itself needs at that rate, only on the close/hangup
path, and the loop stops at the first empty read. I did consider the
interrupt: shutdown() is also the path that quiesces the port's
interrupt handling, so waiting on TXEMPTY there needs a completion
ordered against the teardown interlocks, and TXEMPTY fires when the
FIFO empties - one character before the transmitter is idle - so the
final one-character wait remains either way. The bounded poll keeps
the teardown path simple; the bus it loads belongs to a port being
closed.

Tapio