[PATCH v2 20/33] staging: comedi: dt9812: factor the device reset out of dt9812_probe()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When this driver is converted to the comedi (*auto_attach) mechanism
the device reset will be done during the (*auto_attach). To make the
conversion cleaner, factor the device reset out of the (*probe).

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/dt9812.c | 111 +++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c
index 42a4a9d..57bdb06 100644
--- a/drivers/staging/comedi/drivers/dt9812.c
+++ b/drivers/staging/comedi/drivers/dt9812.c
@@ -774,6 +774,69 @@ static int dt9812_find_endpoints(struct usb_interface *intf,
 	return 0;
 }
 
+static int dt9812_reset_device(struct usb_interface *intf,
+			       struct usb_dt9812 *devpriv)
+{
+	int ret;
+	int i;
+	u32 tmp32;
+	u16 tmp16;
+	u8 tmp8;
+
+	ret = dt9812_read_info(devpriv, 0, &tmp8, sizeof(tmp8));
+	if (ret) {
+		/*
+		 * Seems like a configuration reset is necessary if driver is
+		 * reloaded while device is attached
+		 */
+		usb_reset_configuration(devpriv->udev);
+		for (i = 0; i < 10; i++) {
+			ret = dt9812_read_info(devpriv, 1, &tmp8, sizeof(tmp8));
+			if (ret == 0)
+				break;
+		}
+		if (ret) {
+			dev_err(&intf->dev, "unable to reset configuration\n");
+			return ret;
+		}
+	}
+
+	ret = dt9812_read_info(devpriv, 1, &tmp16, sizeof(tmp16));
+	if (ret) {
+		dev_err(&intf->dev, "failed to read vendor id\n");
+		return ret;
+	}
+	devpriv->vendor = le16_to_cpu(tmp16);
+
+	ret = dt9812_read_info(devpriv, 3, &tmp16, sizeof(tmp16));
+	if (ret) {
+		dev_err(&intf->dev, "failed to read product id\n");
+		return ret;
+	}
+	devpriv->product = le16_to_cpu(tmp16);
+
+	ret = dt9812_read_info(devpriv, 5, &tmp16, sizeof(tmp16));
+	if (ret) {
+		dev_err(&intf->dev, "failed to read device id\n");
+		return ret;
+	}
+	devpriv->device = le16_to_cpu(tmp16);
+
+	ret = dt9812_read_info(devpriv, 7, &tmp32, sizeof(tmp32));
+	if (ret) {
+		dev_err(&intf->dev, "failed to read serial number\n");
+		return ret;
+	}
+	devpriv->serial = le32_to_cpu(tmp32);
+
+	/* let the user know what node this device is now attached to */
+	dev_info(&intf->dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n",
+		 devpriv->vendor, devpriv->product, devpriv->device,
+		 devpriv->serial);
+
+	return 0;
+}
+
 static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
 	struct slot_dt9812 *slot = NULL;
@@ -885,7 +948,6 @@ static int dt9812_probe(struct usb_interface *intf,
 	struct usb_dt9812 *dev = NULL;
 	int retval = -ENOMEM;
 	int i;
-	u8 fw;
 
 	/* allocate memory for our device state and initialize it */
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -920,56 +982,13 @@ static int dt9812_probe(struct usb_interface *intf,
 	if (retval)
 		goto error;
 
-	if (dt9812_read_info(dev, 0, &fw, sizeof(fw)) != 0) {
-		/*
-		 * Seems like a configuration reset is necessary if driver is
-		 * reloaded while device is attached
-		 */
-		usb_reset_configuration(dev->udev);
-		for (i = 0; i < 10; i++) {
-			retval = dt9812_read_info(dev, 1, &fw, sizeof(fw));
-			if (retval == 0) {
-				dev_info(&intf->dev,
-					 "usb_reset_configuration succeeded "
-					 "after %d iterations\n", i);
-				break;
-			}
-		}
-	}
-
-	if (dt9812_read_info(dev, 1, &dev->vendor, sizeof(dev->vendor)) != 0) {
-		dev_err(&intf->dev, "Failed to read vendor.\n");
-		retval = -ENODEV;
-		goto error;
-	}
-	if (dt9812_read_info(dev, 3, &dev->product, sizeof(dev->product)) != 0) {
-		dev_err(&intf->dev, "Failed to read product.\n");
-		retval = -ENODEV;
-		goto error;
-	}
-	if (dt9812_read_info(dev, 5, &dev->device, sizeof(dev->device)) != 0) {
-		dev_err(&intf->dev, "Failed to read device.\n");
-		retval = -ENODEV;
-		goto error;
-	}
-	if (dt9812_read_info(dev, 7, &dev->serial, sizeof(dev->serial)) != 0) {
-		dev_err(&intf->dev, "Failed to read serial.\n");
-		retval = -ENODEV;
+	retval = dt9812_reset_device(intf, dev);
+	if (retval)
 		goto error;
-	}
-
-	dev->vendor = le16_to_cpu(dev->vendor);
-	dev->product = le16_to_cpu(dev->product);
-	dev->device = le16_to_cpu(dev->device);
-	dev->serial = le32_to_cpu(dev->serial);
 
 	/* save our data pointer in this interface device */
 	usb_set_intfdata(intf, dev);
 
-	/* let the user know what node this device is now attached to */
-	dev_info(&intf->dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n",
-		 dev->vendor, dev->product, dev->device, dev->serial);
-
 	return 0;
 
 error:
-- 
1.8.1.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux