stm32: Wait for UART Tx to complete before entering STOP mode
stm32: Wait for UART Tx to complete before entering STOP mode

Before entering STOP mode, we need to ensure UART Tx has completed.
Otherwise, we may lose some characters or some bits within a character.
For Tx DMA mode, this is already done as we wait until TC (Tx complete)
is set before disabling Tx. However, when not using DMA, we enable sleep
when TXE is set. At this moment, the last character is still in the
shift register and going into sleep causes loss of the whole or part of
the last character.

To avoid this, let's enable TC interrupt and enable sleep only if we
have no more characters to send and TC is set.

BRANCH=None
BUG=chrome-os-partner:33219
TEST=Enable low power mode on Ryu P2. Type when the EC is in STOP mode
and check there is no broken character.

Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225283
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit bf8335a0a329f8d40fe3c4e911c9f9bb144ca2ad)
Signed-off-by: Duncan Laurie <70662b43bc1a20b57ded72a2b08be88dd0da4841@chromium.org>

Change-Id: Ife42671882b7f1d1d17734d7d20fb4ba7dffb371
Reviewed-on: https://chromium-review.googlesource.com/225755
Tested-by: Duncan Laurie <70662b43bc1a20b57ded72a2b08be88dd0da4841@chromium.org>
Reviewed-by: Duncan Laurie <70662b43bc1a20b57ded72a2b08be88dd0da4841@chromium.org>
Commit-Queue: Duncan Laurie <70662b43bc1a20b57ded72a2b08be88dd0da4841@chromium.org>

thehobn/ec,thehobn/ec,thehobn/ec,thehobn/ec