@@ -585,61 +585,81 @@ static void ps3avd(struct work_struct *work)
585585 complete (& ps3av -> done );
586586}
587587
588- static int ps3av_resbit2id (u32 res_50 , u32 res_60 )
588+ #define SHIFT_50 0
589+ #define SHIFT_60 4
590+ #define SHIFT_VESA 8
591+
592+ static const struct {
593+ unsigned mask : 19 ;
594+ unsigned id : 4 ;
595+ } ps3av_preferred_modes [] = {
596+ { .mask = PS3AV_RESBIT_WUXGA << SHIFT_VESA , .id = 13 },
597+ { .mask = PS3AV_RESBIT_1920x1080P << SHIFT_60 , .id = 5 },
598+ { .mask = PS3AV_RESBIT_1920x1080P << SHIFT_50 , .id = 10 },
599+ { .mask = PS3AV_RESBIT_1920x1080I << SHIFT_60 , .id = 4 },
600+ { .mask = PS3AV_RESBIT_1920x1080I << SHIFT_50 , .id = 9 },
601+ { .mask = PS3AV_RESBIT_SXGA << SHIFT_VESA , .id = 12 },
602+ { .mask = PS3AV_RESBIT_WXGA << SHIFT_VESA , .id = 11 },
603+ { .mask = PS3AV_RESBIT_1280x720P << SHIFT_60 , .id = 3 },
604+ { .mask = PS3AV_RESBIT_1280x720P << SHIFT_50 , .id = 8 },
605+ { .mask = PS3AV_RESBIT_720x480P << SHIFT_60 , .id = 2 },
606+ { .mask = PS3AV_RESBIT_720x576P << SHIFT_50 , .id = 7 },
607+ };
608+
609+ static int ps3av_resbit2id (u32 res_50 , u32 res_60 , u32 res_vesa )
589610{
590- int id = 0 ;
591-
592- if (res_50 > res_60 ) { /* if res_50 == res_60, res_60 will be used */
593- if (res_50 & PS3AV_RESBIT_1920x1080P )
594- id = 10 ;
595- else if (res_50 & PS3AV_RESBIT_1920x1080I )
596- id = 9 ;
597- else if (res_50 & PS3AV_RESBIT_1280x720P )
598- id = 8 ;
599- else if (res_50 & PS3AV_RESBIT_720x576P )
600- id = 7 ;
601- else
602- id = 0 ;
603- } else {
604- if (res_60 & PS3AV_RESBIT_1920x1080P )
605- id = 5 ;
606- else if (res_60 & PS3AV_RESBIT_1920x1080I )
607- id = 4 ;
608- else if (res_60 & PS3AV_RESBIT_1280x720P )
609- id = 3 ;
610- else if (res_60 & PS3AV_RESBIT_720x480P )
611- id = 2 ;
612- else
613- id = 0 ;
614- }
615- return id ;
611+ unsigned int i ;
612+ u32 res_all ;
613+
614+ /*
615+ * We mask off the resolution bits we care about and combine the
616+ * results in one bitfield, so make sure there's no overlap
617+ */
618+ BUILD_BUG_ON (PS3AV_RES_MASK_50 << SHIFT_50 &
619+ PS3AV_RES_MASK_60 << SHIFT_60 );
620+ BUILD_BUG_ON (PS3AV_RES_MASK_50 << SHIFT_50 &
621+ PS3AV_RES_MASK_VESA << SHIFT_VESA );
622+ BUILD_BUG_ON (PS3AV_RES_MASK_60 << SHIFT_60 &
623+ PS3AV_RES_MASK_VESA << SHIFT_VESA );
624+ res_all = (res_50 & PS3AV_RES_MASK_50 ) << SHIFT_50 |
625+ (res_60 & PS3AV_RES_MASK_60 ) << SHIFT_60 |
626+ (res_vesa & PS3AV_RES_MASK_VESA ) << SHIFT_VESA ;
627+
628+ if (!res_all )
629+ return 0 ;
630+
631+ for (i = 0 ; i < ARRAY_SIZE (ps3av_preferred_modes ); i ++ )
632+ if (res_all & ps3av_preferred_modes [i ].mask )
633+ return ps3av_preferred_modes [i ].id ;
634+
635+ return 0 ;
616636}
617637
618638static int ps3av_hdmi_get_id (struct ps3av_info_monitor * info )
619639{
620- u32 res_50 , res_60 ;
621640 int id ;
622641
623642 /* check native resolution */
624- res_50 = info -> res_50 .native & PS3AV_RES_MASK_50 ;
625- res_60 = info -> res_60 .native & PS3AV_RES_MASK_60 ;
626- if (res_50 || res_60 ) {
627- id = ps3av_resbit2id ( res_50 , res_60 );
643+ id = ps3av_resbit2id ( info -> res_50 .native , info -> res_60 . native ,
644+ info -> res_vesa .native ) ;
645+ if (id ) {
646+ pr_debug ( "%s: Using native mode %d\n" , __func__ , id );
628647 return id ;
629648 }
630649
631- /* check resolution */
632- res_50 = info -> res_50 .res_bits & PS3AV_RES_MASK_50 ;
633- res_60 = info -> res_60 .res_bits & PS3AV_RES_MASK_60 ;
634- if (res_50 || res_60 ) {
635- id = ps3av_resbit2id ( res_50 , res_60 );
650+ /* check supported resolutions */
651+ id = ps3av_resbit2id ( info -> res_50 .res_bits , info -> res_60 . res_bits ,
652+ info -> res_vesa .res_bits ) ;
653+ if (id ) {
654+ pr_debug ( "%s: Using supported mode %d\n" , __func__ , id );
636655 return id ;
637656 }
638657
639658 if (ps3av -> region & PS3AV_REGION_60 )
640659 id = PS3AV_DEFAULT_HDMI_MODE_ID_REG_60 ;
641660 else
642661 id = PS3AV_DEFAULT_HDMI_MODE_ID_REG_50 ;
662+ pr_debug ("%s: Using default mode %d\n" , __func__ , id );
643663 return id ;
644664}
645665
@@ -737,6 +757,7 @@ static int ps3av_auto_videomode(struct ps3av_pkt_av_get_hw_conf *av_hw_conf,
737757 id = PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_50 ;
738758 if (ps3av -> region & PS3AV_REGION_RGB )
739759 rgb = PS3AV_MODE_RGB ;
760+ pr_debug ("%s: Using avmulti mode %d\n" , __func__ , id );
740761 } else if (boot ) {
741762 /* HDMI: using DEFAULT HDMI_MODE_ID while booting up */
742763 info = & monitor_info .info ;
0 commit comments