Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2014 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Author: Rob Herring <robh@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Based on 8250 earlycon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Bjorn Helgaas <bjorn.helgaas@hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/serial_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #ifdef CONFIG_FIX_EARLYCON_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static struct console early_con = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.name =		"uart",		/* fixed up at earlycon registration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.flags =	CON_PRINTBUFFER | CON_BOOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.index =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static struct earlycon_device early_console_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.con = &early_con,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static void __iomem * __init earlycon_map(resource_size_t paddr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #ifdef CONFIG_FIX_EARLYCON_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	set_fixmap_io(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	base += paddr & ~PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	base = ioremap(paddr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (!base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		pr_err("%s: Couldn't map %pa\n", __func__, &paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void __init earlycon_init(struct earlycon_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				 const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct console *earlycon = device->con;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	const char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* scan backwards from end of string for first non-numeral */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	for (s = name + strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	     s > name && s[-1] >= '0' && s[-1] <= '9';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	     s--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (*s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		earlycon->index = simple_strtoul(s, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	len = s - name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	earlycon->data = &early_console_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static void __init earlycon_print_info(struct earlycon_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct console *earlycon = device->con;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct uart_port *port = &device->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM16 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	    port->iotype == UPIO_MEM32 || port->iotype == UPIO_MEM32BE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		pr_info("%s%d at MMIO%s %pa (options '%s')\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			earlycon->name, earlycon->index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			(port->iotype == UPIO_MEM) ? "" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			(port->iotype == UPIO_MEM16) ? "16" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			(port->iotype == UPIO_MEM32) ? "32" : "32be",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			&port->mapbase, device->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		pr_info("%s%d at I/O port 0x%lx (options '%s')\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			earlycon->name, earlycon->index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			port->iobase, device->options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int __init parse_options(struct earlycon_device *device, char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct uart_port *port = &device->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	resource_size_t addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (uart_parse_earlycon(options, &port->iotype, &addr, &options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	switch (port->iotype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	case UPIO_MEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		port->mapbase = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	case UPIO_MEM16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		port->regshift = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		port->mapbase = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	case UPIO_MEM32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case UPIO_MEM32BE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		port->regshift = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		port->mapbase = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	case UPIO_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		port->iobase = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (options) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		device->baud = simple_strtoul(options, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		length = min(strcspn(options, " ") + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			     (size_t)(sizeof(device->options)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		strlcpy(device->options, options, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int __init register_earlycon(char *buf, const struct earlycon_id *match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct uart_port *port = &early_console_dev.port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* On parsing error, pass the options buf to the setup function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (buf && !parse_options(&early_console_dev, buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	spin_lock_init(&port->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	port->uartclk = BASE_BAUD * 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (port->mapbase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		port->membase = earlycon_map(port->mapbase, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	earlycon_init(&early_console_dev, match->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	err = match->setup(&early_console_dev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	earlycon_print_info(&early_console_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!early_console_dev.con->write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	register_console(early_console_dev.con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *	setup_earlycon - match and register earlycon console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  *	@buf:	earlycon param string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *	Registers the earlycon console matching the earlycon specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  *	in the param string @buf. Acceptable param strings are of the form
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *	   <name>,io|mmio|mmio32|mmio32be,<addr>,<options>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  *	   <name>,0x<addr>,<options>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *	   <name>,<options>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  *	   <name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  *	Only for the third form does the earlycon setup() method receive the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  *	<options> string in the 'options' parameter; all other forms set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  *	the parameter to NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  *	Returns 0 if an attempt to register the earlycon was made,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  *	otherwise negative error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int __init setup_earlycon(char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	const struct earlycon_id **p_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	bool empty_compatible = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!buf || !buf[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (early_con.flags & CON_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	for (p_match = __earlycon_table; p_match < __earlycon_table_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	     p_match++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		const struct earlycon_id *match = *p_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		size_t len = strlen(match->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (strncmp(buf, match->name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		/* prefer entries with empty compatible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (empty_compatible && *match->compatible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (buf[len]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			if (buf[len] != ',')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			buf += len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return register_earlycon(buf, match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (empty_compatible) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		empty_compatible = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * This defers the initialization of the early console until after ACPI has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * been initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) bool earlycon_acpi_spcr_enable __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* early_param wrapper for setup_earlycon() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int __init param_setup_earlycon(char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	/* Just 'earlycon' is a valid param for devicetree and ACPI SPCR. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (!buf || !buf[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (IS_ENABLED(CONFIG_ACPI_SPCR_TABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			earlycon_acpi_spcr_enable = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		} else if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			return early_init_dt_scan_chosen_stdout();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	err = setup_earlycon(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (err == -ENOENT || err == -EALREADY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) early_param("earlycon", param_setup_earlycon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #ifdef CONFIG_OF_EARLY_FLATTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int __init of_setup_earlycon(const struct earlycon_id *match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			     unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			     const char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct uart_port *port = &early_console_dev.port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	const __be32 *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	bool big_endian;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	u64 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	spin_lock_init(&port->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	port->iotype = UPIO_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	addr = of_flat_dt_translate_address(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (addr == OF_BAD_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		pr_warn("[%s] bad address\n", match->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	port->mapbase = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	val = of_get_flat_dt_prop(node, "reg-offset", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		port->mapbase += be32_to_cpu(*val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	port->membase = earlycon_map(port->mapbase, SZ_4K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	val = of_get_flat_dt_prop(node, "reg-shift", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		port->regshift = be32_to_cpu(*val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	big_endian = of_get_flat_dt_prop(node, "big-endian", NULL) != NULL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		(IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		 of_get_flat_dt_prop(node, "native-endian", NULL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	val = of_get_flat_dt_prop(node, "reg-io-width", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		switch (be32_to_cpu(*val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			port->iotype = UPIO_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			port->iotype = UPIO_MEM16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			port->iotype = (big_endian) ? UPIO_MEM32BE : UPIO_MEM32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			pr_warn("[%s] unsupported reg-io-width\n", match->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	val = of_get_flat_dt_prop(node, "current-speed", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		early_console_dev.baud = be32_to_cpu(*val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	val = of_get_flat_dt_prop(node, "clock-frequency", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		port->uartclk = be32_to_cpu(*val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (options) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		early_console_dev.baud = simple_strtoul(options, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		strlcpy(early_console_dev.options, options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			sizeof(early_console_dev.options));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	earlycon_init(&early_console_dev, match->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	err = match->setup(&early_console_dev, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	earlycon_print_info(&early_console_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!early_console_dev.con->write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	register_console(early_console_dev.con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #endif /* CONFIG_OF_EARLY_FLATTREE */