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