aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/modedb.c
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2011-09-13 12:05:08 -0400
committerFlorian Tobias Schandinat <FlorianSchandinat@gmx.de>2011-09-14 12:40:52 -0400
commitf92d39e926003f925dc6a8ea6be72a16869337ae (patch)
tree8b3620461cfc45c1859fce3f9ef3815b5fc17ab4 /drivers/video/modedb.c
parenta67472ad1ae040f073e45048cbc5a01195f2e3f5 (diff)
fbdev: fix indentation in modedb.c
Fix the incorrect indentation in functions fb_try_mode() and fb_find_mode(). Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Diffstat (limited to 'drivers/video/modedb.c')
-rw-r--r--drivers/video/modedb.c444
1 files changed, 225 insertions, 219 deletions
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index cb175fe7abc0..a9a907c440d7 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -491,55 +491,56 @@ EXPORT_SYMBOL(vesa_modes);
491static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info, 491static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
492 const struct fb_videomode *mode, unsigned int bpp) 492 const struct fb_videomode *mode, unsigned int bpp)
493{ 493{
494 int err = 0; 494 int err = 0;
495 495
496 DPRINTK("Trying mode %s %dx%d-%d@%d\n", mode->name ? mode->name : "noname", 496 DPRINTK("Trying mode %s %dx%d-%d@%d\n",
497 mode->xres, mode->yres, bpp, mode->refresh); 497 mode->name ? mode->name : "noname",
498 var->xres = mode->xres; 498 mode->xres, mode->yres, bpp, mode->refresh);
499 var->yres = mode->yres; 499 var->xres = mode->xres;
500 var->xres_virtual = mode->xres; 500 var->yres = mode->yres;
501 var->yres_virtual = mode->yres; 501 var->xres_virtual = mode->xres;
502 var->xoffset = 0; 502 var->yres_virtual = mode->yres;
503 var->yoffset = 0; 503 var->xoffset = 0;
504 var->bits_per_pixel = bpp; 504 var->yoffset = 0;
505 var->activate |= FB_ACTIVATE_TEST; 505 var->bits_per_pixel = bpp;
506 var->pixclock = mode->pixclock; 506 var->activate |= FB_ACTIVATE_TEST;
507 var->left_margin = mode->left_margin; 507 var->pixclock = mode->pixclock;
508 var->right_margin = mode->right_margin; 508 var->left_margin = mode->left_margin;
509 var->upper_margin = mode->upper_margin; 509 var->right_margin = mode->right_margin;
510 var->lower_margin = mode->lower_margin; 510 var->upper_margin = mode->upper_margin;
511 var->hsync_len = mode->hsync_len; 511 var->lower_margin = mode->lower_margin;
512 var->vsync_len = mode->vsync_len; 512 var->hsync_len = mode->hsync_len;
513 var->sync = mode->sync; 513 var->vsync_len = mode->vsync_len;
514 var->vmode = mode->vmode; 514 var->sync = mode->sync;
515 if (info->fbops->fb_check_var) 515 var->vmode = mode->vmode;
516 err = info->fbops->fb_check_var(var, info); 516 if (info->fbops->fb_check_var)
517 var->activate &= ~FB_ACTIVATE_TEST; 517 err = info->fbops->fb_check_var(var, info);
518 return err; 518 var->activate &= ~FB_ACTIVATE_TEST;
519 return err;
519} 520}
520 521
521/** 522/**
522 * fb_find_mode - finds a valid video mode 523 * fb_find_mode - finds a valid video mode
523 * @var: frame buffer user defined part of display 524 * @var: frame buffer user defined part of display
524 * @info: frame buffer info structure 525 * @info: frame buffer info structure
525 * @mode_option: string video mode to find 526 * @mode_option: string video mode to find
526 * @db: video mode database 527 * @db: video mode database
527 * @dbsize: size of @db 528 * @dbsize: size of @db
528 * @default_mode: default video mode to fall back to 529 * @default_mode: default video mode to fall back to
529 * @default_bpp: default color depth in bits per pixel 530 * @default_bpp: default color depth in bits per pixel
530 * 531 *
531 * Finds a suitable video mode, starting with the specified mode 532 * Finds a suitable video mode, starting with the specified mode
532 * in @mode_option with fallback to @default_mode. If 533 * in @mode_option with fallback to @default_mode. If
533 * @default_mode fails, all modes in the video mode database will 534 * @default_mode fails, all modes in the video mode database will
534 * be tried. 535 * be tried.
535 * 536 *
536 * Valid mode specifiers for @mode_option: 537 * Valid mode specifiers for @mode_option:
537 * 538 *
538 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or 539 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
539 * <name>[-<bpp>][@<refresh>] 540 * <name>[-<bpp>][@<refresh>]
540 * 541 *
541 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and 542 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
542 * <name> a string. 543 * <name> a string.
543 * 544 *
544 * If 'M' is present after yres (and before refresh/bpp if present), 545 * If 'M' is present after yres (and before refresh/bpp if present),
545 * the function will compute the timings using VESA(tm) Coordinated 546 * the function will compute the timings using VESA(tm) Coordinated
@@ -551,12 +552,12 @@ static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
551 * 552 *
552 * 1024x768MR-8@60m - Reduced blank with margins at 60Hz. 553 * 1024x768MR-8@60m - Reduced blank with margins at 60Hz.
553 * 554 *
554 * NOTE: The passed struct @var is _not_ cleared! This allows you 555 * NOTE: The passed struct @var is _not_ cleared! This allows you
555 * to supply values for e.g. the grayscale and accel_flags fields. 556 * to supply values for e.g. the grayscale and accel_flags fields.
556 * 557 *
557 * Returns zero for failure, 1 if using specified @mode_option, 558 * Returns zero for failure, 1 if using specified @mode_option,
558 * 2 if using specified @mode_option with an ignored refresh rate, 559 * 2 if using specified @mode_option with an ignored refresh rate,
559 * 3 if default mode is used, 4 if fall back to any valid mode. 560 * 3 if default mode is used, 4 if fall back to any valid mode.
560 * 561 *
561 */ 562 */
562 563
@@ -566,198 +567,203 @@ int fb_find_mode(struct fb_var_screeninfo *var,
566 const struct fb_videomode *default_mode, 567 const struct fb_videomode *default_mode,
567 unsigned int default_bpp) 568 unsigned int default_bpp)
568{ 569{
569 int i; 570 int i;
570
571 /* Set up defaults */
572 if (!db) {
573 db = modedb;
574 dbsize = ARRAY_SIZE(modedb);
575 }
576
577 if (!default_mode)
578 default_mode = &db[0];
579
580 if (!default_bpp)
581 default_bpp = 8;
582
583 /* Did the user specify a video mode? */
584 if (!mode_option)
585 mode_option = fb_mode_option;
586 if (mode_option) {
587 const char *name = mode_option;
588 unsigned int namelen = strlen(name);
589 int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
590 unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
591 int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
592 u32 best, diff, tdiff;
593
594 for (i = namelen-1; i >= 0; i--) {
595 switch (name[i]) {
596 case '@':
597 namelen = i;
598 if (!refresh_specified && !bpp_specified &&
599 !yres_specified) {
600 refresh = simple_strtol(&name[i+1], NULL, 10);
601 refresh_specified = 1;
602 if (cvt || rb)
603 cvt = 0;
604 } else
605 goto done;
606 break;
607 case '-':
608 namelen = i;
609 if (!bpp_specified && !yres_specified) {
610 bpp = simple_strtol(&name[i+1], NULL, 10);
611 bpp_specified = 1;
612 if (cvt || rb)
613 cvt = 0;
614 } else
615 goto done;
616 break;
617 case 'x':
618 if (!yres_specified) {
619 yres = simple_strtol(&name[i+1], NULL, 10);
620 yres_specified = 1;
621 } else
622 goto done;
623 break;
624 case '0' ... '9':
625 break;
626 case 'M':
627 if (!yres_specified)
628 cvt = 1;
629 break;
630 case 'R':
631 if (!cvt)
632 rb = 1;
633 break;
634 case 'm':
635 if (!cvt)
636 margins = 1;
637 break;
638 case 'i':
639 if (!cvt)
640 interlace = 1;
641 break;
642 default:
643 goto done;
644 }
645 }
646 if (i < 0 && yres_specified) {
647 xres = simple_strtol(name, NULL, 10);
648 res_specified = 1;
649 }
650done:
651 if (cvt) {
652 struct fb_videomode cvt_mode;
653 int ret;
654
655 DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
656 (refresh) ? refresh : 60, (rb) ? " reduced blanking" :
657 "", (margins) ? " with margins" : "", (interlace) ?
658 " interlaced" : "");
659
660 memset(&cvt_mode, 0, sizeof(cvt_mode));
661 cvt_mode.xres = xres;
662 cvt_mode.yres = yres;
663 cvt_mode.refresh = (refresh) ? refresh : 60;
664 571
665 if (interlace) 572 /* Set up defaults */
666 cvt_mode.vmode |= FB_VMODE_INTERLACED; 573 if (!db) {
667 else 574 db = modedb;
668 cvt_mode.vmode &= ~FB_VMODE_INTERLACED; 575 dbsize = ARRAY_SIZE(modedb);
576 }
669 577
670 ret = fb_find_mode_cvt(&cvt_mode, margins, rb); 578 if (!default_mode)
579 default_mode = &db[0];
580
581 if (!default_bpp)
582 default_bpp = 8;
583
584 /* Did the user specify a video mode? */
585 if (!mode_option)
586 mode_option = fb_mode_option;
587 if (mode_option) {
588 const char *name = mode_option;
589 unsigned int namelen = strlen(name);
590 int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
591 unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
592 int yres_specified = 0, cvt = 0, rb = 0, interlace = 0;
593 int margins = 0;
594 u32 best, diff, tdiff;
595
596 for (i = namelen-1; i >= 0; i--) {
597 switch (name[i]) {
598 case '@':
599 namelen = i;
600 if (!refresh_specified && !bpp_specified &&
601 !yres_specified) {
602 refresh = simple_strtol(&name[i+1], NULL,
603 10);
604 refresh_specified = 1;
605 if (cvt || rb)
606 cvt = 0;
607 } else
608 goto done;
609 break;
610 case '-':
611 namelen = i;
612 if (!bpp_specified && !yres_specified) {
613 bpp = simple_strtol(&name[i+1], NULL,
614 10);
615 bpp_specified = 1;
616 if (cvt || rb)
617 cvt = 0;
618 } else
619 goto done;
620 break;
621 case 'x':
622 if (!yres_specified) {
623 yres = simple_strtol(&name[i+1], NULL,
624 10);
625 yres_specified = 1;
626 } else
627 goto done;
628 break;
629 case '0' ... '9':
630 break;
631 case 'M':
632 if (!yres_specified)
633 cvt = 1;
634 break;
635 case 'R':
636 if (!cvt)
637 rb = 1;
638 break;
639 case 'm':
640 if (!cvt)
641 margins = 1;
642 break;
643 case 'i':
644 if (!cvt)
645 interlace = 1;
646 break;
647 default:
648 goto done;
649 }
650 }
651 if (i < 0 && yres_specified) {
652 xres = simple_strtol(name, NULL, 10);
653 res_specified = 1;
654 }
655done:
656 if (cvt) {
657 struct fb_videomode cvt_mode;
658 int ret;
659
660 DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
661 (refresh) ? refresh : 60,
662 (rb) ? " reduced blanking" : "",
663 (margins) ? " with margins" : "",
664 (interlace) ? " interlaced" : "");
665
666 memset(&cvt_mode, 0, sizeof(cvt_mode));
667 cvt_mode.xres = xres;
668 cvt_mode.yres = yres;
669 cvt_mode.refresh = (refresh) ? refresh : 60;
670
671 if (interlace)
672 cvt_mode.vmode |= FB_VMODE_INTERLACED;
673 else
674 cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
675
676 ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
677
678 if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
679 DPRINTK("modedb CVT: CVT mode ok\n");
680 return 1;
681 }
671 682
672 if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) { 683 DPRINTK("CVT mode invalid, getting mode from database\n");
673 DPRINTK("modedb CVT: CVT mode ok\n"); 684 }
674 return 1;
675 }
676 685
677 DPRINTK("CVT mode invalid, getting mode from database\n"); 686 DPRINTK("Trying specified video mode%s %ix%i\n",
678 } 687 refresh_specified ? "" : " (ignoring refresh rate)",
688 xres, yres);
679 689
680 DPRINTK("Trying specified video mode%s %ix%i\n", 690 if (!refresh_specified) {
681 refresh_specified ? "" : " (ignoring refresh rate)", xres, yres); 691 /*
682 692 * If the caller has provided a custom mode database and
683 if (!refresh_specified) { 693 * a valid monspecs structure, we look for the mode with
684 /* 694 * the highest refresh rate. Otherwise we play it safe
685 * If the caller has provided a custom mode database and a 695 * it and try to find a mode with a refresh rate closest
686 * valid monspecs structure, we look for the mode with the 696 * to the standard 60 Hz.
687 * highest refresh rate. Otherwise we play it safe it and 697 */
688 * try to find a mode with a refresh rate closest to the 698 if (db != modedb &&
689 * standard 60 Hz. 699 info->monspecs.vfmin && info->monspecs.vfmax &&
690 */ 700 info->monspecs.hfmin && info->monspecs.hfmax &&
691 if (db != modedb && 701 info->monspecs.dclkmax) {
692 info->monspecs.vfmin && info->monspecs.vfmax && 702 refresh = 1000;
693 info->monspecs.hfmin && info->monspecs.hfmax && 703 } else {
694 info->monspecs.dclkmax) { 704 refresh = 60;
695 refresh = 1000; 705 }
696 } else {
697 refresh = 60;
698 } 706 }
699 }
700 707
701 diff = -1; 708 diff = -1;
702 best = -1; 709 best = -1;
703 for (i = 0; i < dbsize; i++) { 710 for (i = 0; i < dbsize; i++) {
704 if ((name_matches(db[i], name, namelen) || 711 if ((name_matches(db[i], name, namelen) ||
705 (res_specified && res_matches(db[i], xres, yres))) && 712 (res_specified && res_matches(db[i], xres, yres))) &&
706 !fb_try_mode(var, info, &db[i], bpp)) { 713 !fb_try_mode(var, info, &db[i], bpp)) {
707 if (refresh_specified && db[i].refresh == refresh) { 714 if (refresh_specified && db[i].refresh == refresh)
708 return 1; 715 return 1;
709 } else { 716
710 if (abs(db[i].refresh - refresh) < diff) { 717 if (abs(db[i].refresh - refresh) < diff) {
711 diff = abs(db[i].refresh - refresh); 718 diff = abs(db[i].refresh - refresh);
712 best = i; 719 best = i;
713 } 720 }
714 } 721 }
715 } 722 }
716 } 723 if (best != -1) {
717 if (best != -1) { 724 fb_try_mode(var, info, &db[best], bpp);
718 fb_try_mode(var, info, &db[best], bpp); 725 return (refresh_specified) ? 2 : 1;
719 return (refresh_specified) ? 2 : 1; 726 }
720 }
721
722 diff = 2 * (xres + yres);
723 best = -1;
724 DPRINTK("Trying best-fit modes\n");
725 for (i = 0; i < dbsize; i++) {
726 DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
727 if (!fb_try_mode(var, info, &db[i], bpp)) {
728 tdiff = abs(db[i].xres - xres) +
729 abs(db[i].yres - yres);
730
731 /*
732 * Penalize modes with resolutions smaller
733 * than requested.
734 */
735 if (xres > db[i].xres || yres > db[i].yres)
736 tdiff += xres + yres;
737 727
738 if (diff > tdiff) { 728 diff = 2 * (xres + yres);
739 diff = tdiff; 729 best = -1;
740 best = i; 730 DPRINTK("Trying best-fit modes\n");
731 for (i = 0; i < dbsize; i++) {
732 DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
733 if (!fb_try_mode(var, info, &db[i], bpp)) {
734 tdiff = abs(db[i].xres - xres) +
735 abs(db[i].yres - yres);
736
737 /*
738 * Penalize modes with resolutions smaller
739 * than requested.
740 */
741 if (xres > db[i].xres || yres > db[i].yres)
742 tdiff += xres + yres;
743
744 if (diff > tdiff) {
745 diff = tdiff;
746 best = i;
747 }
741 } 748 }
742 } 749 }
750 if (best != -1) {
751 fb_try_mode(var, info, &db[best], bpp);
752 return 5;
753 }
743 } 754 }
744 if (best != -1) {
745 fb_try_mode(var, info, &db[best], bpp);
746 return 5;
747 }
748 }
749 755
750 DPRINTK("Trying default video mode\n"); 756 DPRINTK("Trying default video mode\n");
751 if (!fb_try_mode(var, info, default_mode, default_bpp)) 757 if (!fb_try_mode(var, info, default_mode, default_bpp))
752 return 3; 758 return 3;
753 759
754 DPRINTK("Trying all modes\n"); 760 DPRINTK("Trying all modes\n");
755 for (i = 0; i < dbsize; i++) 761 for (i = 0; i < dbsize; i++)
756 if (!fb_try_mode(var, info, &db[i], default_bpp)) 762 if (!fb_try_mode(var, info, &db[i], default_bpp))
757 return 4; 763 return 4;
758 764
759 DPRINTK("No valid mode found\n"); 765 DPRINTK("No valid mode found\n");
760 return 0; 766 return 0;
761} 767}
762 768
763/** 769/**