cregit-Linux how code gets into the kernel

Release 4.16 drivers/tty/serial/8250/8250_early.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Early serial console for 8250/16550 devices
 *
 * (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
 *      Bjorn Helgaas <bjorn.helgaas@hp.com>
 *
 * Based on the 8250.c serial driver, Copyright (C) 2001 Russell King,
 * and on early_printk.c by Andi Kleen.
 *
 * This is for use before the serial driver has initialized, in
 * particular, before the UARTs have been discovered and named.
 * Instead of specifying the console device as, e.g., "ttyS0",
 * we locate the device directly by its MMIO or I/O port address.
 *
 * The user can specify the device directly, e.g.,
 *      earlycon=uart8250,io,0x3f8,9600n8
 *      earlycon=uart8250,mmio,0xff5e0000,115200n8
 *      earlycon=uart8250,mmio32,0xff5e0000,115200n8
 * or
 *      console=uart8250,io,0x3f8,9600n8
 *      console=uart8250,mmio,0xff5e0000,115200n8
 *      console=uart8250,mmio32,0xff5e0000,115200n8
 */

#include <linux/tty.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/serial_reg.h>
#include <linux/serial.h>
#include <linux/serial_8250.h>
#include <asm/io.h>
#include <asm/serial.h>


static unsigned int serial8250_early_in(struct uart_port *port, int offset) { int reg_offset = offset; offset <<= port->regshift; switch (port->iotype) { case UPIO_MEM: return readb(port->membase + offset); case UPIO_MEM16: return readw(port->membase + offset); case UPIO_MEM32: return readl(port->membase + offset); case UPIO_MEM32BE: return ioread32be(port->membase + offset); case UPIO_PORT: return inb(port->iobase + offset); case UPIO_AU: return port->serial_in(port, reg_offset); default: return 0; } }

Contributors

PersonTokensPropCommitsCommitProp
Björn Helgaas3832.76%112.50%
Samium Gromoff2622.41%112.50%
Marc Gonzalez1815.52%112.50%
Kevin Cernekee1311.21%112.50%
Masahiro Yamada1311.21%112.50%
Peter Hurley65.17%112.50%
Noam Camus10.86%112.50%
Vineet Gupta10.86%112.50%
Total116100.00%8100.00%


static void serial8250_early_out(struct uart_port *port, int offset, int value) { int reg_offset = offset; offset <<= port->regshift; switch (port->iotype) { case UPIO_MEM: writeb(value, port->membase + offset); break; case UPIO_MEM16: writew(value, port->membase + offset); break; case UPIO_MEM32: writel(value, port->membase + offset); break; case UPIO_MEM32BE: iowrite32be(value, port->membase + offset); break; case UPIO_PORT: outb(value, port->iobase + offset); break; case UPIO_AU: port->serial_out(port, reg_offset, value); break; } }

Contributors

PersonTokensPropCommitsCommitProp
Björn Helgaas4233.33%112.50%
Samium Gromoff3023.81%112.50%
Marc Gonzalez2015.87%112.50%
Masahiro Yamada1511.90%112.50%
Kevin Cernekee118.73%112.50%
Peter Hurley64.76%112.50%
Noam Camus10.79%112.50%
Vineet Gupta10.79%112.50%
Total126100.00%8100.00%

#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
static void serial_putc(struct uart_port *port, int c) { unsigned int status; serial8250_early_out(port, UART_TX, c); for (;;) { status = serial8250_early_in(port, UART_LSR); if ((status & BOTH_EMPTY) == BOTH_EMPTY) break; cpu_relax(); } }

Contributors

PersonTokensPropCommitsCommitProp
Björn Helgaas4273.68%133.33%
Masahiro Yamada1424.56%133.33%
Noam Camus11.75%133.33%
Total57100.00%3100.00%


static void early_serial8250_write(struct console *console, const char *s, unsigned int count) { struct earlycon_device *device = console->data; struct uart_port *port = &device->port; uart_console_write(port, s, count, serial_putc); }

Contributors

PersonTokensPropCommitsCommitProp
Björn Helgaas3468.00%116.67%
Peter Hurley1020.00%116.67%
Russell King36.00%116.67%
Yinghai Lu24.00%233.33%
Rob Herring12.00%116.67%
Total50100.00%6100.00%


static void __init init_port(struct earlycon_device *device) { struct uart_port *port = &device->port; unsigned int divisor; unsigned char c; unsigned int ier; serial8250_early_out(port, UART_LCR, 0x3); /* 8n1 */ ier = serial8250_early_in(port, UART_IER); serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); /* no interrupt */ serial8250_early_out(port, UART_FCR, 0); /* no fifo */ serial8250_early_out(port, UART_MCR, 0x3); /* DTR + RTS */ if (port->uartclk && device->baud) { divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud); c = serial8250_early_in(port, UART_LCR); serial8250_early_out(port, UART_LCR, c | UART_LCR_DLAB); serial8250_early_out(port, UART_DLL, divisor & 0xff); serial8250_early_out(port, UART_DLM, (divisor >> 8) & 0xff); serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB); } }

Contributors

PersonTokensPropCommitsCommitProp
Björn Helgaas12875.29%116.67%
Rob Herring1710.00%233.33%
Matt Redfearn127.06%116.67%
Noam Camus95.29%116.67%
Alexey Brodkin42.35%116.67%
Total170100.00%6100.00%


int __init early_serial8250_setup(struct earlycon_device *device, const char *options) { if (!(device->port.membase || device->port.iobase)) return -ENODEV; if (!device->baud) { struct uart_port *port = &device->port; unsigned int ier; /* assume the device was initialized, only mask interrupts */ ier = serial8250_early_in(port, UART_IER); serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); } else init_port(device); device->con->write = early_serial8250_write; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Hurley3838.78%222.22%
Björn Helgaas3737.76%111.11%
Rob Herring1717.35%222.22%
Alan Cox22.04%111.11%
Samium Gromoff22.04%111.11%
Yinghai Lu11.02%111.11%
Josh Boyer11.02%111.11%
Total98100.00%9100.00%

EARLYCON_DECLARE(uart8250, early_serial8250_setup); EARLYCON_DECLARE(uart, early_serial8250_setup); OF_EARLYCON_DECLARE(ns16550, "ns16550", early_serial8250_setup); OF_EARLYCON_DECLARE(ns16550a, "ns16550a", early_serial8250_setup); OF_EARLYCON_DECLARE(uart, "nvidia,tegra20-uart", early_serial8250_setup); OF_EARLYCON_DECLARE(uart, "snps,dw-apb-uart", early_serial8250_setup); #ifdef CONFIG_SERIAL_8250_OMAP
static int __init early_omap8250_setup(struct earlycon_device *device, const char *options) { struct uart_port *port = &device->port; if (!(device->port.membase || device->port.iobase)) return -ENODEV; port->regshift = 2; device->con->write = early_serial8250_write; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Peter Hurley65100.00%1100.00%
Total65100.00%1100.00%

OF_EARLYCON_DECLARE(omap8250, "ti,omap2-uart", early_omap8250_setup); OF_EARLYCON_DECLARE(omap8250, "ti,omap3-uart", early_omap8250_setup); OF_EARLYCON_DECLARE(omap8250, "ti,omap4-uart", early_omap8250_setup); #endif #ifdef CONFIG_SERIAL_8250_RT288X unsigned int au_serial_in(struct uart_port *p, int offset); void au_serial_out(struct uart_port *p, int offset, int value);
static int __init early_au_setup(struct earlycon_device *dev, const char *opt) { dev->port.serial_in = au_serial_in; dev->port.serial_out = au_serial_out; dev->port.iotype = UPIO_AU; dev->con->write = early_serial8250_write; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Marc Gonzalez52100.00%1100.00%
Total52100.00%1100.00%

OF_EARLYCON_DECLARE(palmchip, "ralink,rt2880-uart", early_au_setup); #endif

Overall Contributors

PersonTokensPropCommitsCommitProp
Björn Helgaas35139.26%13.57%
Peter Hurley15717.56%517.86%
Marc Gonzalez13214.77%13.57%
Samium Gromoff586.49%13.57%
Masahiro Yamada424.70%27.14%
Rob Herring404.47%310.71%
Kevin Cernekee242.68%13.57%
Scott Wood242.68%13.57%
Noam Camus121.34%13.57%
Matt Redfearn121.34%13.57%
Kefeng Wang91.01%13.57%
Jon Hunter91.01%13.57%
Yinghai Lu91.01%27.14%
Alexey Brodkin40.45%13.57%
Alan Cox30.34%13.57%
Russell King30.34%13.57%
Vineet Gupta20.22%13.57%
Greg Kroah-Hartman20.22%27.14%
Josh Boyer10.11%13.57%
Total894100.00%28100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.