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) 2019 Axis Communications AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Based on ttyprintk.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2010 Samo Pogacnik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static const struct tty_port_operations ttynull_port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static struct tty_driver *ttynull_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static struct tty_port ttynull_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static int ttynull_open(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	return tty_port_open(&ttynull_port, tty, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void ttynull_close(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	tty_port_close(&ttynull_port, tty, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void ttynull_hangup(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	tty_port_hangup(&ttynull_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int ttynull_write(struct tty_struct *tty, const unsigned char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 			 int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int ttynull_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	return 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static const struct tty_operations ttynull_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.open = ttynull_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.close = ttynull_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.hangup = ttynull_hangup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.write = ttynull_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.write_room = ttynull_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static struct tty_driver *ttynull_device(struct console *c, int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	*index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return ttynull_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static struct console ttynull_console = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.name = "ttynull",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.device = ttynull_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static int __init ttynull_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct tty_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	driver = tty_alloc_driver(1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		TTY_DRIVER_RESET_TERMIOS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		TTY_DRIVER_REAL_RAW |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		TTY_DRIVER_UNNUMBERED_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (IS_ERR(driver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return PTR_ERR(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	tty_port_init(&ttynull_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ttynull_port.ops = &ttynull_port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	driver->driver_name = "ttynull";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	driver->name = "ttynull";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	driver->type = TTY_DRIVER_TYPE_CONSOLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	driver->init_termios.c_oflag = OPOST | OCRNL | ONOCR | ONLRET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	tty_set_operations(driver, &ttynull_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	tty_port_link_device(&ttynull_port, driver, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	ret = tty_register_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		tty_port_destroy(&ttynull_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	ttynull_driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	register_console(&ttynull_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static void __exit ttynull_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	unregister_console(&ttynull_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	tty_unregister_driver(ttynull_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	put_tty_driver(ttynull_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	tty_port_destroy(&ttynull_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) module_init(ttynull_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) module_exit(ttynull_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) MODULE_LICENSE("GPL v2");