s5j/serial: refactor up_setup()
authorWonsang Ryou <wonsang.yoo@samsung.com>
Mon, 21 Aug 2017 15:36:10 +0000 (00:36 +0900)
committersunghan <sh924.chang@samsung.com>
Wed, 20 Sep 2017 07:52:44 +0000 (16:52 +0900)
This patch separates up_configure() function, which configures baud
rate, bits and parity, from up_setup(). The up_configure() function
can be called when baud, bits or parity is initialized or changed.

Change-Id: I6f12d57f969fe0fbbde0e13583bde4f0032bccd6
Signed-off-by: Wonsang Ryou <wonsang.yoo@samsung.com>
os/arch/arm/src/s5j/s5j_serial.c

index 32ce73d..1a9b5c1 100644 (file)
@@ -301,24 +301,17 @@ static int up_interrupt(int irq, void *context, void *arg)
 }
 
 /****************************************************************************
- * Name: up_setup
+ * Name: up_configure
  *
  * Description:
- *   Configure the UART baud, bits, parity, fifos, etc. This
- *   method is called the first time that the serial port is
- *   opened.
+ *   Configure the UART baud, bits, parity, etc.
  *
  ****************************************************************************/
-static int up_setup(struct uart_dev_s *dev)
+static void up_configure(struct up_dev_s *priv)
 {
-       uint32_t regval;
-       struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
-
-       s5j_clk_enable(priv->pclk);
-       s5j_clk_enable(priv->extclk);
-
 #if !defined(CONFIG_SUPPRESS_UART_CONFIG)
        float div;
+       uint32_t regval;
 
        /* wait until Tx FIFO gets empty not to disturb on-going transmission */
        do {
@@ -391,6 +384,27 @@ static int up_setup(struct uart_dev_s *dev)
        uart_putreg32(priv, S5J_UART_UBRDIV_OFFSET, (uint32_t)div);
        uart_putreg32(priv, S5J_UART_UFRACVAL_OFFSET, ((div - (uint32_t)div) * 16));
 #endif /* CONFIG_SUPPRESS_UART_CONFIG */
+}
+
+/****************************************************************************
+ * Name: up_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, etc.
+ *   This also disables all interrupts and initializes FIFO mode.
+ *   This method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+static int up_setup(struct uart_dev_s *dev)
+{
+       struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
+
+       s5j_clk_enable(priv->pclk);
+       s5j_clk_enable(priv->extclk);
+
+       /* Configure the UART baud, bits, parity, etc. */
+       up_configure(priv);
 
        /* Mask all interrupts; will be enabled by upper-half */
        uart_putreg32(priv, S5J_UART_UINTM_OFFSET,
@@ -398,11 +412,12 @@ static int up_setup(struct uart_dev_s *dev)
                                        UART_UINTM_ERROR_MASK | UART_UINTM_RXD_MASK);
 
        /* Reset TX and RX FIFO and enable FIFO mode */
-       regval = UART_UFCON_FIFO_ENABLE |
-                       UART_UFCON_TX_FIFO_RESET | UART_UFCON_RX_FIFO_RESET |
-                       UART_UFCON_TX_FIFO_TRIG_4BYTES | UART_UFCON_RX_FIFO_TRIG_4BYTES;
-
-       uart_putreg32(priv, S5J_UART_UFCON_OFFSET, regval);
+       uart_putreg32(priv, S5J_UART_UFCON_OFFSET,
+                                       UART_UFCON_FIFO_ENABLE |
+                                       UART_UFCON_TX_FIFO_RESET |
+                                       UART_UFCON_RX_FIFO_RESET |
+                                       UART_UFCON_TX_FIFO_TRIG_4BYTES |
+                                       UART_UFCON_RX_FIFO_TRIG_4BYTES);
 
        return OK;
 }