#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
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;
};
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)
#else
.speed = 9600,
#endif
- .word_len = UART_8BITS_WORD,
+ .word_len = 8,
.parity = GRUB_SERIAL_PARITY_NONE,
.stop_bits = GRUB_SERIAL_STOP_BITS_1
};
/* 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. */
&& 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;
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)
{
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;
}
&& 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;