2 * Stuff used by all variants of the driver
4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>.
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
20 /* Version Information */
21 #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers"
22 #define DRIVER_DESC "Driver for Gigaset 307x"
24 #ifdef CONFIG_GIGASET_DEBUG
25 #define DRIVER_DESC_DEBUG " (debug build)"
27 #define DRIVER_DESC_DEBUG ""
30 /* Module parameters */
31 int gigaset_debuglevel
;
32 EXPORT_SYMBOL_GPL(gigaset_debuglevel
);
33 module_param_named(debug
, gigaset_debuglevel
, int, S_IRUGO
|S_IWUSR
);
34 MODULE_PARM_DESC(debug
, "debug level");
36 /* driver state flags */
37 #define VALID_MINOR 0x01
41 * gigaset_dbg_buffer() - dump data in ASCII and hex for debugging
42 * @level: debugging level.
43 * @msg: message prefix.
44 * @len: number of bytes to dump.
47 * If the current debugging level includes one of the bits set in @level,
48 * @len bytes starting at @buf are logged to dmesg at KERN_DEBUG prio,
49 * prefixed by the text @msg.
51 void gigaset_dbg_buffer(enum debuglevel level
, const unsigned char *msg
,
52 size_t len
, const unsigned char *buf
)
54 unsigned char outbuf
[80];
56 size_t space
= sizeof outbuf
- 1;
57 unsigned char *out
= outbuf
;
62 if (c
== '~' || c
== '^' || c
== '\\') {
73 if (c
< 0x20 || c
== 0x7f) {
85 gig_dbg(level
, "%s (%u bytes): %s", msg
, (unsigned) len
, outbuf
);
87 EXPORT_SYMBOL_GPL(gigaset_dbg_buffer
);
89 static int setflags(struct cardstate
*cs
, unsigned flags
, unsigned delay
)
93 r
= cs
->ops
->set_modem_ctrl(cs
, cs
->control_state
, flags
);
94 cs
->control_state
= flags
;
99 set_current_state(TASK_INTERRUPTIBLE
);
100 schedule_timeout(delay
* HZ
/ 1000);
106 int gigaset_enterconfigmode(struct cardstate
*cs
)
110 cs
->control_state
= TIOCM_RTS
;
112 r
= setflags(cs
, TIOCM_DTR
, 200);
115 r
= setflags(cs
, 0, 200);
118 for (i
= 0; i
< 5; ++i
) {
119 r
= setflags(cs
, TIOCM_RTS
, 100);
122 r
= setflags(cs
, 0, 100);
126 r
= setflags(cs
, TIOCM_RTS
|TIOCM_DTR
, 800);
133 dev_err(cs
->dev
, "error %d on setuartbits\n", -r
);
134 cs
->control_state
= TIOCM_RTS
|TIOCM_DTR
;
135 cs
->ops
->set_modem_ctrl(cs
, 0, TIOCM_RTS
|TIOCM_DTR
);
140 static int test_timeout(struct at_state_t
*at_state
)
142 if (!at_state
->timer_expires
)
145 if (--at_state
->timer_expires
) {
146 gig_dbg(DEBUG_MCMD
, "decreased timer of %p to %lu",
147 at_state
, at_state
->timer_expires
);
151 gigaset_add_event(at_state
->cs
, at_state
, EV_TIMEOUT
, NULL
,
152 at_state
->timer_index
, NULL
);
156 static void timer_tick(unsigned long data
)
158 struct cardstate
*cs
= (struct cardstate
*) data
;
161 struct at_state_t
*at_state
;
164 spin_lock_irqsave(&cs
->lock
, flags
);
166 for (channel
= 0; channel
< cs
->channels
; ++channel
)
167 if (test_timeout(&cs
->bcs
[channel
].at_state
))
170 if (test_timeout(&cs
->at_state
))
173 list_for_each_entry(at_state
, &cs
->temp_at_states
, list
)
174 if (test_timeout(at_state
))
178 mod_timer(&cs
->timer
, jiffies
+ msecs_to_jiffies(GIG_TICK
));
180 gig_dbg(DEBUG_EVENT
, "scheduling timeout");
181 tasklet_schedule(&cs
->event_tasklet
);
185 spin_unlock_irqrestore(&cs
->lock
, flags
);
188 int gigaset_get_channel(struct bc_state
*bcs
)
192 spin_lock_irqsave(&bcs
->cs
->lock
, flags
);
193 if (bcs
->use_count
|| !try_module_get(bcs
->cs
->driver
->owner
)) {
194 gig_dbg(DEBUG_CHANNEL
, "could not allocate channel %d",
196 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
201 gig_dbg(DEBUG_CHANNEL
, "allocated channel %d", bcs
->channel
);
202 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
206 struct bc_state
*gigaset_get_free_channel(struct cardstate
*cs
)
211 spin_lock_irqsave(&cs
->lock
, flags
);
212 if (!try_module_get(cs
->driver
->owner
)) {
213 gig_dbg(DEBUG_CHANNEL
,
214 "could not get module for allocating channel");
215 spin_unlock_irqrestore(&cs
->lock
, flags
);
218 for (i
= 0; i
< cs
->channels
; ++i
)
219 if (!cs
->bcs
[i
].use_count
) {
220 ++cs
->bcs
[i
].use_count
;
222 spin_unlock_irqrestore(&cs
->lock
, flags
);
223 gig_dbg(DEBUG_CHANNEL
, "allocated channel %d", i
);
226 module_put(cs
->driver
->owner
);
227 spin_unlock_irqrestore(&cs
->lock
, flags
);
228 gig_dbg(DEBUG_CHANNEL
, "no free channel");
232 void gigaset_free_channel(struct bc_state
*bcs
)
236 spin_lock_irqsave(&bcs
->cs
->lock
, flags
);
238 gig_dbg(DEBUG_CHANNEL
, "could not free channel %d",
240 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
245 module_put(bcs
->cs
->driver
->owner
);
246 gig_dbg(DEBUG_CHANNEL
, "freed channel %d", bcs
->channel
);
247 spin_unlock_irqrestore(&bcs
->cs
->lock
, flags
);
250 int gigaset_get_channels(struct cardstate
*cs
)
255 spin_lock_irqsave(&cs
->lock
, flags
);
256 for (i
= 0; i
< cs
->channels
; ++i
)
257 if (cs
->bcs
[i
].use_count
) {
258 spin_unlock_irqrestore(&cs
->lock
, flags
);
259 gig_dbg(DEBUG_CHANNEL
,
260 "could not allocate all channels");
263 for (i
= 0; i
< cs
->channels
; ++i
)
264 ++cs
->bcs
[i
].use_count
;
265 spin_unlock_irqrestore(&cs
->lock
, flags
);
267 gig_dbg(DEBUG_CHANNEL
, "allocated all channels");
272 void gigaset_free_channels(struct cardstate
*cs
)
277 gig_dbg(DEBUG_CHANNEL
, "unblocking all channels");
278 spin_lock_irqsave(&cs
->lock
, flags
);
279 for (i
= 0; i
< cs
->channels
; ++i
)
280 --cs
->bcs
[i
].use_count
;
281 spin_unlock_irqrestore(&cs
->lock
, flags
);
284 void gigaset_block_channels(struct cardstate
*cs
)
289 gig_dbg(DEBUG_CHANNEL
, "blocking all channels");
290 spin_lock_irqsave(&cs
->lock
, flags
);
291 for (i
= 0; i
< cs
->channels
; ++i
)
292 ++cs
->bcs
[i
].use_count
;
293 spin_unlock_irqrestore(&cs
->lock
, flags
);
296 static void clear_events(struct cardstate
*cs
)
302 spin_lock_irqsave(&cs
->ev_lock
, flags
);
307 while (tail
!= head
) {
308 ev
= cs
->events
+ head
;
310 head
= (head
+ 1) % MAX_EVENTS
;
315 spin_unlock_irqrestore(&cs
->ev_lock
, flags
);
319 * gigaset_add_event() - add event to device event queue
320 * @cs: device descriptor structure.
321 * @at_state: connection state structure.
323 * @ptr: pointer parameter for event.
324 * @parameter: integer parameter for event.
325 * @arg: pointer parameter for event.
327 * Allocate an event queue entry from the device's event queue, and set it up
328 * with the parameters given.
330 * Return value: added event
332 struct event_t
*gigaset_add_event(struct cardstate
*cs
,
333 struct at_state_t
*at_state
, int type
,
334 void *ptr
, int parameter
, void *arg
)
338 struct event_t
*event
= NULL
;
340 gig_dbg(DEBUG_EVENT
, "queueing event %d", type
);
342 spin_lock_irqsave(&cs
->ev_lock
, flags
);
345 next
= (tail
+ 1) % MAX_EVENTS
;
346 if (unlikely(next
== cs
->ev_head
))
347 dev_err(cs
->dev
, "event queue full\n");
349 event
= cs
->events
+ tail
;
351 event
->at_state
= at_state
;
355 event
->parameter
= parameter
;
359 spin_unlock_irqrestore(&cs
->ev_lock
, flags
);
363 EXPORT_SYMBOL_GPL(gigaset_add_event
);
365 static void free_strings(struct at_state_t
*at_state
)
369 for (i
= 0; i
< STR_NUM
; ++i
) {
370 kfree(at_state
->str_var
[i
]);
371 at_state
->str_var
[i
] = NULL
;
375 static void clear_at_state(struct at_state_t
*at_state
)
377 free_strings(at_state
);
380 static void dealloc_at_states(struct cardstate
*cs
)
382 struct at_state_t
*cur
, *next
;
384 list_for_each_entry_safe(cur
, next
, &cs
->temp_at_states
, list
) {
385 list_del(&cur
->list
);
391 static void gigaset_freebcs(struct bc_state
*bcs
)
395 gig_dbg(DEBUG_INIT
, "freeing bcs[%d]->hw", bcs
->channel
);
396 if (!bcs
->cs
->ops
->freebcshw(bcs
))
397 gig_dbg(DEBUG_INIT
, "failed");
399 gig_dbg(DEBUG_INIT
, "clearing bcs[%d]->at_state", bcs
->channel
);
400 clear_at_state(&bcs
->at_state
);
401 gig_dbg(DEBUG_INIT
, "freeing bcs[%d]->skb", bcs
->channel
);
402 dev_kfree_skb(bcs
->rx_skb
);
405 for (i
= 0; i
< AT_NUM
; ++i
) {
406 kfree(bcs
->commands
[i
]);
407 bcs
->commands
[i
] = NULL
;
411 static struct cardstate
*alloc_cs(struct gigaset_driver
*drv
)
415 struct cardstate
*cs
;
416 struct cardstate
*ret
= NULL
;
418 spin_lock_irqsave(&drv
->lock
, flags
);
421 for (i
= 0; i
< drv
->minors
; ++i
) {
423 if (!(cs
->flags
& VALID_MINOR
)) {
424 cs
->flags
= VALID_MINOR
;
430 spin_unlock_irqrestore(&drv
->lock
, flags
);
434 static void free_cs(struct cardstate
*cs
)
439 static void make_valid(struct cardstate
*cs
, unsigned mask
)
442 struct gigaset_driver
*drv
= cs
->driver
;
443 spin_lock_irqsave(&drv
->lock
, flags
);
445 spin_unlock_irqrestore(&drv
->lock
, flags
);
448 static void make_invalid(struct cardstate
*cs
, unsigned mask
)
451 struct gigaset_driver
*drv
= cs
->driver
;
452 spin_lock_irqsave(&drv
->lock
, flags
);
454 spin_unlock_irqrestore(&drv
->lock
, flags
);
458 * gigaset_freecs() - free all associated ressources of a device
459 * @cs: device descriptor structure.
461 * Stops all tasklets and timers, unregisters the device from all
462 * subsystems it was registered to, deallocates the device structure
463 * @cs and all structures referenced from it.
464 * Operations on the device should be stopped before calling this.
466 void gigaset_freecs(struct cardstate
*cs
)
474 mutex_lock(&cs
->mutex
);
481 spin_lock_irqsave(&cs
->lock
, flags
);
483 spin_unlock_irqrestore(&cs
->lock
, flags
); /* event handler and timer are
484 not rescheduled below */
486 tasklet_kill(&cs
->event_tasklet
);
487 del_timer_sync(&cs
->timer
);
489 switch (cs
->cs_init
) {
491 /* clear B channel structures */
492 for (i
= 0; i
< cs
->channels
; ++i
) {
493 gig_dbg(DEBUG_INIT
, "clearing bcs[%d]", i
);
494 gigaset_freebcs(cs
->bcs
+ i
);
497 /* clear device sysfs */
498 gigaset_free_dev_sysfs(cs
);
502 gig_dbg(DEBUG_INIT
, "clearing hw");
503 cs
->ops
->freecshw(cs
);
506 case 2: /* error in initcshw */
507 /* Deregister from LL */
508 make_invalid(cs
, VALID_ID
);
509 gigaset_isdn_unregdev(cs
);
512 case 1: /* error when registering to LL */
513 gig_dbg(DEBUG_INIT
, "clearing at_state");
514 clear_at_state(&cs
->at_state
);
515 dealloc_at_states(cs
);
518 case 0: /* error in basic setup */
520 gig_dbg(DEBUG_INIT
, "freeing inbuf");
523 f_bcs
: gig_dbg(DEBUG_INIT
, "freeing bcs[]");
525 f_cs
: gig_dbg(DEBUG_INIT
, "freeing cs");
526 mutex_unlock(&cs
->mutex
);
529 EXPORT_SYMBOL_GPL(gigaset_freecs
);
531 void gigaset_at_init(struct at_state_t
*at_state
, struct bc_state
*bcs
,
532 struct cardstate
*cs
, int cid
)
536 INIT_LIST_HEAD(&at_state
->list
);
537 at_state
->waiting
= 0;
538 at_state
->getstring
= 0;
539 at_state
->pending_commands
= 0;
540 at_state
->timer_expires
= 0;
541 at_state
->timer_active
= 0;
542 at_state
->timer_index
= 0;
543 at_state
->seq_index
= 0;
544 at_state
->ConState
= 0;
545 for (i
= 0; i
< STR_NUM
; ++i
)
546 at_state
->str_var
[i
] = NULL
;
547 at_state
->int_var
[VAR_ZDLE
] = 0;
548 at_state
->int_var
[VAR_ZCTP
] = -1;
549 at_state
->int_var
[VAR_ZSAU
] = ZSAU_NULL
;
554 at_state
->replystruct
= cs
->tabnocid
;
556 at_state
->replystruct
= cs
->tabcid
;
560 static void gigaset_inbuf_init(struct inbuf_t
*inbuf
, struct cardstate
*cs
)
561 /* inbuf->read must be allocated before! */
566 inbuf
->inputstate
= INS_command
;
570 * gigaset_fill_inbuf() - append received data to input buffer
571 * @inbuf: buffer structure.
572 * @src: received data.
573 * @numbytes: number of bytes received.
575 int gigaset_fill_inbuf(struct inbuf_t
*inbuf
, const unsigned char *src
,
578 unsigned n
, head
, tail
, bytesleft
;
580 gig_dbg(DEBUG_INTR
, "received %u bytes", numbytes
);
585 bytesleft
= numbytes
;
588 gig_dbg(DEBUG_INTR
, "buffer state: %u -> %u", head
, tail
);
594 n
= (RBUFSIZE
-1) - tail
;
598 dev_err(inbuf
->cs
->dev
,
599 "buffer overflow (%u bytes lost)\n",
605 memcpy(inbuf
->data
+ tail
, src
, n
);
607 tail
= (tail
+ n
) % RBUFSIZE
;
610 gig_dbg(DEBUG_INTR
, "setting tail to %u", tail
);
612 return numbytes
!= bytesleft
;
614 EXPORT_SYMBOL_GPL(gigaset_fill_inbuf
);
616 /* Initialize the b-channel structure */
617 static struct bc_state
*gigaset_initbcs(struct bc_state
*bcs
,
618 struct cardstate
*cs
, int channel
)
624 skb_queue_head_init(&bcs
->squeue
);
630 gig_dbg(DEBUG_INIT
, "setting up bcs[%d]->at_state", channel
);
631 gigaset_at_init(&bcs
->at_state
, bcs
, cs
, -1);
633 #ifdef CONFIG_GIGASET_DEBUG
639 bcs
->rx_fcs
= PPP_INITFCS
;
641 bcs
->channel
= channel
;
647 bcs
->ignore
= cs
->ignoreframes
;
649 for (i
= 0; i
< AT_NUM
; ++i
)
650 bcs
->commands
[i
] = NULL
;
652 spin_lock_init(&bcs
->aplock
);
654 bcs
->apconnstate
= 0;
656 gig_dbg(DEBUG_INIT
, " setting up bcs[%d]->hw", channel
);
657 if (cs
->ops
->initbcshw(bcs
))
660 gig_dbg(DEBUG_INIT
, " failed");
665 * gigaset_initcs() - initialize device structure
666 * @drv: hardware driver the device belongs to
667 * @channels: number of B channels supported by device
668 * @onechannel: !=0 if B channel data and AT commands share one
669 * communication channel (M10x),
670 * ==0 if B channels have separate communication channels (base)
671 * @ignoreframes: number of frames to ignore after setting up B channel
672 * @cidmode: !=0: start in CallID mode
673 * @modulename: name of driver module for LL registration
675 * Allocate and initialize cardstate structure for Gigaset driver
676 * Calls hardware dependent gigaset_initcshw() function
677 * Calls B channel initialization function gigaset_initbcs() for each B channel
680 * pointer to cardstate structure
682 struct cardstate
*gigaset_initcs(struct gigaset_driver
*drv
, int channels
,
683 int onechannel
, int ignoreframes
,
684 int cidmode
, const char *modulename
)
686 struct cardstate
*cs
;
690 gig_dbg(DEBUG_INIT
, "allocating cs");
693 pr_err("maximum number of devices exceeded\n");
697 gig_dbg(DEBUG_INIT
, "allocating bcs[0..%d]", channels
- 1);
698 cs
->bcs
= kmalloc(channels
* sizeof(struct bc_state
), GFP_KERNEL
);
700 pr_err("out of memory\n");
703 gig_dbg(DEBUG_INIT
, "allocating inbuf");
704 cs
->inbuf
= kmalloc(sizeof(struct inbuf_t
), GFP_KERNEL
);
706 pr_err("out of memory\n");
711 cs
->channels
= channels
;
712 cs
->onechannel
= onechannel
;
713 cs
->ignoreframes
= ignoreframes
;
714 INIT_LIST_HEAD(&cs
->temp_at_states
);
716 init_timer(&cs
->timer
); /* clear next & prev */
717 spin_lock_init(&cs
->ev_lock
);
721 tasklet_init(&cs
->event_tasklet
, gigaset_handle_event
,
723 cs
->commands_pending
= 0;
730 cs
->cidmode
= cidmode
!= 0;
731 cs
->tabnocid
= gigaset_tab_nocid
;
732 cs
->tabcid
= gigaset_tab_cid
;
734 init_waitqueue_head(&cs
->waitqueue
);
737 cs
->mode
= M_UNKNOWN
;
738 cs
->mstate
= MS_UNINITIALIZED
;
742 gig_dbg(DEBUG_INIT
, "setting up at_state");
743 spin_lock_init(&cs
->lock
);
744 gigaset_at_init(&cs
->at_state
, NULL
, cs
, 0);
748 gig_dbg(DEBUG_INIT
, "setting up inbuf");
749 gigaset_inbuf_init(cs
->inbuf
, cs
);
754 gig_dbg(DEBUG_INIT
, "setting up cmdbuf");
755 cs
->cmdbuf
= cs
->lastcmdbuf
= NULL
;
756 spin_lock_init(&cs
->cmdlock
);
760 gig_dbg(DEBUG_INIT
, "setting up iif");
761 if (!gigaset_isdn_regdev(cs
, modulename
)) {
762 pr_err("error registering ISDN device\n");
766 make_valid(cs
, VALID_ID
);
768 gig_dbg(DEBUG_INIT
, "setting up hw");
769 if (!cs
->ops
->initcshw(cs
))
774 /* set up character device */
777 /* set up device sysfs */
778 gigaset_init_dev_sysfs(cs
);
780 /* set up channel data structures */
781 for (i
= 0; i
< channels
; ++i
) {
782 gig_dbg(DEBUG_INIT
, "setting up bcs[%d]", i
);
783 if (!gigaset_initbcs(cs
->bcs
+ i
, cs
, i
)) {
784 pr_err("could not allocate channel %d data\n", i
);
789 spin_lock_irqsave(&cs
->lock
, flags
);
791 spin_unlock_irqrestore(&cs
->lock
, flags
);
792 setup_timer(&cs
->timer
, timer_tick
, (unsigned long) cs
);
793 cs
->timer
.expires
= jiffies
+ msecs_to_jiffies(GIG_TICK
);
794 add_timer(&cs
->timer
);
796 gig_dbg(DEBUG_INIT
, "cs initialized");
800 gig_dbg(DEBUG_INIT
, "failed");
804 EXPORT_SYMBOL_GPL(gigaset_initcs
);
806 /* ReInitialize the b-channel structure on hangup */
807 void gigaset_bcs_reinit(struct bc_state
*bcs
)
810 struct cardstate
*cs
= bcs
->cs
;
813 while ((skb
= skb_dequeue(&bcs
->squeue
)) != NULL
)
816 spin_lock_irqsave(&cs
->lock
, flags
);
817 clear_at_state(&bcs
->at_state
);
818 bcs
->at_state
.ConState
= 0;
819 bcs
->at_state
.timer_active
= 0;
820 bcs
->at_state
.timer_expires
= 0;
821 bcs
->at_state
.cid
= -1; /* No CID defined */
822 spin_unlock_irqrestore(&cs
->lock
, flags
);
826 #ifdef CONFIG_GIGASET_DEBUG
830 bcs
->rx_fcs
= PPP_INITFCS
;
833 bcs
->ignore
= cs
->ignoreframes
;
834 dev_kfree_skb(bcs
->rx_skb
);
837 cs
->ops
->reinitbcshw(bcs
);
840 static void cleanup_cs(struct cardstate
*cs
)
842 struct cmdbuf_t
*cb
, *tcb
;
846 spin_lock_irqsave(&cs
->lock
, flags
);
848 cs
->mode
= M_UNKNOWN
;
849 cs
->mstate
= MS_UNINITIALIZED
;
851 clear_at_state(&cs
->at_state
);
852 dealloc_at_states(cs
);
853 free_strings(&cs
->at_state
);
854 gigaset_at_init(&cs
->at_state
, NULL
, cs
, 0);
856 cs
->inbuf
->inputstate
= INS_command
;
866 cs
->cmdbuf
= cs
->lastcmdbuf
= NULL
;
872 cs
->commands_pending
= 0;
875 spin_unlock_irqrestore(&cs
->lock
, flags
);
877 for (i
= 0; i
< cs
->channels
; ++i
) {
878 gigaset_freebcs(cs
->bcs
+ i
);
879 if (!gigaset_initbcs(cs
->bcs
+ i
, cs
, i
))
880 pr_err("could not allocate channel %d data\n", i
);
884 cs
->cmd_result
= -ENODEV
;
886 wake_up_interruptible(&cs
->waitqueue
);
892 * gigaset_start() - start device operations
893 * @cs: device descriptor structure.
895 * Prepares the device for use by setting up communication parameters,
896 * scheduling an EV_START event to initiate device initialization, and
897 * waiting for completion of the initialization.
900 * 1 - success, 0 - error
902 int gigaset_start(struct cardstate
*cs
)
906 if (mutex_lock_interruptible(&cs
->mutex
))
909 spin_lock_irqsave(&cs
->lock
, flags
);
911 spin_unlock_irqrestore(&cs
->lock
, flags
);
913 if (cs
->mstate
!= MS_LOCKED
) {
914 cs
->ops
->set_modem_ctrl(cs
, 0, TIOCM_DTR
|TIOCM_RTS
);
915 cs
->ops
->baud_rate(cs
, B115200
);
916 cs
->ops
->set_line_ctrl(cs
, CS8
);
917 cs
->control_state
= TIOCM_DTR
|TIOCM_RTS
;
922 if (!gigaset_add_event(cs
, &cs
->at_state
, EV_START
, NULL
, 0, NULL
)) {
926 gigaset_schedule_event(cs
);
928 wait_event(cs
->waitqueue
, !cs
->waiting
);
930 mutex_unlock(&cs
->mutex
);
934 mutex_unlock(&cs
->mutex
);
937 EXPORT_SYMBOL_GPL(gigaset_start
);
940 * gigaset_shutdown() - shut down device operations
941 * @cs: device descriptor structure.
943 * Deactivates the device by scheduling an EV_SHUTDOWN event and
944 * waiting for completion of the shutdown.
947 * 0 - success, -1 - error (no device associated)
949 int gigaset_shutdown(struct cardstate
*cs
)
951 mutex_lock(&cs
->mutex
);
953 if (!(cs
->flags
& VALID_MINOR
)) {
954 mutex_unlock(&cs
->mutex
);
960 if (!gigaset_add_event(cs
, &cs
->at_state
, EV_SHUTDOWN
, NULL
, 0, NULL
))
962 gigaset_schedule_event(cs
);
964 wait_event(cs
->waitqueue
, !cs
->waiting
);
969 mutex_unlock(&cs
->mutex
);
972 EXPORT_SYMBOL_GPL(gigaset_shutdown
);
975 * gigaset_stop() - stop device operations
976 * @cs: device descriptor structure.
978 * Stops operations on the device by scheduling an EV_STOP event and
979 * waiting for completion of the shutdown.
981 void gigaset_stop(struct cardstate
*cs
)
983 mutex_lock(&cs
->mutex
);
987 if (!gigaset_add_event(cs
, &cs
->at_state
, EV_STOP
, NULL
, 0, NULL
))
989 gigaset_schedule_event(cs
);
991 wait_event(cs
->waitqueue
, !cs
->waiting
);
996 mutex_unlock(&cs
->mutex
);
998 EXPORT_SYMBOL_GPL(gigaset_stop
);
1000 static LIST_HEAD(drivers
);
1001 static DEFINE_SPINLOCK(driver_lock
);
1003 struct cardstate
*gigaset_get_cs_by_id(int id
)
1005 unsigned long flags
;
1006 struct cardstate
*ret
= NULL
;
1007 struct cardstate
*cs
;
1008 struct gigaset_driver
*drv
;
1011 spin_lock_irqsave(&driver_lock
, flags
);
1012 list_for_each_entry(drv
, &drivers
, list
) {
1013 spin_lock(&drv
->lock
);
1014 for (i
= 0; i
< drv
->minors
; ++i
) {
1016 if ((cs
->flags
& VALID_ID
) && cs
->myid
== id
) {
1021 spin_unlock(&drv
->lock
);
1025 spin_unlock_irqrestore(&driver_lock
, flags
);
1029 void gigaset_debugdrivers(void)
1031 unsigned long flags
;
1032 static struct cardstate
*cs
;
1033 struct gigaset_driver
*drv
;
1036 spin_lock_irqsave(&driver_lock
, flags
);
1037 list_for_each_entry(drv
, &drivers
, list
) {
1038 gig_dbg(DEBUG_DRIVER
, "driver %p", drv
);
1039 spin_lock(&drv
->lock
);
1040 for (i
= 0; i
< drv
->minors
; ++i
) {
1041 gig_dbg(DEBUG_DRIVER
, " index %u", i
);
1043 gig_dbg(DEBUG_DRIVER
, " cardstate %p", cs
);
1044 gig_dbg(DEBUG_DRIVER
, " flags 0x%02x", cs
->flags
);
1045 gig_dbg(DEBUG_DRIVER
, " minor_index %u",
1047 gig_dbg(DEBUG_DRIVER
, " driver %p", cs
->driver
);
1048 gig_dbg(DEBUG_DRIVER
, " i4l id %d", cs
->myid
);
1050 spin_unlock(&drv
->lock
);
1052 spin_unlock_irqrestore(&driver_lock
, flags
);
1055 static struct cardstate
*gigaset_get_cs_by_minor(unsigned minor
)
1057 unsigned long flags
;
1058 struct cardstate
*ret
= NULL
;
1059 struct gigaset_driver
*drv
;
1062 spin_lock_irqsave(&driver_lock
, flags
);
1063 list_for_each_entry(drv
, &drivers
, list
) {
1064 if (minor
< drv
->minor
|| minor
>= drv
->minor
+ drv
->minors
)
1066 index
= minor
- drv
->minor
;
1067 spin_lock(&drv
->lock
);
1068 if (drv
->cs
[index
].flags
& VALID_MINOR
)
1069 ret
= drv
->cs
+ index
;
1070 spin_unlock(&drv
->lock
);
1074 spin_unlock_irqrestore(&driver_lock
, flags
);
1078 struct cardstate
*gigaset_get_cs_by_tty(struct tty_struct
*tty
)
1080 if (tty
->index
< 0 || tty
->index
>= tty
->driver
->num
)
1082 return gigaset_get_cs_by_minor(tty
->index
+ tty
->driver
->minor_start
);
1086 * gigaset_freedriver() - free all associated ressources of a driver
1087 * @drv: driver descriptor structure.
1089 * Unregisters the driver from the system and deallocates the driver
1090 * structure @drv and all structures referenced from it.
1091 * All devices should be shut down before calling this.
1093 void gigaset_freedriver(struct gigaset_driver
*drv
)
1095 unsigned long flags
;
1097 spin_lock_irqsave(&driver_lock
, flags
);
1098 list_del(&drv
->list
);
1099 spin_unlock_irqrestore(&driver_lock
, flags
);
1101 gigaset_if_freedriver(drv
);
1106 EXPORT_SYMBOL_GPL(gigaset_freedriver
);
1109 * gigaset_initdriver() - initialize driver structure
1110 * @minor: First minor number
1111 * @minors: Number of minors this driver can handle
1112 * @procname: Name of the driver
1113 * @devname: Name of the device files (prefix without minor number)
1115 * Allocate and initialize gigaset_driver structure. Initialize interface.
1118 * Pointer to the gigaset_driver structure on success, NULL on failure.
1120 struct gigaset_driver
*gigaset_initdriver(unsigned minor
, unsigned minors
,
1121 const char *procname
,
1122 const char *devname
,
1123 const struct gigaset_ops
*ops
,
1124 struct module
*owner
)
1126 struct gigaset_driver
*drv
;
1127 unsigned long flags
;
1130 drv
= kmalloc(sizeof *drv
, GFP_KERNEL
);
1136 drv
->minors
= minors
;
1137 spin_lock_init(&drv
->lock
);
1141 INIT_LIST_HEAD(&drv
->list
);
1143 drv
->cs
= kmalloc(minors
* sizeof *drv
->cs
, GFP_KERNEL
);
1147 for (i
= 0; i
< minors
; ++i
) {
1148 drv
->cs
[i
].flags
= 0;
1149 drv
->cs
[i
].driver
= drv
;
1150 drv
->cs
[i
].ops
= drv
->ops
;
1151 drv
->cs
[i
].minor_index
= i
;
1152 mutex_init(&drv
->cs
[i
].mutex
);
1155 gigaset_if_initdriver(drv
, procname
, devname
);
1157 spin_lock_irqsave(&driver_lock
, flags
);
1158 list_add(&drv
->list
, &drivers
);
1159 spin_unlock_irqrestore(&driver_lock
, flags
);
1168 EXPORT_SYMBOL_GPL(gigaset_initdriver
);
1171 * gigaset_blockdriver() - block driver
1172 * @drv: driver descriptor structure.
1174 * Prevents the driver from attaching new devices, in preparation for
1177 void gigaset_blockdriver(struct gigaset_driver
*drv
)
1181 EXPORT_SYMBOL_GPL(gigaset_blockdriver
);
1183 static int __init
gigaset_init_module(void)
1185 /* in accordance with the principle of least astonishment,
1186 * setting the 'debug' parameter to 1 activates a sensible
1187 * set of default debug levels
1189 if (gigaset_debuglevel
== 1)
1190 gigaset_debuglevel
= DEBUG_DEFAULT
;
1192 pr_info(DRIVER_DESC DRIVER_DESC_DEBUG
"\n");
1193 gigaset_isdn_regdrv();
1197 static void __exit
gigaset_exit_module(void)
1199 gigaset_isdn_unregdrv();
1202 module_init(gigaset_init_module
);
1203 module_exit(gigaset_exit_module
);
1205 MODULE_AUTHOR(DRIVER_AUTHOR
);
1206 MODULE_DESCRIPTION(DRIVER_DESC
);
1208 MODULE_LICENSE("GPL");