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)  *	linux/arch/alpha/kernel/srmcons.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Callback based driver for SRM Console console device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * (TTY driver and console driver)
^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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static DEFINE_SPINLOCK(srmcons_callback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int srm_is_registered_console = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * The TTY driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define MAX_SRM_CONSOLE_DEVICES 1	/* only support 1 console device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) struct srmcons_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct tty_port port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) } srmcons_singleton;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) typedef union _srmcons_result {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		unsigned long c :61;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		unsigned long status :3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	} bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	long as_long;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) } srmcons_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* called with callback_lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) srmcons_do_receive_chars(struct tty_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	srmcons_result result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int count = 0, loops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		result.as_long = callback_getc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		if (result.bits.status < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			tty_insert_flip_char(port, (char)result.bits.c, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	} while((result.bits.status & 1) && (++loops < 10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		tty_schedule_flip(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) srmcons_receive_chars(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct srmcons_private *srmconsp = from_timer(srmconsp, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct tty_port *port = &srmconsp->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	int incr = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (spin_trylock(&srmcons_callback_lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (!srmcons_do_receive_chars(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			incr = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		spin_unlock(&srmcons_callback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	spin_lock(&port->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (port->tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		mod_timer(&srmconsp->timer, jiffies + incr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	spin_unlock(&port->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /* called with callback_lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) srmcons_do_write(struct tty_port *port, const char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	static char str_cr[1] = "\r";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	long c, remaining = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	srmcons_result result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	char *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int need_cr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	for (cur = (char *)buf; remaining > 0; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		need_cr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		/* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		 * Break it up into reasonable size chunks to allow a chance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		 * for input to get in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		for (c = 0; c < min_t(long, 128L, remaining) && !need_cr; c++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			if (cur[c] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				need_cr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		while (c > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			result.as_long = callback_puts(0, cur, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			c -= result.bits.c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			remaining -= result.bits.c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			cur += result.bits.c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			 * Check for pending input iff a tty port was provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			if (port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				srmcons_do_receive_chars(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		while (need_cr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			result.as_long = callback_puts(0, str_cr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			if (result.bits.c > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				need_cr = 0;
^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 count;
^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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) srmcons_write(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	      const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	spin_lock_irqsave(&srmcons_callback_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	srmcons_do_write(tty->port, (const char *) buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	spin_unlock_irqrestore(&srmcons_callback_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) srmcons_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) srmcons_chars_in_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) srmcons_open(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct srmcons_private *srmconsp = &srmcons_singleton;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct tty_port *port = &srmconsp->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	spin_lock_irqsave(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!port->tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		tty->driver_data = srmconsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		tty->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		port->tty = tty; /* XXX proper refcounting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		mod_timer(&srmconsp->timer, jiffies + 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) srmcons_close(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct srmcons_private *srmconsp = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct tty_port *port = &srmconsp->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	spin_lock_irqsave(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (tty->count == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		port->tty = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		del_timer(&srmconsp->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct tty_driver *srmcons_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static const struct tty_operations srmcons_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.open		= srmcons_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.close		= srmcons_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.write		= srmcons_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.write_room	= srmcons_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	.chars_in_buffer= srmcons_chars_in_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) srmcons_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	timer_setup(&srmcons_singleton.timer, srmcons_receive_chars, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (srm_is_registered_console) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		struct tty_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		driver = alloc_tty_driver(MAX_SRM_CONSOLE_DEVICES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (!driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		tty_port_init(&srmcons_singleton.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		driver->driver_name = "srm";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		driver->name = "srm";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		driver->major = 0; 	/* dynamic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		driver->minor_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		driver->type = TTY_DRIVER_TYPE_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		driver->subtype = SYSTEM_TYPE_SYSCONS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		tty_set_operations(driver, &srmcons_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		tty_port_link_device(&srmcons_singleton.port, driver, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		err = tty_register_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			tty_port_destroy(&srmcons_singleton.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		srmcons_driver = driver;
^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) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) device_initcall(srmcons_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * The console driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) srm_console_write(struct console *co, const char *s, unsigned count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	spin_lock_irqsave(&srmcons_callback_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	srmcons_do_write(NULL, s, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	spin_unlock_irqrestore(&srmcons_callback_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static struct tty_driver *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) srm_console_device(struct console *co, int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	*index = co->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return srmcons_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) srm_console_setup(struct console *co, char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static struct console srmcons = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	.name		= "srm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	.write		= srm_console_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.device		= srm_console_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.setup		= srm_console_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.flags		= CON_PRINTBUFFER | CON_BOOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.index		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) register_srm_console(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (!srm_is_registered_console) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		callback_open_console();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		register_console(&srmcons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		srm_is_registered_console = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unregister_srm_console(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (srm_is_registered_console) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		callback_close_console();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		unregister_console(&srmcons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		srm_is_registered_console = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }