source: mainline/kernel/genarch/include/genarch/drivers/ns16550/ns16550.h

Last change on this file was 98a935e, checked in by jxsvoboda <5887334+jxsvoboda@…>, 5 years ago

Configure NS16550 transmission format settings on initialization on PCs.

Currently, the NS116550 serial line controller is left with its
settings as it was left by the boot firmware and/or bootloader.
On my computer, this was an invalid configuration, and it left me
with a really slow booting system, since each output character
had to go through the full timeout loop in ns16550_sendb().

This patch adds the necessary bit and register descriptions to configure
the baud rate and transmission settings, as well as configuring them on
post-SMP initialization on ia32 and amd64, currently with values matching
the ns8250 userspace character device driver (38400 baud, 8-bit words,
2 stop bits, no parity).

This could perhaps be changed to be adjustable with a kernel command-line
argument, or through the configuration system.

This change does not affect emulators, since those largely ignore these
settings.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2001-2004 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kernel_genarch
30 * @{
31 */
32/**
33 * @file
34 * @brief Headers for NS 16550 serial controller.
35 */
36
37#ifndef KERN_NS16550_H_
38#define KERN_NS16550_H_
39
40#include <ddi/ddi.h>
41#include <ddi/irq.h>
42#include <typedefs.h>
43#include <console/chardev.h>
44
45#define NS156440_CLOCK 115200 /** Internal clock speed, max. baud rate. */
46
47#define IER_ERBFI 0x01 /** Enable Receive Buffer Full Interrupt. */
48#define MCR_OUT2 0x08 /** OUT2. */
49
50#define LCR_DLAB 0x80 /** Divisor Latch Access bit. */
51#define LCR_SBE 0x40 /** RS-232 Break Signal bit. */
52
53#define LCR_PARITY_NONE 0x00 /** No parity bit. */
54#define LCR_PARITY_ODD 0x08 /** Odd parity. */
55#define LCR_PARITY_EVEN 0x18 /** Even parity. */
56#define LCR_PARITY_MARK 0x28 /** Parity bit always one. */
57#define LCR_PARITY_SPACE 0x38 /** Parity bit always zero. */
58
59#define LCR_STOP_BIT_ONE 0x00 /** One stop bit. */
60#define LCR_STOP_BIT_TWO 0x04 /** Two stop bits. */
61
62#define LCR_WORD_LEN_5 0x00 /** 5-bit word length. */
63#define LCR_WORD_LEN_6 0x01 /** 6-bit word length. */
64#define LCR_WORD_LEN_7 0x02 /** 7-bit word length. */
65#define LCR_WORD_LEN_8 0x03 /** 8-bit word length. */
66
67/** NS16550 registers. */
68typedef enum {
69 NS16550_REG_RBR = 0, /**< Receiver Buffer Register (read). */
70 NS16550_REG_THR = 0, /**< Transmitter Holder Register (write). */
71 NS16550_REG_DLL = 0, /**< Baud rate divisor latch low byte (write). */
72 NS16550_REG_IER = 1, /**< Interrupt Enable Register. */
73 NS16550_REG_DLH = 1, /**< Baud rate divisor latch high byte (write). */
74 NS16550_REG_IIR = 2, /**< Interrupt Ident Register (read). */
75 NS16550_REG_FCR = 2, /**< FIFO control register (write). */
76 NS16550_REG_LCR = 3, /**< Line Control register. */
77 NS16550_REG_MCR = 4, /**< Modem Control Register. */
78 NS16550_REG_LSR = 5, /**< Line Status Register. */
79} ns16550_reg_t;
80
81/** Structure representing the ns16550 device. */
82typedef struct {
83 irq_t irq;
84 volatile ioport8_t *ns16550;
85 indev_t *input;
86 outdev_t *output;
87 parea_t parea;
88 int reg_shift;
89} ns16550_instance_t;
90
91extern ns16550_instance_t *ns16550_init(ioport8_t *, unsigned, inr_t, cir_t,
92 void *, outdev_t **);
93extern void ns16550_format_set(ns16550_instance_t *, unsigned, uint8_t);
94extern void ns16550_wire(ns16550_instance_t *, indev_t *);
95
96#endif
97
98/** @}
99 */
Note: See TracBrowser for help on using the repository browser.