@@ -362,7 +362,11 @@ int cvs_dev_fw_dl(void)
362362 }
363363
364364 if (!status ) {
365- status = cvs_wait_for_host_wake (WAIT_HOST_WAKE_RESET_MS );
365+ if (cvs_wait_for_host_wake (WAIT_HOST_WAKE_RESET_MS )) {
366+ dev_err (cvs -> dev , "%s:CV reset FW boot hostwake error" ,
367+ __func__ );
368+ return - ETIMEDOUT ;
369+ }
366370 }
367371
368372 dev_info (cvs -> dev , "%s:Exit with status:0x%x" , __func__ , status );
@@ -392,51 +396,6 @@ static int cvs_get_fwver_vid_pid(void)
392396 return 0 ;
393397}
394398
395- static bool iterate_files (struct dir_context * fdir , const char * name ,
396- int namelen , loff_t offset , u64 ino ,
397- unsigned int d_type )
398- {
399- if (d_type == DT_REG &&
400- strncmp (name , cvs -> file_prefix , strlen (cvs -> file_prefix )) == 0 ) {
401- dev_dbg (cvs -> dev , "%s:File found: %s " , __func__ , name );
402- cvs -> fw_filename = (char * )devm_kzalloc (
403- cvs -> dev , strlen (name ) + 1 , GFP_KERNEL );
404- strcpy (cvs -> fw_filename , name );
405- cvs -> fw_bin_file_found = true;
406-
407- /* Return 'false' to stop (OR) if there are no more entries */
408- return false;
409- }
410-
411- /* Return 'true' to keep going */
412- return true;
413- }
414-
415- static bool cvs_search_fw_file (void )
416- {
417- struct file * filp ;
418- struct dir_context fdir = { 0 };
419- int ret ;
420- const char * path_to_search = "/lib/firmware/" ;
421-
422- sprintf (cvs -> file_prefix , "%d-%d" , cvs -> id .vid , cvs -> id .pid );
423- dev_dbg (cvs -> dev , "%s:VID-PID as string: %s" , __func__ ,
424- cvs -> file_prefix );
425-
426- filp = filp_open (path_to_search , O_RDONLY | O_DIRECTORY , 0 );
427- if (IS_ERR_OR_NULL (filp )) {
428- dev_err (cvs -> dev , "%s:Failed to open directory: %ld" , __func__ ,
429- PTR_ERR (filp ));
430- return PTR_ERR (filp );
431- }
432-
433- fdir .actor = iterate_files ;
434- fdir .pos = 0 ;
435- ret = iterate_dir (filp , & fdir );
436- filp_close (filp , NULL );
437- return cvs -> fw_bin_file_found ;
438- }
439-
440399static u32 cvs_calc_checksum (void * data )
441400{
442401 int i ;
@@ -481,7 +440,7 @@ static int cvs_fw_parse(void)
481440 ptr_fw_header -> fw_ver .hotfix ,
482441 ptr_fw_header -> fw_ver .build );
483442
484- dev_info (cvs -> dev , "%s:Lib VID:%d , PID:%d , fw_offset:%d " ,
443+ dev_info (cvs -> dev , "%s:Lib VID:0X%x , PID:0x%x , fw_offset:0x%x " ,
485444 __func__ , ptr_fw_header -> vid_pid .vid ,
486445 ptr_fw_header -> vid_pid .pid ,
487446 ptr_fw_header -> fw_offset );
@@ -502,37 +461,46 @@ static int cvs_fw_parse(void)
502461 (cvs -> ver .hotfix != ptr_fw_header -> fw_ver .hotfix ) ||
503462 (cvs -> ver .build != ptr_fw_header -> fw_ver .build )) {
504463 cvs -> fw_dl_needed = true;
505- dev_info (cvs -> dev , "%s:FW update needed" , __func__ );
506- } else
464+ dev_dbg (cvs -> dev , "%s:FW update needed" , __func__ );
465+ }
466+ else {
467+ cvs -> fw_dl_needed = false;
507468 dev_info (cvs -> dev , "%s:FW update not needed" , __func__ );
469+ }
508470
509471 return 0 ;
510472}
511473
512474static bool evaluate_fw (void )
513475{
514476 int ret , status = 1 ;
515- dev_info (cvs -> dev , "%s:file name is %s : %p\n" , __func__ ,
516- cvs -> fw_filename , cvs -> dev );
517- ret = firmware_request_nowarn (& cvs -> file , cvs -> fw_filename , cvs -> dev );
477+
478+ if (cvs -> oem_prod_id ) {
479+ sprintf (cvs -> fw_filename , "cvs/%04X%04X-%04llX.bin" ,
480+ cvs -> id .vid , cvs -> id .pid , cvs -> oem_prod_id );
481+ }
482+ else
483+ sprintf (cvs -> fw_filename , "cvs/%04X%04X.bin" ,
484+ cvs -> id .vid , cvs -> id .pid );
485+
486+ ret = request_firmware (& cvs -> file , cvs -> fw_filename , cvs -> dev );
518487 if (ret ) {
519488 dev_err (cvs -> dev ,
520- "%s:firmware_request_nowarn () fail with ret:%d\n " ,
489+ "%s:request_firmware () fail with ret:%d" ,
521490 __func__ , ret );
522491 return ret ;
523492 }
524493
525494 dev_dbg (cvs -> dev ,
526- "%s:firmware_request() pass with name:%s, data:%p, size:%d\n" ,
527- __func__ , cvs -> fw_filename , cvs -> file -> data ,
528- (int )cvs -> file -> size );
495+ "%s: FW bin file found with file_ptr:%p, size:0x%x" ,
496+ __func__ , cvs -> file -> data , (int )cvs -> file -> size );
529497
530498 /* Alloc memory for FW Image Buffer */
531499 cvs -> fw_buffer_size = cvs -> file -> size ;
532500 cvs -> fw_buffer =
533501 devm_kzalloc (cvs -> dev , cvs -> fw_buffer_size , GFP_KERNEL );
534502 if (IS_ERR_OR_NULL (cvs -> fw_buffer )) {
535- dev_err (cvs -> dev , "%s:NO memory for fw_buffer" , __func__ );
503+ dev_err (cvs -> dev , "%s:No memory for fw_buffer" , __func__ );
536504 status = - ENOMEM ;
537505 goto err_fw_release ;
538506 }
@@ -546,8 +514,7 @@ static bool evaluate_fw(void)
546514
547515 status = cvs_fw_parse ();
548516 if (status ) {
549- dev_err (cvs -> dev , "%s:cvs_fw_parse() fail with status:%d\n" ,
550- __func__ , status );
517+ dev_err (cvs -> dev , "%s: FW bin file is invalid" , __func__ );
551518 goto err_fw_release ;
552519 }
553520
@@ -594,15 +561,19 @@ void cvs_fw_dl_thread(struct work_struct *arg)
594561 }
595562 cvs -> icvs_sensor_state = CV_SENSOR_VISION_ACQUIRED_STATE ;
596563
597- if (!cvs_get_fwver_vid_pid () && cvs_search_fw_file ()) {
598- dev_info (cvs -> dev , "%s:FW file found" , __func__ );
564+ if (!cvs_get_fwver_vid_pid ()) {
565+ dev_info (cvs -> dev , "%s:Device FW version is %d.%d.%d.%d" ,
566+ __func__ , cvs -> ver .major , cvs -> ver .minor ,
567+ cvs -> ver .hotfix , cvs -> ver .build );
599568 if (evaluate_fw ()) {
600- dev_err (cvs -> dev , "%s:FW file found is invalid " ,
569+ dev_err (cvs -> dev , "%s:FW file not found " ,
601570 __func__ );
602571 goto err_exit ;
603572 }
604- } else {
605- dev_info (cvs -> dev , "%s:FW file not found" , __func__ );
573+ }
574+ else {
575+ dev_info (cvs -> dev , "%s:I2C error. Not able to read vid/pid" ,
576+ __func__ );
606577 goto err_exit ;
607578 }
608579
0 commit comments