Linux 2.6.21.1
[linux/fpc-iii.git] / drivers / isdn / hisax / st5481_init.c
blobbb3a28a53ff4de2536b06095a54f2516832cef25
1 /*
2 * Driver for ST5481 USB ISDN modem
4 * Author Frode Isaksen
5 * Copyright 2001 by Frode Isaksen <fisaksen@bewan.com>
6 * 2001 by Kai Germaschewski <kai.germaschewski@gmx.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 /*
14 * TODO:
16 * b layer1 delay?
17 * hotplug / unregister issues
18 * mod_inc/dec_use_count
19 * unify parts of d/b channel usb handling
20 * file header
21 * avoid copy to isoc buffer?
22 * improve usb delay?
23 * merge l1 state machines?
24 * clean up debug
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/usb.h>
30 #include <linux/slab.h>
31 #include "st5481.h"
33 MODULE_DESCRIPTION("ISDN4Linux: driver for ST5481 USB ISDN adapter");
34 MODULE_AUTHOR("Frode Isaksen");
35 MODULE_LICENSE("GPL");
37 static int protocol = 2; /* EURO-ISDN Default */
38 module_param(protocol, int, 0);
40 static int number_of_leds = 2; /* 2 LEDs on the adpater default */
41 module_param(number_of_leds, int, 0);
43 #ifdef CONFIG_HISAX_DEBUG
44 static int debug = 0;
45 module_param(debug, int, 0);
46 #endif
47 int st5481_debug;
49 static LIST_HEAD(adapter_list);
51 /* ======================================================================
52 * registration/deregistration with the USB layer
56 * This function will be called when the adapter is plugged
57 * into the USB bus.
59 static int probe_st5481(struct usb_interface *intf,
60 const struct usb_device_id *id)
62 struct usb_device *dev = interface_to_usbdev(intf);
63 struct st5481_adapter *adapter;
64 struct hisax_b_if *b_if[2];
65 int retval, i;
67 printk(KERN_INFO "st541: found adapter VendorId %04x, ProductId %04x, LEDs %d\n",
68 le16_to_cpu(dev->descriptor.idVendor),
69 le16_to_cpu(dev->descriptor.idProduct),
70 number_of_leds);
72 adapter = kzalloc(sizeof(struct st5481_adapter), GFP_KERNEL);
73 if (!adapter)
74 return -ENOMEM;
76 adapter->number_of_leds = number_of_leds;
77 adapter->usb_dev = dev;
79 adapter->hisax_d_if.owner = THIS_MODULE;
80 adapter->hisax_d_if.ifc.priv = adapter;
81 adapter->hisax_d_if.ifc.l2l1 = st5481_d_l2l1;
83 for (i = 0; i < 2; i++) {
84 adapter->bcs[i].adapter = adapter;
85 adapter->bcs[i].channel = i;
86 adapter->bcs[i].b_if.ifc.priv = &adapter->bcs[i];
87 adapter->bcs[i].b_if.ifc.l2l1 = st5481_b_l2l1;
89 list_add(&adapter->list, &adapter_list);
91 retval = st5481_setup_usb(adapter);
92 if (retval < 0)
93 goto err;
95 retval = st5481_setup_d(adapter);
96 if (retval < 0)
97 goto err_usb;
99 retval = st5481_setup_b(&adapter->bcs[0]);
100 if (retval < 0)
101 goto err_d;
103 retval = st5481_setup_b(&adapter->bcs[1]);
104 if (retval < 0)
105 goto err_b;
107 for (i = 0; i < 2; i++)
108 b_if[i] = &adapter->bcs[i].b_if;
110 hisax_register(&adapter->hisax_d_if, b_if, "st5481_usb", protocol);
111 st5481_start(adapter);
113 usb_set_intfdata(intf, adapter);
114 return 0;
116 err_b:
117 st5481_release_b(&adapter->bcs[0]);
118 err_d:
119 st5481_release_d(adapter);
120 err_usb:
121 st5481_release_usb(adapter);
122 err:
123 return -EIO;
127 * This function will be called when the adapter is removed
128 * from the USB bus.
130 static void disconnect_st5481(struct usb_interface *intf)
132 struct st5481_adapter *adapter = usb_get_intfdata(intf);
134 DBG(1,"");
136 usb_set_intfdata(intf, NULL);
137 if (!adapter)
138 return;
140 list_del(&adapter->list);
142 st5481_stop(adapter);
143 st5481_release_b(&adapter->bcs[1]);
144 st5481_release_b(&adapter->bcs[0]);
145 st5481_release_d(adapter);
146 // we would actually better wait for completion of outstanding urbs
147 mdelay(2);
148 st5481_release_usb(adapter);
150 hisax_unregister(&adapter->hisax_d_if);
152 kfree(adapter);
156 * The last 4 bits in the Product Id is set with 4 pins on the chip.
158 static struct usb_device_id st5481_ids[] = {
159 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x0) },
160 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x1) },
161 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x2) },
162 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x3) },
163 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x4) },
164 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x5) },
165 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x6) },
166 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x7) },
167 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x8) },
168 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x9) },
169 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xA) },
170 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xB) },
171 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xC) },
172 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xD) },
173 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xE) },
174 { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xF) },
177 MODULE_DEVICE_TABLE (usb, st5481_ids);
179 static struct usb_driver st5481_usb_driver = {
180 .name = "st5481_usb",
181 .probe = probe_st5481,
182 .disconnect = disconnect_st5481,
183 .id_table = st5481_ids,
186 static int __init st5481_usb_init(void)
188 int retval;
190 #ifdef CONFIG_HISAX_DEBUG
191 st5481_debug = debug;
192 #endif
194 printk(KERN_INFO "hisax_st5481: ST5481 USB ISDN driver $Revision: 2.4.2.3 $\n");
196 retval = st5481_d_init();
197 if (retval < 0)
198 goto out;
200 retval = usb_register(&st5481_usb_driver);
201 if (retval < 0)
202 goto out_d_exit;
204 return 0;
206 out_d_exit:
207 st5481_d_exit();
208 out:
209 return retval;
212 static void __exit st5481_usb_exit(void)
214 usb_deregister(&st5481_usb_driver);
215 st5481_d_exit();
218 module_init(st5481_usb_init);
219 module_exit(st5481_usb_exit);