17 #include <linux/module.h>
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 ""
37 #define VALID_MINOR 0x01
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);
115 r = setflags(cs, 0, 200);
118 for (i = 0; i < 5; ++
i) {
122 r = setflags(cs, 0, 100);
133 dev_err(cs->
dev,
"error %d on setuartbits\n", -r);
140 static int test_timeout(
struct at_state_t *at_state)
167 if (test_timeout(&cs->
bcs[channel].at_state))
174 if (test_timeout(at_state))
185 spin_unlock_irqrestore(&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);
212 if (!try_module_get(cs->
driver->owner)) {
214 "could not get module for allocating channel");
215 spin_unlock_irqrestore(&cs->
lock, flags);
219 if (!cs->
bcs[i].use_count) {
220 ++cs->
bcs[
i].use_count;
222 spin_unlock_irqrestore(&cs->
lock, flags);
226 module_put(cs->
driver->owner);
227 spin_unlock_irqrestore(&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);
257 if (cs->
bcs[i].use_count) {
258 spin_unlock_irqrestore(&cs->
lock, flags);
260 "could not allocate all channels");
264 ++cs->
bcs[i].use_count;
265 spin_unlock_irqrestore(&cs->
lock, flags);
280 --cs->
bcs[i].use_count;
281 spin_unlock_irqrestore(&cs->
lock, flags);
292 ++cs->
bcs[i].use_count;
293 spin_unlock_irqrestore(&cs->
lock, flags);
296 static void clear_events(
struct cardstate *cs)
307 while (tail != head) {
315 spin_unlock_irqrestore(&cs->
ev_lock, flags);
359 spin_unlock_irqrestore(&cs->
ev_lock, flags);
365 static void clear_at_state(
struct at_state_t *at_state)
375 static void dealloc_temp_at_states(
struct cardstate *cs)
391 bcs->
cs->ops->freebcshw(bcs);
396 dev_kfree_skb(bcs->
rx_skb);
415 for (i = 0; i < drv->
minors; ++
i) {
424 spin_unlock_irqrestore(&drv->
lock, flags);
428 static void free_cs(
struct cardstate *cs)
439 spin_unlock_irqrestore(&drv->
lock, flags);
442 static void make_invalid(
struct cardstate *cs,
unsigned mask)
448 spin_unlock_irqrestore(&drv->
lock, flags);
477 spin_unlock_irqrestore(&cs->
lock, flags);
488 gigaset_freebcs(cs->
bcs + i);
497 cs->
ops->freecshw(cs);
509 dealloc_temp_at_states(cs);
530 INIT_LIST_HEAD(&at_state->
list);
581 bytesleft = numbytes;
595 "buffer overflow (%u bytes lost)\n",
608 return numbytes != bytesleft;
620 skb_queue_head_init(&bcs->
squeue);
629 #ifdef CONFIG_GIGASET_DEBUG
653 return cs->
ops->initbcshw(bcs);
676 int cidmode,
const char *modulename)
685 pr_err(
"maximum number of devices exceeded\n");
692 pr_err(
"out of memory\n");
698 pr_err(
"out of memory\n");
716 cs->commands_pending = 0;
721 cs->cidmode = cidmode != 0;
740 gigaset_inbuf_init(cs->inbuf, cs);
746 cs->cmdbuf = cs->lastcmdbuf =
NULL;
753 pr_err(
"error registering ISDN device\n");
760 if (cs->ops->initcshw(cs) < 0)
774 if (gigaset_initbcs(cs->bcs + i, cs, i) < 0) {
775 pr_err(
"could not allocate channel %d data\n", i);
782 spin_unlock_irqrestore(&cs->lock, flags);
813 spin_unlock_irqrestore(&cs->
lock, flags);
817 #ifdef CONFIG_GIGASET_DEBUG
825 dev_kfree_skb(bcs->
rx_skb);
828 cs->
ops->reinitbcshw(bcs);
831 static void cleanup_cs(
struct cardstate *cs)
843 dealloc_temp_at_states(cs);
865 spin_unlock_irqrestore(&cs->
lock, flags);
868 gigaset_freebcs(cs->
bcs + i);
869 if (gigaset_initbcs(cs->
bcs + i, cs, i) < 0)
870 pr_err(
"could not allocate channel %d data\n", i);
901 spin_unlock_irqrestore(&cs->
lock, flags);
906 cs->
ops->set_line_ctrl(cs,
CS8);
916 gigaset_schedule_event(cs);
952 gigaset_schedule_event(cs);
979 gigaset_schedule_event(cs);
1003 spin_lock(&drv->
lock);
1004 for (i = 0; i < drv->
minors; ++
i) {
1011 spin_unlock(&drv->
lock);
1015 spin_unlock_irqrestore(&driver_lock, flags);
1019 static struct cardstate *gigaset_get_cs_by_minor(
unsigned minor)
1021 unsigned long flags;
1028 if (minor < drv->minor || minor >= drv->
minor + drv->
minors)
1030 index = minor - drv->
minor;
1031 spin_lock(&drv->
lock);
1034 spin_unlock(&drv->
lock);
1038 spin_unlock_irqrestore(&driver_lock, flags);
1044 return gigaset_get_cs_by_minor(tty->
index + tty->
driver->minor_start);
1057 unsigned long flags;
1061 spin_unlock_irqrestore(&driver_lock, flags);
1083 const char *procname,
1084 const char *devname,
1089 unsigned long flags;
1103 INIT_LIST_HEAD(&drv->
list);
1109 for (i = 0; i <
minors; ++
i) {
1110 drv->
cs[
i].flags = 0;
1111 drv->
cs[
i].driver = drv;
1112 drv->
cs[
i].ops = drv->
ops;
1113 drv->
cs[
i].minor_index =
i;
1120 list_add(&drv->
list, &drivers);
1121 spin_unlock_irqrestore(&driver_lock, flags);
1144 static int __init gigaset_init_module(
void)
1158 static void __exit gigaset_exit_module(
void)