2 * Driver for ST5481 USB ISDN modem
5 * Copyright 2001 by Frode Isaksen <fisaksen@bewan.com>
6 * 2001 by Kai Germaschewski <kai.germaschewski@gmx.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
17 * hotplug / unregister issues
18 * mod_inc/dec_use_count
19 * unify parts of d/b channel usb handling
21 * avoid copy to isoc buffer?
23 * merge l1 state machines?
27 #include <linux/config.h>
28 #include <linux/version.h>
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/usb.h>
32 #include <linux/slab.h>
35 MODULE_DESCRIPTION("ISDN4Linux: driver for ST5481 USB ISDN adapter");
36 MODULE_AUTHOR("Frode Isaksen");
37 MODULE_LICENSE("GPL");
39 static int protocol = 2; /* EURO-ISDN Default */
40 module_param(protocol, int, 0);
42 static int number_of_leds = 2; /* 2 LEDs on the adpater default */
43 module_param(number_of_leds, int, 0);
45 #ifdef CONFIG_HISAX_DEBUG
47 module_param(debug, int, 0);
51 static LIST_HEAD(adapter_list);
53 /* ======================================================================
54 * registration/deregistration with the USB layer
58 * This function will be called when the adapter is plugged
61 static int probe_st5481(struct usb_interface *intf,
62 const struct usb_device_id *id)
64 struct usb_device *dev = interface_to_usbdev(intf);
65 struct st5481_adapter *adapter;
66 struct hisax_b_if *b_if[2];
69 printk(KERN_INFO "st541: found adapter VendorId %04x, ProductId %04x, LEDs %d\n",
70 le16_to_cpu(dev->descriptor.idVendor),
71 le16_to_cpu(dev->descriptor.idProduct),
74 adapter = kmalloc(sizeof(struct st5481_adapter), GFP_KERNEL);
78 memset(adapter, 0, sizeof(struct st5481_adapter));
80 adapter->number_of_leds = number_of_leds;
81 adapter->usb_dev = dev;
83 adapter->hisax_d_if.owner = THIS_MODULE;
84 adapter->hisax_d_if.ifc.priv = adapter;
85 adapter->hisax_d_if.ifc.l2l1 = st5481_d_l2l1;
87 for (i = 0; i < 2; i++) {
88 adapter->bcs[i].adapter = adapter;
89 adapter->bcs[i].channel = i;
90 adapter->bcs[i].b_if.ifc.priv = &adapter->bcs[i];
91 adapter->bcs[i].b_if.ifc.l2l1 = st5481_b_l2l1;
93 list_add(&adapter->list, &adapter_list);
95 retval = st5481_setup_usb(adapter);
99 retval = st5481_setup_d(adapter);
103 retval = st5481_setup_b(&adapter->bcs[0]);
107 retval = st5481_setup_b(&adapter->bcs[1]);
111 for (i = 0; i < 2; i++)
112 b_if[i] = &adapter->bcs[i].b_if;
114 hisax_register(&adapter->hisax_d_if, b_if, "st5481_usb", protocol);
115 st5481_start(adapter);
117 usb_set_intfdata(intf, adapter);
121 st5481_release_b(&adapter->bcs[0]);
123 st5481_release_d(adapter);
125 st5481_release_usb(adapter);
131 * This function will be called when the adapter is removed
134 static void disconnect_st5481(struct usb_interface *intf)
136 struct st5481_adapter *adapter = usb_get_intfdata(intf);
140 usb_set_intfdata(intf, NULL);
144 list_del(&adapter->list);
146 st5481_stop(adapter);
147 st5481_release_b(&adapter->bcs[1]);
148 st5481_release_b(&adapter->bcs[0]);
149 st5481_release_d(adapter);
150 // we would actually better wait for completion of outstanding urbs
152 st5481_release_usb(adapter);
154 hisax_unregister(&adapter->hisax_d_if);
160 * The last 4 bits in the Product Id is set with 4 pins on the chip.
162 static struct usb_device_id st5481_ids[] = {
163 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x0) },
164 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x1) },
165 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x2) },
166 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x3) },
167 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x4) },
168 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x5) },
169 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x6) },
170 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x7) },
171 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x8) },
172 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x9) },
173 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xA) },
174 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xB) },
175 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xC) },
176 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xD) },
177 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xE) },
178 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xF) },
181 MODULE_DEVICE_TABLE (usb, st5481_ids);
183 static struct usb_driver st5481_usb_driver = {
184 .owner = THIS_MODULE,
185 .name = "st5481_usb",
186 .probe = probe_st5481,
187 .disconnect = disconnect_st5481,
188 .id_table = st5481_ids,
191 static int __init st5481_usb_init(void)
195 #ifdef CONFIG_HISAX_DEBUG
196 st5481_debug = debug;
199 printk(KERN_INFO "hisax_st5481: ST5481 USB ISDN driver $Revision: 2.4.2.3 $\n");
201 retval = st5481_d_init();
205 retval = usb_register(&st5481_usb_driver);
217 static void __exit st5481_usb_exit(void)
219 usb_deregister(&st5481_usb_driver);
223 module_init(st5481_usb_init);
224 module_exit(st5481_usb_exit);