33 |
33 |
34 /*****************************************************************************/ |
34 /*****************************************************************************/ |
35 |
35 |
36 #include <linux/module.h> |
36 #include <linux/module.h> |
37 #include <linux/err.h> |
37 #include <linux/err.h> |
|
38 #include <linux/tty.h> |
|
39 #include <linux/tty_driver.h> |
|
40 #include <linux/termios.h> |
38 |
41 |
39 #include "../master/globals.h" |
42 #include "../master/globals.h" |
40 |
43 |
41 /*****************************************************************************/ |
44 /*****************************************************************************/ |
42 |
45 |
56 MODULE_VERSION(EC_MASTER_VERSION); |
59 MODULE_VERSION(EC_MASTER_VERSION); |
57 |
60 |
58 module_param_named(debug_level, debug_level, uint, S_IRUGO); |
61 module_param_named(debug_level, debug_level, uint, S_IRUGO); |
59 MODULE_PARM_DESC(debug_level, "Debug level"); |
62 MODULE_PARM_DESC(debug_level, "Debug level"); |
60 |
63 |
|
64 struct tty_driver *tty_driver = NULL; |
|
65 struct device *tty_device = NULL; |
|
66 |
|
67 static int ec_tty_open(struct tty_struct *, struct file *); |
|
68 static void ec_tty_close(struct tty_struct *, struct file *); |
|
69 static int ec_tty_write(struct tty_struct *, const unsigned char *, int); |
|
70 |
|
71 static const struct tty_operations ec_tty_ops = { |
|
72 .open = ec_tty_open, |
|
73 .close = ec_tty_close, |
|
74 .write = ec_tty_write, |
|
75 }; |
|
76 |
|
77 static struct ktermios ec_tty_std_termios = { |
|
78 .c_iflag = ICRNL | IXON, |
|
79 .c_oflag = OPOST | ONLCR, |
|
80 .c_cflag = B38400 | CS8 | CREAD | HUPCL, |
|
81 .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN, |
|
82 .c_cc = INIT_C_CC, |
|
83 }; |
|
84 |
61 /** \endcond */ |
85 /** \endcond */ |
62 |
86 |
63 /*****************************************************************************/ |
87 /*****************************************************************************/ |
64 |
88 |
65 /** Module initialization. |
89 /** Module initialization. |
70 { |
94 { |
71 int ret = 0; |
95 int ret = 0; |
72 |
96 |
73 EC_INFO("TTY driver %s\n", EC_MASTER_VERSION); |
97 EC_INFO("TTY driver %s\n", EC_MASTER_VERSION); |
74 |
98 |
|
99 tty_driver = alloc_tty_driver(1); |
|
100 if (!tty_driver) { |
|
101 EC_ERR("Failed to allocate tty driver.\n"); |
|
102 ret = -ENOMEM; |
|
103 goto out_return; |
|
104 } |
|
105 |
|
106 tty_driver->owner = THIS_MODULE; |
|
107 tty_driver->driver_name = "EtherCAT TTY"; |
|
108 tty_driver->name = "ttyEC"; |
|
109 tty_driver->major = 0; |
|
110 tty_driver->minor_start = 0; |
|
111 tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
|
112 tty_driver->subtype = SERIAL_TYPE_NORMAL; |
|
113 tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
|
114 tty_driver->init_termios = ec_tty_std_termios; |
|
115 tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
|
116 tty_set_operations(tty_driver, &ec_tty_ops); |
|
117 |
|
118 ret = tty_register_driver(tty_driver); |
|
119 if (ret) { |
|
120 EC_ERR("Failed to register tty driver.\n"); |
|
121 goto out_put; |
|
122 } |
|
123 |
|
124 tty_device = tty_register_device(tty_driver, 0, NULL); |
|
125 if (IS_ERR(tty_device)) { |
|
126 EC_ERR("Failed to register tty device.\n"); |
|
127 ret = PTR_ERR(tty_device); |
|
128 goto out_unreg; |
|
129 } |
|
130 |
|
131 return ret; |
|
132 |
|
133 out_unreg: |
|
134 tty_unregister_driver(tty_driver); |
|
135 out_put: |
|
136 put_tty_driver(tty_driver); |
|
137 out_return: |
75 return ret; |
138 return ret; |
76 } |
139 } |
77 |
140 |
78 /*****************************************************************************/ |
141 /*****************************************************************************/ |
79 |
142 |
81 * |
144 * |
82 * Clears all master instances. |
145 * Clears all master instances. |
83 */ |
146 */ |
84 void __exit ec_tty_cleanup_module(void) |
147 void __exit ec_tty_cleanup_module(void) |
85 { |
148 { |
|
149 tty_unregister_device(tty_driver, 0); |
|
150 tty_unregister_driver(tty_driver); |
|
151 put_tty_driver(tty_driver); |
86 EC_INFO("TTY module cleaned up.\n"); |
152 EC_INFO("TTY module cleaned up.\n"); |
|
153 } |
|
154 |
|
155 /*****************************************************************************/ |
|
156 |
|
157 static int ec_tty_open(struct tty_struct *tty, struct file *file) |
|
158 { |
|
159 return -EBUSY; |
|
160 } |
|
161 |
|
162 /*****************************************************************************/ |
|
163 |
|
164 static void ec_tty_close(struct tty_struct *tty, struct file *file) |
|
165 { |
|
166 return; |
|
167 } |
|
168 |
|
169 /*****************************************************************************/ |
|
170 |
|
171 static int ec_tty_write( |
|
172 struct tty_struct *tty, |
|
173 const unsigned char *buffer, |
|
174 int count |
|
175 ) |
|
176 { |
|
177 return -EIO; |
87 } |
178 } |
88 |
179 |
89 /*****************************************************************************/ |
180 /*****************************************************************************/ |
90 |
181 |
91 /** \cond */ |
182 /** \cond */ |