@@ -605,8 +605,8 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
605605 v4l2_std_id * id )
606606{
607607 struct xc4000_priv * priv = fe -> tuner_priv ;
608- int i , best_i = -1 , best_nr_matches = 0 ;
609- unsigned int type_mask = 0 ;
608+ int i , best_i = -1 ;
609+ unsigned int best_nr_diffs = 255U ;
610610
611611 if (!priv -> firm ) {
612612 printk ("Error! firmware not loaded\n" );
@@ -616,63 +616,42 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
616616 if (((type & ~SCODE ) == 0 ) && (* id == 0 ))
617617 * id = V4L2_STD_PAL ;
618618
619- if (type & BASE )
620- type_mask = BASE_TYPES ;
621- else if (type & SCODE ) {
622- type &= SCODE_TYPES ;
623- type_mask = SCODE_TYPES & ~HAS_IF ;
624- } else if (type & DTV_TYPES )
625- type_mask = DTV_TYPES ;
626- else if (type & STD_SPECIFIC_TYPES )
627- type_mask = STD_SPECIFIC_TYPES ;
628-
629- type &= type_mask ;
630-
631- if (!(type & SCODE ))
632- type_mask = ~0 ;
633-
634- /* Seek for exact match */
635- for (i = 0 ; i < priv -> firm_size ; i ++ ) {
636- if ((type == (priv -> firm [i ].type & type_mask )) &&
637- (* id == priv -> firm [i ].id ))
638- goto found ;
639- }
640-
641619 /* Seek for generic video standard match */
642620 for (i = 0 ; i < priv -> firm_size ; i ++ ) {
643- v4l2_std_id match_mask ;
644- int nr_matches ;
645-
646- if (type != (priv -> firm [i ].type & type_mask ))
621+ v4l2_std_id id_diff_mask =
622+ (priv -> firm [i ].id ^ (* id )) & (* id );
623+ unsigned int type_diff_mask =
624+ (priv -> firm [i ].type ^ type )
625+ & (BASE_TYPES | DTV_TYPES | LCD | NOGD | MONO | SCODE );
626+ unsigned int nr_diffs ;
627+
628+ if (type_diff_mask
629+ & (BASE | INIT1 | FM | DTV6 | DTV7 | DTV78 | DTV8 | SCODE ))
647630 continue ;
648631
649- match_mask = * id & priv -> firm [i ].id ;
650- if (!match_mask )
651- continue ;
652-
653- if ((* id & match_mask ) == * id )
654- goto found ; /* Supports all the requested standards */
632+ nr_diffs = hweight64 (id_diff_mask ) + hweight32 (type_diff_mask );
633+ if (!nr_diffs ) /* Supports all the requested standards */
634+ goto found ;
655635
656- nr_matches = hweight64 (match_mask );
657- if (nr_matches > best_nr_matches ) {
658- best_nr_matches = nr_matches ;
636+ if (nr_diffs < best_nr_diffs ) {
637+ best_nr_diffs = nr_diffs ;
659638 best_i = i ;
660639 }
661640 }
662641
663- if (best_nr_matches > 0 ) {
664- printk ("Selecting best matching firmware (%d bits) for "
665- "type=" , best_nr_matches );
642+ /* FIXME: Would make sense to seek for type "hint" match ? */
643+ if (best_i < 0 ) {
644+ i = - ENOENT ;
645+ goto ret ;
646+ }
647+
648+ if (best_nr_diffs > 0U ) {
649+ printk ("Selecting best matching firmware (%u bits differ) for "
650+ "type=" , best_nr_diffs );
666651 printk ("(%x), id %016llx:\n" , type , (unsigned long long )* id );
667652 i = best_i ;
668- goto found ;
669653 }
670654
671- /*FIXME: Would make sense to seek for type "hint" match ? */
672-
673- i = - ENOENT ;
674- goto ret ;
675-
676655found :
677656 * id = priv -> firm [i ].id ;
678657
0 commit comments