diff options
-rw-r--r-- | tty/tiny_tty.c | 123 |
1 files changed, 64 insertions, 59 deletions
diff --git a/tty/tiny_tty.c b/tty/tiny_tty.c index 889c789..add9522 100644 --- a/tty/tiny_tty.c +++ b/tty/tiny_tty.c @@ -24,19 +24,18 @@ #include <linux/serial.h> #include <linux/sched.h> #include <linux/seq_file.h> -#include <asm/uaccess.h> - +#include <linux/uaccess.h> #define DRIVER_VERSION "v2.0" #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" #define DRIVER_DESC "Tiny TTY driver" /* Module information */ -MODULE_AUTHOR( DRIVER_AUTHOR ); -MODULE_DESCRIPTION( DRIVER_DESC ); +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); -#define DELAY_TIME HZ * 2 /* 2 seconds per character */ +#define DELAY_TIME (HZ * 2) /* 2 seconds per character */ #define TINY_DATA_CHARACTER 't' #define TINY_TTY_MAJOR 240 /* experimental range */ @@ -59,6 +58,7 @@ struct tiny_serial { }; static struct tiny_serial *tiny_table[TINY_TTY_MINORS]; /* initially all NULL */ +static struct tty_port tiny_tty_port[TINY_TTY_MINORS]; static void tiny_timer(unsigned long timer_data) @@ -135,9 +135,10 @@ static int tiny_open(struct tty_struct *tty, struct file *file) } tiny->timer = timer; } - tiny->timer->data = (unsigned long )tiny; + tiny->timer->data = (unsigned long)tiny; tiny->timer->expires = jiffies + DELAY_TIME; tiny->timer->function = tiny_timer; + init_timer(tiny->timer); add_timer(tiny->timer); } @@ -172,9 +173,9 @@ static void tiny_close(struct tty_struct *tty, struct file *file) if (tiny) do_close(tiny); -} +} -static int tiny_write(struct tty_struct *tty, +static int tiny_write(struct tty_struct *tty, const unsigned char *buffer, int count) { struct tiny_serial *tiny = tty->driver_data; @@ -193,17 +194,17 @@ static int tiny_write(struct tty_struct *tty, /* fake sending the data out a hardware port by * writing it to the kernel debug log. */ - printk(KERN_DEBUG "%s - ", __FUNCTION__); + pr_debug("%s - ", __func__); for (i = 0; i < count; ++i) - printk("%02x ", buffer[i]); - printk("\n"); - + pr_info("%02x ", buffer[i]); + pr_info("\n"); + exit: up(&tiny->sem); return retval; } -static int tiny_write_room(struct tty_struct *tty) +static int tiny_write_room(struct tty_struct *tty) { struct tiny_serial *tiny = tty->driver_data; int room = -EINVAL; @@ -212,7 +213,7 @@ static int tiny_write_room(struct tty_struct *tty) return -ENODEV; down(&tiny->sem); - + if (!tiny->open_count) { /* port was not opened */ goto exit; @@ -239,51 +240,51 @@ static void tiny_set_termios(struct tty_struct *tty, struct ktermios *old_termio if ((cflag == old_termios->c_cflag) && (RELEVANT_IFLAG(tty->termios.c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) { - printk(KERN_DEBUG " - nothing to change...\n"); + pr_debug(" - nothing to change...\n"); return; } } /* get the byte size */ switch (cflag & CSIZE) { - case CS5: - printk(KERN_DEBUG " - data bits = 5\n"); - break; - case CS6: - printk(KERN_DEBUG " - data bits = 6\n"); - break; - case CS7: - printk(KERN_DEBUG " - data bits = 7\n"); - break; - default: - case CS8: - printk(KERN_DEBUG " - data bits = 8\n"); - break; + case CS5: + pr_debug(" - data bits = 5\n"); + break; + case CS6: + pr_debug(" - data bits = 6\n"); + break; + case CS7: + pr_debug(" - data bits = 7\n"); + break; + default: + case CS8: + pr_debug(" - data bits = 8\n"); + break; } - + /* determine the parity */ if (cflag & PARENB) if (cflag & PARODD) - printk(KERN_DEBUG " - parity = odd\n"); + pr_debug(" - parity = odd\n"); else - printk(KERN_DEBUG " - parity = even\n"); + pr_debug(" - parity = even\n"); else - printk(KERN_DEBUG " - parity = none\n"); + pr_debug(" - parity = none\n"); /* figure out the stop bits requested */ if (cflag & CSTOPB) - printk(KERN_DEBUG " - stop bits = 2\n"); + pr_debug(" - stop bits = 2\n"); else - printk(KERN_DEBUG " - stop bits = 1\n"); + pr_debug(" - stop bits = 1\n"); /* figure out the hardware flow control settings */ if (cflag & CRTSCTS) - printk(KERN_DEBUG " - RTS/CTS is enabled\n"); + pr_debug(" - RTS/CTS is enabled\n"); else - printk(KERN_DEBUG " - RTS/CTS is disabled\n"); - + pr_debug(" - RTS/CTS is disabled\n"); + /* determine software flow control */ - /* if we are implementing XON/XOFF, set the start and + /* if we are implementing XON/XOFF, set the start and * stop character in the device */ if (I_IXOFF(tty) || I_IXON(tty)) { unsigned char stop_char = STOP_CHAR(tty); @@ -291,21 +292,21 @@ static void tiny_set_termios(struct tty_struct *tty, struct ktermios *old_termio /* if we are implementing INBOUND XON/XOFF */ if (I_IXOFF(tty)) - printk(KERN_DEBUG " - INBOUND XON/XOFF is enabled, " + pr_debug(" - INBOUND XON/XOFF is enabled, " "XON = %2x, XOFF = %2x", start_char, stop_char); else - printk(KERN_DEBUG" - INBOUND XON/XOFF is disabled"); + pr_debug(" - INBOUND XON/XOFF is disabled"); /* if we are implementing OUTBOUND XON/XOFF */ if (I_IXON(tty)) - printk(KERN_DEBUG" - OUTBOUND XON/XOFF is enabled, " + pr_debug(" - OUTBOUND XON/XOFF is enabled, " "XON = %2x, XOFF = %2x", start_char, stop_char); else - printk(KERN_DEBUG" - OUTBOUND XON/XOFF is disabled"); + pr_debug(" - OUTBOUND XON/XOFF is disabled"); } /* get the baud rate wanted */ - printk(KERN_DEBUG " - baud rate = %d", tty_get_baud_rate(tty)); + pr_debug(" - baud rate = %d", tty_get_baud_rate(tty)); } /* Our fake UART values */ @@ -326,12 +327,12 @@ static int tiny_tiocmget(struct tty_struct *tty) unsigned int mcr = tiny->mcr; result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | /* DTR is set */ - ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | /* RTS is set */ - ((mcr & MCR_LOOP) ? TIOCM_LOOP : 0) | /* LOOP is set */ - ((msr & MSR_CTS) ? TIOCM_CTS : 0) | /* CTS is set */ - ((msr & MSR_CD) ? TIOCM_CAR : 0) | /* Carrier detect is set*/ - ((msr & MSR_RI) ? TIOCM_RI : 0) | /* Ring Indicator is set */ - ((msr & MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */ + ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | /* RTS is set */ + ((mcr & MCR_LOOP) ? TIOCM_LOOP : 0) | /* LOOP is set */ + ((msr & MSR_CTS) ? TIOCM_CTS : 0) | /* CTS is set */ + ((msr & MSR_CD) ? TIOCM_CAR : 0) | /* Carrier detect is set*/ + ((msr & MSR_RI) ? TIOCM_RI : 0) | /* Ring Indicator is set */ + ((msr & MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */ return result; } @@ -438,7 +439,7 @@ static int tiny_ioctl(struct tty_struct *tty, unsigned int cmd, if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || - ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { + ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { return 0; } cprev = cnow; @@ -497,19 +498,19 @@ static int tiny_ioctl(struct tty_struct *tty, unsigned int cmd, static int tiny_proc_open(struct inode *inode, struct file *file) { - return single_open(file, tiny_proc_show, NULL); + return single_open(file, tiny_proc_show, NULL); } static const struct file_operations serial_proc_fops = { - .owner = THIS_MODULE, - .open = tiny_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, + .owner = THIS_MODULE, + .open = tiny_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; -static struct tty_operations serial_ops = { +static const struct tty_operations serial_ops = { .open = tiny_open, .close = tiny_close, .write = tiny_write, @@ -544,11 +545,15 @@ static int __init tiny_init(void) tiny_tty_driver->init_termios = tty_std_termios; tiny_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty_set_operations(tiny_tty_driver, &serial_ops); + for (i = 0; i < TINY_TTY_MINORS; i++) { + tty_port_init(tiny_tty_port + i); + tty_port_link_device(tiny_tty_port + i, tiny_tty_driver, i); + } /* register the tty driver */ retval = tty_register_driver(tiny_tty_driver); if (retval) { - printk(KERN_ERR "failed to register tiny tty driver"); + pr_err("failed to register tiny tty driver"); put_tty_driver(tiny_tty_driver); return retval; } @@ -556,7 +561,7 @@ static int __init tiny_init(void) for (i = 0; i < TINY_TTY_MINORS; ++i) tty_register_device(tiny_tty_driver, i, NULL); - printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION); + pr_info(DRIVER_DESC " " DRIVER_VERSION); return retval; } |