Subversion Repositories shark

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 *  linux/drivers/char/tty_io.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 */


#include <linuxcomp.h>

#include <linux/config.h>
#include <linux/types.h>
#include <linux/major.h>
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/fcntl.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/devpts_fs.h>
#include <linux/file.h>
#include <linux/console.h>
#include <linux/timer.h>
#include <linux/ctype.h>
#include <linux/kd.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/device.h>

#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/bitops.h>

#include <linux/kbd_kern.h>
#include <linux/vt_kern.h>
#include <linux/selection.h>
#include <linux/devfs_fs_kernel.h>

#include <linux/kmod.h>

#undef TTY_DEBUG_HANGUP

#define TTY_PARANOIA_CHECK 1
#define CHECK_TTY_COUNT 1

struct tty_ldisc ldiscs[NR_LDISCS];

struct termios tty_std_termios = {      /* for the benefit of tty drivers  */
        .c_iflag = ICRNL | IXON,
        .c_oflag = OPOST | ONLCR,
  .c_cflag = B38400 | CS8 | CREAD | HUPCL,
        .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK |
                   ECHOCTL | ECHOKE | IEXTEN,
        .c_cc = INIT_C_CC
};

struct tty_driver *alloc_tty_driver(int lines)
{
        struct tty_driver *driver;

        driver = kmalloc(sizeof(struct tty_driver), GFP_KERNEL);
        if (driver) {
                memset(driver, 0, sizeof(struct tty_driver));
                driver->magic = TTY_DRIVER_MAGIC;
                driver->num = lines;
                /* later we'll move allocation of tables here */
        }
        return driver;
}

void put_tty_driver(struct tty_driver *driver)
{
        kfree(driver);
}

void tty_set_operations(struct tty_driver *driver, struct tty_operations *op)
{
        driver->open = op->open;
        driver->close = op->close;
        driver->write = op->write;
        driver->put_char = op->put_char;
        driver->flush_chars = op->flush_chars;
        driver->write_room = op->write_room;
        driver->chars_in_buffer = op->chars_in_buffer;
        driver->ioctl = op->ioctl;
        driver->set_termios = op->set_termios;
        driver->throttle = op->throttle;
        driver->unthrottle = op->unthrottle;
        driver->stop = op->stop;
        driver->start = op->start;
        driver->hangup = op->hangup;
        driver->break_ctl = op->break_ctl;
        driver->flush_buffer = op->flush_buffer;
        driver->set_ldisc = op->set_ldisc;
        driver->wait_until_sent = op->wait_until_sent;
        driver->send_xchar = op->send_xchar;
        driver->read_proc = op->read_proc;
        driver->write_proc = op->write_proc;
        driver->tiocmget = op->tiocmget;
        driver->tiocmset = op->tiocmset;
}

int tty_register_driver(struct tty_driver *driver)
{
        return 0;
}

int tty_unregister_driver(struct tty_driver *driver)
{
        return 0;
}

void tty_register_device(struct tty_driver *driver, unsigned index,
                         struct device *device)
{

}

void tty_unregister_device(struct tty_driver *driver, unsigned index)
{

}

void tty_flip_buffer_push(struct tty_struct *tty)
{
  printk(KERN_INFO "%c\n", *(tty->flip.char_buf_ptr -1));
}

static void flush_to_ldisc(void *private_)
{

}

static struct tty_struct *alloc_tty_struct(void)
{
        struct tty_struct *tty;

        tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL);
//      if (tty)
//              memset(tty, 0, sizeof(struct tty_struct));
        return tty;
}

void do_tty_hangup(void *data)
{

}

/*
 * This subroutine initializes a tty structure.
 */

static void initialize_tty_struct(struct tty_struct *tty)
{
        memset(tty, 0, sizeof(struct tty_struct));
        tty->magic = TTY_MAGIC;
        tty->ldisc = ldiscs[N_TTY];
        tty->pgrp = -1;
        tty->flip.char_buf_ptr = tty->flip.char_buf;
        tty->flip.flag_buf_ptr = tty->flip.flag_buf;
        INIT_WORK(&tty->flip.work, flush_to_ldisc, tty);
        init_MUTEX(&tty->flip.pty_sem);
        init_waitqueue_head(&tty->write_wait);
        init_waitqueue_head(&tty->read_wait);
        INIT_WORK(&tty->hangup_work, do_tty_hangup, tty);
        //*sema_init(&tty->atomic_read, 1);
        //*sema_init(&tty->atomic_write, 1);
        spin_lock_init(&tty->read_lock);
        INIT_LIST_HEAD(&tty->tty_files);
        INIT_WORK(&tty->SAK_work, NULL, NULL);
}

extern int serial_open (struct tty_struct *tty, struct file * filp);
extern int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count);

struct tty_struct *tty;
int serial_usbport_open(int port_number)
{
        int retval;
        tty = alloc_tty_struct();
        if(!tty)
                goto fail_no_mem;

        initialize_tty_struct (tty);

        tty->termios = malloc (sizeof(struct termios));
        *(tty->termios) = tty_std_termios;

        retval = serial_open(tty, NULL);
        return retval;

fail_no_mem:
        return -ENOMEM;
               
}

int serial_usbport_write(const unsigned char *buf, int count)
{
        int retval;
 
        retval = serial_write(tty, 0, buf, count);
        return retval;

//  printk(KERN_DEBUG "######### retval=%d\n", retval);
}