Configure word length
This commit is contained in:
parent
91d135a12c
commit
fd5b663793
5 changed files with 19 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue