aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/io_edgeport.c
diff options
context:
space:
mode:
authorJaswinder Singh <jaswinder@infradead.org>2008-07-03 07:30:23 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2008-07-14 17:44:37 -0400
commit5b9ea9322605da09d6f7119f03f71cc52b044911 (patch)
treeb227024278cf70933fb14ef22361806388635140 /drivers/usb/serial/io_edgeport.c
parentfb54be8755d386008bfadb7fc8ff89451fa3a9c9 (diff)
edgeport: use request_firmware()
Version number provided in first HEX record. Signed-off-by: Jaswinder Singh <jaswinder@infradead.org> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/usb/serial/io_edgeport.c')
-rw-r--r--drivers/usb/serial/io_edgeport.c183
1 files changed, 90 insertions, 93 deletions
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 06b52f4098f1..2fd449bcfa35 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -42,6 +42,8 @@
42#include <linux/serial.h> 42#include <linux/serial.h>
43#include <linux/ioctl.h> 43#include <linux/ioctl.h>
44#include <linux/wait.h> 44#include <linux/wait.h>
45#include <linux/firmware.h>
46#include <linux/ihex.h>
45#include <asm/uaccess.h> 47#include <asm/uaccess.h>
46#include <linux/usb.h> 48#include <linux/usb.h>
47#include <linux/usb/serial.h> 49#include <linux/usb/serial.h>
@@ -56,26 +58,6 @@
56#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli" 58#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
57#define DRIVER_DESC "Edgeport USB Serial Driver" 59#define DRIVER_DESC "Edgeport USB Serial Driver"
58 60
59/* First, the latest boot code - for first generation edgeports */
60#define IMAGE_ARRAY_NAME BootCodeImage_GEN1
61#define IMAGE_VERSION_NAME BootCodeImageVersion_GEN1
62#include "io_fw_boot.h" /* the bootloader firmware to download to a device, if it needs it */
63
64/* for second generation edgeports */
65#define IMAGE_ARRAY_NAME BootCodeImage_GEN2
66#define IMAGE_VERSION_NAME BootCodeImageVersion_GEN2
67#include "io_fw_boot2.h" /* the bootloader firmware to download to a device, if it needs it */
68
69/* Then finally the main run-time operational code - for first generation edgeports */
70#define IMAGE_ARRAY_NAME OperationalCodeImage_GEN1
71#define IMAGE_VERSION_NAME OperationalCodeImageVersion_GEN1
72#include "io_fw_down.h" /* Define array OperationalCodeImage[] */
73
74/* for second generation edgeports */
75#define IMAGE_ARRAY_NAME OperationalCodeImage_GEN2
76#define IMAGE_VERSION_NAME OperationalCodeImageVersion_GEN2
77#include "io_fw_down2.h" /* Define array OperationalCodeImage[] */
78
79#define MAX_NAME_LEN 64 61#define MAX_NAME_LEN 64
80 62
81#define CHASE_TIMEOUT (5*HZ) /* 5 seconds */ 63#define CHASE_TIMEOUT (5*HZ) /* 5 seconds */
@@ -256,9 +238,9 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8
256static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength); 238static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength);
257static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port); 239static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port);
258 240
259static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data); 241static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data);
260static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data); 242static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data);
261static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data); 243static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data);
262static void get_manufacturing_desc (struct edgeport_serial *edge_serial); 244static void get_manufacturing_desc (struct edgeport_serial *edge_serial);
263static void get_boot_desc (struct edgeport_serial *edge_serial); 245static void get_boot_desc (struct edgeport_serial *edge_serial);
264static void load_application_firmware (struct edgeport_serial *edge_serial); 246static void load_application_firmware (struct edgeport_serial *edge_serial);
@@ -283,37 +265,41 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
283{ 265{
284 __u32 BootCurVer; 266 __u32 BootCurVer;
285 __u32 BootNewVer; 267 __u32 BootNewVer;
286 __u8 BootMajorVersion; 268 __u8 BootMajorVersion;
287 __u8 BootMinorVersion; 269 __u8 BootMinorVersion;
288 __le16 BootBuildNumber; 270 __u16 BootBuildNumber;
289 __u8 *BootImage; 271 __u32 Bootaddr;
290 __u32 BootSize; 272 const struct ihex_binrec *rec;
291 struct edge_firmware_image_record *record; 273 const struct firmware *fw;
292 unsigned char *firmware; 274 const char *fw_name;
293 int response; 275 int response;
294 276
295
296 switch (edge_serial->product_info.iDownloadFile) { 277 switch (edge_serial->product_info.iDownloadFile) {
297 case EDGE_DOWNLOAD_FILE_I930: 278 case EDGE_DOWNLOAD_FILE_I930:
298 BootMajorVersion = BootCodeImageVersion_GEN1.MajorVersion; 279 fw_name = "edgeport/boot.fw";
299 BootMinorVersion = BootCodeImageVersion_GEN1.MinorVersion;
300 BootBuildNumber = cpu_to_le16(BootCodeImageVersion_GEN1.BuildNumber);
301 BootImage = &BootCodeImage_GEN1[0];
302 BootSize = sizeof( BootCodeImage_GEN1 );
303 break; 280 break;
304 281
305 case EDGE_DOWNLOAD_FILE_80251: 282 case EDGE_DOWNLOAD_FILE_80251:
306 BootMajorVersion = BootCodeImageVersion_GEN2.MajorVersion; 283 fw_name = "edgeport/boot2.fw";
307 BootMinorVersion = BootCodeImageVersion_GEN2.MinorVersion;
308 BootBuildNumber = cpu_to_le16(BootCodeImageVersion_GEN2.BuildNumber);
309 BootImage = &BootCodeImage_GEN2[0];
310 BootSize = sizeof( BootCodeImage_GEN2 );
311 break; 284 break;
312 285
313 default: 286 default:
314 return; 287 return;
315 } 288 }
316 289
290 response = request_ihex_firmware(&fw, fw_name,
291 &edge_serial->serial->dev->dev);
292 if (response) {
293 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
294 fw_name, response);
295 return;
296 }
297
298 rec = (const struct ihex_binrec *)fw->data;
299 BootMajorVersion = rec->data[0];
300 BootMinorVersion = rec->data[1];
301 BootBuildNumber = (rec->data[2] << 8) | rec->data[3];
302
317 // Check Boot Image Version 303 // Check Boot Image Version
318 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) + 304 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) +
319 (edge_serial->boot_descriptor.MinorVersion << 16) + 305 (edge_serial->boot_descriptor.MinorVersion << 16) +
@@ -321,7 +307,7 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
321 307
322 BootNewVer = (BootMajorVersion << 24) + 308 BootNewVer = (BootMajorVersion << 24) +
323 (BootMinorVersion << 16) + 309 (BootMinorVersion << 16) +
324 le16_to_cpu(BootBuildNumber); 310 BootBuildNumber;
325 311
326 dbg("Current Boot Image version %d.%d.%d", 312 dbg("Current Boot Image version %d.%d.%d",
327 edge_serial->boot_descriptor.MajorVersion, 313 edge_serial->boot_descriptor.MajorVersion,
@@ -334,30 +320,30 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial)
334 edge_serial->boot_descriptor.MajorVersion, 320 edge_serial->boot_descriptor.MajorVersion,
335 edge_serial->boot_descriptor.MinorVersion, 321 edge_serial->boot_descriptor.MinorVersion,
336 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber), 322 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber),
337 BootMajorVersion, 323 BootMajorVersion, BootMinorVersion, BootBuildNumber);
338 BootMinorVersion,
339 le16_to_cpu(BootBuildNumber));
340
341 324
342 dbg("Downloading new Boot Image"); 325 dbg("Downloading new Boot Image");
343 326
344 firmware = BootImage; 327 for (rec = ihex_next_binrec(rec); rec;
345 328 rec = ihex_next_binrec(rec)) {
346 for (;;) { 329 Bootaddr = be32_to_cpu(rec->addr);
347 record = (struct edge_firmware_image_record *)firmware; 330 response = rom_write(edge_serial->serial,
348 response = rom_write (edge_serial->serial, le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), le16_to_cpu(record->Len), &record->Data[0]); 331 Bootaddr >> 16,
332 Bootaddr & 0xFFFF,
333 be16_to_cpu(rec->len),
334 &rec->data[0]);
349 if (response < 0) { 335 if (response < 0) {
350 dev_err(&edge_serial->serial->dev->dev, "rom_write failed (%x, %x, %d)\n", le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), le16_to_cpu(record->Len)); 336 dev_err(&edge_serial->serial->dev->dev,
351 break; 337 "rom_write failed (%x, %x, %d)\n",
352 } 338 Bootaddr >> 16, Bootaddr & 0xFFFF,
353 firmware += sizeof (struct edge_firmware_image_record) + le16_to_cpu(record->Len); 339 be16_to_cpu(rec->len));
354 if (firmware >= &BootImage[BootSize]) {
355 break; 340 break;
356 } 341 }
357 } 342 }
358 } else { 343 } else {
359 dbg("Boot Image -- already up to date"); 344 dbg("Boot Image -- already up to date");
360 } 345 }
346 release_firmware(fw);
361} 347}
362 348
363 349
@@ -447,9 +433,6 @@ static void dump_product_info(struct edgeport_product_info *product_info)
447 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion, 433 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion,
448 product_info->BootMinorVersion, 434 product_info->BootMinorVersion,
449 le16_to_cpu(product_info->BootBuildNumber)); 435 le16_to_cpu(product_info->BootBuildNumber));
450 dbg(" FirmwareMajorVersion %d.%d.%d", product_info->FirmwareMajorVersion,
451 product_info->FirmwareMinorVersion,
452 le16_to_cpu(product_info->FirmwareBuildNumber));
453 dbg(" ManufactureDescDate %d/%d/%d", product_info->ManufactureDescDate[0], 436 dbg(" ManufactureDescDate %d/%d/%d", product_info->ManufactureDescDate[0],
454 product_info->ManufactureDescDate[1], 437 product_info->ManufactureDescDate[1],
455 product_info->ManufactureDescDate[2]+1900); 438 product_info->ManufactureDescDate[2]+1900);
@@ -480,14 +463,8 @@ static void get_product_info(struct edgeport_serial *edge_serial)
480 463
481 // check if this is 2nd generation hardware 464 // check if this is 2nd generation hardware
482 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ION_DEVICE_ID_80251_NETCHIP) { 465 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ION_DEVICE_ID_80251_NETCHIP) {
483 product_info->FirmwareMajorVersion = OperationalCodeImageVersion_GEN2.MajorVersion;
484 product_info->FirmwareMinorVersion = OperationalCodeImageVersion_GEN2.MinorVersion;
485 product_info->FirmwareBuildNumber = cpu_to_le16(OperationalCodeImageVersion_GEN2.BuildNumber);
486 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; 466 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251;
487 } else { 467 } else {
488 product_info->FirmwareMajorVersion = OperationalCodeImageVersion_GEN1.MajorVersion;
489 product_info->FirmwareMinorVersion = OperationalCodeImageVersion_GEN1.MinorVersion;
490 product_info->FirmwareBuildNumber = cpu_to_le16(OperationalCodeImageVersion_GEN1.BuildNumber);
491 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930; 468 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930;
492 } 469 }
493 470
@@ -2130,7 +2107,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 l
2130 * If successful returns the number of bytes written, otherwise it returns 2107 * If successful returns the number of bytes written, otherwise it returns
2131 * a negative error number of the problem. 2108 * a negative error number of the problem.
2132 ****************************************************************************/ 2109 ****************************************************************************/
2133static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data) 2110static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data)
2134{ 2111{
2135 int result; 2112 int result;
2136 __u16 current_length; 2113 __u16 current_length;
@@ -2175,7 +2152,7 @@ static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u
2175 * If successful returns the number of bytes written, otherwise it returns 2152 * If successful returns the number of bytes written, otherwise it returns
2176 * a negative error number of the problem. 2153 * a negative error number of the problem.
2177 ****************************************************************************/ 2154 ****************************************************************************/
2178static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data) 2155static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data)
2179{ 2156{
2180 int result; 2157 int result;
2181 __u16 current_length; 2158 __u16 current_length;
@@ -2761,32 +2738,23 @@ static void get_boot_desc (struct edgeport_serial *edge_serial)
2761 ****************************************************************************/ 2738 ****************************************************************************/
2762static void load_application_firmware (struct edgeport_serial *edge_serial) 2739static void load_application_firmware (struct edgeport_serial *edge_serial)
2763{ 2740{
2764 struct edge_firmware_image_record *record; 2741 const struct ihex_binrec *rec;
2765 unsigned char *firmware; 2742 const struct firmware *fw;
2766 unsigned char *FirmwareImage; 2743 const char *fw_name;
2767 int ImageSize; 2744 const char *fw_info;
2768 int response; 2745 int response;
2769 2746 __u32 Operaddr;
2747 __u16 build;
2770 2748
2771 switch (edge_serial->product_info.iDownloadFile) { 2749 switch (edge_serial->product_info.iDownloadFile) {
2772 case EDGE_DOWNLOAD_FILE_I930: 2750 case EDGE_DOWNLOAD_FILE_I930:
2773 dbg("downloading firmware version (930) %d.%d.%d", 2751 fw_info = "downloading firmware version (930)";
2774 OperationalCodeImageVersion_GEN1.MajorVersion, 2752 fw_name = "edgeport/down.fw";
2775 OperationalCodeImageVersion_GEN1.MinorVersion,
2776 OperationalCodeImageVersion_GEN1.BuildNumber);
2777 firmware = &OperationalCodeImage_GEN1[0];
2778 FirmwareImage = &OperationalCodeImage_GEN1[0];
2779 ImageSize = sizeof(OperationalCodeImage_GEN1);
2780 break; 2753 break;
2781 2754
2782 case EDGE_DOWNLOAD_FILE_80251: 2755 case EDGE_DOWNLOAD_FILE_80251:
2783 dbg("downloading firmware version (80251) %d.%d.%d", 2756 fw_info = "downloading firmware version (80251)";
2784 OperationalCodeImageVersion_GEN2.MajorVersion, 2757 fw_name = "edgeport/down2.fw";
2785 OperationalCodeImageVersion_GEN2.MinorVersion,
2786 OperationalCodeImageVersion_GEN2.BuildNumber);
2787 firmware = &OperationalCodeImage_GEN2[0];
2788 FirmwareImage = &OperationalCodeImage_GEN2[0];
2789 ImageSize = sizeof(OperationalCodeImage_GEN2);
2790 break; 2758 break;
2791 2759
2792 case EDGE_DOWNLOAD_FILE_NONE: 2760 case EDGE_DOWNLOAD_FILE_NONE:
@@ -2797,16 +2765,36 @@ static void load_application_firmware (struct edgeport_serial *edge_serial)
2797 return; 2765 return;
2798 } 2766 }
2799 2767
2768 response = request_ihex_firmware(&fw, fw_name,
2769 &edge_serial->serial->dev->dev);
2770 if (response) {
2771 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
2772 fw_name, response);
2773 return;
2774 }
2775
2776 rec = (const struct ihex_binrec *)fw->data;
2777 build = (rec->data[2] << 8) | rec->data[3];
2778
2779 dbg("%s %d.%d.%d", fw_info, rec->data[0], rec->data[1], build);
2780
2781 edge_serial->product_info.FirmwareMajorVersion = fw->data[0];
2782 edge_serial->product_info.FirmwareMinorVersion = fw->data[1];
2783 edge_serial->product_info.FirmwareBuildNumber = cpu_to_le16(build);
2800 2784
2801 for (;;) { 2785 for (rec = ihex_next_binrec(rec); rec;
2802 record = (struct edge_firmware_image_record *)firmware; 2786 rec = ihex_next_binrec(rec)) {
2803 response = sram_write (edge_serial->serial, le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), le16_to_cpu(record->Len), &record->Data[0]); 2787 Operaddr = be32_to_cpu(rec->addr);
2788 response = sram_write(edge_serial->serial,
2789 Operaddr >> 16,
2790 Operaddr & 0xFFFF,
2791 be16_to_cpu(rec->len),
2792 &rec->data[0]);
2804 if (response < 0) { 2793 if (response < 0) {
2805 dev_err(&edge_serial->serial->dev->dev, "sram_write failed (%x, %x, %d)\n", le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), le16_to_cpu(record->Len)); 2794 dev_err(&edge_serial->serial->dev->dev,
2806 break; 2795 "sram_write failed (%x, %x, %d)\n",
2807 } 2796 Operaddr >> 16, Operaddr & 0xFFFF,
2808 firmware += sizeof (struct edge_firmware_image_record) + le16_to_cpu(record->Len); 2797 be16_to_cpu(rec->len));
2809 if (firmware >= &FirmwareImage[ImageSize]) {
2810 break; 2798 break;
2811 } 2799 }
2812 } 2800 }
@@ -2817,6 +2805,7 @@ static void load_application_firmware (struct edgeport_serial *edge_serial)
2817 USB_REQUEST_ION_EXEC_DL_CODE, 2805 USB_REQUEST_ION_EXEC_DL_CODE,
2818 0x40, 0x4000, 0x0001, NULL, 0, 3000); 2806 0x40, 0x4000, 0x0001, NULL, 0, 3000);
2819 2807
2808 release_firmware(fw);
2820 return; 2809 return;
2821} 2810}
2822 2811
@@ -2903,6 +2892,10 @@ static int edge_startup (struct usb_serial *serial)
2903// dbg("set_configuration 1"); 2892// dbg("set_configuration 1");
2904// usb_set_configuration (dev, 1); 2893// usb_set_configuration (dev, 1);
2905 } 2894 }
2895 dbg(" FirmwareMajorVersion %d.%d.%d",
2896 edge_serial->product_info.FirmwareMajorVersion,
2897 edge_serial->product_info.FirmwareMinorVersion,
2898 le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber));
2906 2899
2907 /* we set up the pointers to the endpoints in the edge_open function, 2900 /* we set up the pointers to the endpoints in the edge_open function,
2908 * as the structures aren't created yet. */ 2901 * as the structures aren't created yet. */
@@ -3115,6 +3108,10 @@ module_exit(edgeport_exit);
3115MODULE_AUTHOR( DRIVER_AUTHOR ); 3108MODULE_AUTHOR( DRIVER_AUTHOR );
3116MODULE_DESCRIPTION( DRIVER_DESC ); 3109MODULE_DESCRIPTION( DRIVER_DESC );
3117MODULE_LICENSE("GPL"); 3110MODULE_LICENSE("GPL");
3111MODULE_FIRMWARE("edgeport/boot.fw");
3112MODULE_FIRMWARE("edgeport/boot2.fw");
3113MODULE_FIRMWARE("edgeport/down.fw");
3114MODULE_FIRMWARE("edgeport/down2.fw");
3118 3115
3119module_param(debug, bool, S_IRUGO | S_IWUSR); 3116module_param(debug, bool, S_IRUGO | S_IWUSR);
3120MODULE_PARM_DESC(debug, "Debug enabled or not"); 3117MODULE_PARM_DESC(debug, "Debug enabled or not");