aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKelley Nielsen <kelleynnn@gmail.com>2013-10-29 11:06:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-29 11:36:17 -0400
commiteb2ec63979702f04d45f608f635b0533defefa16 (patch)
tree5bdb99ca8f757d6581266bd17cc69c70f5782297
parente0a223b465c609e2d03bea3551183e9a8ad2be81 (diff)
staging: ft1000: function write_dpram32_and_check extracted from write_blk
function write_blk is long and overly complex, consisting of a triply nested loop. It also has improper indentation and line lengths throughout, and has return type of u32 rather than int. Some of the lines, when converted to proper indentation, create checkpatch warnings for too many leading tabs. This patch extracts the innermost loop into its own function, write_dpram32_and_check. This removes several levels of indentation from the extracted lines and makes the original function simpler. Two local variables from the original function, u16 resultbuffer[] and a loop counter, have been made local variables of the new function. Two calls to msleep() have been replaced with usleep_range() as per Documentation/ timers/timers-howto.txt (which was referred to in a checkpatch warning). Several other style issues in the extracted code have been corrected as well. Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_download.c107
1 files changed, 58 insertions, 49 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
index afeafcdd517f..e5281b97775b 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
@@ -389,6 +389,61 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
389 return 0; 389 return 0;
390} 390}
391 391
392static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
393 u16 tempbuffer[], u16 dpram)
394{
395 int status;
396 u16 resultbuffer[64];
397 int i;
398
399 for (i = 0; i < 10; i++) {
400 status = ft1000_write_dpram32(ft1000dev, dpram,
401 (u8 *)&tempbuffer[0], 64);
402 if (status == STATUS_SUCCESS) {
403 /* Work around for ASIC bit stuffing problem. */
404 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
405 status = ft1000_write_dpram32(ft1000dev,
406 dpram+12, (u8 *)&tempbuffer[24],
407 64);
408 }
409 /* Let's check the data written */
410 status = ft1000_read_dpram32(ft1000dev, dpram,
411 (u8 *)&resultbuffer[0], 64);
412 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
413 if (check_buffers(tempbuffer, resultbuffer, 28,
414 0)) {
415 DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n");
416 usleep_range(9000, 11000);
417 status = STATUS_FAILURE;
418 break;
419 }
420 status = ft1000_read_dpram32(ft1000dev,
421 dpram+12,
422 (u8 *)&resultbuffer[0], 64);
423
424 if (check_buffers(tempbuffer, resultbuffer, 16,
425 24)) {
426 DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n");
427 usleep_range(9000, 11000);
428 status = STATUS_FAILURE;
429 break;
430 }
431 } else {
432 if (check_buffers(tempbuffer, resultbuffer, 32,
433 0)) {
434 DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n");
435 usleep_range(9000, 11000);
436 status = STATUS_FAILURE;
437 break;
438 }
439 }
440 if (status == STATUS_SUCCESS)
441 break;
442 }
443 }
444 return status;
445}
446
392/* writes a block of DSP image to DPRAM 447/* writes a block of DSP image to DPRAM
393 * Parameters: struct ft1000_usb - device structure 448 * Parameters: struct ft1000_usb - device structure
394 * u16 **pUsFile - DSP image file pointer in u16 449 * u16 **pUsFile - DSP image file pointer in u16
@@ -399,10 +454,9 @@ static u32 write_blk (struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
399{ 454{
400 u32 Status = STATUS_SUCCESS; 455 u32 Status = STATUS_SUCCESS;
401 u16 dpram; 456 u16 dpram;
402 int loopcnt, i, j; 457 int loopcnt, i;
403 u16 tempword; 458 u16 tempword;
404 u16 tempbuffer[64]; 459 u16 tempbuffer[64];
405 u16 resultbuffer[64];
406 460
407 //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); 461 //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length);
408 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC; 462 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
@@ -452,53 +506,8 @@ static u32 write_blk (struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
452 } 506 }
453 else 507 else
454 { 508 {
455 for (j=0; j<10; j++) 509 Status = write_dpram32_and_check(ft1000dev, tempbuffer,
456 { 510 dpram);
457 Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 64);
458 if (Status == STATUS_SUCCESS)
459 {
460 // Work around for ASIC bit stuffing problem.
461 if ( (tempbuffer[31] & 0xfe00) == 0xfe00)
462 {
463 Status = ft1000_write_dpram32(ft1000dev, dpram+12, (u8 *)&tempbuffer[24], 64);
464 }
465 // Let's check the data written
466 Status = ft1000_read_dpram32 (ft1000dev, dpram, (u8 *)&resultbuffer[0], 64);
467 if ( (tempbuffer[31] & 0xfe00) == 0xfe00)
468 {
469 if (check_buffers(tempbuffer, resultbuffer, 28, 0)) {
470 DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n");
471 msleep(10);
472 Status = STATUS_FAILURE;
473 break;
474 }
475 Status = ft1000_read_dpram32 (ft1000dev, dpram+12, (u8 *)&resultbuffer[0], 64);
476
477 if (check_buffers(tempbuffer, resultbuffer, 16, 24)) {
478 DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n");
479 msleep(10);
480 Status = STATUS_FAILURE;
481 break;
482 }
483
484 }
485 else
486 {
487 if (check_buffers(tempbuffer, resultbuffer, 32, 0)) {
488 DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n");
489 msleep(10);
490 Status = STATUS_FAILURE;
491 break;
492 }
493
494 }
495
496 if (Status == STATUS_SUCCESS)
497 break;
498
499 }
500 }
501
502 if (Status != STATUS_SUCCESS) 511 if (Status != STATUS_SUCCESS)
503 { 512 {
504 DEBUG("FT1000:download:Write failed tempbuffer[31] = 0x%x\n", tempbuffer[31]); 513 DEBUG("FT1000:download:Write failed tempbuffer[31] = 0x%x\n", tempbuffer[31]);