tty/serial/core: Introduce poll_init callback
authorAnton Vorontsov <anton.vorontsov@linaro.org>
Mon, 24 Sep 2012 21:27:53 +0000 (14:27 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2012 20:47:02 +0000 (13:47 -0700)
It was noticed that polling drivers (like KGDB) are not able to use
serial ports if the ports were not previously initialized via console.
I.e.  when booting with console=ttyAMA0 kgdboc=ttyAMA0, everything works
fine, but with console=ttyFOO kgdboc=ttyAMA0, the kgdboc doesn't work.

This is because we don't initialize the hardware. Calling ->startup() is
not an option, because drivers request interrupts there, and drivers
fail to handle situations when tty isn't opened with interrupts enabled.

So, we have to implement a new callback (actually, tty_ops already have
a similar callback), which does everything needed to initialize just the
hardware.

Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/serial_core.c
include/linux/serial_core.h

index 78036c510cccd299724d8d42d9d51fe526dc25dd..0fcfd98a9566c09c11a5b567dac8d6bcfd2295cd 100644 (file)
@@ -2129,6 +2129,7 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
        int bits = 8;
        int parity = 'n';
        int flow = 'n';
+       int ret;
 
        if (!state || !state->uart_port)
                return -1;
@@ -2137,6 +2138,22 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
        if (!(port->ops->poll_get_char && port->ops->poll_put_char))
                return -1;
 
+       if (port->ops->poll_init) {
+               struct tty_port *tport = &state->port;
+
+               ret = 0;
+               mutex_lock(&tport->mutex);
+               /*
+                * We don't set ASYNCB_INITIALIZED as we only initialized the
+                * hw, e.g. state->xmit is still uninitialized.
+                */
+               if (!test_bit(ASYNCB_INITIALIZED, &tport->flags))
+                       ret = port->ops->poll_init(port);
+               mutex_unlock(&tport->mutex);
+               if (ret)
+                       return ret;
+       }
+
        if (options) {
                uart_parse_options(options, &baud, &parity, &bits, &flow);
                return uart_set_options(port, NULL, baud, parity, bits, flow);
index bb010030828a4d5fd8a9f5da4d2da42ddcadabfb..f9b22ec7a9f383199d58431c6e6a1ec136ebe46c 100644 (file)
@@ -275,6 +275,7 @@ struct uart_ops {
        int             (*verify_port)(struct uart_port *, struct serial_struct *);
        int             (*ioctl)(struct uart_port *, unsigned int, unsigned long);
 #ifdef CONFIG_CONSOLE_POLL
+       int             (*poll_init)(struct uart_port *);
        void    (*poll_put_char)(struct uart_port *, unsigned char);
        int             (*poll_get_char)(struct uart_port *);
 #endif