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 /* Module parameters */
26 int gigaset_debuglevel = DEBUG_DEFAULT;
27 EXPORT_SYMBOL_GPL(gigaset_debuglevel);
28 module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR);
29 MODULE_PARM_DESC(debug, "debug level");
31 /* driver state flags */
32 #define VALID_MINOR 0x01
35 void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
36 size_t len, const unsigned char *buf)
38 unsigned char outbuf[80];
40 size_t space = sizeof outbuf - 1;
41 unsigned char *out = outbuf;
46 if (c == '~' || c == '^' || c == '\\') {
57 if (c < 0x20 || c == 0x7f) {
69 gig_dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf);
71 EXPORT_SYMBOL_GPL(gigaset_dbg_buffer);
73 static int setflags(struct cardstate *cs, unsigned flags, unsigned delay)
77 r = cs->ops->set_modem_ctrl(cs, cs->control_state, flags);
78 cs->control_state = flags;
83 set_current_state(TASK_INTERRUPTIBLE);
84 schedule_timeout(delay * HZ / 1000);
90 int gigaset_enterconfigmode(struct cardstate *cs)
94 cs->control_state = TIOCM_RTS; //FIXME
96 r = setflags(cs, TIOCM_DTR, 200);
99 r = setflags(cs, 0, 200);
102 for (i = 0; i < 5; ++i) {
103 r = setflags(cs, TIOCM_RTS, 100);
106 r = setflags(cs, 0, 100);
110 r = setflags(cs, TIOCM_RTS|TIOCM_DTR, 800);
117 dev_err(cs->dev, "error %d on setuartbits\n", -r);
118 cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value?
119 cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR);
124 static int test_timeout(struct at_state_t *at_state)
126 if (!at_state->timer_expires)
129 if (--at_state->timer_expires) {
130 gig_dbg(DEBUG_MCMD, "decreased timer of %p to %lu",
131 at_state, at_state->timer_expires);
135 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL,
136 at_state->timer_index, NULL)) {
137 //FIXME what should we do?
143 static void timer_tick(unsigned long data)
145 struct cardstate *cs = (struct cardstate *) data;
148 struct at_state_t *at_state;
151 spin_lock_irqsave(&cs->lock, flags);
153 for (channel = 0; channel < cs->channels; ++channel)
154 if (test_timeout(&cs->bcs[channel].at_state))
157 if (test_timeout(&cs->at_state))
160 list_for_each_entry(at_state, &cs->temp_at_states, list)
161 if (test_timeout(at_state))
165 mod_timer(&cs->timer, jiffies + msecs_to_jiffies(GIG_TICK));
167 gig_dbg(DEBUG_CMD, "scheduling timeout");
168 tasklet_schedule(&cs->event_tasklet);
172 spin_unlock_irqrestore(&cs->lock, flags);
175 int gigaset_get_channel(struct bc_state *bcs)
179 spin_lock_irqsave(&bcs->cs->lock, flags);
180 if (bcs->use_count || !try_module_get(bcs->cs->driver->owner)) {
181 gig_dbg(DEBUG_ANY, "could not allocate channel %d",
183 spin_unlock_irqrestore(&bcs->cs->lock, flags);
188 gig_dbg(DEBUG_ANY, "allocated channel %d", bcs->channel);
189 spin_unlock_irqrestore(&bcs->cs->lock, flags);
193 void gigaset_free_channel(struct bc_state *bcs)
197 spin_lock_irqsave(&bcs->cs->lock, flags);
199 gig_dbg(DEBUG_ANY, "could not free channel %d", bcs->channel);
200 spin_unlock_irqrestore(&bcs->cs->lock, flags);
205 module_put(bcs->cs->driver->owner);
206 gig_dbg(DEBUG_ANY, "freed channel %d", bcs->channel);
207 spin_unlock_irqrestore(&bcs->cs->lock, flags);
210 int gigaset_get_channels(struct cardstate *cs)
215 spin_lock_irqsave(&cs->lock, flags);
216 for (i = 0; i < cs->channels; ++i)
217 if (cs->bcs[i].use_count) {
218 spin_unlock_irqrestore(&cs->lock, flags);
219 gig_dbg(DEBUG_ANY, "could not allocate all channels");
222 for (i = 0; i < cs->channels; ++i)
223 ++cs->bcs[i].use_count;
224 spin_unlock_irqrestore(&cs->lock, flags);
226 gig_dbg(DEBUG_ANY, "allocated all channels");
231 void gigaset_free_channels(struct cardstate *cs)
236 gig_dbg(DEBUG_ANY, "unblocking all channels");
237 spin_lock_irqsave(&cs->lock, flags);
238 for (i = 0; i < cs->channels; ++i)
239 --cs->bcs[i].use_count;
240 spin_unlock_irqrestore(&cs->lock, flags);
243 void gigaset_block_channels(struct cardstate *cs)
248 gig_dbg(DEBUG_ANY, "blocking all channels");
249 spin_lock_irqsave(&cs->lock, flags);
250 for (i = 0; i < cs->channels; ++i)
251 ++cs->bcs[i].use_count;
252 spin_unlock_irqrestore(&cs->lock, flags);
255 static void clear_events(struct cardstate *cs)
261 spin_lock_irqsave(&cs->ev_lock, flags);
266 while (tail != head) {
267 ev = cs->events + head;
269 head = (head + 1) % MAX_EVENTS;
274 spin_unlock_irqrestore(&cs->ev_lock, flags);
277 struct event_t *gigaset_add_event(struct cardstate *cs,
278 struct at_state_t *at_state, int type,
279 void *ptr, int parameter, void *arg)
283 struct event_t *event = NULL;
285 spin_lock_irqsave(&cs->ev_lock, flags);
288 next = (tail + 1) % MAX_EVENTS;
289 if (unlikely(next == cs->ev_head))
290 err("event queue full");
292 event = cs->events + tail;
294 event->at_state = at_state;
298 event->parameter = parameter;
302 spin_unlock_irqrestore(&cs->ev_lock, flags);
306 EXPORT_SYMBOL_GPL(gigaset_add_event);
308 static void free_strings(struct at_state_t *at_state)
312 for (i = 0; i < STR_NUM; ++i) {
313 kfree(at_state->str_var[i]);
314 at_state->str_var[i] = NULL;
318 static void clear_at_state(struct at_state_t *at_state)
320 free_strings(at_state);
323 static void dealloc_at_states(struct cardstate *cs)
325 struct at_state_t *cur, *next;
327 list_for_each_entry_safe(cur, next, &cs->temp_at_states, list) {
328 list_del(&cur->list);
334 static void gigaset_freebcs(struct bc_state *bcs)
338 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel);
339 if (!bcs->cs->ops->freebcshw(bcs)) {
340 gig_dbg(DEBUG_INIT, "failed");
343 gig_dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel);
344 clear_at_state(&bcs->at_state);
345 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel);
348 dev_kfree_skb(bcs->skb);
349 for (i = 0; i < AT_NUM; ++i) {
350 kfree(bcs->commands[i]);
351 bcs->commands[i] = NULL;
355 static struct cardstate *alloc_cs(struct gigaset_driver *drv)
359 struct cardstate *cs;
360 struct cardstate *ret = NULL;
362 spin_lock_irqsave(&drv->lock, flags);
365 for (i = 0; i < drv->minors; ++i) {
367 if (!(cs->flags & VALID_MINOR)) {
368 cs->flags = VALID_MINOR;
374 spin_unlock_irqrestore(&drv->lock, flags);
378 static void free_cs(struct cardstate *cs)
383 static void make_valid(struct cardstate *cs, unsigned mask)
386 struct gigaset_driver *drv = cs->driver;
387 spin_lock_irqsave(&drv->lock, flags);
389 spin_unlock_irqrestore(&drv->lock, flags);
392 static void make_invalid(struct cardstate *cs, unsigned mask)
395 struct gigaset_driver *drv = cs->driver;
396 spin_lock_irqsave(&drv->lock, flags);
398 spin_unlock_irqrestore(&drv->lock, flags);
401 void gigaset_freecs(struct cardstate *cs)
409 mutex_lock(&cs->mutex);
416 spin_lock_irqsave(&cs->lock, flags);
418 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are
419 not rescheduled below */
421 tasklet_kill(&cs->event_tasklet);
422 del_timer_sync(&cs->timer);
424 switch (cs->cs_init) {
426 /* clear device sysfs */
427 gigaset_free_dev_sysfs(cs);
431 gig_dbg(DEBUG_INIT, "clearing hw");
432 cs->ops->freecshw(cs);
437 case 2: /* error in initcshw */
438 /* Deregister from LL */
439 make_invalid(cs, VALID_ID);
440 gig_dbg(DEBUG_INIT, "clearing iif");
441 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
444 case 1: /* error when regestering to LL */
445 gig_dbg(DEBUG_INIT, "clearing at_state");
446 clear_at_state(&cs->at_state);
447 dealloc_at_states(cs);
450 case 0: /* error in one call to initbcs */
451 for (i = 0; i < cs->channels; ++i) {
452 gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i);
453 gigaset_freebcs(cs->bcs + i);
457 gig_dbg(DEBUG_INIT, "freeing inbuf");
460 f_bcs: gig_dbg(DEBUG_INIT, "freeing bcs[]");
462 f_cs: gig_dbg(DEBUG_INIT, "freeing cs");
463 mutex_unlock(&cs->mutex);
466 EXPORT_SYMBOL_GPL(gigaset_freecs);
468 void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
469 struct cardstate *cs, int cid)
473 INIT_LIST_HEAD(&at_state->list);
474 at_state->waiting = 0;
475 at_state->getstring = 0;
476 at_state->pending_commands = 0;
477 at_state->timer_expires = 0;
478 at_state->timer_active = 0;
479 at_state->timer_index = 0;
480 at_state->seq_index = 0;
481 at_state->ConState = 0;
482 for (i = 0; i < STR_NUM; ++i)
483 at_state->str_var[i] = NULL;
484 at_state->int_var[VAR_ZDLE] = 0;
485 at_state->int_var[VAR_ZCTP] = -1;
486 at_state->int_var[VAR_ZSAU] = ZSAU_NULL;
491 at_state->replystruct = cs->tabnocid;
493 at_state->replystruct = cs->tabcid;
497 static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
498 struct cardstate *cs, int inputstate)
499 /* inbuf->read must be allocated before! */
504 inbuf->bcs = bcs; /*base driver: NULL*/
505 inbuf->rcvbuf = NULL;
506 inbuf->inputstate = inputstate;
509 /* append received bytes to inbuf */
510 int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
513 unsigned n, head, tail, bytesleft;
515 gig_dbg(DEBUG_INTR, "received %u bytes", numbytes);
520 bytesleft = numbytes;
523 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
529 n = (RBUFSIZE-1) - tail;
533 dev_err(inbuf->cs->dev,
534 "buffer overflow (%u bytes lost)\n",
540 memcpy(inbuf->data + tail, src, n);
542 tail = (tail + n) % RBUFSIZE;
545 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
547 return numbytes != bytesleft;
549 EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);
551 /* Initialize the b-channel structure */
552 static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
553 struct cardstate *cs, int channel)
557 bcs->tx_skb = NULL; //FIXME -> hw part
559 skb_queue_head_init(&bcs->squeue);
565 gig_dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel);
566 gigaset_at_init(&bcs->at_state, bcs, cs, -1);
570 #ifdef CONFIG_GIGASET_DEBUG
574 gig_dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel);
575 bcs->fcs = PPP_INITFCS;
577 if (cs->ignoreframes) {
578 bcs->inputstate |= INS_skip_frame;
580 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
581 skb_reserve(bcs->skb, HW_HDR_LEN);
583 warn("could not allocate skb");
584 bcs->inputstate |= INS_skip_frame;
587 bcs->channel = channel;
593 bcs->ignore = cs->ignoreframes;
595 for (i = 0; i < AT_NUM; ++i)
596 bcs->commands[i] = NULL;
598 gig_dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel);
599 if (cs->ops->initbcshw(bcs))
602 gig_dbg(DEBUG_INIT, " failed");
604 gig_dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel);
606 dev_kfree_skb(bcs->skb);
612 * Allocate and initialize cardstate structure for Gigaset driver
613 * Calls hardware dependent gigaset_initcshw() function
614 * Calls B channel initialization function gigaset_initbcs() for each B channel
616 * drv hardware driver the device belongs to
617 * channels number of B channels supported by device
618 * onechannel !=0: B channel data and AT commands share one
619 * communication channel
620 * ==0: B channels have separate communication channels
621 * ignoreframes number of frames to ignore after setting up B channel
622 * cidmode !=0: start in CallID mode
623 * modulename name of driver module (used for I4L registration)
625 * pointer to cardstate structure
627 struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
628 int onechannel, int ignoreframes,
629 int cidmode, const char *modulename)
631 struct cardstate *cs = NULL;
635 gig_dbg(DEBUG_INIT, "allocating cs");
636 if (!(cs = alloc_cs(drv))) {
637 err("maximum number of devices exceeded");
640 mutex_init(&cs->mutex);
642 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
643 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
645 err("out of memory");
648 gig_dbg(DEBUG_INIT, "allocating inbuf");
649 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
651 err("out of memory");
656 cs->channels = channels;
657 cs->onechannel = onechannel;
658 cs->ignoreframes = ignoreframes;
659 INIT_LIST_HEAD(&cs->temp_at_states);
661 init_timer(&cs->timer); /* clear next & prev */
662 spin_lock_init(&cs->ev_lock);
666 tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
668 cs->commands_pending = 0;
675 cs->cidmode = cidmode != 0;
677 //if(onechannel) { //FIXME
678 cs->tabnocid = gigaset_tab_nocid_m10x;
679 cs->tabcid = gigaset_tab_cid_m10x;
681 // cs->tabnocid = gigaset_tab_nocid;
682 // cs->tabcid = gigaset_tab_cid;
685 init_waitqueue_head(&cs->waitqueue);
688 cs->mode = M_UNKNOWN;
689 cs->mstate = MS_UNINITIALIZED;
691 for (i = 0; i < channels; ++i) {
692 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
693 if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
694 err("could not allocate channel %d data", i);
701 gig_dbg(DEBUG_INIT, "setting up at_state");
702 spin_lock_init(&cs->lock);
703 gigaset_at_init(&cs->at_state, NULL, cs, 0);
707 gig_dbg(DEBUG_INIT, "setting up inbuf");
708 if (onechannel) { //FIXME distinction necessary?
709 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command);
711 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command);
716 gig_dbg(DEBUG_INIT, "setting up cmdbuf");
717 cs->cmdbuf = cs->lastcmdbuf = NULL;
718 spin_lock_init(&cs->cmdlock);
722 gig_dbg(DEBUG_INIT, "setting up iif");
723 if (!gigaset_register_to_LL(cs, modulename)) {
724 err("register_isdn failed");
728 make_valid(cs, VALID_ID);
730 gig_dbg(DEBUG_INIT, "setting up hw");
731 if (!cs->ops->initcshw(cs)) {
732 err("could not allocate device specific data");
738 /* set up character device */
741 /* set up device sysfs */
742 gigaset_init_dev_sysfs(cs);
744 spin_lock_irqsave(&cs->lock, flags);
746 spin_unlock_irqrestore(&cs->lock, flags);
747 setup_timer(&cs->timer, timer_tick, (unsigned long) cs);
748 cs->timer.expires = jiffies + msecs_to_jiffies(GIG_TICK);
749 /* FIXME: can jiffies increase too much until the timer is added?
750 * Same problem(?) with mod_timer() in timer_tick(). */
751 add_timer(&cs->timer);
753 gig_dbg(DEBUG_INIT, "cs initialized");
757 gig_dbg(DEBUG_INIT, "failed");
761 EXPORT_SYMBOL_GPL(gigaset_initcs);
763 /* ReInitialize the b-channel structure on hangup */
764 void gigaset_bcs_reinit(struct bc_state *bcs)
767 struct cardstate *cs = bcs->cs;
770 while ((skb = skb_dequeue(&bcs->squeue)) != NULL)
773 spin_lock_irqsave(&cs->lock, flags);
774 clear_at_state(&bcs->at_state);
775 bcs->at_state.ConState = 0;
776 bcs->at_state.timer_active = 0;
777 bcs->at_state.timer_expires = 0;
778 bcs->at_state.cid = -1; /* No CID defined */
779 spin_unlock_irqrestore(&cs->lock, flags);
783 #ifdef CONFIG_GIGASET_DEBUG
787 bcs->fcs = PPP_INITFCS;
790 bcs->ignore = cs->ignoreframes;
792 bcs->inputstate |= INS_skip_frame;
795 cs->ops->reinitbcshw(bcs);
798 static void cleanup_cs(struct cardstate *cs)
800 struct cmdbuf_t *cb, *tcb;
804 spin_lock_irqsave(&cs->lock, flags);
806 cs->mode = M_UNKNOWN;
807 cs->mstate = MS_UNINITIALIZED;
809 clear_at_state(&cs->at_state);
810 dealloc_at_states(cs);
811 free_strings(&cs->at_state);
812 gigaset_at_init(&cs->at_state, NULL, cs, 0);
814 kfree(cs->inbuf->rcvbuf);
815 cs->inbuf->rcvbuf = NULL;
816 cs->inbuf->inputstate = INS_command;
826 cs->cmdbuf = cs->lastcmdbuf = NULL;
832 cs->commands_pending = 0;
835 spin_unlock_irqrestore(&cs->lock, flags);
837 for (i = 0; i < cs->channels; ++i) {
838 gigaset_freebcs(cs->bcs + i);
839 if (!gigaset_initbcs(cs->bcs + i, cs, i))
840 break; //FIXME error handling
844 cs->cmd_result = -ENODEV;
846 wake_up_interruptible(&cs->waitqueue);
851 int gigaset_start(struct cardstate *cs)
855 if (mutex_lock_interruptible(&cs->mutex))
858 spin_lock_irqsave(&cs->lock, flags);
860 spin_unlock_irqrestore(&cs->lock, flags);
862 if (cs->mstate != MS_LOCKED) {
863 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
864 cs->ops->baud_rate(cs, B115200);
865 cs->ops->set_line_ctrl(cs, CS8);
866 cs->control_state = TIOCM_DTR|TIOCM_RTS;
868 //FIXME use some saved values?
873 if (!gigaset_add_event(cs, &cs->at_state, EV_START, NULL, 0, NULL)) {
875 //FIXME what should we do?
879 gig_dbg(DEBUG_CMD, "scheduling START");
880 gigaset_schedule_event(cs);
882 wait_event(cs->waitqueue, !cs->waiting);
884 mutex_unlock(&cs->mutex);
888 mutex_unlock(&cs->mutex);
891 EXPORT_SYMBOL_GPL(gigaset_start);
894 * check if a device is associated to the cardstate structure and stop it
895 * return value: 0 if ok, -1 if no device was associated
897 int gigaset_shutdown(struct cardstate *cs)
899 mutex_lock(&cs->mutex);
901 if (!(cs->flags & VALID_MINOR))
906 if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) {
907 //FIXME what should we do?
911 gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN");
912 gigaset_schedule_event(cs);
914 wait_event(cs->waitqueue, !cs->waiting);
919 mutex_unlock(&cs->mutex);
922 EXPORT_SYMBOL_GPL(gigaset_shutdown);
924 void gigaset_stop(struct cardstate *cs)
926 mutex_lock(&cs->mutex);
930 if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL)) {
931 //FIXME what should we do?
935 gig_dbg(DEBUG_CMD, "scheduling STOP");
936 gigaset_schedule_event(cs);
938 wait_event(cs->waitqueue, !cs->waiting);
943 mutex_unlock(&cs->mutex);
945 EXPORT_SYMBOL_GPL(gigaset_stop);
947 static LIST_HEAD(drivers);
948 static DEFINE_SPINLOCK(driver_lock);
950 struct cardstate *gigaset_get_cs_by_id(int id)
953 struct cardstate *ret = NULL;
954 struct cardstate *cs;
955 struct gigaset_driver *drv;
958 spin_lock_irqsave(&driver_lock, flags);
959 list_for_each_entry(drv, &drivers, list) {
960 spin_lock(&drv->lock);
961 for (i = 0; i < drv->minors; ++i) {
963 if ((cs->flags & VALID_ID) && cs->myid == id) {
968 spin_unlock(&drv->lock);
972 spin_unlock_irqrestore(&driver_lock, flags);
976 void gigaset_debugdrivers(void)
979 static struct cardstate *cs;
980 struct gigaset_driver *drv;
983 spin_lock_irqsave(&driver_lock, flags);
984 list_for_each_entry(drv, &drivers, list) {
985 gig_dbg(DEBUG_DRIVER, "driver %p", drv);
986 spin_lock(&drv->lock);
987 for (i = 0; i < drv->minors; ++i) {
988 gig_dbg(DEBUG_DRIVER, " index %u", i);
990 gig_dbg(DEBUG_DRIVER, " cardstate %p", cs);
991 gig_dbg(DEBUG_DRIVER, " flags 0x%02x", cs->flags);
992 gig_dbg(DEBUG_DRIVER, " minor_index %u",
994 gig_dbg(DEBUG_DRIVER, " driver %p", cs->driver);
995 gig_dbg(DEBUG_DRIVER, " i4l id %d", cs->myid);
997 spin_unlock(&drv->lock);
999 spin_unlock_irqrestore(&driver_lock, flags);
1002 static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
1004 unsigned long flags;
1005 struct cardstate *ret = NULL;
1006 struct gigaset_driver *drv;
1009 spin_lock_irqsave(&driver_lock, flags);
1010 list_for_each_entry(drv, &drivers, list) {
1011 if (minor < drv->minor || minor >= drv->minor + drv->minors)
1013 index = minor - drv->minor;
1014 spin_lock(&drv->lock);
1015 if (drv->cs[index].flags & VALID_MINOR)
1016 ret = drv->cs + index;
1017 spin_unlock(&drv->lock);
1021 spin_unlock_irqrestore(&driver_lock, flags);
1025 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
1027 if (tty->index < 0 || tty->index >= tty->driver->num)
1029 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
1032 void gigaset_freedriver(struct gigaset_driver *drv)
1034 unsigned long flags;
1036 spin_lock_irqsave(&driver_lock, flags);
1037 list_del(&drv->list);
1038 spin_unlock_irqrestore(&driver_lock, flags);
1040 gigaset_if_freedriver(drv);
1045 EXPORT_SYMBOL_GPL(gigaset_freedriver);
1047 /* gigaset_initdriver
1048 * Allocate and initialize gigaset_driver structure. Initialize interface.
1050 * minor First minor number
1051 * minors Number of minors this driver can handle
1052 * procname Name of the driver
1053 * devname Name of the device files (prefix without minor number)
1055 * Pointer to the gigaset_driver structure on success, NULL on failure.
1057 struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1058 const char *procname,
1059 const char *devname,
1060 const struct gigaset_ops *ops,
1061 struct module *owner)
1063 struct gigaset_driver *drv;
1064 unsigned long flags;
1067 drv = kmalloc(sizeof *drv, GFP_KERNEL);
1073 drv->minors = minors;
1074 spin_lock_init(&drv->lock);
1078 INIT_LIST_HEAD(&drv->list);
1080 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1084 for (i = 0; i < minors; ++i) {
1085 drv->cs[i].flags = 0;
1086 drv->cs[i].driver = drv;
1087 drv->cs[i].ops = drv->ops;
1088 drv->cs[i].minor_index = i;
1091 gigaset_if_initdriver(drv, procname, devname);
1093 spin_lock_irqsave(&driver_lock, flags);
1094 list_add(&drv->list, &drivers);
1095 spin_unlock_irqrestore(&driver_lock, flags);
1104 EXPORT_SYMBOL_GPL(gigaset_initdriver);
1106 void gigaset_blockdriver(struct gigaset_driver *drv)
1110 EXPORT_SYMBOL_GPL(gigaset_blockdriver);
1112 static int __init gigaset_init_module(void)
1114 /* in accordance with the principle of least astonishment,
1115 * setting the 'debug' parameter to 1 activates a sensible
1116 * set of default debug levels
1118 if (gigaset_debuglevel == 1)
1119 gigaset_debuglevel = DEBUG_DEFAULT;
1121 info(DRIVER_AUTHOR);
1126 static void __exit gigaset_exit_module(void)
1130 module_init(gigaset_init_module);
1131 module_exit(gigaset_exit_module);
1133 MODULE_AUTHOR(DRIVER_AUTHOR);
1134 MODULE_DESCRIPTION(DRIVER_DESC);
1136 MODULE_LICENSE("GPL");