]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/isdn/gigaset/ser-gigaset.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mirror_ubuntu-artful-kernel.git] / drivers / isdn / gigaset / ser-gigaset.c
1 /* This is the serial hardware link layer (HLL) for the Gigaset 307x isdn
2 * DECT base (aka Sinus 45 isdn) using the RS232 DECT data module M101,
3 * written as a line discipline.
4 *
5 * =====================================================================
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 * =====================================================================
11 */
12
13 #include "gigaset.h"
14
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/platform_device.h>
18 #include <linux/tty.h>
19 #include <linux/completion.h>
20 #include <linux/slab.h>
21
22 /* Version Information */
23 #define DRIVER_AUTHOR "Tilman Schmidt"
24 #define DRIVER_DESC "Serial Driver for Gigaset 307x using Siemens M101"
25
26 #define GIGASET_MINORS 1
27 #define GIGASET_MINOR 0
28 #define GIGASET_MODULENAME "ser_gigaset"
29 #define GIGASET_DEVNAME "ttyGS"
30
31 /* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */
32 #define IF_WRITEBUF 264
33
34 MODULE_AUTHOR(DRIVER_AUTHOR);
35 MODULE_DESCRIPTION(DRIVER_DESC);
36 MODULE_LICENSE("GPL");
37 MODULE_ALIAS_LDISC(N_GIGASET_M101);
38
39 static int startmode = SM_ISDN;
40 module_param(startmode, int, S_IRUGO);
41 MODULE_PARM_DESC(startmode, "initial operation mode");
42 static int cidmode = 1;
43 module_param(cidmode, int, S_IRUGO);
44 MODULE_PARM_DESC(cidmode, "stay in CID mode when idle");
45
46 static struct gigaset_driver *driver;
47
48 struct ser_cardstate {
49 struct platform_device dev;
50 struct tty_struct *tty;
51 atomic_t refcnt;
52 struct completion dead_cmp;
53 };
54
55 static struct platform_driver device_driver = {
56 .driver = {
57 .name = GIGASET_MODULENAME,
58 },
59 };
60
61 static void flush_send_queue(struct cardstate *);
62
63 /* transmit data from current open skb
64 * result: number of bytes sent or error code < 0
65 */
66 static int write_modem(struct cardstate *cs)
67 {
68 struct tty_struct *tty = cs->hw.ser->tty;
69 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
70 struct sk_buff *skb = bcs->tx_skb;
71 int sent = -EOPNOTSUPP;
72
73 if (!tty || !tty->driver || !skb)
74 return -EINVAL;
75
76 if (!skb->len) {
77 dev_kfree_skb_any(skb);
78 bcs->tx_skb = NULL;
79 return -EINVAL;
80 }
81
82 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
83 if (tty->ops->write)
84 sent = tty->ops->write(tty, skb->data, skb->len);
85 gig_dbg(DEBUG_OUTPUT, "write_modem: sent %d", sent);
86 if (sent < 0) {
87 /* error */
88 flush_send_queue(cs);
89 return sent;
90 }
91 skb_pull(skb, sent);
92 if (!skb->len) {
93 /* skb sent completely */
94 gigaset_skb_sent(bcs, skb);
95
96 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
97 (unsigned long) skb);
98 dev_kfree_skb_any(skb);
99 bcs->tx_skb = NULL;
100 }
101 return sent;
102 }
103
104 /*
105 * transmit first queued command buffer
106 * result: number of bytes sent or error code < 0
107 */
108 static int send_cb(struct cardstate *cs)
109 {
110 struct tty_struct *tty = cs->hw.ser->tty;
111 struct cmdbuf_t *cb, *tcb;
112 unsigned long flags;
113 int sent = 0;
114
115 if (!tty || !tty->driver)
116 return -EFAULT;
117
118 cb = cs->cmdbuf;
119 if (!cb)
120 return 0; /* nothing to do */
121
122 if (cb->len) {
123 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
124 sent = tty->ops->write(tty, cb->buf + cb->offset, cb->len);
125 if (sent < 0) {
126 /* error */
127 gig_dbg(DEBUG_OUTPUT, "send_cb: write error %d", sent);
128 flush_send_queue(cs);
129 return sent;
130 }
131 cb->offset += sent;
132 cb->len -= sent;
133 gig_dbg(DEBUG_OUTPUT, "send_cb: sent %d, left %u, queued %u",
134 sent, cb->len, cs->cmdbytes);
135 }
136
137 while (cb && !cb->len) {
138 spin_lock_irqsave(&cs->cmdlock, flags);
139 cs->cmdbytes -= cs->curlen;
140 tcb = cb;
141 cs->cmdbuf = cb = cb->next;
142 if (cb) {
143 cb->prev = NULL;
144 cs->curlen = cb->len;
145 } else {
146 cs->lastcmdbuf = NULL;
147 cs->curlen = 0;
148 }
149 spin_unlock_irqrestore(&cs->cmdlock, flags);
150
151 if (tcb->wake_tasklet)
152 tasklet_schedule(tcb->wake_tasklet);
153 kfree(tcb);
154 }
155 return sent;
156 }
157
158 /*
159 * send queue tasklet
160 * If there is already a skb opened, put data to the transfer buffer
161 * by calling "write_modem".
162 * Otherwise take a new skb out of the queue.
163 */
164 static void gigaset_modem_fill(unsigned long data)
165 {
166 struct cardstate *cs = (struct cardstate *) data;
167 struct bc_state *bcs;
168 struct sk_buff *nextskb;
169 int sent = 0;
170
171 if (!cs) {
172 gig_dbg(DEBUG_OUTPUT, "%s: no cardstate", __func__);
173 return;
174 }
175 bcs = cs->bcs;
176 if (!bcs) {
177 gig_dbg(DEBUG_OUTPUT, "%s: no cardstate", __func__);
178 return;
179 }
180 if (!bcs->tx_skb) {
181 /* no skb is being sent; send command if any */
182 sent = send_cb(cs);
183 gig_dbg(DEBUG_OUTPUT, "%s: send_cb -> %d", __func__, sent);
184 if (sent)
185 /* something sent or error */
186 return;
187
188 /* no command to send; get skb */
189 nextskb = skb_dequeue(&bcs->squeue);
190 if (!nextskb)
191 /* no skb either, nothing to do */
192 return;
193 bcs->tx_skb = nextskb;
194
195 gig_dbg(DEBUG_INTR, "Dequeued skb (Adr: %lx)",
196 (unsigned long) bcs->tx_skb);
197 }
198
199 /* send skb */
200 gig_dbg(DEBUG_OUTPUT, "%s: tx_skb", __func__);
201 if (write_modem(cs) < 0)
202 gig_dbg(DEBUG_OUTPUT, "%s: write_modem failed", __func__);
203 }
204
205 /*
206 * throw away all data queued for sending
207 */
208 static void flush_send_queue(struct cardstate *cs)
209 {
210 struct sk_buff *skb;
211 struct cmdbuf_t *cb;
212 unsigned long flags;
213
214 /* command queue */
215 spin_lock_irqsave(&cs->cmdlock, flags);
216 while ((cb = cs->cmdbuf) != NULL) {
217 cs->cmdbuf = cb->next;
218 if (cb->wake_tasklet)
219 tasklet_schedule(cb->wake_tasklet);
220 kfree(cb);
221 }
222 cs->cmdbuf = cs->lastcmdbuf = NULL;
223 cs->cmdbytes = cs->curlen = 0;
224 spin_unlock_irqrestore(&cs->cmdlock, flags);
225
226 /* data queue */
227 if (cs->bcs->tx_skb)
228 dev_kfree_skb_any(cs->bcs->tx_skb);
229 while ((skb = skb_dequeue(&cs->bcs->squeue)) != NULL)
230 dev_kfree_skb_any(skb);
231 }
232
233
234 /* Gigaset Driver Interface */
235 /* ======================== */
236
237 /*
238 * queue an AT command string for transmission to the Gigaset device
239 * parameters:
240 * cs controller state structure
241 * buf buffer containing the string to send
242 * len number of characters to send
243 * wake_tasklet tasklet to run when transmission is complete, or NULL
244 * return value:
245 * number of bytes queued, or error code < 0
246 */
247 static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
248 int len, struct tasklet_struct *wake_tasklet)
249 {
250 struct cmdbuf_t *cb;
251 unsigned long flags;
252
253 gigaset_dbg_buffer(cs->mstate != MS_LOCKED ?
254 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
255 "CMD Transmit", len, buf);
256
257 if (len <= 0)
258 return 0;
259
260 cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC);
261 if (!cb) {
262 dev_err(cs->dev, "%s: out of memory!\n", __func__);
263 return -ENOMEM;
264 }
265
266 memcpy(cb->buf, buf, len);
267 cb->len = len;
268 cb->offset = 0;
269 cb->next = NULL;
270 cb->wake_tasklet = wake_tasklet;
271
272 spin_lock_irqsave(&cs->cmdlock, flags);
273 cb->prev = cs->lastcmdbuf;
274 if (cs->lastcmdbuf)
275 cs->lastcmdbuf->next = cb;
276 else {
277 cs->cmdbuf = cb;
278 cs->curlen = len;
279 }
280 cs->cmdbytes += len;
281 cs->lastcmdbuf = cb;
282 spin_unlock_irqrestore(&cs->cmdlock, flags);
283
284 spin_lock_irqsave(&cs->lock, flags);
285 if (cs->connected)
286 tasklet_schedule(&cs->write_tasklet);
287 spin_unlock_irqrestore(&cs->lock, flags);
288 return len;
289 }
290
291 /*
292 * tty_driver.write_room interface routine
293 * return number of characters the driver will accept to be written
294 * parameter:
295 * controller state structure
296 * return value:
297 * number of characters
298 */
299 static int gigaset_write_room(struct cardstate *cs)
300 {
301 unsigned bytes;
302
303 bytes = cs->cmdbytes;
304 return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0;
305 }
306
307 /*
308 * tty_driver.chars_in_buffer interface routine
309 * return number of characters waiting to be sent
310 * parameter:
311 * controller state structure
312 * return value:
313 * number of characters
314 */
315 static int gigaset_chars_in_buffer(struct cardstate *cs)
316 {
317 return cs->cmdbytes;
318 }
319
320 /*
321 * implementation of ioctl(GIGASET_BRKCHARS)
322 * parameter:
323 * controller state structure
324 * return value:
325 * -EINVAL (unimplemented function)
326 */
327 static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
328 {
329 /* not implemented */
330 return -EINVAL;
331 }
332
333 /*
334 * Open B channel
335 * Called by "do_action" in ev-layer.c
336 */
337 static int gigaset_init_bchannel(struct bc_state *bcs)
338 {
339 /* nothing to do for M10x */
340 gigaset_bchannel_up(bcs);
341 return 0;
342 }
343
344 /*
345 * Close B channel
346 * Called by "do_action" in ev-layer.c
347 */
348 static int gigaset_close_bchannel(struct bc_state *bcs)
349 {
350 /* nothing to do for M10x */
351 gigaset_bchannel_down(bcs);
352 return 0;
353 }
354
355 /*
356 * Set up B channel structure
357 * This is called by "gigaset_initcs" in common.c
358 */
359 static int gigaset_initbcshw(struct bc_state *bcs)
360 {
361 /* unused */
362 bcs->hw.ser = NULL;
363 return 1;
364 }
365
366 /*
367 * Free B channel structure
368 * Called by "gigaset_freebcs" in common.c
369 */
370 static int gigaset_freebcshw(struct bc_state *bcs)
371 {
372 /* unused */
373 return 1;
374 }
375
376 /*
377 * Reinitialize B channel structure
378 * This is called by "bcs_reinit" in common.c
379 */
380 static void gigaset_reinitbcshw(struct bc_state *bcs)
381 {
382 /* nothing to do for M10x */
383 }
384
385 /*
386 * Free hardware specific device data
387 * This will be called by "gigaset_freecs" in common.c
388 */
389 static void gigaset_freecshw(struct cardstate *cs)
390 {
391 tasklet_kill(&cs->write_tasklet);
392 if (!cs->hw.ser)
393 return;
394 dev_set_drvdata(&cs->hw.ser->dev.dev, NULL);
395 platform_device_unregister(&cs->hw.ser->dev);
396 kfree(cs->hw.ser);
397 cs->hw.ser = NULL;
398 }
399
400 static void gigaset_device_release(struct device *dev)
401 {
402 struct platform_device *pdev = to_platform_device(dev);
403
404 /* adapted from platform_device_release() in drivers/base/platform.c */
405 kfree(dev->platform_data);
406 kfree(pdev->resource);
407 }
408
409 /*
410 * Set up hardware specific device data
411 * This is called by "gigaset_initcs" in common.c
412 */
413 static int gigaset_initcshw(struct cardstate *cs)
414 {
415 int rc;
416 struct ser_cardstate *scs;
417
418 scs = kzalloc(sizeof(struct ser_cardstate), GFP_KERNEL);
419 if (!scs) {
420 pr_err("out of memory\n");
421 return 0;
422 }
423 cs->hw.ser = scs;
424
425 cs->hw.ser->dev.name = GIGASET_MODULENAME;
426 cs->hw.ser->dev.id = cs->minor_index;
427 cs->hw.ser->dev.dev.release = gigaset_device_release;
428 rc = platform_device_register(&cs->hw.ser->dev);
429 if (rc != 0) {
430 pr_err("error %d registering platform device\n", rc);
431 kfree(cs->hw.ser);
432 cs->hw.ser = NULL;
433 return 0;
434 }
435 dev_set_drvdata(&cs->hw.ser->dev.dev, cs);
436
437 tasklet_init(&cs->write_tasklet,
438 gigaset_modem_fill, (unsigned long) cs);
439 return 1;
440 }
441
442 /*
443 * set modem control lines
444 * Parameters:
445 * card state structure
446 * modem control line state ([TIOCM_DTR]|[TIOCM_RTS])
447 * Called by "gigaset_start" and "gigaset_enterconfigmode" in common.c
448 * and by "if_lock" and "if_termios" in interface.c
449 */
450 static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
451 unsigned new_state)
452 {
453 struct tty_struct *tty = cs->hw.ser->tty;
454 unsigned int set, clear;
455
456 if (!tty || !tty->driver || !tty->ops->tiocmset)
457 return -EINVAL;
458 set = new_state & ~old_state;
459 clear = old_state & ~new_state;
460 if (!set && !clear)
461 return 0;
462 gig_dbg(DEBUG_IF, "tiocmset set %x clear %x", set, clear);
463 return tty->ops->tiocmset(tty, NULL, set, clear);
464 }
465
466 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
467 {
468 return -EINVAL;
469 }
470
471 static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
472 {
473 return -EINVAL;
474 }
475
476 static const struct gigaset_ops ops = {
477 gigaset_write_cmd,
478 gigaset_write_room,
479 gigaset_chars_in_buffer,
480 gigaset_brkchars,
481 gigaset_init_bchannel,
482 gigaset_close_bchannel,
483 gigaset_initbcshw,
484 gigaset_freebcshw,
485 gigaset_reinitbcshw,
486 gigaset_initcshw,
487 gigaset_freecshw,
488 gigaset_set_modem_ctrl,
489 gigaset_baud_rate,
490 gigaset_set_line_ctrl,
491 gigaset_m10x_send_skb, /* asyncdata.c */
492 gigaset_m10x_input, /* asyncdata.c */
493 };
494
495
496 /* Line Discipline Interface */
497 /* ========================= */
498
499 /* helper functions for cardstate refcounting */
500 static struct cardstate *cs_get(struct tty_struct *tty)
501 {
502 struct cardstate *cs = tty->disc_data;
503
504 if (!cs || !cs->hw.ser) {
505 gig_dbg(DEBUG_ANY, "%s: no cardstate", __func__);
506 return NULL;
507 }
508 atomic_inc(&cs->hw.ser->refcnt);
509 return cs;
510 }
511
512 static void cs_put(struct cardstate *cs)
513 {
514 if (atomic_dec_and_test(&cs->hw.ser->refcnt))
515 complete(&cs->hw.ser->dead_cmp);
516 }
517
518 /*
519 * Called by the tty driver when the line discipline is pushed onto the tty.
520 * Called in process context.
521 */
522 static int
523 gigaset_tty_open(struct tty_struct *tty)
524 {
525 struct cardstate *cs;
526
527 gig_dbg(DEBUG_INIT, "Starting HLL for Gigaset M101");
528
529 pr_info(DRIVER_DESC "\n");
530
531 if (!driver) {
532 pr_err("%s: no driver structure\n", __func__);
533 return -ENODEV;
534 }
535
536 /* allocate memory for our device state and intialize it */
537 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
538 if (!cs)
539 goto error;
540
541 cs->dev = &cs->hw.ser->dev.dev;
542 cs->hw.ser->tty = tty;
543 atomic_set(&cs->hw.ser->refcnt, 1);
544 init_completion(&cs->hw.ser->dead_cmp);
545
546 tty->disc_data = cs;
547
548 /* OK.. Initialization of the datastructures and the HW is done.. Now
549 * startup system and notify the LL that we are ready to run
550 */
551 if (startmode == SM_LOCKED)
552 cs->mstate = MS_LOCKED;
553 if (!gigaset_start(cs)) {
554 tasklet_kill(&cs->write_tasklet);
555 goto error;
556 }
557
558 gig_dbg(DEBUG_INIT, "Startup of HLL done");
559 return 0;
560
561 error:
562 gig_dbg(DEBUG_INIT, "Startup of HLL failed");
563 tty->disc_data = NULL;
564 gigaset_freecs(cs);
565 return -ENODEV;
566 }
567
568 /*
569 * Called by the tty driver when the line discipline is removed.
570 * Called from process context.
571 */
572 static void
573 gigaset_tty_close(struct tty_struct *tty)
574 {
575 struct cardstate *cs = tty->disc_data;
576
577 gig_dbg(DEBUG_INIT, "Stopping HLL for Gigaset M101");
578
579 if (!cs) {
580 gig_dbg(DEBUG_INIT, "%s: no cardstate", __func__);
581 return;
582 }
583
584 /* prevent other callers from entering ldisc methods */
585 tty->disc_data = NULL;
586
587 if (!cs->hw.ser)
588 pr_err("%s: no hw cardstate\n", __func__);
589 else {
590 /* wait for running methods to finish */
591 if (!atomic_dec_and_test(&cs->hw.ser->refcnt))
592 wait_for_completion(&cs->hw.ser->dead_cmp);
593 }
594
595 /* stop operations */
596 gigaset_stop(cs);
597 tasklet_kill(&cs->write_tasklet);
598 flush_send_queue(cs);
599 cs->dev = NULL;
600 gigaset_freecs(cs);
601
602 gig_dbg(DEBUG_INIT, "Shutdown of HLL done");
603 }
604
605 /*
606 * Called by the tty driver when the tty line is hung up.
607 * Wait for I/O to driver to complete and unregister ISDN device.
608 * This is already done by the close routine, so just call that.
609 * Called from process context.
610 */
611 static int gigaset_tty_hangup(struct tty_struct *tty)
612 {
613 gigaset_tty_close(tty);
614 return 0;
615 }
616
617 /*
618 * Read on the tty.
619 * Unused, received data goes only to the Gigaset driver.
620 */
621 static ssize_t
622 gigaset_tty_read(struct tty_struct *tty, struct file *file,
623 unsigned char __user *buf, size_t count)
624 {
625 return -EAGAIN;
626 }
627
628 /*
629 * Write on the tty.
630 * Unused, transmit data comes only from the Gigaset driver.
631 */
632 static ssize_t
633 gigaset_tty_write(struct tty_struct *tty, struct file *file,
634 const unsigned char *buf, size_t count)
635 {
636 return -EAGAIN;
637 }
638
639 /*
640 * Ioctl on the tty.
641 * Called in process context only.
642 * May be re-entered by multiple ioctl calling threads.
643 */
644 static int
645 gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
646 unsigned int cmd, unsigned long arg)
647 {
648 struct cardstate *cs = cs_get(tty);
649 int rc, val;
650 int __user *p = (int __user *)arg;
651
652 if (!cs)
653 return -ENXIO;
654
655 switch (cmd) {
656
657 case FIONREAD:
658 /* unused, always return zero */
659 val = 0;
660 rc = put_user(val, p);
661 break;
662
663 case TCFLSH:
664 /* flush our buffers and the serial port's buffer */
665 switch (arg) {
666 case TCIFLUSH:
667 /* no own input buffer to flush */
668 break;
669 case TCIOFLUSH:
670 case TCOFLUSH:
671 flush_send_queue(cs);
672 break;
673 }
674 /* Pass through */
675
676 default:
677 /* pass through to underlying serial device */
678 rc = n_tty_ioctl_helper(tty, file, cmd, arg);
679 break;
680 }
681 cs_put(cs);
682 return rc;
683 }
684
685 /*
686 * Called by the tty driver when a block of data has been received.
687 * Will not be re-entered while running but other ldisc functions
688 * may be called in parallel.
689 * Can be called from hard interrupt level as well as soft interrupt
690 * level or mainline.
691 * Parameters:
692 * tty tty structure
693 * buf buffer containing received characters
694 * cflags buffer containing error flags for received characters (ignored)
695 * count number of received characters
696 */
697 static void
698 gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
699 char *cflags, int count)
700 {
701 struct cardstate *cs = cs_get(tty);
702 unsigned tail, head, n;
703 struct inbuf_t *inbuf;
704
705 if (!cs)
706 return;
707 inbuf = cs->inbuf;
708 if (!inbuf) {
709 dev_err(cs->dev, "%s: no inbuf\n", __func__);
710 cs_put(cs);
711 return;
712 }
713
714 tail = inbuf->tail;
715 head = inbuf->head;
716 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
717 head, tail, count);
718
719 if (head <= tail) {
720 /* possible buffer wraparound */
721 n = min_t(unsigned, count, RBUFSIZE - tail);
722 memcpy(inbuf->data + tail, buf, n);
723 tail = (tail + n) % RBUFSIZE;
724 buf += n;
725 count -= n;
726 }
727
728 if (count > 0) {
729 /* tail < head and some data left */
730 n = head - tail - 1;
731 if (count > n) {
732 dev_err(cs->dev,
733 "inbuf overflow, discarding %d bytes\n",
734 count - n);
735 count = n;
736 }
737 memcpy(inbuf->data + tail, buf, count);
738 tail += count;
739 }
740
741 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
742 inbuf->tail = tail;
743
744 /* Everything was received .. Push data into handler */
745 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
746 gigaset_schedule_event(cs);
747 cs_put(cs);
748 }
749
750 /*
751 * Called by the tty driver when there's room for more data to send.
752 */
753 static void
754 gigaset_tty_wakeup(struct tty_struct *tty)
755 {
756 struct cardstate *cs = cs_get(tty);
757
758 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
759 if (!cs)
760 return;
761 tasklet_schedule(&cs->write_tasklet);
762 cs_put(cs);
763 }
764
765 static struct tty_ldisc_ops gigaset_ldisc = {
766 .owner = THIS_MODULE,
767 .magic = TTY_LDISC_MAGIC,
768 .name = "ser_gigaset",
769 .open = gigaset_tty_open,
770 .close = gigaset_tty_close,
771 .hangup = gigaset_tty_hangup,
772 .read = gigaset_tty_read,
773 .write = gigaset_tty_write,
774 .ioctl = gigaset_tty_ioctl,
775 .receive_buf = gigaset_tty_receive,
776 .write_wakeup = gigaset_tty_wakeup,
777 };
778
779
780 /* Initialization / Shutdown */
781 /* ========================= */
782
783 static int __init ser_gigaset_init(void)
784 {
785 int rc;
786
787 gig_dbg(DEBUG_INIT, "%s", __func__);
788 rc = platform_driver_register(&device_driver);
789 if (rc != 0) {
790 pr_err("error %d registering platform driver\n", rc);
791 return rc;
792 }
793
794 /* allocate memory for our driver state and intialize it */
795 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
796 GIGASET_MODULENAME, GIGASET_DEVNAME,
797 &ops, THIS_MODULE);
798 if (!driver)
799 goto error;
800
801 rc = tty_register_ldisc(N_GIGASET_M101, &gigaset_ldisc);
802 if (rc != 0) {
803 pr_err("error %d registering line discipline\n", rc);
804 goto error;
805 }
806
807 return 0;
808
809 error:
810 if (driver) {
811 gigaset_freedriver(driver);
812 driver = NULL;
813 }
814 platform_driver_unregister(&device_driver);
815 return rc;
816 }
817
818 static void __exit ser_gigaset_exit(void)
819 {
820 int rc;
821
822 gig_dbg(DEBUG_INIT, "%s", __func__);
823
824 if (driver) {
825 gigaset_freedriver(driver);
826 driver = NULL;
827 }
828
829 rc = tty_unregister_ldisc(N_GIGASET_M101);
830 if (rc != 0)
831 pr_err("error %d unregistering line discipline\n", rc);
832
833 platform_driver_unregister(&device_driver);
834 }
835
836 module_init(ser_gigaset_init);
837 module_exit(ser_gigaset_exit);