[PATCH 3/5] USB: io_ti: Move download and boot mode code out of download_fw

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

 



From: "Peter E. Berger" <pberger@xxxxxxxxxxx>

Separate the download and boot mode code from download_fw() into two new
helper functions: do_download_mode() and do_boot_mode(), and fix formatting
in some of the comments.

Signed-off-by: Peter E. Berger <pberger@xxxxxxxxxxx>
---
 drivers/usb/serial/io_ti.c | 111 +++++++++++++++++++++++++++++----------------
 1 file changed, 73 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index d41ba74..58254ca 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -223,6 +223,11 @@ static void edge_set_termios(struct tty_struct *tty,
 		struct usb_serial_port *port, struct ktermios *old_termios);
 static void edge_send(struct usb_serial_port *port, struct tty_struct *tty);
 
+static int do_download_mode(struct edgeport_serial *serial,
+		const struct firmware *fw);
+static int do_boot_mode(struct edgeport_serial *serial,
+		const struct firmware *fw);
+
 /* sysfs attributes */
 static int edge_create_sysfs_attrs(struct usb_serial_port *port);
 static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
@@ -980,7 +985,7 @@ static int check_fw_sanity(struct edgeport_serial *serial,
 	return 0;
 }
 
-/**
+/*
  * DownloadTIFirmware - Download run-time operating firmware to the TI5052
  *
  * This routine downloads the main operating code into the TI5052, using the
@@ -991,11 +996,7 @@ static int download_fw(struct edgeport_serial *serial,
 {
 	struct device *dev = &serial->serial->interface->dev;
 	int status = 0;
-	int start_address;
-	struct edge_ti_manuf_descriptor *ti_manuf_desc;
 	struct usb_interface_descriptor *interface;
-	int download_cur_ver;
-	int download_new_ver;
 	struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
 
 	if (check_fw_sanity(serial, fw))
@@ -1005,7 +1006,8 @@ static int download_fw(struct edgeport_serial *serial,
 	serial->fw_version = (fw_hdr->major_version << 8) +
 			fw_hdr->minor_version;
 
-	/* This routine is entered by both the BOOT mode and the Download mode
+	/*
+	 * This routine is entered by both the BOOT mode and the Download mode
 	 * We can determine which code is running by the reading the config
 	 * descriptor and if we have only one bulk pipe it is in boot mode
 	 */
@@ -1029,17 +1031,28 @@ static int download_fw(struct edgeport_serial *serial,
 	 * if we have more than one endpoint we are definitely in download
 	 * mode
 	 */
-	if (interface->bNumEndpoints > 1)
+	if (interface->bNumEndpoints > 1) {
 		serial->product_info.TiMode = TI_MODE_DOWNLOAD;
-	else
-		/* Otherwise we will remain in configuring mode */
-		serial->product_info.TiMode = TI_MODE_CONFIGURING;
+		return do_download_mode(serial, fw);
+	}
 
-	/********************************************************************/
-	/* Download Mode */
-	/********************************************************************/
-	if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
-		struct ti_i2c_desc *rom_desc;
+	/* Otherwise we will remain in configuring mode */
+	serial->product_info.TiMode = TI_MODE_CONFIGURING;
+	return do_boot_mode(serial, fw);
+
+}
+
+static int do_download_mode(struct edgeport_serial *serial,
+		const struct firmware *fw)
+{
+	struct device *dev = &serial->serial->interface->dev;
+	int status = 0;
+	int start_address;
+	struct edge_ti_manuf_descriptor *ti_manuf_desc;
+	int download_cur_ver;
+	int download_new_ver;
+	struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
+	struct ti_i2c_desc *rom_desc;
 
 		dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
 
@@ -1049,7 +1062,8 @@ static int download_fw(struct edgeport_serial *serial,
 			return status;
 		}
 
-		/* Validate Hardware version number
+		/*
+		 * Validate Hardware version number
 		 * Read Manufacturing Descriptor from TI Based Edgeport
 		 */
 		ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
@@ -1068,7 +1082,7 @@ static int download_fw(struct edgeport_serial *serial,
 				__func__, ti_cpu_rev(ti_manuf_desc));
 			kfree(ti_manuf_desc);
 			return -EINVAL;
-  		}
+		}
 
 		rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
 		if (!rom_desc) {
@@ -1093,7 +1107,8 @@ static int download_fw(struct edgeport_serial *serial,
 				return -ENOMEM;
 			}
 
-			/* Validate version number
+			/*
+			 * Validate version number
 			 * Read the descriptor data
 			 */
 			status = read_rom(serial, start_address +
@@ -1107,8 +1122,10 @@ static int download_fw(struct edgeport_serial *serial,
 				return status;
 			}
 
-			/* Check version number of download with current
-			   version in I2c */
+			/*
+			 * Check version number of download with current
+			 * version in I2c
+			 */
 			download_cur_ver = (firmware_version->Ver_Major << 8) +
 					   (firmware_version->Ver_Minor);
 			download_new_ver = (fw_hdr->major_version << 8) +
@@ -1119,8 +1136,10 @@ static int download_fw(struct edgeport_serial *serial,
 				firmware_version->Ver_Minor,
 				fw_hdr->major_version, fw_hdr->minor_version);
 
-			/* Check if we have an old version in the I2C and
-			   update if necessary */
+			/*
+			 * Check if we have an old version in the I2C and
+			 * update if necessary
+			 */
 			if (download_cur_ver < download_new_ver) {
 				dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
 					__func__,
@@ -1136,7 +1155,8 @@ static int download_fw(struct edgeport_serial *serial,
 					kfree(ti_manuf_desc);
 					return -ENOMEM;
 				}
-				/* In order to update the I2C firmware we must
+				/*
+				 * In order to update the I2C firmware we must
 				 * change the type 2 record to type 0xF2. This
 				 * will force the UMP to come up in Boot Mode.
 				 * Then while in boot mode, the driver will
@@ -1150,8 +1170,10 @@ static int download_fw(struct edgeport_serial *serial,
 				 */
 				*record = I2C_DESC_TYPE_FIRMWARE_BLANK;
 
-				/* Change the I2C Firmware record type to
-				   0xf2 to trigger an update */
+				/*
+				 * Change the I2C Firmware record type to
+				 * 0xf2 to trigger an update
+				 */
 				status = write_rom(serial, start_address,
 						sizeof(*record), record);
 				if (status) {
@@ -1162,7 +1184,8 @@ static int download_fw(struct edgeport_serial *serial,
 					return status;
 				}
 
-				/* verify the write -- must do this in order
+				/*
+				 * verify the write -- must do this in order
 				 * for write to complete before we do the
 				 * hardware reset
 				 */
@@ -1253,8 +1276,10 @@ static int download_fw(struct edgeport_serial *serial,
 				return -EINVAL;
 			}
 
-			/* Update I2C with type 0xf2 record with correct
-			   size and checksum */
+			/*
+			 * Update I2C with type 0xf2 record with correct
+			 * size and checksum
+			 */
 			status = write_rom(serial,
 						start_address,
 						HEADER_SIZE,
@@ -1267,8 +1292,10 @@ static int download_fw(struct edgeport_serial *serial,
 				return -EINVAL;
 			}
 
-			/* verify the write -- must do this in order for
-			   write to complete before we do the hardware reset */
+			/*
+			 * verify the write -- must do this in order for
+			 * write to complete before we do the hardware reset
+			 */
 			status = read_rom(serial, start_address,
 							HEADER_SIZE, vheader);
 
@@ -1311,15 +1338,20 @@ static int download_fw(struct edgeport_serial *serial,
 			}
 		}
 
-		// The device is running the download code
+		/* The device is running the download code */
 		kfree(rom_desc);
 		kfree(ti_manuf_desc);
 		return 0;
-	}
+}
+
+static int do_boot_mode(struct edgeport_serial *serial,
+		const struct firmware *fw)
+{
+	struct device *dev = &serial->serial->interface->dev;
+	int status = 0;
+	struct edge_ti_manuf_descriptor *ti_manuf_desc;
+	struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw->data;
 
-	/********************************************************************/
-	/* Boot Mode */
-	/********************************************************************/
 	dev_dbg(dev, "%s - RUNNING IN BOOT MODE\n", __func__);
 
 	/* Configure the TI device so we can use the BULK pipes for download */
@@ -1335,8 +1367,10 @@ static int download_fw(struct edgeport_serial *serial,
 		goto stayinbootmode;
 	}
 
-	/* We have an ION device (I2c Must be programmed)
-	   Determine I2C image type */
+	/*
+	 * We have an ION device (I2c Must be programmed)
+	 * Determine I2C image type
+	 */
 	if (i2c_type_bootmode(serial))
 		goto stayinbootmode;
 
@@ -1348,7 +1382,8 @@ static int download_fw(struct edgeport_serial *serial,
 		__u8 *buffer;
 		int buffer_size;
 
-		/* Validate Hardware version number
+		/*
+		 * Validate Hardware version number
 		 * Read Manufacturing Descriptor from TI Based Edgeport
 		 */
 		ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux