From fd5b6637939816e80ed8bb7fc6efb68b9f174a7b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 18 Jul 2010 15:07:59 +0200 Subject: [PATCH] Configure word length --- include/grub/ns8250.h | 6 ++++++ include/grub/serial.h | 10 ++-------- term/ns8250.c | 6 +++++- term/serial.c | 13 +------------ term/usbserial.c | 6 +++++- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/grub/ns8250.h b/include/grub/ns8250.h index f21a1a3e3..f8b9c3a8c 100644 --- a/include/grub/ns8250.h +++ b/include/grub/ns8250.h @@ -45,6 +45,12 @@ #define UART_ODD_PARITY 0x08 #define UART_EVEN_PARITY 0x18 +/* The type of word length. */ +#define UART_5BITS_WORD 0x00 +#define UART_6BITS_WORD 0x01 +#define UART_7BITS_WORD 0x02 +#define UART_8BITS_WORD 0x03 + /* The type of the length of stop bit. */ #define UART_1_STOP_BIT 0x00 #define UART_2_STOP_BITS 0x04 diff --git a/include/grub/serial.h b/include/grub/serial.h index 5afc1f172..e66dcf80d 100644 --- a/include/grub/serial.h +++ b/include/grub/serial.h @@ -53,7 +53,7 @@ typedef enum struct grub_serial_config { unsigned speed; - unsigned short word_len; + int word_len; grub_serial_parity_t parity; grub_serial_stop_bits_t stop_bits; }; @@ -84,12 +84,6 @@ grub_err_t grub_serial_register (struct grub_serial_port *port); void grub_serial_unregister (struct grub_serial_port *port); -/* The type of word length. */ -#define UART_5BITS_WORD 0x00 -#define UART_6BITS_WORD 0x01 -#define UART_7BITS_WORD 0x02 -#define UART_8BITS_WORD 0x03 - /* Set default settings. */ static inline grub_err_t grub_serial_config_defaults (struct grub_serial_port *port) @@ -101,7 +95,7 @@ grub_serial_config_defaults (struct grub_serial_port *port) #else .speed = 9600, #endif - .word_len = UART_8BITS_WORD, + .word_len = 8, .parity = GRUB_SERIAL_PARITY_NONE, .stop_bits = GRUB_SERIAL_STOP_BITS_1 }; diff --git a/term/ns8250.c b/term/ns8250.c index 9677913be..93a5e215e 100644 --- a/term/ns8250.c +++ b/term/ns8250.c @@ -104,7 +104,8 @@ do_real_config (struct grub_serial_port *port) /* Set the line status. */ status |= (parities[port->config.parity] - | port->config.word_len | stop_bits[port->config.stop_bits]); + | (port->config.word_len - 5) + | stop_bits[port->config.stop_bits]); grub_outb (status, port->port + UART_LCR); /* In Yeeloong serial port has only 3 wires. */ @@ -185,6 +186,9 @@ serial_hw_configure (struct grub_serial_port *port, && config->stop_bits != GRUB_SERIAL_STOP_BITS_2) return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported stop bits"); + if (config->word_len < 5 || config->word_len > 8) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported word length"); + port->config = *config; port->configured = 0; diff --git a/term/serial.c b/term/serial.c index 5f27b16b6..aeaec5c88 100644 --- a/term/serial.c +++ b/term/serial.c @@ -187,18 +187,7 @@ grub_cmd_serial (grub_extcmd_t cmd, int argc, char **args) config.speed = grub_strtoul (state[2].arg, 0, 0); if (state[3].set) - { - if (! grub_strcmp (state[3].arg, "5")) - config.word_len = UART_5BITS_WORD; - else if (! grub_strcmp (state[3].arg, "6")) - config.word_len = UART_6BITS_WORD; - else if (! grub_strcmp (state[3].arg, "7")) - config.word_len = UART_7BITS_WORD; - else if (! grub_strcmp (state[3].arg, "8")) - config.word_len = UART_8BITS_WORD; - else - return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad word length"); - } + config.word_len = grub_strtoul (state[3].arg, 0, 0); if (state[4].set) { diff --git a/term/usbserial.c b/term/usbserial.c index 7a5aead2c..b27df8ae2 100644 --- a/term/usbserial.c +++ b/term/usbserial.c @@ -100,7 +100,8 @@ real_config (struct grub_serial_port *port) grub_usb_control_msg (port->usbdev, GRUB_USB_REQTYPE_VENDOR_OUT, GRUB_USBSERIAL_DATA_CTRL, parities[port->config.parity] - | stop_bits[port->config.stop_bits] , 0, 0, 0); + | stop_bits[port->config.stop_bits] + | port->config.word_len, 0, 0, 0); port->configured = 1; } @@ -155,6 +156,9 @@ usbserial_hw_configure (struct grub_serial_port *port, && config->stop_bits != GRUB_SERIAL_STOP_BITS_2) return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported stop bits"); + if (config->word_len < 5 || config->word_len > 8) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported word length"); + port->config = *config; port->configured = 0;