usbatm cxacru2.c,1.2,1.3

kagan at infradead.org kagan at infradead.org
Thu Jan 27 03:35:54 EST 2005


Update of /home/cvs/usbatm
In directory phoenix.infradead.org:/tmp/cvs-serv9038

Modified Files:
	cxacru2.c 
Log Message:
Update to the new API.


Index: cxacru2.c
===================================================================
RCS file: /home/cvs/usbatm/cxacru2.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- cxacru2.c	20 Jan 2005 21:58:06 -0000	1.2
+++ cxacru2.c	27 Jan 2005 08:35:51 -0000	1.3
@@ -25,21 +25,18 @@
 #include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/errno.h>
-#include <linux/proc_fs.h>
 #include <linux/slab.h>
 #include <linux/wait.h>
-#include <linux/list.h>
 #include <asm/processor.h>
 #include <asm/uaccess.h>
 #include <linux/smp_lock.h>
 #include <linux/interrupt.h>
 #include <linux/atm.h>
 #include <linux/atmdev.h>
-#include <linux/crc32.h>
 #include <linux/init.h>
 #include <linux/firmware.h>
 
-#include "cxacru2.h"
+#include "usbatm.h"
 
 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
 #	define USE_FW_LOADER
@@ -51,9 +48,6 @@
 
 static const char cxacru_driver_name[] = "cxacru";
 
-#define UDSL_IOCTL_LINE_UP		1
-#define UDSL_IOCTL_LINE_DOWN		2
-
 #define CXACRU_EP_CMD		0x01	/* Bulk/interrupt in/out */
 #define CXACRU_EP_DATA		0x02	/* Bulk in/out */
 
@@ -159,17 +153,13 @@
 	CXINF_MAX = 0x1c,
 };
 
-struct cxacru_instance_data {
-	struct usbatm_data u;
-
-	struct semaphore start_serialize;
-#ifdef USE_FW_LOADER
-	int firmware_start_run;
-#endif
+struct cxacru_data {
+	struct usbatm_data *usbatm;
 
 	int line_status; 
 	struct work_struct poll_work;
 	struct timer_list poll_timer;
+
 	/* contol handles */
 	struct semaphore cm_serialize;
 	u8 *rcv_buf;
@@ -213,7 +203,7 @@
 	return status;
 }
 
-static int cxacru_cm(struct cxacru_instance_data *instance, enum cxacru_cm_request cm,
+static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
 		     u8 *wdata, int wsize, u8 *rdata, int rsize)
 {
 	int ret, actlen;
@@ -303,7 +293,7 @@
 	return ret;
 }
 
-static int cxacru_cm_get_array(struct cxacru_instance_data *instance, enum cxacru_cm_request cm,
+static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
 			       u32 *data, int size)
 {
 	int ret, len;
@@ -347,7 +337,7 @@
 	return ret;
 }
 
-static void cxacru_do_timer_poll(struct cxacru_instance_data *instance)
+static void cxacru_do_timer_poll(struct cxacru_data *instance)
 {
 	schedule_work(&instance->poll_work);
 	mod_timer(&instance->poll_timer, jiffies + (5 * HZ));
@@ -355,80 +345,61 @@
 
 static void cxacru_timer_poll(unsigned long data)
 {
-	cxacru_do_timer_poll((struct cxacru_instance_data *)data);
+	cxacru_do_timer_poll((struct cxacru_data *)data);
 }
 
-#ifdef USE_FW_LOADER
-static void cxacru_firmware_start(struct cxacru_instance_data *instance);
-#endif
+static int cxacru_card_status(struct cxacru_data *instance)
+{
+	int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
+	if (ret < 0) {		/* firmware not loaded */
+		dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
+		return ret;
+	}
+	return 0;
+}
 
-static void cxacru_adsl_start(struct cxacru_instance_data *instance)
+static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
+		struct atm_dev *atm_dev)
 {
+	struct cxacru_data *instance = usbatm_instance->driver_data;
+	struct device *dev = &usbatm_instance->usb_intf->dev;
+	/*
+	struct atm_dev *atm_dev = usbatm_instance->atm_dev;
+	*/
 	int ret;
 
-	dbg("cxacru_adsl_start");
-	down(&instance->start_serialize);
-
-	if (!instance->u.atm_dev) {	/* ! fully initialised */
-		u8 esi[sizeof(instance->u.atm_dev->esi)] = {};
+	dbg("cxacru_atm_start");
 
-		ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
-		if (ret < 0) {		/* firmware not loaded */
-			dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
-#ifdef USE_FW_LOADER
-			if (!instance->firmware_start_run) {
-				instance->firmware_start_run = 1;
-				cxacru_firmware_start(instance);
-			}
-#endif /* USE_FW_LOADER */
-			goto out;
-		}
-
-		/* Read MAC address */
-		ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0, 
-				esi, sizeof(esi));
-		if (ret < 0) {
-			err("cxacru_adsl_start: CARD_GET_MAC_ADDRESS returned %d", ret);
-			goto out;
-		}
-
-		/* FIXME: remove dev from args; should have been set in probe */
-		ret = udsl_instance_setup(instance->u.usb_dev, &instance->u);
-		if (ret)
-			goto out;
-		memcpy(instance->u.atm_dev->esi, esi, sizeof(esi));
-		/* FIXME: remove */
-		instance->u.status = UDSL_LOADED_FIRMWARE;
-
-		dev_info(&instance->u.usb_dev->dev, "cxacru: MAC = %02x", esi[0]);
-		for (ret = 1; ret < sizeof(esi); ret++)
-			printk(":%02x", esi[ret]);
-		printk("\n");
+	/* Read MAC address */
+	ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0, 
+			atm_dev->esi, sizeof(atm_dev->esi));
+	if (ret < 0) {
+		dev_err(dev, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
+		return ret;
 	}
 
 	/* start ADSL */
 	ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
 	if (ret < 0) {
-		err("cxacru_adst_start: CHIP_ADSL_LINE_START returned %d", ret);
-		goto out;
+		dev_err(dev, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
+		return ret;
 	}
-	
+
 	/* Start status polling */
 	cxacru_do_timer_poll(instance);
-
-	tasklet_schedule(&instance->u.receive_tasklet);
-out:
-	up(&instance->start_serialize);
+	return 0;
 }
 
-static void cxacru_poll_status(struct cxacru_instance_data *instance)
+static void cxacru_poll_status(struct cxacru_data *instance)
 {
 	u32 buf[CXINF_MAX] = {};
+	struct device *dev = &instance->usbatm->usb_intf->dev;
+	struct atm_dev *atm_dev = instance->usbatm->atm_dev;
 	int ret;
 
 	ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
 	if (ret < 0) {
-		dev_warn(&instance->u.usb_dev->dev, "poll status: error %d\n", ret);
+		dev_warn(dev, "poll status: error %d\n", ret);
 		return;
 	}
 
@@ -438,65 +409,63 @@
 	instance->line_status = buf[CXINF_LINE_STATUS];
 	switch (instance->line_status) {
 	case 0:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: down\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: down\n");
 		break;
 
 	case 1:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: attemtping to activate\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: attemtping to activate\n");
 		break;
 
 	case 2:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: training\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: training\n");
 		break;
 
 	case 3:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: channel analysis\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: channel analysis\n");
 		break;
 
 	case 4:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: exchange\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: exchange\n");
 		break;
 
 	case 5:
-		instance->u.atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
-		instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND;
+		atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
+		atm_dev->signal = ATM_PHY_SIG_FOUND;
 
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: up (%d Kib/s down | %d Kib/s up)\n",
+		dev_info(dev, "ADSL line: up (%d Kib/s down | %d Kib/s up)\n",
 		     buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
 		break;
 
 	case 6:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: waiting\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: waiting\n");
 		break;
 
 	case 7:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
-		dev_info(&instance->u.usb_dev->dev, "ADSL line: initializing\n");
+		atm_dev->signal = ATM_PHY_SIG_LOST;
+		dev_info(dev, "ADSL line: initializing\n");
 		break;
 
 	default:
-		instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
-		dev_info(&instance->u.usb_dev->dev, "Unknown line state %02x\n",
-				instance->line_status);
+		atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
+		dev_info(dev, "Unknown line state %02x\n", instance->line_status);
 		break;
 	}
 }
 
 #ifdef USE_FW_LOADER
-static int cxacru_fw(struct cxacru_instance_data *instance, enum cxacru_fw_request fw,
+static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
 		     u8 code1, u8 code2, u32 addr, u8 *data, int size)
 {
 	int ret;
 	u8 *buf;
 	int offd, offb;
 	const int stride = CMD_PACKET_SIZE - 8;
-	struct usb_device *usb_dev = instance->u.usb_dev;
 
 	buf = (u8 *) __get_free_page(GFP_KERNEL);
 	if (!buf)
@@ -537,23 +506,23 @@
 	return ret;
 }
 
-static void cxacru_upload_firmware(struct cxacru_instance_data *instance,
+static void cxacru_upload_firmware(struct cxacru_data *instance,
 				   const struct firmware *fw,
 				   const struct firmware *br,
 				   const struct firmware *cf)
 {
 	int ret;
 	int off;
-	struct usb_device *dev = instance->u.usb_dev;
-	const u32 vid = dev->descriptor.idVendor;
-	const u32 pid = dev->descriptor.idProduct;
+	struct usb_device *usb_dev = instance->usbatm->usb_dev;
+	const u32 vid = usb_dev->descriptor.idVendor;
+	const u32 pid = usb_dev->descriptor.idProduct;
 	u32 val;
 
 	dbg("cxacru_upload_firmware");
 
 	/* FirmwarePllFClkValue */
 	val = br ? PLLFCLK_OLD : PLLFCLK_NEW;
-	ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
+	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
 	if (ret) {
 		err("FirmwarePllFClkValue failed: %d", ret);
 		return;
@@ -561,7 +530,7 @@
 
 	/* FirmwarePllBClkValue */
 	val = br ? PLLBCLK_OLD : PLLBCLK_NEW;
-	ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
+	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
 	if (ret) {
 		err("FirmwarePllBClkValue failed: %d", ret);
 		return;
@@ -569,14 +538,14 @@
 
 	/* Enable SDRAM */
 	val = SDRAM_ENA;
-	ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
+	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
 	if (ret) {
 		err("Enable SDRAM failed: %d", ret);
 		return;
 	}
 
 	/* Firmware */
-	ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
+	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
 	if (ret) {
 		err("Firmware upload failed: %d", ret);
 		return;
@@ -584,7 +553,7 @@
 
 	/* Boot ROM patch */
 	if (br) {
-		ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, br->data, br->size);
+		ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, br->data, br->size);
 		if (ret) {
 			err("Boot ROM patching failed: %d", ret);
 			return;
@@ -593,7 +562,7 @@
 
 	/* Signature */
 	val = (pid << 16) | (vid & 0xffff);
-	ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) &val, 4);
+	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) &val, 4);
 	if (ret) {
 		err("Signature storing failed: %d", ret);
 		return;
@@ -601,24 +570,23 @@
 
 	if (br) {
 		val = BR_ADDR;
-		ret = cxacru_fw(instance, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
+		ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
 	}
 	else {
-		ret = cxacru_fw(instance, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
+		ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
 	}
 	if (ret) {
 		err("Passing control to firmware failed: %d", ret);
 		return;
 	}
 
-	/* Delay to allow firmware to start up. We can do this here
-	   because we're in our own kernel thread anyway. */
-	msleep(1000);
-
-	usb_clear_halt(dev, usb_sndbulkpipe(dev, CXACRU_EP_CMD));
-	usb_clear_halt(dev, usb_rcvbulkpipe(dev, CXACRU_EP_CMD));
-	usb_clear_halt(dev, usb_sndbulkpipe(dev, CXACRU_EP_DATA));
-	usb_clear_halt(dev, usb_rcvbulkpipe(dev, CXACRU_EP_DATA));
+	/* Delay to allow firmware to start up. */
+	msleep_interruptible(1000);
+
+	usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
+	usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
+	usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
+	usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
 
 	ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
 	if (ret < 0) {
@@ -643,159 +611,114 @@
 		}
 	}
 
-	msleep(4000);
-
-	dbg("done setting up the modem");
-
-	cxacru_adsl_start(instance);
+	msleep_interruptible(4000);
 }
 
-static int cxacru_find_firmware(struct cxacru_instance_data *instance,
+static int cxacru_find_firmware(struct cxacru_data *instance,
 				char* phase, const struct firmware **fw_p)
 {
+	struct device *dev = &instance->usbatm->usb_dev->dev;
 	char buf[16];
 
 	sprintf(buf, "cxacru-%s.bin", phase);
 	dbg("cxacru_find_firmware: looking for %s", buf);
 
-	if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) {
-		dev_warn(&instance->u.usb_dev->dev, "no stage %s firmware found\n", phase);
+	if (request_firmware(fw_p, buf, dev)) {
+		dev_warn(dev, "no stage %s firmware found\n", phase);
 		return -ENOENT;
 	}
 
-	dev_info(&instance->u.usb_dev->dev, "found firmware %s\n", buf);
+	dev_info(dev, "found firmware %s\n", buf);
 
 	return 0;
 }
 
-static int cxacru_load_firmware(void *arg)
+static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
+		struct usb_interface *usb_intf)
 {
 	const struct firmware *fw, *bp, *cf;
-	struct cxacru_instance_data *instance = arg;
-
-	BUG_ON(!instance);
-
-	daemonize("firmware/cxacru");
+	struct cxacru_data *instance = usbatm_instance->driver_data;
+	int ret = -ENOENT;
 
 	if (!cxacru_find_firmware(instance, "fw", &fw)) {
 		if (!cxacru_find_firmware(instance, "cf", &cf)) {
-			if (!cxacru_find_firmware(instance, "bp", &bp))
+			if (cxacru_find_firmware(instance, "bp", &bp))
 				/* ok, assume it's not needed */
 				bp = NULL;
 			cxacru_upload_firmware(instance, fw, bp, cf);
+
+			ret = cxacru_card_status(instance);
+			if (ret)
+				dbg("modem initialisation failed");
+			else
+				dbg("done setting up the modem");
+
+			if (bp)
+				release_firmware(bp);
 			release_firmware(cf);
 		}
 		release_firmware(fw);
 	}
 
-	module_put(THIS_MODULE);
-	return 0;
-}
-
-static void cxacru_firmware_start(struct cxacru_instance_data *instance)
-{
-	int ret;
-
-	try_module_get(THIS_MODULE);
-
-	ret = kernel_thread(cxacru_load_firmware, instance,
-			    CLONE_FS | CLONE_FILES);
-
-	if (ret >= 0)
-		return;		/* OK */
-
-	dbg("cxacru_firmware_start: kernel_thread failed (%d)!", ret);
-
-	module_put(THIS_MODULE);
+	return ret;
 }
 #endif /* USE_FW_LOADER */
 
-static int cxacru_usb_ioctl(struct usb_interface *intf, unsigned int code,
-			      void *user_data)
-{
-	struct cxacru_instance_data *instance = usb_get_intfdata(intf);
-
-	dbg("cxacru_usb_ioctl entered");
-
-	if (!instance) {
-		dbg("cxacru_usb_ioctl: NULL instance!");
-		return -ENODEV;
-	}
-
-	switch (code) {
-	case UDSL_IOCTL_LINE_UP:
-		cxacru_adsl_start(instance);
-		return (instance->u.status == UDSL_LOADED_FIRMWARE) ? 0 : -EIO;
-	case UDSL_IOCTL_LINE_DOWN:
-		cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0);
-		cxacru_do_timer_poll(instance);
-		return 0;
-	default:
-		return -ENOTTY;
-	}
-}
-
-static int cxacru_usb_probe(struct usb_interface *intf,
-			      const struct usb_device_id *id)
+static int cxacru_bind(struct usbatm_data *usbatm_instance,
+		struct usb_interface *intf, int *need_heavy_init)
 {
-	struct usb_device *dev = interface_to_usbdev(intf);
-	struct cxacru_instance_data *instance;
+	struct cxacru_data *instance;
+	struct usb_device *usb_dev = interface_to_usbdev(intf);
 	int ret;
 
-	dbg("cxacru_usb_probe: trying device with vendor=0x%x, product=0x%x",
-			dev->descriptor.idVendor, dev->descriptor.idProduct);
-
 	/* instance init */
 	instance = kmalloc(sizeof(*instance), GFP_KERNEL);
 	if (!instance) {
-		dbg("cxacru_usb_probe: no memory for instance data");
+		dbg("cxacru_bind: no memory for instance data");
 		return -ENOMEM;
 	}
 
-	memset(instance, 0, sizeof(struct cxacru_instance_data));
+	memset(instance, 0, sizeof(*instance));
+
+	instance->usbatm = usbatm_instance;
 
 	instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
 	if (!instance->rcv_buf) {
-		dbg("cxacru_usb_probe: no memory for rcv_buf");
+		dbg("cxacru_bind: no memory for rcv_buf");
 		ret = -ENOMEM;
 		goto fail;
 	}
 	instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
 	if (!instance->snd_buf) {
-		dbg("cxacru_usb_probe: no memory for snd_buf");
+		dbg("cxacru_bind: no memory for snd_buf");
 		ret = -ENOMEM;
 		goto fail;
 	}
 	instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!instance->rcv_urb) {
-		dbg("cxacru_usb_probe: no memory for rcv_urb");
+		dbg("cxacru_bind: no memory for rcv_urb");
 		ret = -ENOMEM;
 		goto fail;
 	}
 	instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!instance->snd_urb) {
-		dbg("cxacru_usb_probe: no memory for snd_urb");
+		dbg("cxacru_bind: no memory for snd_urb");
 		ret = -ENOMEM;
 		goto fail;
 	}
 
-	instance->u.data_endpoint = CXACRU_EP_DATA;
-	instance->u.snd_padding = 11;
-	instance->u.rcv_padding = 3;
-	instance->u.driver_name = cxacru_driver_name;
-	instance->u.usb_dev = dev;
-
-	usb_fill_int_urb(instance->rcv_urb, dev, usb_rcvintpipe(dev, CXACRU_EP_CMD),
-			 instance->rcv_buf, PAGE_SIZE,
-			 cxacru_blocking_completion, &instance->rcv_done, 1);
+	usb_fill_int_urb(instance->rcv_urb,
+			usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
+			instance->rcv_buf, PAGE_SIZE,
+			cxacru_blocking_completion, &instance->rcv_done, 1);
 	instance->rcv_urb->transfer_flags |= URB_ASYNC_UNLINK;
 
-	usb_fill_int_urb(instance->snd_urb, dev, usb_sndintpipe(dev, CXACRU_EP_CMD),
-			 instance->snd_buf, PAGE_SIZE,
-			 cxacru_blocking_completion, &instance->snd_done, 4);
+	usb_fill_int_urb(instance->snd_urb,
+			usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
+			instance->snd_buf, PAGE_SIZE,
+			cxacru_blocking_completion, &instance->snd_done, 4);
 	instance->snd_urb->transfer_flags |= URB_ASYNC_UNLINK;
 
-	init_MUTEX(&instance->start_serialize);
 	init_MUTEX(&instance->cm_serialize);
 
 	init_timer(&instance->poll_timer);
@@ -804,9 +727,10 @@
 
 	INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance);
 
-	usb_set_intfdata(intf, instance);
+	wmb();
+	usbatm_instance->driver_data = instance;
 
-	cxacru_adsl_start(instance);
+	*need_heavy_init = cxacru_card_status(instance);
 
 	return 0;
 
@@ -824,14 +748,15 @@
 	return ret;
 }
 
-static void cxacru_usb_disconnect(struct usb_interface *intf)
+static void cxacru_unbind(struct usbatm_data *usbatm_instance,
+		struct usb_interface *intf)
 {
-	struct cxacru_instance_data *instance = usb_get_intfdata(intf);
+	struct cxacru_data *instance = usbatm_instance->driver_data;
 
-	dbg("cxacru_usb_disconnect entered");
+	dbg("cxacru_unbind entered");
 
 	if (!instance) {
-		dbg("cxacru_usb_disconnect: NULL instance!");
+		dbg("cxacru_unbind: NULL instance!");
 		return;
 	}
 
@@ -846,11 +771,97 @@
 
 	free_page((unsigned long) instance->snd_buf);
 	free_page((unsigned long) instance->rcv_buf);
+	kfree(instance);
+
+	usbatm_instance->driver_data = NULL;
+}
+
+static struct usbatm_driver cxacru_driver;
+
+static const struct usb_device_id cxacru_usb_ids[] = {
+	{
+		/* V = Conexant				P = ADSL modem (Euphrates project)	*/
+		USB_DEVICE(0x0572, 0xcafe),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Conexant				P = ADSL modem (Hasbani project)	*/
+		USB_DEVICE(0x0572, 0xcb00),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Conexant				P = ADSL modem				*/
+		USB_DEVICE(0x0572, 0xcb01),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Conexant				P = ADSL modem				*/
+		USB_DEVICE(0x0572, 0xcb06),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Olitec				P = ADSL modem version 2		*/
+		USB_DEVICE(0x08e3, 0x0100),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Olitec				P = ADSL modem version 3		*/
+		USB_DEVICE(0x08e3, 0x0102),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Trust/Amigo Technology Co.	P = AMX-CA86U				*/
+		USB_DEVICE(0x0eb0, 0x3457),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Zoom				P = 5510				*/
+		USB_DEVICE(0x1803, 0x5510),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Draytek				P = Vigor 318				*/
+		USB_DEVICE(0x0675, 0x0200),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{
+		/* V = Zyxel				P = 630-C1 aka OMNI ADSL USB modem	*/
+		USB_DEVICE(0x0586, 0x330a),
+		.driver_info = (unsigned long) &cxacru_driver
+	},
+	{}
+};
 
-	udsl_instance_disconnect(&instance->u);
+MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
 
-	/* clean up */
-	usb_set_intfdata(intf, NULL);
-	/* FIXME: do we need this refcount? */
-	udsl_put_instance(&instance->u);
+static struct usbatm_driver cxacru_driver = {
+	.owner		= THIS_MODULE,
+	.driver_name	= cxacru_driver_name,
+	.id_table	= cxacru_usb_ids,
+	.bind		= cxacru_bind,
+	.heavy_init	= cxacru_heavy_init,
+	.unbind		= cxacru_unbind,
+	.atm_start	= cxacru_atm_start,
+	.in		= CXACRU_EP_DATA,
+	.out		= CXACRU_EP_DATA,
+	.rx_padding	= 3,
+	.tx_padding	= 11,
+};
+
+static int __init cxacru_init(void)
+{
+	return usbatm_register(&cxacru_driver);
+}
+
+static void __exit cxacru_cleanup(void)
+{
+	usbatm_deregister(&cxacru_driver);
 }
+
+module_init(cxacru_init);
+module_exit(cxacru_cleanup);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);




More information about the Usbatm-commits mailing list