st5481_init.c 5.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
/*
 * Driver for ST5481 USB ISDN modem
 *
 * Author       Frode Isaksen
 * Copyright    2001 by Frode Isaksen      <fisaksen@bewan.com>
 *              2001 by Kai Germaschewski  <kai.germaschewski@gmx.de>
7
 *
L
Linus Torvalds 已提交
8 9 10 11 12
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 *
 */

13
/*
L
Linus Torvalds 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 * TODO:
 *
 * b layer1 delay?
 * hotplug / unregister issues
 * mod_inc/dec_use_count
 * unify parts of d/b channel usb handling
 * file header
 * avoid copy to isoc buffer?
 * improve usb delay?
 * merge l1 state machines?
 * clean up debug
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/usb.h>
#include <linux/slab.h>
#include "st5481.h"

MODULE_DESCRIPTION("ISDN4Linux: driver for ST5481 USB ISDN adapter");
MODULE_AUTHOR("Frode Isaksen");
MODULE_LICENSE("GPL");

static int protocol = 2;       /* EURO-ISDN Default */
module_param(protocol, int, 0);

static int number_of_leds = 2;       /* 2 LEDs on the adpater default */
module_param(number_of_leds, int, 0);

#ifdef CONFIG_HISAX_DEBUG
K
Karsten Keil 已提交
44
static int debug = 0;
L
Linus Torvalds 已提交
45 46
module_param(debug, int, 0);
#endif
K
Karsten Keil 已提交
47
int st5481_debug;
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

/* ======================================================================
 * registration/deregistration with the USB layer
 */

/*
 * This function will be called when the adapter is plugged
 * into the USB bus.
 */
static int probe_st5481(struct usb_interface *intf,
			const struct usb_device_id *id)
{
	struct usb_device *dev = interface_to_usbdev(intf);
	struct st5481_adapter *adapter;
	struct hisax_b_if *b_if[2];
	int retval, i;

	printk(KERN_INFO "st541: found adapter VendorId %04x, ProductId %04x, LEDs %d\n",
66 67 68
	       le16_to_cpu(dev->descriptor.idVendor),
	       le16_to_cpu(dev->descriptor.idProduct),
	       number_of_leds);
L
Linus Torvalds 已提交
69

70
	adapter = kzalloc(sizeof(struct st5481_adapter), GFP_KERNEL);
L
Linus Torvalds 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
	if (!adapter)
		return -ENOMEM;

	adapter->number_of_leds = number_of_leds;
	adapter->usb_dev = dev;

	adapter->hisax_d_if.owner = THIS_MODULE;
	adapter->hisax_d_if.ifc.priv = adapter;
	adapter->hisax_d_if.ifc.l2l1 = st5481_d_l2l1;

	for (i = 0; i < 2; i++) {
		adapter->bcs[i].adapter = adapter;
		adapter->bcs[i].channel = i;
		adapter->bcs[i].b_if.ifc.priv = &adapter->bcs[i];
		adapter->bcs[i].b_if.ifc.l2l1 = st5481_b_l2l1;
	}

	retval = st5481_setup_usb(adapter);
	if (retval < 0)
		goto err;

	retval = st5481_setup_d(adapter);
	if (retval < 0)
		goto err_usb;

	retval = st5481_setup_b(&adapter->bcs[0]);
	if (retval < 0)
		goto err_d;

	retval = st5481_setup_b(&adapter->bcs[1]);
	if (retval < 0)
		goto err_b;

	for (i = 0; i < 2; i++)
		b_if[i] = &adapter->bcs[i].b_if;

107
	if (hisax_register(&adapter->hisax_d_if, b_if, "st5481_usb",
108
			   protocol) != 0)
109 110
		goto err_b1;

L
Linus Torvalds 已提交
111 112 113 114 115
	st5481_start(adapter);

	usb_set_intfdata(intf, adapter);
	return 0;

116
err_b1:
117
	st5481_release_b(&adapter->bcs[1]);
118
err_b:
L
Linus Torvalds 已提交
119
	st5481_release_b(&adapter->bcs[0]);
120
err_d:
L
Linus Torvalds 已提交
121
	st5481_release_d(adapter);
122
err_usb:
L
Linus Torvalds 已提交
123
	st5481_release_usb(adapter);
124
err:
125
	kfree(adapter);
L
Linus Torvalds 已提交
126 127 128 129 130 131 132 133 134 135 136
	return -EIO;
}

/*
 * This function will be called when the adapter is removed
 * from the USB bus.
 */
static void disconnect_st5481(struct usb_interface *intf)
{
	struct st5481_adapter *adapter = usb_get_intfdata(intf);

137
	DBG(1, "");
L
Linus Torvalds 已提交
138 139 140 141

	usb_set_intfdata(intf, NULL);
	if (!adapter)
		return;
142

L
Linus Torvalds 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
	st5481_stop(adapter);
	st5481_release_b(&adapter->bcs[1]);
	st5481_release_b(&adapter->bcs[0]);
	st5481_release_d(adapter);
	// we would actually better wait for completion of outstanding urbs
	mdelay(2);
	st5481_release_usb(adapter);

	hisax_unregister(&adapter->hisax_d_if);

	kfree(adapter);
}

/*
 * The last 4 bits in the Product Id is set with 4 pins on the chip.
 */
static struct usb_device_id st5481_ids[] = {
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x0) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x1) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x2) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x3) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x4) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x5) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x6) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x7) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x8) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0x9) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0xA) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0xB) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0xC) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0xD) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0xE) },
	{ USB_DEVICE(ST_VENDOR_ID, ST5481_PRODUCT_ID + 0xF) },
L
Linus Torvalds 已提交
176 177
	{ }
};
178
MODULE_DEVICE_TABLE(usb, st5481_ids);
L
Linus Torvalds 已提交
179 180 181 182 183 184

static struct usb_driver st5481_usb_driver = {
	.name =		"st5481_usb",
	.probe =	probe_st5481,
	.disconnect =	disconnect_st5481,
	.id_table =	st5481_ids,
185
	.disable_hub_initiated_lpm = 1,
L
Linus Torvalds 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
};

static int __init st5481_usb_init(void)
{
	int retval;

#ifdef CONFIG_HISAX_DEBUG
	st5481_debug = debug;
#endif

	printk(KERN_INFO "hisax_st5481: ST5481 USB ISDN driver $Revision: 2.4.2.3 $\n");

	retval = st5481_d_init();
	if (retval < 0)
		goto out;

	retval = usb_register(&st5481_usb_driver);
	if (retval < 0)
		goto out_d_exit;

	return 0;

208
out_d_exit:
L
Linus Torvalds 已提交
209
	st5481_d_exit();
210
out:
L
Linus Torvalds 已提交
211 212 213 214 215 216 217 218 219 220 221
	return retval;
}

static void __exit st5481_usb_exit(void)
{
	usb_deregister(&st5481_usb_driver);
	st5481_d_exit();
}

module_init(st5481_usb_init);
module_exit(st5481_usb_exit);