This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / um / drivers / tty.c
1 /* 
2  * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdio.h>
7 #include <termios.h>
8 #include <errno.h>
9 #include <unistd.h>
10 #include "chan_user.h"
11 #include "user_util.h"
12 #include "user.h"
13 #include "os.h"
14
15 struct tty_chan {
16         char *dev;
17         int raw;
18         struct termios tt;
19 };
20
21 void *tty_chan_init(char *str, int device, struct chan_opts *opts)
22 {
23         struct tty_chan *data;
24
25         if(*str != ':'){
26                 printk("tty_init : channel type 'tty' must specify "
27                        "a device\n");
28                 return(NULL);
29         }
30         str++;
31
32         data = um_kmalloc(sizeof(*data)); 
33         if(data == NULL) 
34                 return(NULL);
35         *data = ((struct tty_chan) { .dev       = str,
36                                      .raw       = opts->raw });
37                                      
38         return(data);
39 }
40
41 int tty_open(int input, int output, int primary, void *d, char **dev_out)
42 {
43         struct tty_chan *data = d;
44         int fd;
45
46         fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0);
47         if(fd < 0) return(fd);
48         if(data->raw){
49                 tcgetattr(fd, &data->tt);
50                 raw(fd, 0);
51         }
52
53         *dev_out = data->dev;
54         return(fd);
55 }
56
57 int tty_console_write(int fd, const char *buf, int n, void *d)
58 {
59         struct tty_chan *data = d;
60
61         return(generic_console_write(fd, buf, n, &data->tt));
62 }
63
64 struct chan_ops tty_ops = {
65         .type           = "tty",
66         .init           = tty_chan_init,
67         .open           = tty_open,
68         .close          = generic_close,
69         .read           = generic_read,
70         .write          = generic_write,
71         .console_write  = tty_console_write,
72         .window_size    = generic_window_size,
73         .free           = generic_free,
74         .winch          = 0,
75 };
76
77 /*
78  * Overrides for Emacs so that we follow Linus's tabbing style.
79  * Emacs will notice this stuff at the end of the file and automatically
80  * adjust the settings for this buffer only.  This must remain at the end
81  * of the file.
82  * ---------------------------------------------------------------------------
83  * Local variables:
84  * c-file-style: "linux"
85  * End:
86  */