viafb: add new funcions to select a single mode

This patch introduces 2 new functions for selecting a single mode
based on hres, vres and refresh rate and changes some uses to use
those. The advantage is that it is less error prone than doing the
selection based on refresh rate everywhere and allows replacing the
modetable structure. This includes a little change that users may
notice: If a refresh rate was given as module parameters but does
not exist in the modetable prior to this patch a refresh rate of 60
was assumed and after this patch the closest supported refresh rate
to the one provided by the user is used.
Signed-off-by: default avatarFlorian Tobias Schandinat <FlorianSchandinat@gmx.de>
parent 36369972
...@@ -2035,40 +2035,24 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp, ...@@ -2035,40 +2035,24 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
int viafb_get_pixclock(int hres, int vres, int vmode_refresh) int viafb_get_pixclock(int hres, int vres, int vmode_refresh)
{ {
int i;
struct crt_mode_table *best; struct crt_mode_table *best;
struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
if (!vmode) best = viafb_get_best_mode(hres, vres, vmode_refresh);
if (!best)
return RES_640X480_60HZ_PIXCLOCK; return RES_640X480_60HZ_PIXCLOCK;
best = &vmode->crtc[0];
for (i = 1; i < vmode->mode_array; i++) {
if (abs(vmode->crtc[i].refresh_rate - vmode_refresh)
< abs(best->refresh_rate - vmode_refresh))
best = &vmode->crtc[i];
}
return 1000000000 / (best->crtc.hor_total * best->crtc.ver_total) return 1000000000 / (best->crtc.hor_total * best->crtc.ver_total)
* 1000 / best->refresh_rate; * 1000 / best->refresh_rate;
} }
int viafb_get_refresh(int hres, int vres, u32 long_refresh) int viafb_get_refresh(int hres, int vres, u32 long_refresh)
{ {
int i;
struct crt_mode_table *best; struct crt_mode_table *best;
struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
if (!vmode) best = viafb_get_best_mode(hres, vres, long_refresh);
if (!best)
return 60; return 60;
best = &vmode->crtc[0];
for (i = 1; i < vmode->mode_array; i++) {
if (abs(vmode->crtc[i].refresh_rate - long_refresh)
< abs(best->refresh_rate - long_refresh))
best = &vmode->crtc[i];
}
if (abs(best->refresh_rate - long_refresh) > 3) { if (abs(best->refresh_rate - long_refresh) > 3) {
if (hres == 1200 && vres == 900) if (hres == 1200 && vres == 900)
return 49; /* OLPC DCON only supports 50 Hz */ return 49; /* OLPC DCON only supports 50 Hz */
...@@ -2170,21 +2154,14 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\ ...@@ -2170,21 +2154,14 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
} }
/*According var's xres, yres fill var's other timing information*/ /*According var's xres, yres fill var's other timing information*/
void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh, void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
struct VideoModeTable *vmode_tbl) struct crt_mode_table *mode)
{ {
struct crt_mode_table *crt_timing = NULL;
struct display_timing crt_reg; struct display_timing crt_reg;
int i = 0, index = 0;
crt_timing = vmode_tbl->crtc;
for (i = 0; i < vmode_tbl->mode_array; i++) {
index = i;
if (crt_timing[i].refresh_rate == refresh)
break;
}
crt_reg = crt_timing[index].crtc; crt_reg = mode->crtc;
var->pixclock = viafb_get_pixclock(var->xres, var->yres, refresh); var->pixclock = viafb_get_pixclock(var->xres, var->yres,
mode->refresh_rate);
var->left_margin = var->left_margin =
crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end); crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end);
var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr; var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr;
...@@ -2194,8 +2171,8 @@ void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh, ...@@ -2194,8 +2171,8 @@ void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
var->lower_margin = crt_reg.ver_sync_start - crt_reg.ver_addr; var->lower_margin = crt_reg.ver_sync_start - crt_reg.ver_addr;
var->vsync_len = crt_reg.ver_sync_end; var->vsync_len = crt_reg.ver_sync_end;
var->sync = 0; var->sync = 0;
if (crt_timing[index].h_sync_polarity == POSITIVE) if (mode->h_sync_polarity == POSITIVE)
var->sync |= FB_SYNC_HOR_HIGH_ACT; var->sync |= FB_SYNC_HOR_HIGH_ACT;
if (crt_timing[index].v_sync_polarity == POSITIVE) if (mode->v_sync_polarity == POSITIVE)
var->sync |= FB_SYNC_VERT_HIGH_ACT; var->sync |= FB_SYNC_VERT_HIGH_ACT;
} }
...@@ -661,8 +661,8 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\ ...@@ -661,8 +661,8 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp, int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
struct VideoModeTable *vmode_tbl1, int video_bpp1); struct VideoModeTable *vmode_tbl1, int video_bpp1);
void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh, void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
struct VideoModeTable *vmode_tbl); struct crt_mode_table *mode);
void __devinit viafb_init_chip_info(int chip_type); void __devinit viafb_init_chip_info(int chip_type);
void __devinit viafb_init_dac(int set_iga); void __devinit viafb_init_dac(int set_iga);
int viafb_get_pixclock(int hres, int vres, int vmode_refresh); int viafb_get_pixclock(int hres, int vres, int vmode_refresh);
......
...@@ -201,7 +201,6 @@ static int viafb_check_var(struct fb_var_screeninfo *var, ...@@ -201,7 +201,6 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
struct fb_info *info) struct fb_info *info)
{ {
int depth, refresh; int depth, refresh;
struct VideoModeTable *vmode_entry;
struct viafb_par *ppar = info->par; struct viafb_par *ppar = info->par;
u32 line; u32 line;
...@@ -211,8 +210,10 @@ static int viafb_check_var(struct fb_var_screeninfo *var, ...@@ -211,8 +210,10 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE) if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
return -EINVAL; return -EINVAL;
vmode_entry = viafb_get_mode(var->xres, var->yres); /* the refresh rate is not important here, as we only want to know
if (!vmode_entry) { * whether the resolution exists
*/
if (!viafb_get_best_mode(var->xres, var->yres, 60)) {
DEBUG_MSG(KERN_INFO DEBUG_MSG(KERN_INFO
"viafb: Mode %dx%dx%d not supported!!\n", "viafb: Mode %dx%dx%d not supported!!\n",
var->xres, var->yres, var->bits_per_pixel); var->xres, var->yres, var->bits_per_pixel);
...@@ -254,7 +255,8 @@ static int viafb_check_var(struct fb_var_screeninfo *var, ...@@ -254,7 +255,8 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
get_var_refresh(var)); get_var_refresh(var));
/* Adjust var according to our driver's own table */ /* Adjust var according to our driver's own table */
viafb_fill_var_timing_info(var, refresh, vmode_entry); viafb_fill_var_timing_info(var,
viafb_get_best_mode(var->xres, var->yres, refresh));
if (var->accel_flags & FB_ACCELF_TEXT && if (var->accel_flags & FB_ACCELF_TEXT &&
!ppar->shared->vdev->engine_mmio) !ppar->shared->vdev->engine_mmio)
var->accel_flags = 0; var->accel_flags = 0;
...@@ -1816,9 +1818,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev) ...@@ -1816,9 +1818,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
default_var.xres_virtual = default_xres; default_var.xres_virtual = default_xres;
default_var.yres_virtual = default_yres; default_var.yres_virtual = default_yres;
default_var.bits_per_pixel = viafb_bpp; default_var.bits_per_pixel = viafb_bpp;
viafb_fill_var_timing_info(&default_var, viafb_get_refresh( viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
default_var.xres, default_var.yres, viafb_refresh), default_var.xres, default_var.yres, viafb_refresh));
viafb_get_mode(default_var.xres, default_var.yres));
viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo); viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
viafbinfo->var = default_var; viafbinfo->var = default_var;
...@@ -1857,9 +1858,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev) ...@@ -1857,9 +1858,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
default_var.xres_virtual = viafb_second_xres; default_var.xres_virtual = viafb_second_xres;
default_var.yres_virtual = viafb_second_yres; default_var.yres_virtual = viafb_second_yres;
default_var.bits_per_pixel = viafb_bpp1; default_var.bits_per_pixel = viafb_bpp1;
viafb_fill_var_timing_info(&default_var, viafb_get_refresh( viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
default_var.xres, default_var.yres, viafb_refresh1), default_var.xres, default_var.yres, viafb_refresh1));
viafb_get_mode(default_var.xres, default_var.yres));
viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1); viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
viafb_check_var(&default_var, viafbinfo1); viafb_check_var(&default_var, viafbinfo1);
...@@ -2032,9 +2032,9 @@ int __init viafb_init(void) ...@@ -2032,9 +2032,9 @@ int __init viafb_init(void)
return r; return r;
#endif #endif
if (parse_mode(viafb_mode, &dummy_x, &dummy_y) if (parse_mode(viafb_mode, &dummy_x, &dummy_y)
|| !viafb_get_mode(dummy_x, dummy_y) || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh)
|| parse_mode(viafb_mode1, &dummy_x, &dummy_y) || parse_mode(viafb_mode1, &dummy_x, &dummy_y)
|| !viafb_get_mode(dummy_x, dummy_y) || !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh1)
|| viafb_bpp < 0 || viafb_bpp > 32 || viafb_bpp < 0 || viafb_bpp > 32
|| viafb_bpp1 < 0 || viafb_bpp1 > 32 || viafb_bpp1 < 0 || viafb_bpp1 > 32
|| parse_active_dev()) || parse_active_dev())
......
...@@ -863,26 +863,56 @@ int NUM_TOTAL_CLE266_ModeXregs = ARRAY_SIZE(CLE266_ModeXregs); ...@@ -863,26 +863,56 @@ int NUM_TOTAL_CLE266_ModeXregs = ARRAY_SIZE(CLE266_ModeXregs);
int NUM_TOTAL_PATCH_MODE = ARRAY_SIZE(res_patch_table); int NUM_TOTAL_PATCH_MODE = ARRAY_SIZE(res_patch_table);
struct VideoModeTable *viafb_get_mode(int hres, int vres) static struct VideoModeTable *get_modes(struct VideoModeTable *vmt, int n,
int hres, int vres)
{ {
u32 i; int i;
for (i = 0; i < ARRAY_SIZE(viafb_modes); i++)
if (viafb_modes[i].mode_array && for (i = 0; i < n; i++)
viafb_modes[i].crtc[0].crtc.hor_addr == hres && if (vmt[i].mode_array &&
viafb_modes[i].crtc[0].crtc.ver_addr == vres) vmt[i].crtc[0].crtc.hor_addr == hres &&
vmt[i].crtc[0].crtc.ver_addr == vres)
return &viafb_modes[i]; return &viafb_modes[i];
return NULL; return NULL;
} }
struct VideoModeTable *viafb_get_rb_mode(int hres, int vres) static struct crt_mode_table *get_best_mode(struct VideoModeTable *vmt,
int refresh)
{ {
u32 i; struct crt_mode_table *best;
for (i = 0; i < ARRAY_SIZE(viafb_rb_modes); i++) int i;
if (viafb_rb_modes[i].mode_array &&
viafb_rb_modes[i].crtc[0].crtc.hor_addr == hres &&
viafb_rb_modes[i].crtc[0].crtc.ver_addr == vres)
return &viafb_rb_modes[i];
if (!vmt)
return NULL; return NULL;
best = &vmt->crtc[0];
for (i = 1; i < vmt->mode_array; i++) {
if (abs(vmt->crtc[i].refresh_rate - refresh)
< abs(best->refresh_rate - refresh))
best = &vmt->crtc[i];
}
return best;
}
struct VideoModeTable *viafb_get_mode(int hres, int vres)
{
return get_modes(viafb_modes, ARRAY_SIZE(viafb_modes), hres, vres);
}
struct crt_mode_table *viafb_get_best_mode(int hres, int vres, int refresh)
{
return get_best_mode(viafb_get_mode(hres, vres), refresh);
}
struct VideoModeTable *viafb_get_rb_mode(int hres, int vres)
{
return get_modes(viafb_rb_modes, ARRAY_SIZE(viafb_rb_modes), hres,
vres);
}
struct crt_mode_table *viafb_get_best_rb_mode(int hres, int vres, int refresh)
{
return get_best_mode(viafb_get_rb_mode(hres, vres), refresh);
} }
...@@ -61,6 +61,8 @@ extern struct patch_table res_patch_table[]; ...@@ -61,6 +61,8 @@ extern struct patch_table res_patch_table[];
extern struct VPITTable VPIT; extern struct VPITTable VPIT;
struct VideoModeTable *viafb_get_mode(int hres, int vres); struct VideoModeTable *viafb_get_mode(int hres, int vres);
struct crt_mode_table *viafb_get_best_mode(int hres, int vres, int refresh);
struct VideoModeTable *viafb_get_rb_mode(int hres, int vres); struct VideoModeTable *viafb_get_rb_mode(int hres, int vres);
struct crt_mode_table *viafb_get_best_rb_mode(int hres, int vres, int refresh);
#endif /* __VIAMODE_H__ */ #endif /* __VIAMODE_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment