aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/interface.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-04-12 16:54:43 -0400
committerJeff Garzik <jeff@garzik.org>2006-04-12 16:54:43 -0400
commita890b15c0990cc8d686edcc85f5fccde71ad5ce9 (patch)
tree73162355b58283a2531f13fbbf663809f95c1483 /drivers/isdn/gigaset/interface.c
parent79fa1b677be3a985cc66b9218a4dd09818f1051b (diff)
parent26ec634c31a11a003040e10b4d650495158632fd (diff)
Merge branch 'upstream'
Diffstat (limited to 'drivers/isdn/gigaset/interface.c')
-rw-r--r--drivers/isdn/gigaset/interface.c235
1 files changed, 121 insertions, 114 deletions
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index 3a81d9c65141..08e4c4eea14d 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -9,8 +9,6 @@
9 * published by the Free Software Foundation; either version 2 of 9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version. 10 * the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * Version: $Id: interface.c,v 1.14.4.15 2006/02/04 18:28:16 hjlipp Exp $
13 * =====================================================================
14 */ 12 */
15 13
16#include "gigaset.h" 14#include "gigaset.h"
@@ -24,7 +22,7 @@ static int if_lock(struct cardstate *cs, int *arg)
24{ 22{
25 int cmd = *arg; 23 int cmd = *arg;
26 24
27 dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd); 25 gig_dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd);
28 26
29 if (cmd > 1) 27 if (cmd > 1)
30 return -EINVAL; 28 return -EINVAL;
@@ -35,7 +33,7 @@ static int if_lock(struct cardstate *cs, int *arg)
35 } 33 }
36 34
37 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED 35 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
38 && atomic_read(&cs->connected)) { 36 && cs->connected) {
39 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS); 37 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
40 cs->ops->baud_rate(cs, B115200); 38 cs->ops->baud_rate(cs, B115200);
41 cs->ops->set_line_ctrl(cs, CS8); 39 cs->ops->set_line_ctrl(cs, CS8);
@@ -44,12 +42,12 @@ static int if_lock(struct cardstate *cs, int *arg)
44 42
45 cs->waiting = 1; 43 cs->waiting = 1;
46 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK, 44 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
47 NULL, cmd, NULL)) { 45 NULL, cmd, NULL)) {
48 cs->waiting = 0; 46 cs->waiting = 0;
49 return -ENOMEM; 47 return -ENOMEM;
50 } 48 }
51 49
52 dbg(DEBUG_CMD, "scheduling IF_LOCK"); 50 gig_dbg(DEBUG_CMD, "scheduling IF_LOCK");
53 gigaset_schedule_event(cs); 51 gigaset_schedule_event(cs);
54 52
55 wait_event(cs->waitqueue, !cs->waiting); 53 wait_event(cs->waitqueue, !cs->waiting);
@@ -68,7 +66,7 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
68 static const unsigned compat[4] = GIG_COMPAT; 66 static const unsigned compat[4] = GIG_COMPAT;
69 unsigned cmd = arg[0]; 67 unsigned cmd = arg[0];
70 68
71 dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd); 69 gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
72 70
73 switch (cmd) { 71 switch (cmd) {
74 case GIGVER_DRIVER: 72 case GIGVER_DRIVER:
@@ -80,12 +78,12 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
80 case GIGVER_FWBASE: 78 case GIGVER_FWBASE:
81 cs->waiting = 1; 79 cs->waiting = 1;
82 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER, 80 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
83 NULL, 0, arg)) { 81 NULL, 0, arg)) {
84 cs->waiting = 0; 82 cs->waiting = 0;
85 return -ENOMEM; 83 return -ENOMEM;
86 } 84 }
87 85
88 dbg(DEBUG_CMD, "scheduling IF_VER"); 86 gig_dbg(DEBUG_CMD, "scheduling IF_VER");
89 gigaset_schedule_event(cs); 87 gigaset_schedule_event(cs);
90 88
91 wait_event(cs->waitqueue, !cs->waiting); 89 wait_event(cs->waitqueue, !cs->waiting);
@@ -101,7 +99,7 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
101 99
102static int if_config(struct cardstate *cs, int *arg) 100static int if_config(struct cardstate *cs, int *arg)
103{ 101{
104 dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg); 102 gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
105 103
106 if (*arg != 1) 104 if (*arg != 1)
107 return -EINVAL; 105 return -EINVAL;
@@ -109,6 +107,11 @@ static int if_config(struct cardstate *cs, int *arg)
109 if (atomic_read(&cs->mstate) != MS_LOCKED) 107 if (atomic_read(&cs->mstate) != MS_LOCKED)
110 return -EBUSY; 108 return -EBUSY;
111 109
110 if (!cs->connected) {
111 err("not connected!");
112 return -ENODEV;
113 }
114
112 *arg = 0; 115 *arg = 0;
113 return gigaset_enterconfigmode(cs); 116 return gigaset_enterconfigmode(cs);
114} 117}
@@ -119,7 +122,7 @@ static int if_config(struct cardstate *cs, int *arg)
119static int if_open(struct tty_struct *tty, struct file *filp); 122static int if_open(struct tty_struct *tty, struct file *filp);
120static void if_close(struct tty_struct *tty, struct file *filp); 123static void if_close(struct tty_struct *tty, struct file *filp);
121static int if_ioctl(struct tty_struct *tty, struct file *file, 124static int if_ioctl(struct tty_struct *tty, struct file *file,
122 unsigned int cmd, unsigned long arg); 125 unsigned int cmd, unsigned long arg);
123static int if_write_room(struct tty_struct *tty); 126static int if_write_room(struct tty_struct *tty);
124static int if_chars_in_buffer(struct tty_struct *tty); 127static int if_chars_in_buffer(struct tty_struct *tty);
125static void if_throttle(struct tty_struct *tty); 128static void if_throttle(struct tty_struct *tty);
@@ -127,9 +130,9 @@ static void if_unthrottle(struct tty_struct *tty);
127static void if_set_termios(struct tty_struct *tty, struct termios *old); 130static void if_set_termios(struct tty_struct *tty, struct termios *old);
128static int if_tiocmget(struct tty_struct *tty, struct file *file); 131static int if_tiocmget(struct tty_struct *tty, struct file *file);
129static int if_tiocmset(struct tty_struct *tty, struct file *file, 132static int if_tiocmset(struct tty_struct *tty, struct file *file,
130 unsigned int set, unsigned int clear); 133 unsigned int set, unsigned int clear);
131static int if_write(struct tty_struct *tty, 134static int if_write(struct tty_struct *tty,
132 const unsigned char *buf, int count); 135 const unsigned char *buf, int count);
133 136
134static struct tty_operations if_ops = { 137static struct tty_operations if_ops = {
135 .open = if_open, 138 .open = if_open,
@@ -153,8 +156,8 @@ static int if_open(struct tty_struct *tty, struct file *filp)
153 struct cardstate *cs; 156 struct cardstate *cs;
154 unsigned long flags; 157 unsigned long flags;
155 158
156 dbg(DEBUG_IF, "%d+%d: %s()", tty->driver->minor_start, tty->index, 159 gig_dbg(DEBUG_IF, "%d+%d: %s()",
157 __FUNCTION__); 160 tty->driver->minor_start, tty->index, __func__);
158 161
159 tty->driver_data = NULL; 162 tty->driver_data = NULL;
160 163
@@ -162,7 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
162 if (!cs) 165 if (!cs)
163 return -ENODEV; 166 return -ENODEV;
164 167
165 if (down_interruptible(&cs->sem)) 168 if (mutex_lock_interruptible(&cs->mutex))
166 return -ERESTARTSYS; // FIXME -EINTR? 169 return -ERESTARTSYS; // FIXME -EINTR?
167 tty->driver_data = cs; 170 tty->driver_data = cs;
168 171
@@ -173,10 +176,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
173 cs->tty = tty; 176 cs->tty = tty;
174 spin_unlock_irqrestore(&cs->lock, flags); 177 spin_unlock_irqrestore(&cs->lock, flags);
175 tty->low_latency = 1; //FIXME test 178 tty->low_latency = 1; //FIXME test
176 //FIXME
177 } 179 }
178 180
179 up(&cs->sem); 181 mutex_unlock(&cs->mutex);
180 return 0; 182 return 0;
181} 183}
182 184
@@ -187,30 +189,29 @@ static void if_close(struct tty_struct *tty, struct file *filp)
187 189
188 cs = (struct cardstate *) tty->driver_data; 190 cs = (struct cardstate *) tty->driver_data;
189 if (!cs) { 191 if (!cs) {
190 err("cs==NULL in %s", __FUNCTION__); 192 err("cs==NULL in %s", __func__);
191 return; 193 return;
192 } 194 }
193 195
194 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 196 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
195 197
196 down(&cs->sem); 198 mutex_lock(&cs->mutex);
197 199
198 if (!cs->open_count) 200 if (!cs->open_count)
199 warn("%s: device not opened", __FUNCTION__); 201 warn("%s: device not opened", __func__);
200 else { 202 else {
201 if (!--cs->open_count) { 203 if (!--cs->open_count) {
202 spin_lock_irqsave(&cs->lock, flags); 204 spin_lock_irqsave(&cs->lock, flags);
203 cs->tty = NULL; 205 cs->tty = NULL;
204 spin_unlock_irqrestore(&cs->lock, flags); 206 spin_unlock_irqrestore(&cs->lock, flags);
205 //FIXME
206 } 207 }
207 } 208 }
208 209
209 up(&cs->sem); 210 mutex_unlock(&cs->mutex);
210} 211}
211 212
212static int if_ioctl(struct tty_struct *tty, struct file *file, 213static int if_ioctl(struct tty_struct *tty, struct file *file,
213 unsigned int cmd, unsigned long arg) 214 unsigned int cmd, unsigned long arg)
214{ 215{
215 struct cardstate *cs; 216 struct cardstate *cs;
216 int retval = -ENODEV; 217 int retval = -ENODEV;
@@ -220,17 +221,17 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
220 221
221 cs = (struct cardstate *) tty->driver_data; 222 cs = (struct cardstate *) tty->driver_data;
222 if (!cs) { 223 if (!cs) {
223 err("cs==NULL in %s", __FUNCTION__); 224 err("cs==NULL in %s", __func__);
224 return -ENODEV; 225 return -ENODEV;
225 } 226 }
226 227
227 dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __FUNCTION__, cmd); 228 gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
228 229
229 if (down_interruptible(&cs->sem)) 230 if (mutex_lock_interruptible(&cs->mutex))
230 return -ERESTARTSYS; // FIXME -EINTR? 231 return -ERESTARTSYS; // FIXME -EINTR?
231 232
232 if (!cs->open_count) 233 if (!cs->open_count)
233 warn("%s: device not opened", __FUNCTION__); 234 warn("%s: device not opened", __func__);
234 else { 235 else {
235 retval = 0; 236 retval = 0;
236 switch (cmd) { 237 switch (cmd) {
@@ -250,37 +251,40 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
250 break; 251 break;
251 case GIGASET_BRKCHARS: 252 case GIGASET_BRKCHARS:
252 //FIXME test if MS_LOCKED 253 //FIXME test if MS_LOCKED
253 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS", 254 if (!cs->connected) {
254 6, (const unsigned char *) arg, 1); 255 gig_dbg(DEBUG_ANY,
255 if (!atomic_read(&cs->connected)) { 256 "can't communicate with unplugged device");
256 dbg(DEBUG_ANY, "can't communicate with unplugged device");
257 retval = -ENODEV; 257 retval = -ENODEV;
258 break; 258 break;
259 } 259 }
260 retval = copy_from_user(&buf, 260 retval = copy_from_user(&buf,
261 (const unsigned char __user *) arg, 6) 261 (const unsigned char __user *) arg, 6)
262 ? -EFAULT : 0; 262 ? -EFAULT : 0;
263 if (retval >= 0) 263 if (retval >= 0) {
264 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
265 6, (const unsigned char *) arg);
264 retval = cs->ops->brkchars(cs, buf); 266 retval = cs->ops->brkchars(cs, buf);
267 }
265 break; 268 break;
266 case GIGASET_VERSION: 269 case GIGASET_VERSION:
267 retval = copy_from_user(version, (unsigned __user *) arg, 270 retval = copy_from_user(version,
268 sizeof version) ? -EFAULT : 0; 271 (unsigned __user *) arg, sizeof version)
272 ? -EFAULT : 0;
269 if (retval >= 0) 273 if (retval >= 0)
270 retval = if_version(cs, version); 274 retval = if_version(cs, version);
271 if (retval >= 0) 275 if (retval >= 0)
272 retval = copy_to_user((unsigned __user *) arg, version, 276 retval = copy_to_user((unsigned __user *) arg,
273 sizeof version) 277 version, sizeof version)
274 ? -EFAULT : 0; 278 ? -EFAULT : 0;
275 break; 279 break;
276 default: 280 default:
277 dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x", 281 gig_dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
278 __FUNCTION__, cmd); 282 __func__, cmd);
279 retval = -ENOIOCTLCMD; 283 retval = -ENOIOCTLCMD;
280 } 284 }
281 } 285 }
282 286
283 up(&cs->sem); 287 mutex_unlock(&cs->mutex);
284 288
285 return retval; 289 return retval;
286} 290}
@@ -292,25 +296,25 @@ static int if_tiocmget(struct tty_struct *tty, struct file *file)
292 296
293 cs = (struct cardstate *) tty->driver_data; 297 cs = (struct cardstate *) tty->driver_data;
294 if (!cs) { 298 if (!cs) {
295 err("cs==NULL in %s", __FUNCTION__); 299 err("cs==NULL in %s", __func__);
296 return -ENODEV; 300 return -ENODEV;
297 } 301 }
298 302
299 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 303 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
300 304
301 if (down_interruptible(&cs->sem)) 305 if (mutex_lock_interruptible(&cs->mutex))
302 return -ERESTARTSYS; // FIXME -EINTR? 306 return -ERESTARTSYS; // FIXME -EINTR?
303 307
304 // FIXME read from device? 308 // FIXME read from device?
305 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR); 309 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
306 310
307 up(&cs->sem); 311 mutex_unlock(&cs->mutex);
308 312
309 return retval; 313 return retval;
310} 314}
311 315
312static int if_tiocmset(struct tty_struct *tty, struct file *file, 316static int if_tiocmset(struct tty_struct *tty, struct file *file,
313 unsigned int set, unsigned int clear) 317 unsigned int set, unsigned int clear)
314{ 318{
315 struct cardstate *cs; 319 struct cardstate *cs;
316 int retval; 320 int retval;
@@ -318,18 +322,18 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
318 322
319 cs = (struct cardstate *) tty->driver_data; 323 cs = (struct cardstate *) tty->driver_data;
320 if (!cs) { 324 if (!cs) {
321 err("cs==NULL in %s", __FUNCTION__); 325 err("cs==NULL in %s", __func__);
322 return -ENODEV; 326 return -ENODEV;
323 } 327 }
324 328
325 dbg(DEBUG_IF, 329 gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
326 "%u: %s(0x%x, 0x%x)", cs->minor_index, __FUNCTION__, set, clear); 330 cs->minor_index, __func__, set, clear);
327 331
328 if (down_interruptible(&cs->sem)) 332 if (mutex_lock_interruptible(&cs->mutex))
329 return -ERESTARTSYS; // FIXME -EINTR? 333 return -ERESTARTSYS; // FIXME -EINTR?
330 334
331 if (!atomic_read(&cs->connected)) { 335 if (!cs->connected) {
332 dbg(DEBUG_ANY, "can't communicate with unplugged device"); 336 gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
333 retval = -ENODEV; 337 retval = -ENODEV;
334 } else { 338 } else {
335 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR); 339 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
@@ -337,7 +341,7 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
337 cs->control_state = mc; 341 cs->control_state = mc;
338 } 342 }
339 343
340 up(&cs->sem); 344 mutex_unlock(&cs->mutex);
341 345
342 return retval; 346 return retval;
343} 347}
@@ -349,29 +353,29 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
349 353
350 cs = (struct cardstate *) tty->driver_data; 354 cs = (struct cardstate *) tty->driver_data;
351 if (!cs) { 355 if (!cs) {
352 err("cs==NULL in %s", __FUNCTION__); 356 err("cs==NULL in %s", __func__);
353 return -ENODEV; 357 return -ENODEV;
354 } 358 }
355 359
356 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 360 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
357 361
358 if (down_interruptible(&cs->sem)) 362 if (mutex_lock_interruptible(&cs->mutex))
359 return -ERESTARTSYS; // FIXME -EINTR? 363 return -ERESTARTSYS; // FIXME -EINTR?
360 364
361 if (!cs->open_count) 365 if (!cs->open_count)
362 warn("%s: device not opened", __FUNCTION__); 366 warn("%s: device not opened", __func__);
363 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 367 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
364 warn("can't write to unlocked device"); 368 warn("can't write to unlocked device");
365 retval = -EBUSY; 369 retval = -EBUSY;
366 } else if (!atomic_read(&cs->connected)) { 370 } else if (!cs->connected) {
367 dbg(DEBUG_ANY, "can't write to unplugged device"); 371 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
368 retval = -EBUSY; //FIXME 372 retval = -EBUSY; //FIXME
369 } else { 373 } else {
370 retval = cs->ops->write_cmd(cs, buf, count, 374 retval = cs->ops->write_cmd(cs, buf, count,
371 &cs->if_wake_tasklet); 375 &cs->if_wake_tasklet);
372 } 376 }
373 377
374 up(&cs->sem); 378 mutex_unlock(&cs->mutex);
375 379
376 return retval; 380 return retval;
377} 381}
@@ -383,27 +387,27 @@ static int if_write_room(struct tty_struct *tty)
383 387
384 cs = (struct cardstate *) tty->driver_data; 388 cs = (struct cardstate *) tty->driver_data;
385 if (!cs) { 389 if (!cs) {
386 err("cs==NULL in %s", __FUNCTION__); 390 err("cs==NULL in %s", __func__);
387 return -ENODEV; 391 return -ENODEV;
388 } 392 }
389 393
390 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 394 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
391 395
392 if (down_interruptible(&cs->sem)) 396 if (mutex_lock_interruptible(&cs->mutex))
393 return -ERESTARTSYS; // FIXME -EINTR? 397 return -ERESTARTSYS; // FIXME -EINTR?
394 398
395 if (!cs->open_count) 399 if (!cs->open_count)
396 warn("%s: device not opened", __FUNCTION__); 400 warn("%s: device not opened", __func__);
397 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 401 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
398 warn("can't write to unlocked device"); 402 warn("can't write to unlocked device");
399 retval = -EBUSY; //FIXME 403 retval = -EBUSY; //FIXME
400 } else if (!atomic_read(&cs->connected)) { 404 } else if (!cs->connected) {
401 dbg(DEBUG_ANY, "can't write to unplugged device"); 405 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
402 retval = -EBUSY; //FIXME 406 retval = -EBUSY; //FIXME
403 } else 407 } else
404 retval = cs->ops->write_room(cs); 408 retval = cs->ops->write_room(cs);
405 409
406 up(&cs->sem); 410 mutex_unlock(&cs->mutex);
407 411
408 return retval; 412 return retval;
409} 413}
@@ -415,27 +419,27 @@ static int if_chars_in_buffer(struct tty_struct *tty)
415 419
416 cs = (struct cardstate *) tty->driver_data; 420 cs = (struct cardstate *) tty->driver_data;
417 if (!cs) { 421 if (!cs) {
418 err("cs==NULL in %s", __FUNCTION__); 422 err("cs==NULL in %s", __func__);
419 return -ENODEV; 423 return -ENODEV;
420 } 424 }
421 425
422 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 426 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
423 427
424 if (down_interruptible(&cs->sem)) 428 if (mutex_lock_interruptible(&cs->mutex))
425 return -ERESTARTSYS; // FIXME -EINTR? 429 return -ERESTARTSYS; // FIXME -EINTR?
426 430
427 if (!cs->open_count) 431 if (!cs->open_count)
428 warn("%s: device not opened", __FUNCTION__); 432 warn("%s: device not opened", __func__);
429 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 433 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
430 warn("can't write to unlocked device"); 434 warn("can't write to unlocked device");
431 retval = -EBUSY; 435 retval = -EBUSY;
432 } else if (!atomic_read(&cs->connected)) { 436 } else if (!cs->connected) {
433 dbg(DEBUG_ANY, "can't write to unplugged device"); 437 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
434 retval = -EBUSY; //FIXME 438 retval = -EBUSY; //FIXME
435 } else 439 } else
436 retval = cs->ops->chars_in_buffer(cs); 440 retval = cs->ops->chars_in_buffer(cs);
437 441
438 up(&cs->sem); 442 mutex_unlock(&cs->mutex);
439 443
440 return retval; 444 return retval;
441} 445}
@@ -446,21 +450,21 @@ static void if_throttle(struct tty_struct *tty)
446 450
447 cs = (struct cardstate *) tty->driver_data; 451 cs = (struct cardstate *) tty->driver_data;
448 if (!cs) { 452 if (!cs) {
449 err("cs==NULL in %s", __FUNCTION__); 453 err("cs==NULL in %s", __func__);
450 return; 454 return;
451 } 455 }
452 456
453 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 457 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
454 458
455 down(&cs->sem); 459 mutex_lock(&cs->mutex);
456 460
457 if (!cs->open_count) 461 if (!cs->open_count)
458 warn("%s: device not opened", __FUNCTION__); 462 warn("%s: device not opened", __func__);
459 else { 463 else {
460 //FIXME 464 //FIXME
461 } 465 }
462 466
463 up(&cs->sem); 467 mutex_unlock(&cs->mutex);
464} 468}
465 469
466static void if_unthrottle(struct tty_struct *tty) 470static void if_unthrottle(struct tty_struct *tty)
@@ -469,21 +473,21 @@ static void if_unthrottle(struct tty_struct *tty)
469 473
470 cs = (struct cardstate *) tty->driver_data; 474 cs = (struct cardstate *) tty->driver_data;
471 if (!cs) { 475 if (!cs) {
472 err("cs==NULL in %s", __FUNCTION__); 476 err("cs==NULL in %s", __func__);
473 return; 477 return;
474 } 478 }
475 479
476 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 480 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
477 481
478 down(&cs->sem); 482 mutex_lock(&cs->mutex);
479 483
480 if (!cs->open_count) 484 if (!cs->open_count)
481 warn("%s: device not opened", __FUNCTION__); 485 warn("%s: device not opened", __func__);
482 else { 486 else {
483 //FIXME 487 //FIXME
484 } 488 }
485 489
486 up(&cs->sem); 490 mutex_unlock(&cs->mutex);
487} 491}
488 492
489static void if_set_termios(struct tty_struct *tty, struct termios *old) 493static void if_set_termios(struct tty_struct *tty, struct termios *old)
@@ -496,21 +500,21 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
496 500
497 cs = (struct cardstate *) tty->driver_data; 501 cs = (struct cardstate *) tty->driver_data;
498 if (!cs) { 502 if (!cs) {
499 err("cs==NULL in %s", __FUNCTION__); 503 err("cs==NULL in %s", __func__);
500 return; 504 return;
501 } 505 }
502 506
503 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 507 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
504 508
505 down(&cs->sem); 509 mutex_lock(&cs->mutex);
506 510
507 if (!cs->open_count) { 511 if (!cs->open_count) {
508 warn("%s: device not opened", __FUNCTION__); 512 warn("%s: device not opened", __func__);
509 goto out; 513 goto out;
510 } 514 }
511 515
512 if (!atomic_read(&cs->connected)) { 516 if (!cs->connected) {
513 dbg(DEBUG_ANY, "can't communicate with unplugged device"); 517 gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
514 goto out; 518 goto out;
515 } 519 }
516 520
@@ -518,8 +522,8 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
518 iflag = tty->termios->c_iflag; 522 iflag = tty->termios->c_iflag;
519 cflag = tty->termios->c_cflag; 523 cflag = tty->termios->c_cflag;
520 old_cflag = old ? old->c_cflag : cflag; //FIXME? 524 old_cflag = old ? old->c_cflag : cflag; //FIXME?
521 dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", cs->minor_index, 525 gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
522 iflag, cflag, old_cflag); 526 cs->minor_index, iflag, cflag, old_cflag);
523 527
524 /* get a local copy of the current port settings */ 528 /* get a local copy of the current port settings */
525 control_state = cs->control_state; 529 control_state = cs->control_state;
@@ -531,14 +535,15 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
531 * Premature optimization is the root of all evil. 535 * Premature optimization is the root of all evil.
532 */ 536 */
533 537
534 /* reassert DTR and (maybe) RTS on transition from B0 */ 538 /* reassert DTR and (maybe) RTS on transition from B0 */
535 if ((old_cflag & CBAUD) == B0) { 539 if ((old_cflag & CBAUD) == B0) {
536 new_state = control_state | TIOCM_DTR; 540 new_state = control_state | TIOCM_DTR;
537 /* don't set RTS if using hardware flow control */ 541 /* don't set RTS if using hardware flow control */
538 if (!(old_cflag & CRTSCTS)) 542 if (!(old_cflag & CRTSCTS))
539 new_state |= TIOCM_RTS; 543 new_state |= TIOCM_RTS;
540 dbg(DEBUG_IF, "%u: from B0 - set DTR%s", cs->minor_index, 544 gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
541 (new_state & TIOCM_RTS) ? " only" : "/RTS"); 545 cs->minor_index,
546 (new_state & TIOCM_RTS) ? " only" : "/RTS");
542 cs->ops->set_modem_ctrl(cs, control_state, new_state); 547 cs->ops->set_modem_ctrl(cs, control_state, new_state);
543 control_state = new_state; 548 control_state = new_state;
544 } 549 }
@@ -547,7 +552,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
547 552
548 if ((cflag & CBAUD) == B0) { 553 if ((cflag & CBAUD) == B0) {
549 /* Drop RTS and DTR */ 554 /* Drop RTS and DTR */
550 dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index); 555 gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
551 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS); 556 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
552 cs->ops->set_modem_ctrl(cs, control_state, new_state); 557 cs->ops->set_modem_ctrl(cs, control_state, new_state);
553 control_state = new_state; 558 control_state = new_state;
@@ -567,15 +572,17 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
567 * Just do what we have seen with SniffUSB on Win98. 572 * Just do what we have seen with SniffUSB on Win98.
568 */ 573 */
569 /* Drop DTR/RTS if no flow control otherwise assert */ 574 /* Drop DTR/RTS if no flow control otherwise assert */
570 dbg(DEBUG_IF, "%u: control_state %x", cs->minor_index, control_state); 575 gig_dbg(DEBUG_IF, "%u: control_state %x",
576 cs->minor_index, control_state);
571 new_state = control_state; 577 new_state = control_state;
572 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS)) 578 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
573 new_state |= TIOCM_DTR | TIOCM_RTS; 579 new_state |= TIOCM_DTR | TIOCM_RTS;
574 else 580 else
575 new_state &= ~(TIOCM_DTR | TIOCM_RTS); 581 new_state &= ~(TIOCM_DTR | TIOCM_RTS);
576 if (new_state != control_state) { 582 if (new_state != control_state) {
577 dbg(DEBUG_IF, "%u: new_state %x", cs->minor_index, new_state); 583 gig_dbg(DEBUG_IF, "%u: new_state %x",
578 gigaset_set_modem_ctrl(cs, control_state, new_state); // FIXME: mct_u232.c sets the old state here. is this a bug? 584 cs->minor_index, new_state);
585 gigaset_set_modem_ctrl(cs, control_state, new_state);
579 control_state = new_state; 586 control_state = new_state;
580 } 587 }
581#endif 588#endif
@@ -584,7 +591,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
584 cs->control_state = control_state; 591 cs->control_state = control_state;
585 592
586out: 593out:
587 up(&cs->sem); 594 mutex_unlock(&cs->mutex);
588} 595}
589 596
590 597
@@ -600,7 +607,7 @@ static void if_wake(unsigned long data)
600 607
601 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && 608 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
602 tty->ldisc.write_wakeup) { 609 tty->ldisc.write_wakeup) {
603 dbg(DEBUG_IF, "write wakeup call"); 610 gig_dbg(DEBUG_IF, "write wakeup call");
604 tty->ldisc.write_wakeup(tty); 611 tty->ldisc.write_wakeup(tty);
605 } 612 }
606 613
@@ -635,14 +642,14 @@ void gigaset_if_free(struct cardstate *cs)
635} 642}
636 643
637void gigaset_if_receive(struct cardstate *cs, 644void gigaset_if_receive(struct cardstate *cs,
638 unsigned char *buffer, size_t len) 645 unsigned char *buffer, size_t len)
639{ 646{
640 unsigned long flags; 647 unsigned long flags;
641 struct tty_struct *tty; 648 struct tty_struct *tty;
642 649
643 spin_lock_irqsave(&cs->lock, flags); 650 spin_lock_irqsave(&cs->lock, flags);
644 if ((tty = cs->tty) == NULL) 651 if ((tty = cs->tty) == NULL)
645 dbg(DEBUG_ANY, "receive on closed device"); 652 gig_dbg(DEBUG_ANY, "receive on closed device");
646 else { 653 else {
647 tty_buffer_request_room(tty, len); 654 tty_buffer_request_room(tty, len);
648 tty_insert_flip_string(tty, buffer, len); 655 tty_insert_flip_string(tty, buffer, len);
@@ -655,13 +662,13 @@ EXPORT_SYMBOL_GPL(gigaset_if_receive);
655/* gigaset_if_initdriver 662/* gigaset_if_initdriver
656 * Initialize tty interface. 663 * Initialize tty interface.
657 * parameters: 664 * parameters:
658 * drv Driver 665 * drv Driver
659 * procname Name of the driver (e.g. for /proc/tty/drivers) 666 * procname Name of the driver (e.g. for /proc/tty/drivers)
660 * devname Name of the device files (prefix without minor number) 667 * devname Name of the device files (prefix without minor number)
661 * devfsname Devfs name of the device files without %d 668 * devfsname Devfs name of the device files without %d
662 */ 669 */
663void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 670void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
664 const char *devname, const char *devfsname) 671 const char *devname, const char *devfsname)
665{ 672{
666 unsigned minors = drv->minors; 673 unsigned minors = drv->minors;
667 int ret; 674 int ret;
@@ -696,7 +703,7 @@ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
696 warn("failed to register tty driver (error %d)", ret); 703 warn("failed to register tty driver (error %d)", ret);
697 goto error; 704 goto error;
698 } 705 }
699 dbg(DEBUG_IF, "tty driver initialized"); 706 gig_dbg(DEBUG_IF, "tty driver initialized");
700 drv->have_tty = 1; 707 drv->have_tty = 1;
701 return; 708 return;
702 709