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)  * printf.c:  Internal prom library printf facility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Copyright (c) 2002 Pete Zaitcev (zaitcev@yahoo.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  * We used to warn all over the code: DO NOT USE prom_printf(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  * and yet people do. Anton's banking code was outputting banks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  * with prom_printf for most of the 2.4 lifetime. Since an effective
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)  * stick is not available, we deployed a carrot: an early printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)  * through PROM by means of -p boot option. This ought to fix it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)  * USE printk; if you need, deploy -p.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/openprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define CONSOLE_WRITE_BUF_SIZE	1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static char ppbuf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static char console_write_buf[CONSOLE_WRITE_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static DEFINE_RAW_SPINLOCK(console_write_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void notrace prom_write(const char *buf, unsigned int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	unsigned int dest_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	char *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	dest = console_write_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	raw_spin_lock_irqsave(&console_write_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	dest_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	while (n-- != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		char ch = *buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		if (ch == '\n') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 			*dest++ = '\r';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 			dest_len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		*dest++ = ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		dest_len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		if (dest_len >= CONSOLE_WRITE_BUF_SIZE - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 			prom_console_write_buf(console_write_buf, dest_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 			dest = console_write_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 			dest_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	if (dest_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		prom_console_write_buf(console_write_buf, dest_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	raw_spin_unlock_irqrestore(&console_write_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void notrace prom_printf(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	i = vscnprintf(ppbuf, sizeof(ppbuf), fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	prom_write(ppbuf, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }