author | Florian Pose <fp@igh-essen.com> |
Fri, 08 Jan 2010 13:10:12 +0100 | |
changeset 1613 | 070b4b420ab1 |
parent 1595 | 8d8657654921 |
child 1778 | 94dbb44884ec |
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> |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
40 |
#include <linux/tty_flip.h> |
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
41 |
#include <linux/termios.h> |
1575 | 42 |
#include <linux/timer.h> |
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
43 |
#include <linux/version.h> |
1565 | 44 |
|
45 |
#include "../master/globals.h" |
|
1569 | 46 |
#include "../include/ectty.h" |
47 |
||
48 |
/*****************************************************************************/ |
|
49 |
||
1570 | 50 |
#define PFX "ec_tty: " |
51 |
||
1569 | 52 |
#define EC_TTY_MAX_DEVICES 10 |
1575 | 53 |
#define EC_TTY_TX_BUFFER_SIZE 100 |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
54 |
#define EC_TTY_RX_BUFFER_SIZE 100 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
55 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
56 |
#define EC_TTY_DEBUG 0 |
1569 | 57 |
|
58 |
/*****************************************************************************/ |
|
59 |
||
1565 | 60 |
char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */ |
1570 | 61 |
unsigned int debug_level = 0; |
1565 | 62 |
|
1569 | 63 |
static struct tty_driver *tty_driver = NULL; |
64 |
ec_tty_t *ttys[EC_TTY_MAX_DEVICES]; |
|
65 |
struct semaphore tty_sem; |
|
66 |
||
1565 | 67 |
/*****************************************************************************/ |
68 |
||
69 |
/** \cond */ |
|
70 |
||
71 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
|
72 |
MODULE_DESCRIPTION("EtherCAT TTY driver module"); |
|
73 |
MODULE_LICENSE("GPL"); |
|
74 |
MODULE_VERSION(EC_MASTER_VERSION); |
|
75 |
||
76 |
module_param_named(debug_level, debug_level, uint, S_IRUGO); |
|
77 |
MODULE_PARM_DESC(debug_level, "Debug level"); |
|
78 |
||
1569 | 79 |
/** \endcond */ |
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
80 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
81 |
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
|
82 |
.c_iflag = ICRNL | IXON, |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
83 |
.c_oflag = OPOST, |
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
84 |
.c_cflag = B38400 | CS8 | CREAD | HUPCL, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
85 |
.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
|
86 |
.c_cc = INIT_C_CC, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
87 |
}; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
88 |
|
1569 | 89 |
struct ec_tty { |
90 |
int minor; |
|
91 |
struct device *dev; |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
92 |
|
1575 | 93 |
uint8_t tx_buffer[EC_TTY_TX_BUFFER_SIZE]; |
94 |
unsigned int tx_read_idx; |
|
95 |
unsigned int tx_write_idx; |
|
96 |
unsigned int wakeup; |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
97 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
98 |
uint8_t rx_buffer[EC_TTY_RX_BUFFER_SIZE]; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
99 |
unsigned int rx_read_idx; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
100 |
unsigned int rx_write_idx; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
101 |
|
1575 | 102 |
struct timer_list timer; |
103 |
struct tty_struct *tty; |
|
1569 | 104 |
}; |
1565 | 105 |
|
1575 | 106 |
static const struct tty_operations ec_tty_ops; // see below |
107 |
||
1565 | 108 |
/*****************************************************************************/ |
109 |
||
110 |
/** Module initialization. |
|
111 |
* |
|
112 |
* \return 0 on success, else < 0 |
|
113 |
*/ |
|
114 |
int __init ec_tty_init_module(void) |
|
115 |
{ |
|
1569 | 116 |
int i, ret = 0; |
1565 | 117 |
|
1570 | 118 |
printk(KERN_INFO PFX "TTY driver %s\n", EC_MASTER_VERSION); |
1565 | 119 |
|
1569 | 120 |
init_MUTEX(&tty_sem); |
121 |
||
122 |
for (i = 0; i < EC_TTY_MAX_DEVICES; i++) { |
|
123 |
ttys[i] = NULL; |
|
124 |
} |
|
125 |
||
126 |
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
|
127 |
if (!tty_driver) { |
1570 | 128 |
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
|
129 |
ret = -ENOMEM; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
130 |
goto out_return; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
131 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
132 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
133 |
tty_driver->owner = THIS_MODULE; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
134 |
tty_driver->driver_name = "EtherCAT TTY"; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
135 |
tty_driver->name = "ttyEC"; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
136 |
tty_driver->major = 0; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
137 |
tty_driver->minor_start = 0; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
138 |
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
|
139 |
tty_driver->subtype = SERIAL_TYPE_NORMAL; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
145 |
ret = tty_register_driver(tty_driver); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
146 |
if (ret) { |
1570 | 147 |
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
|
148 |
goto out_put; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
149 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
150 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
151 |
return ret; |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
152 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
153 |
out_put: |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
154 |
put_tty_driver(tty_driver); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
155 |
out_return: |
1565 | 156 |
return ret; |
157 |
} |
|
158 |
||
159 |
/*****************************************************************************/ |
|
160 |
||
161 |
/** Module cleanup. |
|
162 |
* |
|
163 |
* Clears all master instances. |
|
164 |
*/ |
|
165 |
void __exit ec_tty_cleanup_module(void) |
|
166 |
{ |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
167 |
tty_unregister_driver(tty_driver); |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
168 |
put_tty_driver(tty_driver); |
1570 | 169 |
printk(KERN_INFO PFX "Module unloading.\n"); |
1565 | 170 |
} |
171 |
||
172 |
/*****************************************************************************/ |
|
173 |
||
1575 | 174 |
unsigned int ec_tty_tx_size(ec_tty_t *tty) |
175 |
{ |
|
176 |
unsigned int ret; |
|
177 |
||
178 |
if (tty->tx_write_idx >= tty->tx_read_idx) { |
|
179 |
ret = tty->tx_write_idx - tty->tx_read_idx; |
|
180 |
} else { |
|
181 |
ret = EC_TTY_TX_BUFFER_SIZE + tty->tx_write_idx - tty->tx_read_idx; |
|
182 |
} |
|
183 |
||
184 |
return ret; |
|
185 |
} |
|
186 |
||
187 |
/*****************************************************************************/ |
|
188 |
||
189 |
unsigned int ec_tty_tx_space(ec_tty_t *tty) |
|
190 |
{ |
|
191 |
return EC_TTY_TX_BUFFER_SIZE - 1 - ec_tty_tx_size(tty); |
|
192 |
} |
|
193 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
194 |
/*****************************************************************************/ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
195 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
196 |
unsigned int ec_tty_rx_size(ec_tty_t *tty) |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
197 |
{ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
198 |
unsigned int ret; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
199 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
200 |
if (tty->rx_write_idx >= tty->rx_read_idx) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
201 |
ret = tty->rx_write_idx - tty->rx_read_idx; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
202 |
} else { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
203 |
ret = EC_TTY_RX_BUFFER_SIZE + tty->rx_write_idx - tty->rx_read_idx; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
204 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
205 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
206 |
return ret; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
207 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
208 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
209 |
/*****************************************************************************/ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
210 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
211 |
unsigned int ec_tty_rx_space(ec_tty_t *tty) |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
212 |
{ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
213 |
return EC_TTY_RX_BUFFER_SIZE - 1 - ec_tty_rx_size(tty); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
214 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
215 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
216 |
/*****************************************************************************/ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
217 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
218 |
void ec_tty_wakeup(unsigned long data) |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
219 |
{ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
220 |
ec_tty_t *tty = (ec_tty_t *) data; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
221 |
size_t to_recv; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
222 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
223 |
/* Wake up any process waiting to send data */ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
224 |
if (tty->wakeup) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
225 |
if (tty->tty) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
226 |
#if EC_TTY_DEBUG >= 1 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
227 |
printk(KERN_INFO PFX "Waking up.\n"); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
228 |
#endif |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
229 |
tty_wakeup(tty->tty); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
230 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
231 |
tty->wakeup = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
232 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
233 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
234 |
/* Push received data into TTY core. */ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
235 |
to_recv = ec_tty_rx_size(tty); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
236 |
if (to_recv && tty->tty) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
237 |
unsigned char *cbuf; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
238 |
int space = tty_prepare_flip_string(tty->tty, &cbuf, to_recv); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
239 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
240 |
if (space < to_recv) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
241 |
printk(KERN_WARNING PFX "Insufficient space to_recv=%d space=%d\n", |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
242 |
to_recv, space); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
243 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
244 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
245 |
if (space < 0) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
246 |
to_recv = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
247 |
} else { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
248 |
to_recv = space; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
249 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
250 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
251 |
if (to_recv) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
252 |
unsigned int i; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
253 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
254 |
#if EC_TTY_DEBUG >= 1 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
255 |
printk(KERN_INFO PFX "Pushing %u bytes to TTY core.\n", to_recv); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
256 |
#endif |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
257 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
258 |
for (i = 0; i < to_recv; i++) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
259 |
cbuf[i] = tty->rx_buffer[tty->rx_read_idx]; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
260 |
tty->rx_read_idx = (tty->rx_read_idx + 1) % EC_TTY_RX_BUFFER_SIZE; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
261 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
262 |
tty_flip_buffer_push(tty->tty); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
263 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
264 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
265 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
266 |
tty->timer.expires += 1; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
267 |
add_timer(&tty->timer); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
268 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
269 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
270 |
/*****************************************************************************/ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
271 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
272 |
int ec_tty_init(ec_tty_t *tty, int minor) |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
273 |
{ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
274 |
tty->minor = minor; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
275 |
tty->tx_read_idx = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
276 |
tty->tx_write_idx = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
277 |
tty->wakeup = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
278 |
tty->rx_read_idx = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
279 |
tty->rx_write_idx = 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
280 |
init_timer(&tty->timer); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
281 |
tty->tty = NULL; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
282 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
283 |
tty->dev = tty_register_device(tty_driver, tty->minor, NULL); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
284 |
if (IS_ERR(tty->dev)) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
285 |
printk(KERN_ERR PFX "Failed to register tty device.\n"); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
286 |
return PTR_ERR(tty->dev); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
287 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
288 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
289 |
tty->timer.function = ec_tty_wakeup; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
290 |
tty->timer.data = (unsigned long) tty; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
291 |
tty->timer.expires = jiffies + 10; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
292 |
add_timer(&tty->timer); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
293 |
return 0; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
294 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
295 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
296 |
/*****************************************************************************/ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
297 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
298 |
void ec_tty_clear(ec_tty_t *tty) |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
299 |
{ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
300 |
del_timer_sync(&tty->timer); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
301 |
tty_unregister_device(tty_driver, tty->minor); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
302 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
303 |
|
1569 | 304 |
/****************************************************************************** |
305 |
* Device callbacks |
|
306 |
*****************************************************************************/ |
|
307 |
||
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
308 |
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
|
309 |
{ |
1571 | 310 |
ec_tty_t *t; |
311 |
int line = tty->index; |
|
312 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
313 |
#if EC_TTY_DEBUG >= 1 |
1571 | 314 |
printk(KERN_INFO PFX "Opening line %i.\n", line); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
315 |
#endif |
1571 | 316 |
|
317 |
if (line < 0 || line >= EC_TTY_MAX_DEVICES) { |
|
318 |
return -ENXIO; |
|
319 |
} |
|
320 |
||
321 |
t = ttys[line]; |
|
322 |
if (!t) { |
|
323 |
return -ENXIO; |
|
324 |
} |
|
325 |
||
1575 | 326 |
if (t->tty) { |
327 |
return -EBUSY; |
|
328 |
} |
|
329 |
||
330 |
t->tty = tty; |
|
1571 | 331 |
tty->driver_data = t; |
332 |
return 0; |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
333 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
334 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
335 |
/*****************************************************************************/ |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
336 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
337 |
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
|
338 |
{ |
1575 | 339 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
340 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
341 |
#if EC_TTY_DEBUG >= 1 |
1571 | 342 |
printk(KERN_INFO PFX "Closing line %i.\n", tty->index); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
343 |
#endif |
1575 | 344 |
|
345 |
if (t->tty == tty) { |
|
346 |
t->tty = NULL; |
|
347 |
} |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
348 |
} |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
349 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
350 |
/*****************************************************************************/ |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
351 |
|
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
352 |
static int ec_tty_write( |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
353 |
struct tty_struct *tty, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
354 |
const unsigned char *buffer, |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
355 |
int count |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
356 |
) |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
357 |
{ |
1575 | 358 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
359 |
unsigned int data_size, i; |
|
360 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
361 |
#if EC_TTY_DEBUG >= 1 |
1575 | 362 |
printk(KERN_INFO PFX "%s(count=%i)\n", __func__, count); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
363 |
#endif |
1575 | 364 |
|
365 |
if (count <= 0) { |
|
366 |
return 0; |
|
367 |
} |
|
368 |
||
369 |
data_size = min(ec_tty_tx_space(t), (unsigned int) count); |
|
370 |
for (i = 0; i < data_size; i++) { |
|
371 |
t->tx_buffer[t->tx_write_idx] = buffer[i]; |
|
372 |
t->tx_write_idx = (t->tx_write_idx + 1) % EC_TTY_TX_BUFFER_SIZE; |
|
373 |
} |
|
374 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
375 |
#if EC_TTY_DEBUG >= 1 |
1575 | 376 |
printk(KERN_INFO PFX "%s(): %u bytes written.\n", __func__, data_size); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
377 |
#endif |
1575 | 378 |
return data_size; |
379 |
} |
|
380 |
||
381 |
/*****************************************************************************/ |
|
382 |
||
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
383 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
384 |
static int ec_tty_put_char(struct tty_struct *tty, unsigned char ch) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
385 |
#else |
1575 | 386 |
static void ec_tty_put_char(struct tty_struct *tty, unsigned char ch) |
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
387 |
#endif |
1575 | 388 |
{ |
389 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
|
390 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
391 |
#if EC_TTY_DEBUG >= 1 |
1575 | 392 |
printk(KERN_INFO PFX "%s(): c=%02x.\n", __func__, (unsigned int) ch); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
393 |
#endif |
1575 | 394 |
|
395 |
if (ec_tty_tx_space(t)) { |
|
396 |
t->tx_buffer[t->tx_write_idx] = ch; |
|
397 |
t->tx_write_idx = (t->tx_write_idx + 1) % EC_TTY_TX_BUFFER_SIZE; |
|
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
398 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
399 |
return 1; |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
400 |
#endif |
1575 | 401 |
} else { |
402 |
printk(KERN_WARNING PFX "%s(): Dropped a byte!\n", __func__); |
|
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
403 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
404 |
return 0; |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
405 |
#endif |
1575 | 406 |
} |
407 |
} |
|
408 |
||
409 |
/*****************************************************************************/ |
|
410 |
||
411 |
static int ec_tty_write_room(struct tty_struct *tty) |
|
412 |
{ |
|
413 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
|
414 |
int ret = ec_tty_tx_space(t); |
|
415 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
416 |
#if EC_TTY_DEBUG >= 2 |
1575 | 417 |
printk(KERN_INFO PFX "%s() = %i.\n", __func__, ret); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
418 |
#endif |
1575 | 419 |
|
420 |
return ret; |
|
421 |
} |
|
422 |
||
423 |
/*****************************************************************************/ |
|
424 |
||
425 |
static int ec_tty_chars_in_buffer(struct tty_struct *tty) |
|
426 |
{ |
|
427 |
ec_tty_t *t = (ec_tty_t *) tty->driver_data; |
|
428 |
int ret; |
|
429 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
430 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
431 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
432 |
#endif |
1575 | 433 |
|
434 |
ret = ec_tty_tx_size(t); |
|
435 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
436 |
#if EC_TTY_DEBUG >= 2 |
1575 | 437 |
printk(KERN_INFO PFX "%s() = %i.\n", __func__, ret); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
438 |
#endif |
1575 | 439 |
|
440 |
return ret; |
|
441 |
} |
|
442 |
||
443 |
/*****************************************************************************/ |
|
444 |
||
445 |
static void ec_tty_flush_buffer(struct tty_struct *tty) |
|
446 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
447 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
448 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
449 |
#endif |
1575 | 450 |
} |
451 |
||
452 |
/*****************************************************************************/ |
|
453 |
||
454 |
static int ec_tty_ioctl(struct tty_struct *tty, struct file *file, |
|
455 |
unsigned int cmd, unsigned long arg) |
|
456 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
457 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
458 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
459 |
#endif |
1575 | 460 |
return -ENOTTY; |
461 |
} |
|
462 |
||
463 |
/*****************************************************************************/ |
|
464 |
||
465 |
static void ec_tty_throttle(struct tty_struct *tty) |
|
466 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
467 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
468 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
469 |
#endif |
1575 | 470 |
} |
471 |
||
472 |
/*****************************************************************************/ |
|
473 |
||
474 |
static void ec_tty_unthrottle(struct tty_struct *tty) |
|
475 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
476 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
477 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
478 |
#endif |
1575 | 479 |
} |
480 |
||
481 |
/*****************************************************************************/ |
|
482 |
||
483 |
static void ec_tty_set_termios(struct tty_struct *tty, |
|
484 |
struct ktermios *old_termios) |
|
485 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
486 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
487 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
488 |
#endif |
1575 | 489 |
} |
490 |
||
491 |
/*****************************************************************************/ |
|
492 |
||
493 |
static void ec_tty_stop(struct tty_struct *tty) |
|
494 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
495 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
496 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
497 |
#endif |
1575 | 498 |
} |
499 |
||
500 |
/*****************************************************************************/ |
|
501 |
||
502 |
static void ec_tty_start(struct tty_struct *tty) |
|
503 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
504 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
505 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
506 |
#endif |
1575 | 507 |
} |
508 |
||
509 |
/*****************************************************************************/ |
|
510 |
||
511 |
static void ec_tty_hangup(struct tty_struct *tty) |
|
512 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
513 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
514 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
515 |
#endif |
1575 | 516 |
} |
517 |
||
518 |
/*****************************************************************************/ |
|
519 |
||
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
520 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
521 |
static int ec_tty_break(struct tty_struct *tty, int break_state) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
522 |
#else |
1575 | 523 |
static void ec_tty_break(struct tty_struct *tty, int break_state) |
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
524 |
#endif |
1575 | 525 |
{ |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
526 |
#if EC_TTY_DEBUG >= 2 |
1575 | 527 |
printk(KERN_INFO PFX "%s(break_state = %i).\n", __func__, break_state); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
528 |
#endif |
1595
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
529 |
|
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
530 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
531 |
return -EIO; // not implemented |
8d8657654921
Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents:
1577
diff
changeset
|
532 |
#endif |
1575 | 533 |
} |
534 |
||
535 |
/*****************************************************************************/ |
|
536 |
||
537 |
static void ec_tty_send_xchar(struct tty_struct *tty, char ch) |
|
538 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
539 |
#if EC_TTY_DEBUG >= 2 |
1575 | 540 |
printk(KERN_INFO PFX "%s(ch=%02x).\n", __func__, (unsigned int) ch); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
541 |
#endif |
1575 | 542 |
} |
543 |
||
544 |
/*****************************************************************************/ |
|
545 |
||
546 |
static void ec_tty_wait_until_sent(struct tty_struct *tty, int timeout) |
|
547 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
548 |
#if EC_TTY_DEBUG >= 2 |
1575 | 549 |
printk(KERN_INFO PFX "%s(timeout=%i).\n", __func__, timeout); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
550 |
#endif |
1575 | 551 |
} |
552 |
||
553 |
/*****************************************************************************/ |
|
554 |
||
555 |
static int ec_tty_tiocmget(struct tty_struct *tty, struct file *file) |
|
556 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
557 |
#if EC_TTY_DEBUG >= 2 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
558 |
printk(KERN_INFO PFX "%s().\n", __func__); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
559 |
#endif |
1575 | 560 |
return -EBUSY; |
561 |
} |
|
562 |
||
563 |
/*****************************************************************************/ |
|
564 |
||
565 |
static int ec_tty_tiocmset(struct tty_struct *tty, struct file *file, |
|
566 |
unsigned int set, unsigned int clear) |
|
567 |
{ |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
568 |
#if EC_TTY_DEBUG >= 2 |
1575 | 569 |
printk(KERN_INFO PFX "%s(set=%u, clear=%u).\n", __func__, set, clear); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
570 |
#endif |
1575 | 571 |
return -EBUSY; |
572 |
} |
|
573 |
||
574 |
/*****************************************************************************/ |
|
575 |
||
576 |
static const struct tty_operations ec_tty_ops = { |
|
577 |
.open = ec_tty_open, |
|
578 |
.close = ec_tty_close, |
|
579 |
.write = ec_tty_write, |
|
580 |
.put_char = ec_tty_put_char, |
|
581 |
.write_room = ec_tty_write_room, |
|
582 |
.chars_in_buffer = ec_tty_chars_in_buffer, |
|
583 |
.flush_buffer = ec_tty_flush_buffer, |
|
584 |
.ioctl = ec_tty_ioctl, |
|
585 |
.throttle = ec_tty_throttle, |
|
586 |
.unthrottle = ec_tty_unthrottle, |
|
587 |
.set_termios = ec_tty_set_termios, |
|
588 |
.stop = ec_tty_stop, |
|
589 |
.start = ec_tty_start, |
|
590 |
.hangup = ec_tty_hangup, |
|
591 |
.break_ctl = ec_tty_break, |
|
592 |
.send_xchar = ec_tty_send_xchar, |
|
593 |
.wait_until_sent = ec_tty_wait_until_sent, |
|
594 |
.tiocmget = ec_tty_tiocmget, |
|
595 |
.tiocmset = ec_tty_tiocmset, |
|
596 |
}; |
|
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
597 |
|
1569 | 598 |
/****************************************************************************** |
599 |
* Public functions and methods |
|
600 |
*****************************************************************************/ |
|
601 |
||
602 |
ec_tty_t *ectty_create(void) |
|
603 |
{ |
|
604 |
ec_tty_t *tty; |
|
605 |
int minor, ret; |
|
606 |
||
607 |
if (down_interruptible(&tty_sem)) { |
|
608 |
return ERR_PTR(-EINTR); |
|
609 |
} |
|
610 |
||
611 |
for (minor = 0; minor < EC_TTY_MAX_DEVICES; minor++) { |
|
612 |
if (!ttys[minor]) { |
|
1575 | 613 |
printk(KERN_INFO PFX "Creating TTY interface %i.\n", minor); |
614 |
||
1569 | 615 |
tty = kmalloc(sizeof(ec_tty_t), GFP_KERNEL); |
616 |
if (!tty) { |
|
617 |
up(&tty_sem); |
|
1570 | 618 |
printk(KERN_ERR PFX "Failed to allocate memory.\n"); |
1569 | 619 |
return ERR_PTR(-ENOMEM); |
620 |
} |
|
621 |
||
622 |
ret = ec_tty_init(tty, minor); |
|
623 |
if (ret) { |
|
624 |
up(&tty_sem); |
|
625 |
kfree(tty); |
|
626 |
return ERR_PTR(ret); |
|
627 |
} |
|
628 |
||
629 |
ttys[minor] = tty; |
|
630 |
up(&tty_sem); |
|
631 |
return tty; |
|
632 |
} |
|
633 |
} |
|
634 |
||
635 |
up(&tty_sem); |
|
1570 | 636 |
printk(KERN_ERR PFX "No free interfaces avaliable.\n"); |
1569 | 637 |
return ERR_PTR(-EBUSY); |
638 |
} |
|
639 |
||
640 |
/*****************************************************************************/ |
|
641 |
||
642 |
void ectty_free(ec_tty_t *tty) |
|
643 |
{ |
|
1575 | 644 |
printk(KERN_INFO PFX "Freeing TTY interface %i.\n", tty->minor); |
645 |
||
1569 | 646 |
ec_tty_clear(tty); |
1570 | 647 |
ttys[tty->minor] = NULL; |
1569 | 648 |
kfree(tty); |
649 |
} |
|
650 |
||
1568
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
651 |
/*****************************************************************************/ |
d9bbbe1883ab
Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents:
1565
diff
changeset
|
652 |
|
1575 | 653 |
unsigned int ectty_tx_data(ec_tty_t *tty, uint8_t *buffer, size_t size) |
654 |
{ |
|
655 |
unsigned int data_size = min(ec_tty_tx_size(tty), size), i; |
|
656 |
||
657 |
if (data_size) { |
|
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
658 |
#if EC_TTY_DEBUG >= 1 |
1575 | 659 |
printk(KERN_INFO PFX "Fetching %u bytes to send.\n", data_size); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
660 |
#endif |
1575 | 661 |
} |
662 |
||
663 |
for (i = 0; i < data_size; i++) { |
|
664 |
buffer[i] = tty->tx_buffer[tty->tx_read_idx]; |
|
665 |
tty->tx_read_idx = (tty->tx_read_idx + 1) % EC_TTY_TX_BUFFER_SIZE; |
|
666 |
} |
|
667 |
||
668 |
if (data_size) { |
|
669 |
tty->wakeup = 1; |
|
670 |
} |
|
671 |
||
672 |
return data_size; |
|
673 |
} |
|
674 |
||
675 |
/*****************************************************************************/ |
|
676 |
||
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
677 |
void ectty_rx_data(ec_tty_t *tty, const uint8_t *buffer, size_t size) |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
678 |
{ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
679 |
size_t to_recv; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
680 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
681 |
if (size) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
682 |
unsigned int i; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
683 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
684 |
#if EC_TTY_DEBUG >= 1 |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
685 |
printk(KERN_INFO PFX "Received %u bytes.\n", size); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
686 |
#endif |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
687 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
688 |
to_recv = min(ec_tty_rx_space(tty), size); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
689 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
690 |
if (to_recv < size) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
691 |
printk(KERN_WARNING PFX "Dropping %u bytes.\n", size - to_recv); |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
692 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
693 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
694 |
for (i = 0; i < size; i++) { |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
695 |
tty->rx_buffer[tty->rx_write_idx] = buffer[i]; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
696 |
tty->rx_write_idx = (tty->rx_write_idx + 1) % EC_TTY_RX_BUFFER_SIZE; |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
697 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
698 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
699 |
} |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
700 |
|
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
701 |
/*****************************************************************************/ |
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
702 |
|
1565 | 703 |
/** \cond */ |
704 |
||
705 |
module_init(ec_tty_init_module); |
|
706 |
module_exit(ec_tty_cleanup_module); |
|
707 |
||
1569 | 708 |
EXPORT_SYMBOL(ectty_create); |
709 |
EXPORT_SYMBOL(ectty_free); |
|
1575 | 710 |
EXPORT_SYMBOL(ectty_tx_data); |
1577
fa3f66b783c1
Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents:
1575
diff
changeset
|
711 |
EXPORT_SYMBOL(ectty_rx_data); |
1569 | 712 |
|
1565 | 713 |
/** \endcond */ |
714 |
||
715 |
/*****************************************************************************/ |