]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/serial/serial_core.c
serial: switch the serial core to int put_char methods
[linux-2.6-omap-h63xx.git] / drivers / serial / serial_core.c
index a9ca03ead3e5dc0337b9b7a1eecdf8bb4ce1569a..6c7a5cf765828fc7007e7e630a5a90b8f6a0c414 100644 (file)
@@ -329,13 +329,15 @@ EXPORT_SYMBOL(uart_update_timeout);
  *     If it's still invalid, we try 9600 baud.
  *
  *     Update the @termios structure to reflect the baud rate
- *     we're actually going to be using.
+ *     we're actually going to be using. Don't do this for the case
+ *     where B0 is requested ("hang up").
  */
 unsigned int
 uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
                   struct ktermios *old, unsigned int min, unsigned int max)
 {
        unsigned int try, baud, altbaud = 38400;
+       int hung_up = 0;
        upf_t flags = port->flags & UPF_SPD_MASK;
 
        if (flags == UPF_SPD_HI)
@@ -360,8 +362,10 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
                /*
                 * Special case: B0 rate.
                 */
-               if (baud == 0)
+               if (baud == 0) {
+                       hung_up = 1;
                        baud = 9600;
+               }
 
                if (baud >= min && baud <= max)
                        return baud;
@@ -373,7 +377,9 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
                termios->c_cflag &= ~CBAUD;
                if (old) {
                        baud = tty_termios_baud_rate(old);
-                       tty_termios_encode_baud_rate(termios, baud, baud);
+                       if (!hung_up)
+                               tty_termios_encode_baud_rate(termios,
+                                                               baud, baud);
                        old = NULL;
                        continue;
                }
@@ -382,7 +388,8 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
                 * As a last resort, if the quotient is zero,
                 * default to 9600 bps
                 */
-               tty_termios_encode_baud_rate(termios, 9600, 9600);
+               if (!hung_up)
+                       tty_termios_encode_baud_rate(termios, 9600, 9600);
        }
 
        return 0;
@@ -415,6 +422,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
 
 EXPORT_SYMBOL(uart_get_divisor);
 
+/* FIXME: Consistent locking policy */
 static void
 uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
 {
@@ -447,27 +455,30 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
        port->ops->set_termios(port, termios, old_termios);
 }
 
-static inline void
+static inline int
 __uart_put_char(struct uart_port *port, struct circ_buf *circ, unsigned char c)
 {
        unsigned long flags;
+       int ret = 0;
 
        if (!circ->buf)
-               return;
+               return 0;
 
        spin_lock_irqsave(&port->lock, flags);
        if (uart_circ_chars_free(circ) != 0) {
                circ->buf[circ->head] = c;
                circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1);
+               ret = 1;
        }
        spin_unlock_irqrestore(&port->lock, flags);
+       return ret;
 }
 
-static void uart_put_char(struct tty_struct *tty, unsigned char ch)
+static int uart_put_char(struct tty_struct *tty, unsigned char ch)
 {
        struct uart_state *state = tty->driver_data;
 
-       __uart_put_char(state->port, &state->info->xmit, ch);
+       return __uart_put_char(state->port, &state->info->xmit, ch);
 }
 
 static void uart_flush_chars(struct tty_struct *tty)
@@ -907,14 +918,14 @@ static void uart_break_ctl(struct tty_struct *tty, int break_state)
        struct uart_state *state = tty->driver_data;
        struct uart_port *port = state->port;
 
-       BUG_ON(!kernel_locked());
-
+       lock_kernel();
        mutex_lock(&state->mutex);
 
        if (port->type != PORT_UNKNOWN)
                port->ops->break_ctl(port, break_state);
 
        mutex_unlock(&state->mutex);
+       unlock_kernel();
 }
 
 static int uart_do_autoconfig(struct uart_state *state)
@@ -1052,7 +1063,7 @@ static int uart_get_count(struct uart_state *state,
 }
 
 /*
- * Called via sys_ioctl under the BKL.  We can use spin_lock_irq() here.
+ * Called via sys_ioctl.  We can use spin_lock_irq() here.
  */
 static int
 uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
@@ -1062,8 +1073,8 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
        void __user *uarg = (void __user *)arg;
        int ret = -ENOIOCTLCMD;
 
-       BUG_ON(!kernel_locked());
 
+       lock_kernel();
        /*
         * These ioctls don't rely on the hardware to be present.
         */
@@ -1136,6 +1147,7 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
  out_up:
        mutex_unlock(&state->mutex);
  out:
+       unlock_kernel();
        return ret;
 }
 
@@ -1146,7 +1158,6 @@ static void uart_set_termios(struct tty_struct *tty,
        unsigned long flags;
        unsigned int cflag = tty->termios->c_cflag;
 
-       BUG_ON(!kernel_locked());
 
        /*
         * These are the bits that are used to setup various
@@ -1158,9 +1169,11 @@ static void uart_set_termios(struct tty_struct *tty,
        if ((cflag ^ old_termios->c_cflag) == 0 &&
            tty->termios->c_ospeed == old_termios->c_ospeed &&
            tty->termios->c_ispeed == old_termios->c_ispeed &&
-           RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0)
+           RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) {
                return;
+       }
 
+       lock_kernel();
        uart_change_speed(state, old_termios);
 
        /* Handle transition to B0 status */
@@ -1193,7 +1206,7 @@ static void uart_set_termios(struct tty_struct *tty,
                }
                spin_unlock_irqrestore(&state->port->lock, flags);
        }
-
+       unlock_kernel();
 #if 0
        /*
         * No need to wake up processes in open wait, since they