Linux Audio

Check our new training course

Loading...
v3.15
  1#include "boot.h"
  2
  3#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
  4
  5#define XMTRDY          0x20
  6
  7#define DLAB		0x80
  8
  9#define TXR             0       /*  Transmit register (WRITE) */
 10#define RXR             0       /*  Receive register  (READ)  */
 11#define IER             1       /*  Interrupt Enable          */
 12#define IIR             2       /*  Interrupt ID              */
 13#define FCR             2       /*  FIFO control              */
 14#define LCR             3       /*  Line control              */
 15#define MCR             4       /*  Modem control             */
 16#define LSR             5       /*  Line Status               */
 17#define MSR             6       /*  Modem Status              */
 18#define DLL             0       /*  Divisor Latch Low         */
 19#define DLH             1       /*  Divisor latch High        */
 20
 21#define DEFAULT_BAUD 9600
 22
 23static void early_serial_init(int port, int baud)
 24{
 25	unsigned char c;
 26	unsigned divisor;
 27
 28	outb(0x3, port + LCR);	/* 8n1 */
 29	outb(0, port + IER);	/* no interrupt */
 30	outb(0, port + FCR);	/* no fifo */
 31	outb(0x3, port + MCR);	/* DTR + RTS */
 32
 33	divisor	= 115200 / baud;
 34	c = inb(port + LCR);
 35	outb(c | DLAB, port + LCR);
 36	outb(divisor & 0xff, port + DLL);
 37	outb((divisor >> 8) & 0xff, port + DLH);
 38	outb(c & ~DLAB, port + LCR);
 39
 40	early_serial_base = port;
 41}
 42
 43static void parse_earlyprintk(void)
 44{
 45	int baud = DEFAULT_BAUD;
 46	char arg[32];
 47	int pos = 0;
 48	int port = 0;
 49
 50	if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
 51		char *e;
 52
 53		if (!strncmp(arg, "serial", 6)) {
 54			port = DEFAULT_SERIAL_PORT;
 55			pos += 6;
 56		}
 57
 58		if (arg[pos] == ',')
 59			pos++;
 60
 61		/*
 62		 * make sure we have
 63		 *	"serial,0x3f8,115200"
 64		 *	"serial,ttyS0,115200"
 65		 *	"ttyS0,115200"
 66		 */
 67		if (pos == 7 && !strncmp(arg + pos, "0x", 2)) {
 68			port = simple_strtoull(arg + pos, &e, 16);
 69			if (port == 0 || arg + pos == e)
 70				port = DEFAULT_SERIAL_PORT;
 71			else
 72				pos = e - arg;
 73		} else if (!strncmp(arg + pos, "ttyS", 4)) {
 74			static const int bases[] = { 0x3f8, 0x2f8 };
 75			int idx = 0;
 76
 77			if (!strncmp(arg + pos, "ttyS", 4))
 78				pos += 4;
 79
 80			if (arg[pos++] == '1')
 81				idx = 1;
 82
 83			port = bases[idx];
 84		}
 85
 86		if (arg[pos] == ',')
 87			pos++;
 88
 89		baud = simple_strtoull(arg + pos, &e, 0);
 90		if (baud == 0 || arg + pos == e)
 91			baud = DEFAULT_BAUD;
 92	}
 93
 94	if (port)
 95		early_serial_init(port, baud);
 96}
 97
 98#define BASE_BAUD (1843200/16)
 99static unsigned int probe_baud(int port)
100{
101	unsigned char lcr, dll, dlh;
102	unsigned int quot;
103
104	lcr = inb(port + LCR);
105	outb(lcr | DLAB, port + LCR);
106	dll = inb(port + DLL);
107	dlh = inb(port + DLH);
108	outb(lcr, port + LCR);
109	quot = (dlh << 8) | dll;
110
111	return BASE_BAUD / quot;
112}
113
114static void parse_console_uart8250(void)
115{
116	char optstr[64], *options;
117	int baud = DEFAULT_BAUD;
118	int port = 0;
119
120	/*
121	 * console=uart8250,io,0x3f8,115200n8
122	 * need to make sure it is last one console !
123	 */
124	if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
125		return;
126
127	options = optstr;
128
129	if (!strncmp(options, "uart8250,io,", 12))
130		port = simple_strtoull(options + 12, &options, 0);
131	else if (!strncmp(options, "uart,io,", 8))
132		port = simple_strtoull(options + 8, &options, 0);
133	else
134		return;
135
136	if (options && (options[0] == ','))
137		baud = simple_strtoull(options + 1, &options, 0);
138	else
139		baud = probe_baud(port);
140
141	if (port)
142		early_serial_init(port, baud);
143}
144
145void console_init(void)
146{
147	parse_earlyprintk();
148
149	if (!early_serial_base)
150		parse_console_uart8250();
151}
v4.6
  1#include "boot.h"
  2
  3#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
  4
 
 
  5#define DLAB		0x80
  6
  7#define TXR             0       /*  Transmit register (WRITE) */
  8#define RXR             0       /*  Receive register  (READ)  */
  9#define IER             1       /*  Interrupt Enable          */
 10#define IIR             2       /*  Interrupt ID              */
 11#define FCR             2       /*  FIFO control              */
 12#define LCR             3       /*  Line control              */
 13#define MCR             4       /*  Modem control             */
 14#define LSR             5       /*  Line Status               */
 15#define MSR             6       /*  Modem Status              */
 16#define DLL             0       /*  Divisor Latch Low         */
 17#define DLH             1       /*  Divisor latch High        */
 18
 19#define DEFAULT_BAUD 9600
 20
 21static void early_serial_init(int port, int baud)
 22{
 23	unsigned char c;
 24	unsigned divisor;
 25
 26	outb(0x3, port + LCR);	/* 8n1 */
 27	outb(0, port + IER);	/* no interrupt */
 28	outb(0, port + FCR);	/* no fifo */
 29	outb(0x3, port + MCR);	/* DTR + RTS */
 30
 31	divisor	= 115200 / baud;
 32	c = inb(port + LCR);
 33	outb(c | DLAB, port + LCR);
 34	outb(divisor & 0xff, port + DLL);
 35	outb((divisor >> 8) & 0xff, port + DLH);
 36	outb(c & ~DLAB, port + LCR);
 37
 38	early_serial_base = port;
 39}
 40
 41static void parse_earlyprintk(void)
 42{
 43	int baud = DEFAULT_BAUD;
 44	char arg[32];
 45	int pos = 0;
 46	int port = 0;
 47
 48	if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
 49		char *e;
 50
 51		if (!strncmp(arg, "serial", 6)) {
 52			port = DEFAULT_SERIAL_PORT;
 53			pos += 6;
 54		}
 55
 56		if (arg[pos] == ',')
 57			pos++;
 58
 59		/*
 60		 * make sure we have
 61		 *	"serial,0x3f8,115200"
 62		 *	"serial,ttyS0,115200"
 63		 *	"ttyS0,115200"
 64		 */
 65		if (pos == 7 && !strncmp(arg + pos, "0x", 2)) {
 66			port = simple_strtoull(arg + pos, &e, 16);
 67			if (port == 0 || arg + pos == e)
 68				port = DEFAULT_SERIAL_PORT;
 69			else
 70				pos = e - arg;
 71		} else if (!strncmp(arg + pos, "ttyS", 4)) {
 72			static const int bases[] = { 0x3f8, 0x2f8 };
 73			int idx = 0;
 74
 75			/* += strlen("ttyS"); */
 76			pos += 4;
 77
 78			if (arg[pos++] == '1')
 79				idx = 1;
 80
 81			port = bases[idx];
 82		}
 83
 84		if (arg[pos] == ',')
 85			pos++;
 86
 87		baud = simple_strtoull(arg + pos, &e, 0);
 88		if (baud == 0 || arg + pos == e)
 89			baud = DEFAULT_BAUD;
 90	}
 91
 92	if (port)
 93		early_serial_init(port, baud);
 94}
 95
 96#define BASE_BAUD (1843200/16)
 97static unsigned int probe_baud(int port)
 98{
 99	unsigned char lcr, dll, dlh;
100	unsigned int quot;
101
102	lcr = inb(port + LCR);
103	outb(lcr | DLAB, port + LCR);
104	dll = inb(port + DLL);
105	dlh = inb(port + DLH);
106	outb(lcr, port + LCR);
107	quot = (dlh << 8) | dll;
108
109	return BASE_BAUD / quot;
110}
111
112static void parse_console_uart8250(void)
113{
114	char optstr[64], *options;
115	int baud = DEFAULT_BAUD;
116	int port = 0;
117
118	/*
119	 * console=uart8250,io,0x3f8,115200n8
120	 * need to make sure it is last one console !
121	 */
122	if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
123		return;
124
125	options = optstr;
126
127	if (!strncmp(options, "uart8250,io,", 12))
128		port = simple_strtoull(options + 12, &options, 0);
129	else if (!strncmp(options, "uart,io,", 8))
130		port = simple_strtoull(options + 8, &options, 0);
131	else
132		return;
133
134	if (options && (options[0] == ','))
135		baud = simple_strtoull(options + 1, &options, 0);
136	else
137		baud = probe_baud(port);
138
139	if (port)
140		early_serial_init(port, baud);
141}
142
143void console_init(void)
144{
145	parse_earlyprintk();
146
147	if (!early_serial_base)
148		parse_console_uart8250();
149}