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