Lines Matching refs:cs

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;
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);
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);
151 gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL,
158 struct cardstate *cs = (struct cardstate *) data;
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)
177 if (cs->running) {
178 mod_timer(&cs->timer, jiffies + msecs_to_jiffies(GIG_TICK));
181 tasklet_schedule(&cs->event_tasklet);
185 spin_unlock_irqrestore(&cs->lock, flags);
192 spin_lock_irqsave(&bcs->cs->lock, flags);
193 if (bcs->use_count || !try_module_get(bcs->cs->driver->owner)) {
196 spin_unlock_irqrestore(&bcs->cs->lock, flags);
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)) {
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;
221 cs->bcs[i].busy = 1;
222 spin_unlock_irqrestore(&cs->lock, flags);
224 return cs->bcs + i;
226 module_put(cs->driver->owner);
227 spin_unlock_irqrestore(&cs->lock, flags);
236 spin_lock_irqsave(&bcs->cs->lock, flags);
240 spin_unlock_irqrestore(&bcs->cs->lock, flags);
245 module_put(bcs->cs->driver->owner);
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);
263 for (i = 0; i < cs->channels; ++i)
264 ++cs->bcs[i].use_count;
265 spin_unlock_irqrestore(&cs->lock, flags);
272 void gigaset_free_channels(struct cardstate *cs)
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)
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);
304 head = cs->ev_head;
305 tail = cs->ev_tail;
308 ev = cs->events + head;
313 cs->ev_head = tail;
315 spin_unlock_irqrestore(&cs->ev_lock, flags);
320 * @cs: device descriptor structure.
332 struct event_t *gigaset_add_event(struct cardstate *cs,
342 spin_lock_irqsave(&cs->ev_lock, flags);
344 tail = cs->ev_tail;
346 if (unlikely(next == cs->ev_head))
347 dev_err(cs->dev, "event queue full\n");
349 event = cs->events + tail;
356 cs->ev_tail = next;
359 spin_unlock_irqrestore(&cs->ev_lock, flags);
375 static void dealloc_temp_at_states(struct cardstate *cs)
379 list_for_each_entry_safe(cur, next, &cs->temp_at_states, list) {
391 bcs->cs->ops->freebcshw(bcs);
409 struct cardstate *cs;
416 cs = drv->cs + i;
417 if (!(cs->flags & VALID_MINOR)) {
418 cs->flags = VALID_MINOR;
419 ret = cs;
428 static void free_cs(struct cardstate *cs)
430 cs->flags = 0;
433 static void make_valid(struct cardstate *cs, unsigned mask)
436 struct gigaset_driver *drv = cs->driver;
438 cs->flags |= mask;
442 static void make_invalid(struct cardstate *cs, unsigned mask)
445 struct gigaset_driver *drv = cs->driver;
447 cs->flags &= ~mask;
453 * @cs: device descriptor structure.
457 * @cs and all structures referenced from it.
460 void gigaset_freecs(struct cardstate *cs)
465 if (!cs)
468 mutex_lock(&cs->mutex);
470 spin_lock_irqsave(&cs->lock, flags);
471 cs->running = 0;
472 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are
475 tasklet_kill(&cs->event_tasklet);
476 del_timer_sync(&cs->timer);
478 switch (cs->cs_init) {
481 for (i = 0; i < cs->channels; ++i) {
483 gigaset_freebcs(cs->bcs + i);
487 gigaset_free_dev_sysfs(cs);
489 gigaset_if_free(cs);
492 cs->ops->freecshw(cs);
497 make_invalid(cs, VALID_ID);
498 gigaset_isdn_unregdev(cs);
503 clear_at_state(&cs->at_state);
504 dealloc_temp_at_states(cs);
505 clear_events(cs);
506 tty_port_destroy(&cs->port);
511 kfree(cs->inbuf);
512 kfree(cs->bcs);
515 mutex_unlock(&cs->mutex);
516 free_cs(cs);
521 struct cardstate *cs, int cid)
539 at_state->cs = cs;
543 at_state->replystruct = cs->tabnocid;
545 at_state->replystruct = cs->tabcid;
549 static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct cardstate *cs)
554 inbuf->cs = cs;
589 dev_err(inbuf->cs->dev,
608 static int gigaset_initbcs(struct bc_state *bcs, struct cardstate *cs,
622 gigaset_at_init(&bcs->at_state, bcs, cs, -1);
633 bcs->cs = cs;
638 bcs->ignore = cs->ignoreframes;
648 return cs->ops->initbcshw(bcs);
673 struct cardstate *cs;
677 gig_dbg(DEBUG_INIT, "allocating cs");
678 cs = alloc_cs(drv);
679 if (!cs) {
684 cs->cs_init = 0;
685 cs->channels = channels;
686 cs->onechannel = onechannel;
687 cs->ignoreframes = ignoreframes;
688 INIT_LIST_HEAD(&cs->temp_at_states);
689 cs->running = 0;
690 init_timer(&cs->timer); /* clear next & prev */
691 spin_lock_init(&cs->ev_lock);
692 cs->ev_tail = 0;
693 cs->ev_head = 0;
695 tasklet_init(&cs->event_tasklet, gigaset_handle_event,
696 (unsigned long) cs);
697 tty_port_init(&cs->port);
698 cs->commands_pending = 0;
699 cs->cur_at_seq = 0;
700 cs->gotfwver = -1;
701 cs->dev = NULL;
702 cs->tty_dev = NULL;
703 cs->cidmode = cidmode != 0;
704 cs->tabnocid = gigaset_tab_nocid;
705 cs->tabcid = gigaset_tab_cid;
707 init_waitqueue_head(&cs->waitqueue);
708 cs->waiting = 0;
710 cs->mode = M_UNKNOWN;
711 cs->mstate = MS_UNINITIALIZED;
713 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
714 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
715 if (!cs->bcs || !cs->inbuf) {
719 ++cs->cs_init;
722 spin_lock_init(&cs->lock);
723 gigaset_at_init(&cs->at_state, NULL, cs, 0);
724 cs->dle = 0;
725 cs->cbytes = 0;
728 gigaset_inbuf_init(cs->inbuf, cs);
730 cs->connected = 0;
731 cs->isdn_up = 0;
734 cs->cmdbuf = cs->lastcmdbuf = NULL;
735 spin_lock_init(&cs->cmdlock);
736 cs->curlen = 0;
737 cs->cmdbytes = 0;
740 if (gigaset_isdn_regdev(cs, modulename) < 0) {
745 make_valid(cs, VALID_ID);
746 ++cs->cs_init;
748 if (cs->ops->initcshw(cs) < 0)
751 ++cs->cs_init;
754 gigaset_if_init(cs);
757 gigaset_init_dev_sysfs(cs);
762 if (gigaset_initbcs(cs->bcs + i, cs, i) < 0) {
768 spin_lock_irqsave(&cs->lock, flags);
769 cs->running = 1;
770 spin_unlock_irqrestore(&cs->lock, flags);
771 setup_timer(&cs->timer, timer_tick, (unsigned long) cs);
772 cs->timer.expires = jiffies + msecs_to_jiffies(GIG_TICK);
773 add_timer(&cs->timer);
775 gig_dbg(DEBUG_INIT, "cs initialized");
776 return cs;
780 gigaset_freecs(cs);
789 struct cardstate *cs = bcs->cs;
795 spin_lock_irqsave(&cs->lock, flags);
801 spin_unlock_irqrestore(&cs->lock, flags);
812 bcs->ignore = cs->ignoreframes;
816 cs->ops->reinitbcshw(bcs);
819 static void cleanup_cs(struct cardstate *cs)
825 spin_lock_irqsave(&cs->lock, flags);
827 cs->mode = M_UNKNOWN;
828 cs->mstate = MS_UNINITIALIZED;
830 clear_at_state(&cs->at_state);
831 dealloc_temp_at_states(cs);
832 gigaset_at_init(&cs->at_state, NULL, cs, 0);
834 cs->inbuf->inputstate = INS_command;
835 cs->inbuf->head = 0;
836 cs->inbuf->tail = 0;
838 cb = cs->cmdbuf;
844 cs->cmdbuf = cs->lastcmdbuf = NULL;
845 cs->curlen = 0;
846 cs->cmdbytes = 0;
847 cs->gotfwver = -1;
848 cs->dle = 0;
849 cs->cur_at_seq = 0;
850 cs->commands_pending = 0;
851 cs->cbytes = 0;
853 spin_unlock_irqrestore(&cs->lock, flags);
855 for (i = 0; i < cs->channels; ++i) {
856 gigaset_freebcs(cs->bcs + i);
857 if (gigaset_initbcs(cs->bcs + i, cs, i) < 0)
861 if (cs->waiting) {
862 cs->cmd_result = -ENODEV;
863 cs->waiting = 0;
864 wake_up_interruptible(&cs->waitqueue);
871 * @cs: device descriptor structure.
880 int gigaset_start(struct cardstate *cs)
884 if (mutex_lock_interruptible(&cs->mutex))
887 spin_lock_irqsave(&cs->lock, flags);
888 cs->connected = 1;
889 spin_unlock_irqrestore(&cs->lock, flags);
891 if (cs->mstate != MS_LOCKED) {
892 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR | TIOCM_RTS);
893 cs->ops->baud_rate(cs, B115200);
894 cs->ops->set_line_ctrl(cs, CS8);
895 cs->control_state = TIOCM_DTR | TIOCM_RTS;
898 cs->waiting = 1;
900 if (!gigaset_add_event(cs, &cs->at_state, EV_START, NULL, 0, NULL)) {
901 cs->waiting = 0;
904 gigaset_schedule_event(cs);
906 wait_event(cs->waitqueue, !cs->waiting);
908 mutex_unlock(&cs->mutex);
912 mutex_unlock(&cs->mutex);
919 * @cs: device descriptor structure.
927 int gigaset_shutdown(struct cardstate *cs)
929 mutex_lock(&cs->mutex);
931 if (!(cs->flags & VALID_MINOR)) {
932 mutex_unlock(&cs->mutex);
936 cs->waiting = 1;
938 if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL))
940 gigaset_schedule_event(cs);
942 wait_event(cs->waitqueue, !cs->waiting);
944 cleanup_cs(cs);
947 mutex_unlock(&cs->mutex);
954 * @cs: device descriptor structure.
959 void gigaset_stop(struct cardstate *cs)
961 mutex_lock(&cs->mutex);
963 cs->waiting = 1;
965 if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL))
967 gigaset_schedule_event(cs);
969 wait_event(cs->waitqueue, !cs->waiting);
971 cleanup_cs(cs);
974 mutex_unlock(&cs->mutex);
985 struct cardstate *cs;
993 cs = drv->cs + i;
994 if ((cs->flags & VALID_ID) && cs->myid == id) {
995 ret = cs;
1020 if (drv->cs[index].flags & VALID_MINOR)
1021 ret = drv->cs + index;
1053 kfree(drv->cs);
1093 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1094 if (!drv->cs)
1098 drv->cs[i].flags = 0;
1099 drv->cs[i].driver = drv;
1100 drv->cs[i].ops = drv->ops;
1101 drv->cs[i].minor_index = i;
1102 mutex_init(&drv->cs[i].mutex);