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/ctype.h>
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
21 /* Version Information */
22 #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers"
23 #define DRIVER_DESC "Driver for Gigaset 307x"
25 #ifdef CONFIG_GIGASET_DEBUG
26 #define DRIVER_DESC_DEBUG " (debug build)"
28 #define DRIVER_DESC_DEBUG ""
31 /* Module parameters */
32 int gigaset_debuglevel = DEBUG_DEFAULT;
33 EXPORT_SYMBOL_GPL(gigaset_debuglevel);
34 module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR);
35 MODULE_PARM_DESC(debug, "debug level");
37 /* driver state flags */
38 #define VALID_MINOR 0x01
41 void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
42 size_t len, const unsigned char *buf)
44 unsigned char outbuf[80];
46 size_t space = sizeof outbuf - 1;
47 unsigned char *out = outbuf;
52 if (c == '~' || c == '^' || c == '\\') {
63 if (c < 0x20 || c == 0x7f) {
75 gig_dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf);
77 EXPORT_SYMBOL_GPL(gigaset_dbg_buffer);
79 static int setflags(struct cardstate *cs, unsigned flags, unsigned delay)
83 r = cs->ops->set_modem_ctrl(cs, cs->control_state, flags);
84 cs->control_state = flags;
89 set_current_state(TASK_INTERRUPTIBLE);
90 schedule_timeout(delay * HZ / 1000);
96 int gigaset_enterconfigmode(struct cardstate *cs)
100 cs->control_state = TIOCM_RTS; //FIXME
102 r = setflags(cs, TIOCM_DTR, 200);
105 r = setflags(cs, 0, 200);
108 for (i = 0; i < 5; ++i) {
109 r = setflags(cs, TIOCM_RTS, 100);
112 r = setflags(cs, 0, 100);
116 r = setflags(cs, TIOCM_RTS|TIOCM_DTR, 800);
123 dev_err(cs->dev, "error %d on setuartbits\n", -r);
124 cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value?
125 cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR);
130 static int test_timeout(struct at_state_t *at_state)
132 if (!at_state->timer_expires)
135 if (--at_state->timer_expires) {
136 gig_dbg(DEBUG_MCMD, "decreased timer of %p to %lu",
137 at_state, at_state->timer_expires);
141 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL,
142 at_state->timer_index, NULL)) {
143 //FIXME what should we do?
149 static void timer_tick(unsigned long data)
151 struct cardstate *cs = (struct cardstate *) data;
154 struct at_state_t *at_state;
157 spin_lock_irqsave(&cs->lock, flags);
159 for (channel = 0; channel < cs->channels; ++channel)
160 if (test_timeout(&cs->bcs[channel].at_state))
163 if (test_timeout(&cs->at_state))
166 list_for_each_entry(at_state, &cs->temp_at_states, list)
167 if (test_timeout(at_state))
171 mod_timer(&cs->timer, jiffies + msecs_to_jiffies(GIG_TICK));
173 gig_dbg(DEBUG_CMD, "scheduling timeout");
174 tasklet_schedule(&cs->event_tasklet);
178 spin_unlock_irqrestore(&cs->lock, flags);
181 int gigaset_get_channel(struct bc_state *bcs)
185 spin_lock_irqsave(&bcs->cs->lock, flags);
186 if (bcs->use_count || !try_module_get(bcs->cs->driver->owner)) {
187 gig_dbg(DEBUG_ANY, "could not allocate channel %d",
189 spin_unlock_irqrestore(&bcs->cs->lock, flags);
194 gig_dbg(DEBUG_ANY, "allocated channel %d", bcs->channel);
195 spin_unlock_irqrestore(&bcs->cs->lock, flags);
199 void gigaset_free_channel(struct bc_state *bcs)
203 spin_lock_irqsave(&bcs->cs->lock, flags);
205 gig_dbg(DEBUG_ANY, "could not free channel %d", bcs->channel);
206 spin_unlock_irqrestore(&bcs->cs->lock, flags);
211 module_put(bcs->cs->driver->owner);
212 gig_dbg(DEBUG_ANY, "freed channel %d", bcs->channel);
213 spin_unlock_irqrestore(&bcs->cs->lock, flags);
216 int gigaset_get_channels(struct cardstate *cs)
221 spin_lock_irqsave(&cs->lock, flags);
222 for (i = 0; i < cs->channels; ++i)
223 if (cs->bcs[i].use_count) {
224 spin_unlock_irqrestore(&cs->lock, flags);
225 gig_dbg(DEBUG_ANY, "could not allocate all channels");
228 for (i = 0; i < cs->channels; ++i)
229 ++cs->bcs[i].use_count;
230 spin_unlock_irqrestore(&cs->lock, flags);
232 gig_dbg(DEBUG_ANY, "allocated all channels");
237 void gigaset_free_channels(struct cardstate *cs)
242 gig_dbg(DEBUG_ANY, "unblocking all channels");
243 spin_lock_irqsave(&cs->lock, flags);
244 for (i = 0; i < cs->channels; ++i)
245 --cs->bcs[i].use_count;
246 spin_unlock_irqrestore(&cs->lock, flags);
249 void gigaset_block_channels(struct cardstate *cs)
254 gig_dbg(DEBUG_ANY, "blocking all channels");
255 spin_lock_irqsave(&cs->lock, flags);
256 for (i = 0; i < cs->channels; ++i)
257 ++cs->bcs[i].use_count;
258 spin_unlock_irqrestore(&cs->lock, flags);
261 static void clear_events(struct cardstate *cs)
267 spin_lock_irqsave(&cs->ev_lock, flags);
272 while (tail != head) {
273 ev = cs->events + head;
275 head = (head + 1) % MAX_EVENTS;
280 spin_unlock_irqrestore(&cs->ev_lock, flags);
283 struct event_t *gigaset_add_event(struct cardstate *cs,
284 struct at_state_t *at_state, int type,
285 void *ptr, int parameter, void *arg)
289 struct event_t *event = NULL;
291 spin_lock_irqsave(&cs->ev_lock, flags);
294 next = (tail + 1) % MAX_EVENTS;
295 if (unlikely(next == cs->ev_head))
296 dev_err(cs->dev, "event queue full\n");
298 event = cs->events + tail;
300 event->at_state = at_state;
304 event->parameter = parameter;
308 spin_unlock_irqrestore(&cs->ev_lock, flags);
312 EXPORT_SYMBOL_GPL(gigaset_add_event);
314 static void free_strings(struct at_state_t *at_state)
318 for (i = 0; i < STR_NUM; ++i) {
319 kfree(at_state->str_var[i]);
320 at_state->str_var[i] = NULL;
324 static void clear_at_state(struct at_state_t *at_state)
326 free_strings(at_state);
329 static void dealloc_at_states(struct cardstate *cs)
331 struct at_state_t *cur, *next;
333 list_for_each_entry_safe(cur, next, &cs->temp_at_states, list) {
334 list_del(&cur->list);
340 static void gigaset_freebcs(struct bc_state *bcs)
344 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel);
345 if (!bcs->cs->ops->freebcshw(bcs)) {
346 gig_dbg(DEBUG_INIT, "failed");
349 gig_dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel);
350 clear_at_state(&bcs->at_state);
351 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel);
354 dev_kfree_skb(bcs->skb);
355 for (i = 0; i < AT_NUM; ++i) {
356 kfree(bcs->commands[i]);
357 bcs->commands[i] = NULL;
361 static struct cardstate *alloc_cs(struct gigaset_driver *drv)
365 struct cardstate *cs;
366 struct cardstate *ret = NULL;
368 spin_lock_irqsave(&drv->lock, flags);
371 for (i = 0; i < drv->minors; ++i) {
373 if (!(cs->flags & VALID_MINOR)) {
374 cs->flags = VALID_MINOR;
380 spin_unlock_irqrestore(&drv->lock, flags);
384 static void free_cs(struct cardstate *cs)
389 static void make_valid(struct cardstate *cs, unsigned mask)
392 struct gigaset_driver *drv = cs->driver;
393 spin_lock_irqsave(&drv->lock, flags);
395 spin_unlock_irqrestore(&drv->lock, flags);
398 static void make_invalid(struct cardstate *cs, unsigned mask)
401 struct gigaset_driver *drv = cs->driver;
402 spin_lock_irqsave(&drv->lock, flags);
404 spin_unlock_irqrestore(&drv->lock, flags);
407 void gigaset_freecs(struct cardstate *cs)
415 mutex_lock(&cs->mutex);
422 spin_lock_irqsave(&cs->lock, flags);
424 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are
425 not rescheduled below */
427 tasklet_kill(&cs->event_tasklet);
428 del_timer_sync(&cs->timer);
430 switch (cs->cs_init) {
432 /* clear device sysfs */
433 gigaset_free_dev_sysfs(cs);
437 gig_dbg(DEBUG_INIT, "clearing hw");
438 cs->ops->freecshw(cs);
443 case 2: /* error in initcshw */
444 /* Deregister from LL */
445 make_invalid(cs, VALID_ID);
446 gig_dbg(DEBUG_INIT, "clearing iif");
447 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
450 case 1: /* error when regestering to LL */
451 gig_dbg(DEBUG_INIT, "clearing at_state");
452 clear_at_state(&cs->at_state);
453 dealloc_at_states(cs);
456 case 0: /* error in one call to initbcs */
457 for (i = 0; i < cs->channels; ++i) {
458 gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i);
459 gigaset_freebcs(cs->bcs + i);
463 gig_dbg(DEBUG_INIT, "freeing inbuf");
466 f_bcs: gig_dbg(DEBUG_INIT, "freeing bcs[]");
468 f_cs: gig_dbg(DEBUG_INIT, "freeing cs");
469 mutex_unlock(&cs->mutex);
472 EXPORT_SYMBOL_GPL(gigaset_freecs);
474 void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
475 struct cardstate *cs, int cid)
479 INIT_LIST_HEAD(&at_state->list);
480 at_state->waiting = 0;
481 at_state->getstring = 0;
482 at_state->pending_commands = 0;
483 at_state->timer_expires = 0;
484 at_state->timer_active = 0;
485 at_state->timer_index = 0;
486 at_state->seq_index = 0;
487 at_state->ConState = 0;
488 for (i = 0; i < STR_NUM; ++i)
489 at_state->str_var[i] = NULL;
490 at_state->int_var[VAR_ZDLE] = 0;
491 at_state->int_var[VAR_ZCTP] = -1;
492 at_state->int_var[VAR_ZSAU] = ZSAU_NULL;
497 at_state->replystruct = cs->tabnocid;
499 at_state->replystruct = cs->tabcid;
503 static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
504 struct cardstate *cs, int inputstate)
505 /* inbuf->read must be allocated before! */
510 inbuf->bcs = bcs; /*base driver: NULL*/
511 inbuf->rcvbuf = NULL;
512 inbuf->inputstate = inputstate;
515 /* append received bytes to inbuf */
516 int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
519 unsigned n, head, tail, bytesleft;
521 gig_dbg(DEBUG_INTR, "received %u bytes", numbytes);
526 bytesleft = numbytes;
529 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
535 n = (RBUFSIZE-1) - tail;
539 dev_err(inbuf->cs->dev,
540 "buffer overflow (%u bytes lost)\n",
546 memcpy(inbuf->data + tail, src, n);
548 tail = (tail + n) % RBUFSIZE;
551 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
553 return numbytes != bytesleft;
555 EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);
557 /* Initialize the b-channel structure */
558 static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
559 struct cardstate *cs, int channel)
563 bcs->tx_skb = NULL; //FIXME -> hw part
565 skb_queue_head_init(&bcs->squeue);
571 gig_dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel);
572 gigaset_at_init(&bcs->at_state, bcs, cs, -1);
574 #ifdef CONFIG_GIGASET_DEBUG
578 gig_dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel);
579 bcs->fcs = PPP_INITFCS;
581 if (cs->ignoreframes) {
582 bcs->inputstate |= INS_skip_frame;
584 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
585 skb_reserve(bcs->skb, HW_HDR_LEN);
587 pr_err("out of memory\n");
588 bcs->inputstate |= INS_skip_frame;
591 bcs->channel = channel;
597 bcs->ignore = cs->ignoreframes;
599 for (i = 0; i < AT_NUM; ++i)
600 bcs->commands[i] = NULL;
602 gig_dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel);
603 if (cs->ops->initbcshw(bcs))
606 gig_dbg(DEBUG_INIT, " failed");
608 gig_dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel);
610 dev_kfree_skb(bcs->skb);
616 * Allocate and initialize cardstate structure for Gigaset driver
617 * Calls hardware dependent gigaset_initcshw() function
618 * Calls B channel initialization function gigaset_initbcs() for each B channel
620 * drv hardware driver the device belongs to
621 * channels number of B channels supported by device
622 * onechannel !=0: B channel data and AT commands share one
623 * communication channel
624 * ==0: B channels have separate communication channels
625 * ignoreframes number of frames to ignore after setting up B channel
626 * cidmode !=0: start in CallID mode
627 * modulename name of driver module (used for I4L registration)
629 * pointer to cardstate structure
631 struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
632 int onechannel, int ignoreframes,
633 int cidmode, const char *modulename)
635 struct cardstate *cs = NULL;
639 gig_dbg(DEBUG_INIT, "allocating cs");
640 if (!(cs = alloc_cs(drv))) {
641 pr_err("maximum number of devices exceeded\n");
645 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
646 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
648 pr_err("out of memory\n");
651 gig_dbg(DEBUG_INIT, "allocating inbuf");
652 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
654 pr_err("out of memory\n");
659 cs->channels = channels;
660 cs->onechannel = onechannel;
661 cs->ignoreframes = ignoreframes;
662 INIT_LIST_HEAD(&cs->temp_at_states);
664 init_timer(&cs->timer); /* clear next & prev */
665 spin_lock_init(&cs->ev_lock);
669 tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
671 cs->commands_pending = 0;
678 cs->cidmode = cidmode != 0;
679 cs->tabnocid = gigaset_tab_nocid;
680 cs->tabcid = gigaset_tab_cid;
682 init_waitqueue_head(&cs->waitqueue);
685 cs->mode = M_UNKNOWN;
686 cs->mstate = MS_UNINITIALIZED;
688 for (i = 0; i < channels; ++i) {
689 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
690 if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
691 pr_err("could not allocate channel %d data\n", i);
698 gig_dbg(DEBUG_INIT, "setting up at_state");
699 spin_lock_init(&cs->lock);
700 gigaset_at_init(&cs->at_state, NULL, cs, 0);
704 gig_dbg(DEBUG_INIT, "setting up inbuf");
705 if (onechannel) { //FIXME distinction necessary?
706 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command);
708 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command);
713 gig_dbg(DEBUG_INIT, "setting up cmdbuf");
714 cs->cmdbuf = cs->lastcmdbuf = NULL;
715 spin_lock_init(&cs->cmdlock);
719 gig_dbg(DEBUG_INIT, "setting up iif");
720 if (!gigaset_register_to_LL(cs, modulename)) {
721 pr_err("error registering ISDN device\n");
725 make_valid(cs, VALID_ID);
727 gig_dbg(DEBUG_INIT, "setting up hw");
728 if (!cs->ops->initcshw(cs))
733 /* set up character device */
736 /* set up device sysfs */
737 gigaset_init_dev_sysfs(cs);
739 spin_lock_irqsave(&cs->lock, flags);
741 spin_unlock_irqrestore(&cs->lock, flags);
742 setup_timer(&cs->timer, timer_tick, (unsigned long) cs);
743 cs->timer.expires = jiffies + msecs_to_jiffies(GIG_TICK);
744 /* FIXME: can jiffies increase too much until the timer is added?
745 * Same problem(?) with mod_timer() in timer_tick(). */
746 add_timer(&cs->timer);
748 gig_dbg(DEBUG_INIT, "cs initialized");
752 gig_dbg(DEBUG_INIT, "failed");
756 EXPORT_SYMBOL_GPL(gigaset_initcs);
758 /* ReInitialize the b-channel structure on hangup */
759 void gigaset_bcs_reinit(struct bc_state *bcs)
762 struct cardstate *cs = bcs->cs;
765 while ((skb = skb_dequeue(&bcs->squeue)) != NULL)
768 spin_lock_irqsave(&cs->lock, flags);
769 clear_at_state(&bcs->at_state);
770 bcs->at_state.ConState = 0;
771 bcs->at_state.timer_active = 0;
772 bcs->at_state.timer_expires = 0;
773 bcs->at_state.cid = -1; /* No CID defined */
774 spin_unlock_irqrestore(&cs->lock, flags);
778 #ifdef CONFIG_GIGASET_DEBUG
782 bcs->fcs = PPP_INITFCS;
785 bcs->ignore = cs->ignoreframes;
787 bcs->inputstate |= INS_skip_frame;
790 cs->ops->reinitbcshw(bcs);
793 static void cleanup_cs(struct cardstate *cs)
795 struct cmdbuf_t *cb, *tcb;
799 spin_lock_irqsave(&cs->lock, flags);
801 cs->mode = M_UNKNOWN;
802 cs->mstate = MS_UNINITIALIZED;
804 clear_at_state(&cs->at_state);
805 dealloc_at_states(cs);
806 free_strings(&cs->at_state);
807 gigaset_at_init(&cs->at_state, NULL, cs, 0);
809 kfree(cs->inbuf->rcvbuf);
810 cs->inbuf->rcvbuf = NULL;
811 cs->inbuf->inputstate = INS_command;
821 cs->cmdbuf = cs->lastcmdbuf = NULL;
827 cs->commands_pending = 0;
830 spin_unlock_irqrestore(&cs->lock, flags);
832 for (i = 0; i < cs->channels; ++i) {
833 gigaset_freebcs(cs->bcs + i);
834 if (!gigaset_initbcs(cs->bcs + i, cs, i))
835 pr_err("could not allocate channel %d data\n", i);
839 cs->cmd_result = -ENODEV;
841 wake_up_interruptible(&cs->waitqueue);
846 int gigaset_start(struct cardstate *cs)
850 if (mutex_lock_interruptible(&cs->mutex))
853 spin_lock_irqsave(&cs->lock, flags);
855 spin_unlock_irqrestore(&cs->lock, flags);
857 if (cs->mstate != MS_LOCKED) {
858 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
859 cs->ops->baud_rate(cs, B115200);
860 cs->ops->set_line_ctrl(cs, CS8);
861 cs->control_state = TIOCM_DTR|TIOCM_RTS;
863 //FIXME use some saved values?
868 if (!gigaset_add_event(cs, &cs->at_state, EV_START, NULL, 0, NULL)) {
870 //FIXME what should we do?
874 gig_dbg(DEBUG_CMD, "scheduling START");
875 gigaset_schedule_event(cs);
877 wait_event(cs->waitqueue, !cs->waiting);
879 mutex_unlock(&cs->mutex);
883 mutex_unlock(&cs->mutex);
886 EXPORT_SYMBOL_GPL(gigaset_start);
889 * check if a device is associated to the cardstate structure and stop it
890 * return value: 0 if ok, -1 if no device was associated
892 int gigaset_shutdown(struct cardstate *cs)
894 mutex_lock(&cs->mutex);
896 if (!(cs->flags & VALID_MINOR)) {
897 mutex_unlock(&cs->mutex);
903 if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) {
904 //FIXME what should we do?
908 gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN");
909 gigaset_schedule_event(cs);
911 wait_event(cs->waitqueue, !cs->waiting);
916 mutex_unlock(&cs->mutex);
919 EXPORT_SYMBOL_GPL(gigaset_shutdown);
921 void gigaset_stop(struct cardstate *cs)
923 mutex_lock(&cs->mutex);
927 if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL)) {
928 //FIXME what should we do?
932 gig_dbg(DEBUG_CMD, "scheduling STOP");
933 gigaset_schedule_event(cs);
935 wait_event(cs->waitqueue, !cs->waiting);
940 mutex_unlock(&cs->mutex);
942 EXPORT_SYMBOL_GPL(gigaset_stop);
944 static LIST_HEAD(drivers);
945 static DEFINE_SPINLOCK(driver_lock);
947 struct cardstate *gigaset_get_cs_by_id(int id)
950 struct cardstate *ret = NULL;
951 struct cardstate *cs;
952 struct gigaset_driver *drv;
955 spin_lock_irqsave(&driver_lock, flags);
956 list_for_each_entry(drv, &drivers, list) {
957 spin_lock(&drv->lock);
958 for (i = 0; i < drv->minors; ++i) {
960 if ((cs->flags & VALID_ID) && cs->myid == id) {
965 spin_unlock(&drv->lock);
969 spin_unlock_irqrestore(&driver_lock, flags);
973 void gigaset_debugdrivers(void)
976 static struct cardstate *cs;
977 struct gigaset_driver *drv;
980 spin_lock_irqsave(&driver_lock, flags);
981 list_for_each_entry(drv, &drivers, list) {
982 gig_dbg(DEBUG_DRIVER, "driver %p", drv);
983 spin_lock(&drv->lock);
984 for (i = 0; i < drv->minors; ++i) {
985 gig_dbg(DEBUG_DRIVER, " index %u", i);
987 gig_dbg(DEBUG_DRIVER, " cardstate %p", cs);
988 gig_dbg(DEBUG_DRIVER, " flags 0x%02x", cs->flags);
989 gig_dbg(DEBUG_DRIVER, " minor_index %u",
991 gig_dbg(DEBUG_DRIVER, " driver %p", cs->driver);
992 gig_dbg(DEBUG_DRIVER, " i4l id %d", cs->myid);
994 spin_unlock(&drv->lock);
996 spin_unlock_irqrestore(&driver_lock, flags);
999 static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
1001 unsigned long flags;
1002 struct cardstate *ret = NULL;
1003 struct gigaset_driver *drv;
1006 spin_lock_irqsave(&driver_lock, flags);
1007 list_for_each_entry(drv, &drivers, list) {
1008 if (minor < drv->minor || minor >= drv->minor + drv->minors)
1010 index = minor - drv->minor;
1011 spin_lock(&drv->lock);
1012 if (drv->cs[index].flags & VALID_MINOR)
1013 ret = drv->cs + index;
1014 spin_unlock(&drv->lock);
1018 spin_unlock_irqrestore(&driver_lock, flags);
1022 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
1024 if (tty->index < 0 || tty->index >= tty->driver->num)
1026 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
1029 void gigaset_freedriver(struct gigaset_driver *drv)
1031 unsigned long flags;
1033 spin_lock_irqsave(&driver_lock, flags);
1034 list_del(&drv->list);
1035 spin_unlock_irqrestore(&driver_lock, flags);
1037 gigaset_if_freedriver(drv);
1042 EXPORT_SYMBOL_GPL(gigaset_freedriver);
1044 /* gigaset_initdriver
1045 * Allocate and initialize gigaset_driver structure. Initialize interface.
1047 * minor First minor number
1048 * minors Number of minors this driver can handle
1049 * procname Name of the driver
1050 * devname Name of the device files (prefix without minor number)
1052 * Pointer to the gigaset_driver structure on success, NULL on failure.
1054 struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1055 const char *procname,
1056 const char *devname,
1057 const struct gigaset_ops *ops,
1058 struct module *owner)
1060 struct gigaset_driver *drv;
1061 unsigned long flags;
1064 drv = kmalloc(sizeof *drv, GFP_KERNEL);
1070 drv->minors = minors;
1071 spin_lock_init(&drv->lock);
1075 INIT_LIST_HEAD(&drv->list);
1077 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1081 for (i = 0; i < minors; ++i) {
1082 drv->cs[i].flags = 0;
1083 drv->cs[i].driver = drv;
1084 drv->cs[i].ops = drv->ops;
1085 drv->cs[i].minor_index = i;
1086 mutex_init(&drv->cs[i].mutex);
1089 gigaset_if_initdriver(drv, procname, devname);
1091 spin_lock_irqsave(&driver_lock, flags);
1092 list_add(&drv->list, &drivers);
1093 spin_unlock_irqrestore(&driver_lock, flags);
1102 EXPORT_SYMBOL_GPL(gigaset_initdriver);
1104 void gigaset_blockdriver(struct gigaset_driver *drv)
1108 EXPORT_SYMBOL_GPL(gigaset_blockdriver);
1110 static int __init gigaset_init_module(void)
1112 /* in accordance with the principle of least astonishment,
1113 * setting the 'debug' parameter to 1 activates a sensible
1114 * set of default debug levels
1116 if (gigaset_debuglevel == 1)
1117 gigaset_debuglevel = DEBUG_DEFAULT;
1119 pr_info(DRIVER_DESC DRIVER_DESC_DEBUG "\n");
1123 static void __exit gigaset_exit_module(void)
1127 module_init(gigaset_init_module);
1128 module_exit(gigaset_exit_module);
1130 MODULE_AUTHOR(DRIVER_AUTHOR);
1131 MODULE_DESCRIPTION(DRIVER_DESC);
1133 MODULE_LICENSE("GPL");