Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
846 | giacomo | 1 | /* |
2 | * linux/drivers/char/tty_io.c |
||
3 | * |
||
4 | * Copyright (C) 1991, 1992 Linus Torvalds |
||
5 | */ |
||
6 | |||
7 | #include <linuxcomp.h> |
||
8 | |||
9 | #include <linux/config.h> |
||
10 | #include <linux/types.h> |
||
11 | #include <linux/major.h> |
||
12 | #include <linux/errno.h> |
||
13 | #include <linux/signal.h> |
||
14 | #include <linux/fcntl.h> |
||
15 | #include <linux/sched.h> |
||
16 | #include <linux/interrupt.h> |
||
17 | #include <linux/tty.h> |
||
18 | #include <linux/tty_driver.h> |
||
19 | #include <linux/tty_flip.h> |
||
20 | #include <linux/devpts_fs.h> |
||
21 | #include <linux/file.h> |
||
22 | #include <linux/console.h> |
||
23 | #include <linux/timer.h> |
||
24 | #include <linux/ctype.h> |
||
25 | #include <linux/kd.h> |
||
26 | #include <linux/mm.h> |
||
27 | #include <linux/string.h> |
||
28 | #include <linux/slab.h> |
||
29 | #include <linux/poll.h> |
||
30 | #include <linux/proc_fs.h> |
||
31 | #include <linux/init.h> |
||
32 | #include <linux/module.h> |
||
33 | #include <linux/smp_lock.h> |
||
34 | #include <linux/device.h> |
||
35 | |||
36 | #include <asm/uaccess.h> |
||
37 | #include <asm/system.h> |
||
38 | #include <asm/bitops.h> |
||
39 | |||
40 | #include <linux/kbd_kern.h> |
||
41 | #include <linux/vt_kern.h> |
||
42 | #include <linux/selection.h> |
||
43 | #include <linux/devfs_fs_kernel.h> |
||
44 | |||
45 | #include <linux/kmod.h> |
||
46 | |||
47 | #undef TTY_DEBUG_HANGUP |
||
48 | |||
49 | #define TTY_PARANOIA_CHECK 1 |
||
50 | #define CHECK_TTY_COUNT 1 |
||
51 | |||
52 | struct tty_ldisc ldiscs[NR_LDISCS]; |
||
53 | |||
54 | struct termios tty_std_termios = { /* for the benefit of tty drivers */ |
||
55 | .c_iflag = ICRNL | IXON, |
||
56 | .c_oflag = OPOST | ONLCR, |
||
57 | .c_cflag = B38400 | CS8 | CREAD | HUPCL, |
||
58 | .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | |
||
59 | ECHOCTL | ECHOKE | IEXTEN, |
||
60 | .c_cc = INIT_C_CC |
||
61 | }; |
||
62 | |||
63 | struct tty_driver *alloc_tty_driver(int lines) |
||
64 | { |
||
65 | struct tty_driver *driver; |
||
66 | |||
67 | driver = kmalloc(sizeof(struct tty_driver), GFP_KERNEL); |
||
68 | if (driver) { |
||
69 | memset(driver, 0, sizeof(struct tty_driver)); |
||
70 | driver->magic = TTY_DRIVER_MAGIC; |
||
71 | driver->num = lines; |
||
72 | /* later we'll move allocation of tables here */ |
||
73 | } |
||
74 | return driver; |
||
75 | } |
||
76 | |||
77 | void put_tty_driver(struct tty_driver *driver) |
||
78 | { |
||
79 | kfree(driver); |
||
80 | } |
||
81 | |||
82 | void tty_set_operations(struct tty_driver *driver, struct tty_operations *op) |
||
83 | { |
||
84 | driver->open = op->open; |
||
85 | driver->close = op->close; |
||
86 | driver->write = op->write; |
||
87 | driver->put_char = op->put_char; |
||
88 | driver->flush_chars = op->flush_chars; |
||
89 | driver->write_room = op->write_room; |
||
90 | driver->chars_in_buffer = op->chars_in_buffer; |
||
91 | driver->ioctl = op->ioctl; |
||
92 | driver->set_termios = op->set_termios; |
||
93 | driver->throttle = op->throttle; |
||
94 | driver->unthrottle = op->unthrottle; |
||
95 | driver->stop = op->stop; |
||
96 | driver->start = op->start; |
||
97 | driver->hangup = op->hangup; |
||
98 | driver->break_ctl = op->break_ctl; |
||
99 | driver->flush_buffer = op->flush_buffer; |
||
100 | driver->set_ldisc = op->set_ldisc; |
||
101 | driver->wait_until_sent = op->wait_until_sent; |
||
102 | driver->send_xchar = op->send_xchar; |
||
103 | driver->read_proc = op->read_proc; |
||
104 | driver->write_proc = op->write_proc; |
||
105 | driver->tiocmget = op->tiocmget; |
||
106 | driver->tiocmset = op->tiocmset; |
||
107 | } |
||
108 | |||
109 | int tty_register_driver(struct tty_driver *driver) |
||
110 | { |
||
111 | return 0; |
||
112 | } |
||
113 | |||
114 | int tty_unregister_driver(struct tty_driver *driver) |
||
115 | { |
||
116 | return 0; |
||
117 | } |
||
118 | |||
119 | void tty_register_device(struct tty_driver *driver, unsigned index, |
||
120 | struct device *device) |
||
121 | { |
||
122 | |||
123 | } |
||
124 | |||
125 | void tty_unregister_device(struct tty_driver *driver, unsigned index) |
||
126 | { |
||
127 | |||
128 | } |
||
129 | |||
130 | void tty_flip_buffer_push(struct tty_struct *tty) |
||
131 | { |
||
132 | printk(KERN_INFO "%c\n", *(tty->flip.char_buf_ptr -1)); |
||
133 | } |
||
134 | |||
135 | static void flush_to_ldisc(void *private_) |
||
136 | { |
||
137 | |||
138 | } |
||
139 | |||
140 | static struct tty_struct *alloc_tty_struct(void) |
||
141 | { |
||
142 | struct tty_struct *tty; |
||
143 | |||
144 | tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL); |
||
145 | // if (tty) |
||
146 | // memset(tty, 0, sizeof(struct tty_struct)); |
||
147 | return tty; |
||
148 | } |
||
149 | |||
150 | void do_tty_hangup(void *data) |
||
151 | { |
||
152 | |||
153 | } |
||
154 | |||
155 | /* |
||
156 | * This subroutine initializes a tty structure. |
||
157 | */ |
||
158 | static void initialize_tty_struct(struct tty_struct *tty) |
||
159 | { |
||
160 | memset(tty, 0, sizeof(struct tty_struct)); |
||
161 | tty->magic = TTY_MAGIC; |
||
162 | tty->ldisc = ldiscs[N_TTY]; |
||
163 | tty->pgrp = -1; |
||
164 | tty->flip.char_buf_ptr = tty->flip.char_buf; |
||
165 | tty->flip.flag_buf_ptr = tty->flip.flag_buf; |
||
166 | INIT_WORK(&tty->flip.work, flush_to_ldisc, tty); |
||
167 | init_MUTEX(&tty->flip.pty_sem); |
||
168 | init_waitqueue_head(&tty->write_wait); |
||
169 | init_waitqueue_head(&tty->read_wait); |
||
170 | INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); |
||
171 | //*sema_init(&tty->atomic_read, 1); |
||
172 | //*sema_init(&tty->atomic_write, 1); |
||
173 | spin_lock_init(&tty->read_lock); |
||
174 | INIT_LIST_HEAD(&tty->tty_files); |
||
175 | INIT_WORK(&tty->SAK_work, NULL, NULL); |
||
176 | } |
||
177 | |||
178 | extern int serial_open (struct tty_struct *tty, struct file * filp); |
||
179 | extern int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count); |
||
180 | |||
181 | struct tty_struct *tty; |
||
182 | int serial_usbport_open(int port_number) |
||
183 | { |
||
184 | int retval; |
||
185 | tty = alloc_tty_struct(); |
||
186 | if(!tty) |
||
187 | goto fail_no_mem; |
||
188 | |||
189 | initialize_tty_struct (tty); |
||
190 | |||
191 | tty->termios = malloc (sizeof(struct termios)); |
||
192 | *(tty->termios) = tty_std_termios; |
||
193 | |||
194 | retval = serial_open(tty, NULL); |
||
195 | return retval; |
||
196 | |||
197 | fail_no_mem: |
||
198 | return -ENOMEM; |
||
199 | |||
200 | } |
||
201 | |||
202 | int serial_usbport_write(const unsigned char *buf, int count) |
||
203 | { |
||
204 | int retval; |
||
205 | |||
206 | retval = serial_write(tty, 0, buf, count); |
||
207 | return retval; |
||
208 | |||
209 | // printk(KERN_DEBUG "######### retval=%d\n", retval); |
||
210 | } |