]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Configure word length
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 18 Jul 2010 13:07:59 +0000 (15:07 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 18 Jul 2010 13:07:59 +0000 (15:07 +0200)
include/grub/ns8250.h
include/grub/serial.h
term/ns8250.c
term/serial.c
term/usbserial.c

index f21a1a3e3d13b4ceb1adac6570f7f872cc4ba29a..f8b9c3a8c69b8e5adcfc6a98c0a20c80a3d08090 100644 (file)
 #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
index 5afc1f172ce5e12854a4de22b50efa44e47b21c3..e66dcf80d0974f46b7e2755a391398afc222886c 100644 (file)
@@ -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
     };
index 9677913be1c9c296a7d26a1b77fc9ff426766f28..93a5e215e07ecb8256db47f4ba42930753f51310 100644 (file)
@@ -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;
 
index 5f27b16b6c3276a840bfbc7f1e2c8f0ba6813add..aeaec5c88cbef2b730ade86b1a82e0ea28323f0b 100644 (file)
@@ -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)
     {
index 7a5aead2c6df621ec620d814c2dcc74fcd941840..b27df8ae2e0dd9b9287f0d6a656cbeb972f6214f 100644 (file)
@@ -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;