Release 4.7 drivers/input/serio/serport.c
  
  
/*
 * Input device TTY line discipline
 *
 * Copyright (c) 1999-2002 Vojtech Pavlik
 *
 * This is a module that converts a tty line into a much simpler
 * 'serial io port' abstraction that the input device drivers use.
 */
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */
#include <asm/uaccess.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/serio.h>
#include <linux/tty.h>
#include <linux/compat.h>
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Input device TTY line discipline");
MODULE_LICENSE("GPL");
MODULE_ALIAS_LDISC(N_MOUSE);
#define SERPORT_BUSY	1
#define SERPORT_ACTIVE	2
#define SERPORT_DEAD	3
struct serport {
	
struct tty_struct *tty;
	
wait_queue_head_t wait;
	
struct serio *serio;
	
struct serio_device_id id;
	
spinlock_t lock;
	
unsigned long flags;
};
/*
 * Callback functions from the serio code.
 */
static int serport_serio_write(struct serio *serio, unsigned char data)
{
	struct serport *serport = serio->port_data;
	return -(serport->tty->ops->write(serport->tty, &data, 1) != 1);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 45 | 93.75% | 1 | 25.00% | 
| dmitry torokhov | dmitry torokhov | 1 | 2.08% | 1 | 25.00% | 
| alan cox | alan cox | 1 | 2.08% | 1 | 25.00% | 
| al viro | al viro | 1 | 2.08% | 1 | 25.00% | 
 | Total | 48 | 100.00% | 4 | 100.00% | 
static int serport_serio_open(struct serio *serio)
{
	struct serport *serport = serio->port_data;
	unsigned long flags;
	spin_lock_irqsave(&serport->lock, flags);
	set_bit(SERPORT_ACTIVE, &serport->flags);
	spin_unlock_irqrestore(&serport->lock, flags);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dmitry torokhov | dmitry torokhov | 57 | 100.00% | 1 | 100.00% | 
 | Total | 57 | 100.00% | 1 | 100.00% | 
static void serport_serio_close(struct serio *serio)
{
	struct serport *serport = serio->port_data;
	unsigned long flags;
	spin_lock_irqsave(&serport->lock, flags);
	clear_bit(SERPORT_ACTIVE, &serport->flags);
	set_bit(SERPORT_DEAD, &serport->flags);
	spin_unlock_irqrestore(&serport->lock, flags);
	wake_up_interruptible(&serport->wait);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dmitry torokhov | dmitry torokhov | 42 | 58.33% | 3 | 60.00% | 
| pre-git | pre-git | 27 | 37.50% | 1 | 20.00% | 
| vojtech pavlik | vojtech pavlik | 3 | 4.17% | 1 | 20.00% | 
 | Total | 72 | 100.00% | 5 | 100.00% | 
/*
 * serport_ldisc_open() is the routine that is called upon setting our line
 * discipline on a tty. It prepares the serio struct.
 */
static int serport_ldisc_open(struct tty_struct *tty)
{
	struct serport *serport;
	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;
	serport = kzalloc(sizeof(struct serport), GFP_KERNEL);
	if (!serport)
		return -ENOMEM;
	serport->tty = tty;
	spin_lock_init(&serport->lock);
	init_waitqueue_head(&serport->wait);
	tty->disc_data = serport;
	tty->receive_room = 256;
	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 36 | 37.11% | 1 | 12.50% | 
| dmitry torokhov | dmitry torokhov | 34 | 35.05% | 2 | 25.00% | 
| vojtech pavlik | vojtech pavlik | 15 | 15.46% | 2 | 25.00% | 
| alan cox | alan cox | 6 | 6.19% | 1 | 12.50% | 
| christoph hellwig | christoph hellwig | 5 | 5.15% | 1 | 12.50% | 
| pekka j enberg | pekka j enberg | 1 | 1.03% | 1 | 12.50% | 
 | Total | 97 | 100.00% | 8 | 100.00% | 
/*
 * serport_ldisc_close() is the opposite of serport_ldisc_open()
 */
static void serport_ldisc_close(struct tty_struct *tty)
{
	struct serport *serport = (struct serport *) tty->disc_data;
	kfree(serport);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 30 | 100.00% | 1 | 100.00% | 
 | Total | 30 | 100.00% | 1 | 100.00% | 
/*
 * serport_ldisc_receive() is called by the low level tty driver when characters
 * are ready for us. We forward the characters and flags, one by one to the
 * 'interrupt' routine.
 */
static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *cp, char *fp, int count)
{
	struct serport *serport = (struct serport*) tty->disc_data;
	unsigned long flags;
	unsigned int ch_flags = 0;
	int i;
	spin_lock_irqsave(&serport->lock, flags);
	if (!test_bit(SERPORT_ACTIVE, &serport->flags))
		goto out;
	for (i = 0; i < count; i++) {
		if (fp) {
			switch (fp[i]) {
			case TTY_FRAME:
				ch_flags = SERIO_FRAME;
				break;
			case TTY_PARITY:
				ch_flags = SERIO_PARITY;
				break;
			default:
				ch_flags = 0;
				break;
			}
		}
		serio_interrupt(serport->serio, cp[i], ch_flags);
	}
out:
	spin_unlock_irqrestore(&serport->lock, flags);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 65 | 41.94% | 1 | 16.67% | 
| dmitry torokhov | dmitry torokhov | 42 | 27.10% | 1 | 16.67% | 
| david engraf | david engraf | 38 | 24.52% | 1 | 16.67% | 
| peter hurley | peter hurley | 8 | 5.16% | 1 | 16.67% | 
| linus torvalds | linus torvalds | 1 | 0.65% | 1 | 16.67% | 
| vojtech pavlik | vojtech pavlik | 1 | 0.65% | 1 | 16.67% | 
 | Total | 155 | 100.00% | 6 | 100.00% | 
/*
 * serport_ldisc_read() just waits indefinitely if everything goes well.
 * However, when the serio driver closes the serio port, it finishes,
 * returning 0 characters.
 */
static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, unsigned char __user * buf, size_t nr)
{
	struct serport *serport = (struct serport*) tty->disc_data;
	struct serio *serio;
	if (test_and_set_bit(SERPORT_BUSY, &serport->flags))
		return -EBUSY;
	serport->serio = serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
	if (!serio)
		return -ENOMEM;
	strlcpy(serio->name, "Serial port", sizeof(serio->name));
	snprintf(serio->phys, sizeof(serio->phys), "%s/serio0", tty_name(tty));
	serio->id = serport->id;
	serio->id.type = SERIO_RS232;
	serio->write = serport_serio_write;
	serio->open = serport_serio_open;
	serio->close = serport_serio_close;
	serio->port_data = serport;
	serio->dev.parent = tty->dev;
	serio_register_port(serport->serio);
	printk(KERN_INFO "serio: Serial port %s\n", tty_name(tty));
	wait_event_interruptible(serport->wait, test_bit(SERPORT_DEAD, &serport->flags));
	serio_unregister_port(serport->serio);
	serport->serio = NULL;
	clear_bit(SERPORT_DEAD, &serport->flags);
	clear_bit(SERPORT_BUSY, &serport->flags);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dmitry torokhov | dmitry torokhov | 130 | 53.28% | 1 | 12.50% | 
| pre-git | pre-git | 74 | 30.33% | 1 | 12.50% | 
| vojtech pavlik | vojtech pavlik | 23 | 9.43% | 2 | 25.00% | 
| dmitry eremin-baryshkov | dmitry eremin-baryshkov | 10 | 4.10% | 1 | 12.50% | 
| linus torvalds | linus torvalds | 5 | 2.05% | 1 | 12.50% | 
| pekka j enberg | pekka j enberg | 1 | 0.41% | 1 | 12.50% | 
| al viro | al viro | 1 | 0.41% | 1 | 12.50% | 
 | Total | 244 | 100.00% | 8 | 100.00% | 
static void serport_set_type(struct tty_struct *tty, unsigned long type)
{
	struct serport *serport = tty->disc_data;
	serport->id.proto = type & 0x000000ff;
	serport->id.id    = (type & 0x0000ff00) >> 8;
	serport->id.extra = (type & 0x00ff0000) >> 16;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dmitry torokhov | dmitry torokhov | 38 | 61.29% | 2 | 50.00% | 
| pre-git | pre-git | 20 | 32.26% | 1 | 25.00% | 
| john sung | john sung | 4 | 6.45% | 1 | 25.00% | 
 | Total | 62 | 100.00% | 4 | 100.00% | 
/*
 * serport_ldisc_ioctl() allows to set the port protocol, and device ID
 */
static int serport_ldisc_ioctl(struct tty_struct *tty, struct file *file,
			       unsigned int cmd, unsigned long arg)
{
	if (cmd == SPIOCSTYPE) {
		unsigned long type;
		if (get_user(type, (unsigned long __user *) arg))
			return -EFAULT;
		serport_set_type(tty, type);
		return 0;
	}
	return -EINVAL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| john sung | john sung | 60 | 86.96% | 1 | 33.33% | 
| pre-git | pre-git | 6 | 8.70% | 1 | 33.33% | 
| dmitry torokhov | dmitry torokhov | 3 | 4.35% | 1 | 33.33% | 
 | Total | 69 | 100.00% | 3 | 100.00% | 
#ifdef CONFIG_COMPAT
#define COMPAT_SPIOCSTYPE	_IOW('q', 0x01, compat_ulong_t)
static long serport_ldisc_compat_ioctl(struct tty_struct *tty,
				       struct file *file,
				       unsigned int cmd, unsigned long arg)
{
	if (cmd == COMPAT_SPIOCSTYPE) {
		void __user *uarg = compat_ptr(arg);
		compat_ulong_t compat_type;
		if (get_user(compat_type, (compat_ulong_t __user *)uarg))
			return -EFAULT;
		serport_set_type(tty, compat_type);
		return 0;
	}
	return -EINVAL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| john sung | john sung | 77 | 100.00% | 1 | 100.00% | 
 | Total | 77 | 100.00% | 1 | 100.00% | 
#endif
static void serport_ldisc_write_wakeup(struct tty_struct * tty)
{
	struct serport *serport = (struct serport *) tty->disc_data;
	unsigned long flags;
	spin_lock_irqsave(&serport->lock, flags);
	if (test_bit(SERPORT_ACTIVE, &serport->flags))
		serio_drv_write_wakeup(serport->serio);
	spin_unlock_irqrestore(&serport->lock, flags);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dmitry torokhov | dmitry torokhov | 39 | 57.35% | 2 | 66.67% | 
| vojtech pavlik | vojtech pavlik | 29 | 42.65% | 1 | 33.33% | 
 | Total | 68 | 100.00% | 3 | 100.00% | 
/*
 * The line discipline structure.
 */
static struct tty_ldisc_ops serport_ldisc = {
	.owner =	THIS_MODULE,
	.name =		"input",
	.open =		serport_ldisc_open,
	.close =	serport_ldisc_close,
	.read =		serport_ldisc_read,
	.ioctl =	serport_ldisc_ioctl,
#ifdef CONFIG_COMPAT
	.compat_ioctl =	serport_ldisc_compat_ioctl,
#endif
	.receive_buf =	serport_ldisc_receive,
	.write_wakeup =	serport_ldisc_write_wakeup
};
/*
 * The functions for insering/removing us as a module.
 */
static int __init serport_init(void)
{
	int retval;
	retval = tty_register_ldisc(N_MOUSE, &serport_ldisc);
	if (retval)
		printk(KERN_ERR "serport.c: Error registering line discipline.\n");
	return  retval;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 24 | 68.57% | 1 | 33.33% | 
| randy dunlap | randy dunlap | 10 | 28.57% | 1 | 33.33% | 
| christoph hellwig | christoph hellwig | 1 | 2.86% | 1 | 33.33% | 
 | Total | 35 | 100.00% | 3 | 100.00% | 
static void __exit serport_exit(void)
{
	tty_unregister_ldisc(N_MOUSE);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 12 | 85.71% | 1 | 33.33% | 
| alexey dobriyan | alexey dobriyan | 1 | 7.14% | 1 | 33.33% | 
| christoph hellwig | christoph hellwig | 1 | 7.14% | 1 | 33.33% | 
 | Total | 14 | 100.00% | 3 | 100.00% | 
module_init(serport_init);
module_exit(serport_exit);
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 414 | 34.44% | 1 | 3.33% | 
| dmitry torokhov | dmitry torokhov | 403 | 33.53% | 6 | 20.00% | 
| john sung | john sung | 164 | 13.64% | 1 | 3.33% | 
| vojtech pavlik | vojtech pavlik | 114 | 9.48% | 5 | 16.67% | 
| david engraf | david engraf | 39 | 3.24% | 1 | 3.33% | 
| christoph hellwig | christoph hellwig | 12 | 1.00% | 1 | 3.33% | 
| dmitry eremin-baryshkov | dmitry eremin-baryshkov | 10 | 0.83% | 1 | 3.33% | 
| randy dunlap | randy dunlap | 10 | 0.83% | 1 | 3.33% | 
| peter hurley | peter hurley | 8 | 0.67% | 1 | 3.33% | 
| alan cox | alan cox | 8 | 0.67% | 3 | 10.00% | 
| linus torvalds | linus torvalds | 7 | 0.58% | 3 | 10.00% | 
| andrew morton | andrew morton | 5 | 0.42% | 1 | 3.33% | 
| alexey dobriyan | alexey dobriyan | 4 | 0.33% | 2 | 6.67% | 
| pekka j enberg | pekka j enberg | 2 | 0.17% | 1 | 3.33% | 
| al viro | al viro | 2 | 0.17% | 2 | 6.67% | 
 | Total | 1202 | 100.00% | 30 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.