author | Florian Pose <fp@igh-essen.com> |
Wed, 02 Dec 2009 15:46:00 +0100 | |
changeset 1576 | 0a3d96138e8b |
parent 1575 | 17598f2332b6 |
child 1577 | fa3f66b783c1 |
permissions | -rw-r--r-- |
1565 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 |
* |
|
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
|
11 |
* published by the Free Software Foundation. |
|
12 |
* |
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
16 |
* Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License along |
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 |
* |
|
22 |
* --- |
|
23 |
* |
|
24 |
* The license mentioned above concerns the source code only. Using the |
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
|
27 |
* |
|
28 |
*****************************************************************************/ |
|
29 |
||
30 |
/** \file |
|
31 |
* EtherCAT tty driver module. |
|
32 |
*/ |
|
33 |
||
34 |
/*****************************************************************************/ |
|
35 |
||
36 |
#include <linux/module.h> |
|
37 |
#include <linux/err.h> |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
38 |
#include <linux/tty.h> |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
39 |
#include <linux/tty_driver.h> |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
40 |
#include <linux/termios.h> |
1575 | 41 |
#include <linux/timer.h> |
1565 | 42 |
|
43 |
#include "../master/globals.h" |
|
1569 | 44 |
#include "../include/ectty.h" |
45 |
||
46 |
/*****************************************************************************/ |
|
47 |
||
1570 | 48 |
#define PFX "ec_tty: " |
49 |
||
1569 | 50 |
#define EC_TTY_MAX_DEVICES 10 |
1575 | 51 |
#define EC_TTY_TX_BUFFER_SIZE 100 |
1569 | 52 |
|
53 |
/*****************************************************************************/ |
|
54 |
||
1565 | 55 |
char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */ |
1570 | 56 |
unsigned int debug_level = 0; |
1565 | 57 |
|
1569 | 58 |
static struct tty_driver *tty_driver = NULL; |
59 |
ec_tty_t *ttys[EC_TTY_MAX_DEVICES]; |
|
60 |
struct semaphore tty_sem; |
|
61 |
||
1565 | 62 |
/*****************************************************************************/ |
63 |
||
64 |
/** \cond */ |
|
65 |
||
66 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
|
67 |
MODULE_DESCRIPTION("EtherCAT TTY driver module"); |
|
68 |
MODULE_LICENSE("GPL"); |
|
69 |
MODULE_VERSION(EC_MASTER_VERSION); |
|
70 |
||
71 |
module_param_named(debug_level, debug_level, uint, S_IRUGO); |
|
72 |
MODULE_PARM_DESC(debug_level, "Debug level"); |
|
73 |
||
1569 | 74 |
/** \endcond */ |
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
75 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
76 |
static struct ktermios ec_tty_std_termios = { |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
77 |
.c_iflag = ICRNL | IXON, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
78 |
.c_oflag = OPOST | ONLCR, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
79 |
.c_cflag = B38400 | CS8 | CREAD | HUPCL, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
80 |
.c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
81 |
.c_cc = INIT_C_CC, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
82 |
}; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
83 |
|
1569 | 84 |
struct ec_tty { |
85 |
int minor; |
|
86 |
struct device *dev; |
|
1575 | 87 |
uint8_t tx_buffer[EC_TTY_TX_BUFFER_SIZE]; |
88 |
unsigned int tx_read_idx; |
|
89 |
unsigned int tx_write_idx; |
|
90 |
unsigned int wakeup; |
|
91 |
struct timer_list timer; |
|
92 |
struct tty_struct *tty; |
|
1569 | 93 |
}; |
1565 | 94 |
|
1575 | 95 |
static const struct tty_operations ec_tty_ops; // see below |
96 |
||
1565 | 97 |
/*****************************************************************************/ |
98 |
||
99 |
/** Module initialization. |
|
100 |
* |
|
101 |
* \return 0 on success, else < 0 |
|
102 |
*/ |
|
103 |
int __init ec_tty_init_module(void) |
|
104 |
{ |
|
1569 | 105 |
int i, ret = 0; |
1565 | 106 |
|
1570 | 107 |
printk(KERN_INFO PFX "TTY driver %s\n", EC_MASTER_VERSION); |
1565 | 108 |
|
1569 | 109 |
init_MUTEX(&tty_sem); |
110 |
||
111 |
for (i = 0; i < EC_TTY_MAX_DEVICES; i++) { |
|
112 |
ttys[i] = NULL; |
|
113 |
} |
|
114 |
||
115 |
tty_driver = alloc_tty_driver(EC_TTY_MAX_DEVICES); |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
116 |
if (!tty_driver) { |
1570 | 117 |
printk(KERN_ERR PFX "Failed to allocate tty driver.\n"); |
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
118 |
ret = -ENOMEM; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
119 |
goto out_return; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
120 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
121 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
122 |
tty_driver->owner = THIS_MODULE; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
123 |
tty_driver->driver_name = "EtherCAT TTY"; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
124 |
tty_driver->name = "ttyEC"; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
125 |
tty_driver->major = 0; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
126 |
tty_driver->minor_start = 0; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
127 |
tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
128 |
tty_driver->subtype = SERIAL_TYPE_NORMAL; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
129 |
tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
130 |
tty_driver->init_termios = ec_tty_std_termios; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
131 |
tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
132 |
tty_set_operations(tty_driver, &ec_tty_ops); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
133 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
134 |
ret = tty_register_driver(tty_driver); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
135 |
if (ret) { |
1570 | 136 |
printk(KERN_ERR PFX "Failed to register tty driver.\n"); |
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
137 |
goto out_put; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
138 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
139 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
140 |
return ret; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
141 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
142 |
out_put: |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
143 |
put_tty_driver(tty_driver); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
144 |
out_return: |
1565 | 145 |
return ret; |
146 |
} |
|
147 |
||
148 |
/*****************************************************************************/ |
|
149 |
||
150 |
/** Module cleanup. |
|
151 |
* |
|
152 |
* Clears all master instances. |
|
153 |
*/ |
|
154 |
void __exit ec_tty_cleanup_module(void) |
|
155 |
{ |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
156 |
tty_unregister_driver(tty_driver); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
157 |
put_tty_driver(tty_driver); |
1570 | 158 |
printk(KERN_INFO PFX "Module unloading.\n"); |
1565 | 159 |
} |
160 |
||
161 |
/*****************************************************************************/ |
|
162 |
||
1575 | 163 |
void ec_tty_wakeup(unsigned long data) |
164 |
{ |
|
165 |
ec_tty_t *tty = (ec_tty_t *) data; |
|
166 |
||
167 |
if (tty->wakeup) { |
|
168 |
if (tty->tty) { |
|
169 |
printk("Waking up.\n"); |
|
170 |
tty_wakeup(tty->tty); |
|
171 |
} |
|
172 |
tty->wakeup = 0; |
|
173 |
} |
|
174 |
||
175 |
tty->timer.expires += 1; |
|
176 |
add_timer(&tty->timer); |
|
177 |
} |
|
178 |
||
179 |
/*****************************************************************************/ |
|
180 |
||
1569 | 181 |
int ec_tty_init(ec_tty_t *tty, int minor) |
182 |
{ |
|
183 |
tty->minor = minor; |
|
1575 | 184 |
tty->tx_read_idx = 0; |
185 |
tty->tx_write_idx = 0; |
|
186 |
tty->wakeup = 0; |
|
187 |
init_timer(&tty->timer); |
|
188 |
tty->tty = NULL; |
|
1569 | 189 |
|
190 |
tty->dev = tty_register_device(tty_driver, tty->minor, NULL); |
|
191 |
if (IS_ERR(tty->dev)) { |
|
1570 | 192 |
printk(KERN_ERR PFX "Failed to register tty device.\n"); |
1569 | 193 |
return PTR_ERR(tty->dev); |
194 |
} |
|
195 |
||
1575 | 196 |
tty->timer.function = ec_tty_wakeup; |
197 |
tty->timer.data = (unsigned long) tty; |
|
198 |
tty->timer.expires = jiffies + 10; |
|
199 |
add_timer(&tty->timer); |
|
1569 | 200 |
return 0; |
201 |
} |
|
202 |
||
203 |
/*****************************************************************************/ |
|
204 |
||
205 |
void ec_tty_clear(ec_tty_t *tty) |
|
206 |
{ |
|
1575 | 207 |
del_timer_sync(&tty->timer); |
1569 | 208 |
tty_unregister_device(tty_driver, tty->minor); |
209 |
} |
|
210 |
||
1575 | 211 |
/*****************************************************************************/ |
212 |
||
213 |
unsigned int ec_tty_tx_size(ec_tty_t *tty) |
|
214 |
{ |
|
215 |
unsigned int ret; |
|
216 |
||
217 |
if (tty->tx_write_idx >= tty->tx_read_idx) { |
|
218 |
ret = tty->tx_write_idx - tty->tx_read_idx; |
|
219 |
} else { |
|
220 |
ret = EC_TTY_TX_BUFFER_SIZE + tty->tx_write_idx - tty->tx_read_idx; |
|
221 |
} |
|
222 |
||
223 |
return ret; |
|
224 |
} |
|
225 |
||
226 |
/*****************************************************************************/ |
|
227 |
||
228 |
unsigned int ec_tty_tx_space(ec_tty_t *tty) |
|
229 |
{ |
|
230 |
return EC_TTY_TX_BUFFER_SIZE - 1 - ec_tty_tx_size(tty); |
|
231 |
} |
|
232 |
||
1569 | 233 |
/****************************************************************************** |
234 |
* Device callbacks |
|
235 |
*****************************************************************************/ |
|
236 |
||
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
237 |
static int ec_tty_open(struct tty_struct *tty, struct file *file) |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
238 |
{ |
1571 | 239 |
ec_tty_t *t; |
240 |
int line = tty->index; |
|
241 |
||
242 |
printk(KERN_INFO PFX "Opening line %i.\n", line); |
|
243 |
||
244 |
if (line < 0 || line >= EC_TTY_MAX_DEVICES) { |
|
245 |
return -ENXIO; |
|
246 |
} |
|
247 |
||
248 |
t = ttys[line]; |
|
249 |
if (!t) { |
|
250 |
return -ENXIO; |
|
251 |
} |
|
252 |
||
1575 | 253 |
if (t->tty) { |
254 |
return -EBUSY; |
|
255 |
} |
|
256 |
||
257 |
t->tty = tty; |
|
1571 | 258 |
tty->driver_data = t; |
259 |
return 0; |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
260 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
261 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
262 |
/*****************************************************************************/ |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
263 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
264 |
static void ec_tty_close(struct tty_struct *tty, struct file *file) |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
265 |
{ |
1575 | 266 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
267 |
||
1571 | 268 |
printk(KERN_INFO PFX "Closing line %i.\n", tty->index); |
1575 | 269 |
|
270 |
if (t->tty == tty) { |
|
271 |
t->tty = NULL; |
|
272 |
} |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
273 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
274 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
275 |
/*****************************************************************************/ |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
276 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
277 |
static int ec_tty_write( |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
278 |
struct tty_struct *tty, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
279 |
const unsigned char *buffer, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
280 |
int count |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
281 |
) |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
282 |
{ |
1575 | 283 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
284 |
unsigned int data_size, i; |
|
285 |
||
286 |
printk(KERN_INFO PFX "%s(count=%i)\n", __func__, count); |
|
287 |
||
288 |
if (count <= 0) { |
|
289 |
return 0; |
|
290 |
} |
|
291 |
||
292 |
data_size = min(ec_tty_tx_space(t), (unsigned int) count); |
|
293 |
for (i = 0; i < data_size; i++) { |
|
294 |
t->tx_buffer[t->tx_write_idx] = buffer[i]; |
|
295 |
t->tx_write_idx = (t->tx_write_idx + 1) % EC_TTY_TX_BUFFER_SIZE; |
|
296 |
} |
|
297 |
||
298 |
printk(KERN_INFO PFX "%s(): %u bytes written.\n", __func__, data_size); |
|
299 |
return data_size; |
|
300 |
} |
|
301 |
||
302 |
/*****************************************************************************/ |
|
303 |
||
304 |
static void ec_tty_put_char(struct tty_struct *tty, unsigned char ch) |
|
305 |
{ |
|
306 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
|
307 |
||
308 |
printk(KERN_INFO PFX "%s(): c=%02x.\n", __func__, (unsigned int) ch); |
|
309 |
||
310 |
if (ec_tty_tx_space(t)) { |
|
311 |
t->tx_buffer[t->tx_write_idx] = ch; |
|
312 |
t->tx_write_idx = (t->tx_write_idx + 1) % EC_TTY_TX_BUFFER_SIZE; |
|
313 |
} else { |
|
314 |
printk(KERN_WARNING PFX "%s(): Dropped a byte!\n", __func__); |
|
315 |
} |
|
316 |
} |
|
317 |
||
318 |
/*****************************************************************************/ |
|
319 |
||
320 |
static int ec_tty_write_room(struct tty_struct *tty) |
|
321 |
{ |
|
322 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
|
323 |
int ret = ec_tty_tx_space(t); |
|
324 |
||
325 |
printk(KERN_INFO PFX "%s() = %i.\n", __func__, ret); |
|
326 |
||
327 |
return ret; |
|
328 |
} |
|
329 |
||
330 |
/*****************************************************************************/ |
|
331 |
||
332 |
static int ec_tty_chars_in_buffer(struct tty_struct *tty) |
|
333 |
{ |
|
334 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
|
335 |
int ret; |
|
336 |
||
337 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
338 |
||
339 |
ret = ec_tty_tx_size(t); |
|
340 |
||
341 |
printk(KERN_INFO PFX "%s() = %i.\n", __func__, ret); |
|
342 |
||
343 |
return ret; |
|
344 |
} |
|
345 |
||
346 |
/*****************************************************************************/ |
|
347 |
||
348 |
static void ec_tty_flush_buffer(struct tty_struct *tty) |
|
349 |
{ |
|
350 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
351 |
} |
|
352 |
||
353 |
/*****************************************************************************/ |
|
354 |
||
355 |
static int ec_tty_ioctl(struct tty_struct *tty, struct file *file, |
|
356 |
unsigned int cmd, unsigned long arg) |
|
357 |
{ |
|
358 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
359 |
return -ENOTTY; |
|
360 |
} |
|
361 |
||
362 |
/*****************************************************************************/ |
|
363 |
||
364 |
static void ec_tty_throttle(struct tty_struct *tty) |
|
365 |
{ |
|
366 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
367 |
} |
|
368 |
||
369 |
/*****************************************************************************/ |
|
370 |
||
371 |
static void ec_tty_unthrottle(struct tty_struct *tty) |
|
372 |
{ |
|
373 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
374 |
} |
|
375 |
||
376 |
/*****************************************************************************/ |
|
377 |
||
378 |
static void ec_tty_set_termios(struct tty_struct *tty, |
|
379 |
struct ktermios *old_termios) |
|
380 |
{ |
|
381 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
382 |
} |
|
383 |
||
384 |
/*****************************************************************************/ |
|
385 |
||
386 |
static void ec_tty_stop(struct tty_struct *tty) |
|
387 |
{ |
|
388 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
389 |
} |
|
390 |
||
391 |
/*****************************************************************************/ |
|
392 |
||
393 |
static void ec_tty_start(struct tty_struct *tty) |
|
394 |
{ |
|
395 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
396 |
} |
|
397 |
||
398 |
/*****************************************************************************/ |
|
399 |
||
400 |
static void ec_tty_hangup(struct tty_struct *tty) |
|
401 |
{ |
|
402 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
403 |
} |
|
404 |
||
405 |
/*****************************************************************************/ |
|
406 |
||
407 |
static void ec_tty_break(struct tty_struct *tty, int break_state) |
|
408 |
{ |
|
409 |
printk(KERN_INFO PFX "%s(break_state = %i).\n", __func__, break_state); |
|
410 |
} |
|
411 |
||
412 |
/*****************************************************************************/ |
|
413 |
||
414 |
static void ec_tty_send_xchar(struct tty_struct *tty, char ch) |
|
415 |
{ |
|
416 |
printk(KERN_INFO PFX "%s(ch=%02x).\n", __func__, (unsigned int) ch); |
|
417 |
} |
|
418 |
||
419 |
/*****************************************************************************/ |
|
420 |
||
421 |
static void ec_tty_wait_until_sent(struct tty_struct *tty, int timeout) |
|
422 |
{ |
|
423 |
printk(KERN_INFO PFX "%s(timeout=%i).\n", __func__, timeout); |
|
424 |
} |
|
425 |
||
426 |
/*****************************************************************************/ |
|
427 |
||
428 |
static int ec_tty_tiocmget(struct tty_struct *tty, struct file *file) |
|
429 |
{ |
|
430 |
printk(KERN_INFO PFX "%s().\n", __func__); |
|
431 |
return -EBUSY; |
|
432 |
} |
|
433 |
||
434 |
/*****************************************************************************/ |
|
435 |
||
436 |
static int ec_tty_tiocmset(struct tty_struct *tty, struct file *file, |
|
437 |
unsigned int set, unsigned int clear) |
|
438 |
{ |
|
439 |
printk(KERN_INFO PFX "%s(set=%u, clear=%u).\n", __func__, set, clear); |
|
440 |
return -EBUSY; |
|
441 |
} |
|
442 |
||
443 |
/*****************************************************************************/ |
|
444 |
||
445 |
static const struct tty_operations ec_tty_ops = { |
|
446 |
.open = ec_tty_open, |
|
447 |
.close = ec_tty_close, |
|
448 |
.write = ec_tty_write, |
|
449 |
.put_char = ec_tty_put_char, |
|
450 |
.write_room = ec_tty_write_room, |
|
451 |
.chars_in_buffer = ec_tty_chars_in_buffer, |
|
452 |
.flush_buffer = ec_tty_flush_buffer, |
|
453 |
.ioctl = ec_tty_ioctl, |
|
454 |
.throttle = ec_tty_throttle, |
|
455 |
.unthrottle = ec_tty_unthrottle, |
|
456 |
.set_termios = ec_tty_set_termios, |
|
457 |
.stop = ec_tty_stop, |
|
458 |
.start = ec_tty_start, |
|
459 |
.hangup = ec_tty_hangup, |
|
460 |
.break_ctl = ec_tty_break, |
|
461 |
.send_xchar = ec_tty_send_xchar, |
|
462 |
.wait_until_sent = ec_tty_wait_until_sent, |
|
463 |
.tiocmget = ec_tty_tiocmget, |
|
464 |
.tiocmset = ec_tty_tiocmset, |
|
465 |
}; |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
466 |
|
1569 | 467 |
/****************************************************************************** |
468 |
* Public functions and methods |
|
469 |
*****************************************************************************/ |
|
470 |
||
471 |
ec_tty_t *ectty_create(void) |
|
472 |
{ |
|
473 |
ec_tty_t *tty; |
|
474 |
int minor, ret; |
|
475 |
||
476 |
if (down_interruptible(&tty_sem)) { |
|
477 |
return ERR_PTR(-EINTR); |
|
478 |
} |
|
479 |
||
480 |
for (minor = 0; minor < EC_TTY_MAX_DEVICES; minor++) { |
|
481 |
if (!ttys[minor]) { |
|
1575 | 482 |
printk(KERN_INFO PFX "Creating TTY interface %i.\n", minor); |
483 |
||
1569 | 484 |
tty = kmalloc(sizeof(ec_tty_t), GFP_KERNEL); |
485 |
if (!tty) { |
|
486 |
up(&tty_sem); |
|
1570 | 487 |
printk(KERN_ERR PFX "Failed to allocate memory.\n"); |
1569 | 488 |
return ERR_PTR(-ENOMEM); |
489 |
} |
|
490 |
||
491 |
ret = ec_tty_init(tty, minor); |
|
492 |
if (ret) { |
|
493 |
up(&tty_sem); |
|
494 |
kfree(tty); |
|
495 |
return ERR_PTR(ret); |
|
496 |
} |
|
497 |
||
498 |
ttys[minor] = tty; |
|
499 |
up(&tty_sem); |
|
500 |
return tty; |
|
501 |
} |
|
502 |
} |
|
503 |
||
504 |
up(&tty_sem); |
|
1570 | 505 |
printk(KERN_ERR PFX "No free interfaces avaliable.\n"); |
1569 | 506 |
return ERR_PTR(-EBUSY); |
507 |
} |
|
508 |
||
509 |
/*****************************************************************************/ |
|
510 |
||
511 |
void ectty_free(ec_tty_t *tty) |
|
512 |
{ |
|
1575 | 513 |
printk(KERN_INFO PFX "Freeing TTY interface %i.\n", tty->minor); |
514 |
||
1569 | 515 |
ec_tty_clear(tty); |
1570 | 516 |
ttys[tty->minor] = NULL; |
1569 | 517 |
kfree(tty); |
518 |
} |
|
519 |
||
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
520 |
/*****************************************************************************/ |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
521 |
|
1575 | 522 |
unsigned int ectty_tx_data(ec_tty_t *tty, uint8_t *buffer, size_t size) |
523 |
{ |
|
524 |
unsigned int data_size = min(ec_tty_tx_size(tty), size), i; |
|
525 |
||
526 |
if (data_size) { |
|
527 |
printk(KERN_INFO PFX "Fetching %u bytes to send.\n", data_size); |
|
528 |
} |
|
529 |
||
530 |
for (i = 0; i < data_size; i++) { |
|
531 |
buffer[i] = tty->tx_buffer[tty->tx_read_idx]; |
|
532 |
tty->tx_read_idx = (tty->tx_read_idx + 1) % EC_TTY_TX_BUFFER_SIZE; |
|
533 |
} |
|
534 |
||
535 |
if (data_size) { |
|
536 |
tty->wakeup = 1; |
|
537 |
} |
|
538 |
||
539 |
return data_size; |
|
540 |
} |
|
541 |
||
542 |
/*****************************************************************************/ |
|
543 |
||
1565 | 544 |
/** \cond */ |
545 |
||
546 |
module_init(ec_tty_init_module); |
|
547 |
module_exit(ec_tty_cleanup_module); |
|
548 |
||
1569 | 549 |
EXPORT_SYMBOL(ectty_create); |
550 |
EXPORT_SYMBOL(ectty_free); |
|
1575 | 551 |
EXPORT_SYMBOL(ectty_tx_data); |
1569 | 552 |
|
1565 | 553 |
/** \endcond */ |
554 |
||
555 |
/*****************************************************************************/ |