st5481_init.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Driver for ST5481 USB ISDN modem
  3. *
  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.
  10. *
  11. */
  12. /*
  13. * TODO:
  14. *
  15. * b layer1 delay?
  16. * hotplug / unregister issues
  17. * mod_inc/dec_use_count
  18. * unify parts of d/b channel usb handling
  19. * file header
  20. * avoid copy to isoc buffer?
  21. * improve usb delay?
  22. * merge l1 state machines?
  23. * clean up debug
  24. */
  25. #include <linux/config.h>
  26. #include <linux/version.h>
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/usb.h>
  30. #include <linux/slab.h>
  31. #include "st5481.h"
  32. MODULE_DESCRIPTION("ISDN4Linux: driver for ST5481 USB ISDN adapter");
  33. MODULE_AUTHOR("Frode Isaksen");
  34. MODULE_LICENSE("GPL");
  35. static int protocol = 2; /* EURO-ISDN Default */
  36. module_param(protocol, int, 0);
  37. static int number_of_leds = 2; /* 2 LEDs on the adpater default */
  38. module_param(number_of_leds, int, 0);
  39. #ifdef CONFIG_HISAX_DEBUG
  40. static int debug = 0x1;
  41. module_param(debug, int, 0);
  42. int st5481_debug;
  43. #endif
  44. static LIST_HEAD(adapter_list);
  45. /* ======================================================================
  46. * registration/deregistration with the USB layer
  47. */
  48. /*
  49. * This function will be called when the adapter is plugged
  50. * into the USB bus.
  51. */
  52. static int probe_st5481(struct usb_interface *intf,
  53. const struct usb_device_id *id)
  54. {
  55. struct usb_device *dev = interface_to_usbdev(intf);
  56. struct st5481_adapter *adapter;
  57. struct hisax_b_if *b_if[2];
  58. int retval, i;
  59. printk(KERN_INFO "st541: found adapter VendorId %04x, ProductId %04x, LEDs %d\n",
  60. le16_to_cpu(dev->descriptor.idVendor),
  61. le16_to_cpu(dev->descriptor.idProduct),
  62. number_of_leds);
  63. adapter = kmalloc(sizeof(struct st5481_adapter), GFP_KERNEL);
  64. if (!adapter)
  65. return -ENOMEM;
  66. memset(adapter, 0, sizeof(struct st5481_adapter));
  67. adapter->number_of_leds = number_of_leds;
  68. adapter->usb_dev = dev;
  69. adapter->hisax_d_if.owner = THIS_MODULE;
  70. adapter->hisax_d_if.ifc.priv = adapter;
  71. adapter->hisax_d_if.ifc.l2l1 = st5481_d_l2l1;
  72. for (i = 0; i < 2; i++) {
  73. adapter->bcs[i].adapter = adapter;
  74. adapter->bcs[i].channel = i;
  75. adapter->bcs[i].b_if.ifc.priv = &adapter->bcs[i];
  76. adapter->bcs[i].b_if.ifc.l2l1 = st5481_b_l2l1;
  77. }
  78. list_add(&adapter->list, &adapter_list);
  79. retval = st5481_setup_usb(adapter);
  80. if (retval < 0)
  81. goto err;
  82. retval = st5481_setup_d(adapter);
  83. if (retval < 0)
  84. goto err_usb;
  85. retval = st5481_setup_b(&adapter->bcs[0]);
  86. if (retval < 0)
  87. goto err_d;
  88. retval = st5481_setup_b(&adapter->bcs[1]);
  89. if (retval < 0)
  90. goto err_b;
  91. for (i = 0; i < 2; i++)
  92. b_if[i] = &adapter->bcs[i].b_if;
  93. hisax_register(&adapter->hisax_d_if, b_if, "st5481_usb", protocol);
  94. st5481_start(adapter);
  95. usb_set_intfdata(intf, adapter);
  96. return 0;
  97. err_b:
  98. st5481_release_b(&adapter->bcs[0]);
  99. err_d:
  100. st5481_release_d(adapter);
  101. err_usb:
  102. st5481_release_usb(adapter);
  103. err:
  104. return -EIO;
  105. }
  106. /*
  107. * This function will be called when the adapter is removed
  108. * from the USB bus.
  109. */
  110. static void disconnect_st5481(struct usb_interface *intf)
  111. {
  112. struct st5481_adapter *adapter = usb_get_intfdata(intf);
  113. DBG(1,"");
  114. usb_set_intfdata(intf, NULL);
  115. if (!adapter)
  116. return;
  117. list_del(&adapter->list);
  118. st5481_stop(adapter);
  119. st5481_release_b(&adapter->bcs[1]);
  120. st5481_release_b(&adapter->bcs[0]);
  121. st5481_release_d(adapter);
  122. // we would actually better wait for completion of outstanding urbs
  123. mdelay(2);
  124. st5481_release_usb(adapter);
  125. hisax_unregister(&adapter->hisax_d_if);
  126. kfree(adapter);
  127. }
  128. /*
  129. * The last 4 bits in the Product Id is set with 4 pins on the chip.
  130. */
  131. static struct usb_device_id st5481_ids[] = {
  132. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x0) },
  133. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x1) },
  134. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x2) },
  135. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x3) },
  136. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x4) },
  137. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x5) },
  138. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x6) },
  139. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x7) },
  140. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x8) },
  141. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0x9) },
  142. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xA) },
  143. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xB) },
  144. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xC) },
  145. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xD) },
  146. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xE) },
  147. { USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID+0xF) },
  148. { }
  149. };
  150. MODULE_DEVICE_TABLE (usb, st5481_ids);
  151. static struct usb_driver st5481_usb_driver = {
  152. .owner = THIS_MODULE,
  153. .name = "st5481_usb",
  154. .probe = probe_st5481,
  155. .disconnect = disconnect_st5481,
  156. .id_table = st5481_ids,
  157. };
  158. static int __init st5481_usb_init(void)
  159. {
  160. int retval;
  161. #ifdef CONFIG_HISAX_DEBUG
  162. st5481_debug = debug;
  163. #endif
  164. printk(KERN_INFO "hisax_st5481: ST5481 USB ISDN driver $Revision: 2.4.2.3 $\n");
  165. retval = st5481_d_init();
  166. if (retval < 0)
  167. goto out;
  168. retval = usb_register(&st5481_usb_driver);
  169. if (retval < 0)
  170. goto out_d_exit;
  171. return 0;
  172. out_d_exit:
  173. st5481_d_exit();
  174. out:
  175. return retval;
  176. }
  177. static void __exit st5481_usb_exit(void)
  178. {
  179. usb_deregister(&st5481_usb_driver);
  180. st5481_d_exit();
  181. }
  182. module_init(st5481_usb_init);
  183. module_exit(st5481_usb_exit);