]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
viafb: always return the best possible clock
authorFlorian Tobias Schandinat <FlorianSchandinat@gmx.de>
Thu, 10 Mar 2011 22:39:22 +0000 (22:39 +0000)
committerFlorian Tobias Schandinat <FlorianSchandinat@gmx.de>
Sat, 12 Mar 2011 10:22:00 +0000 (10:22 +0000)
Before this patch only clocks that perfectly match were used and if
none existed this was not handled properly. This patch changes this
to always use the closest clock supported. This should behave like
before for clocks that have a perfect match but be much saner for
clocks which are slightly off.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
drivers/video/via/hw.c
drivers/video/via/hw.h

index 8c1393e49b0a52c6507eab5e4e041d87f6fe3b64..a7a5614c1ad8307376303a94283d4f7d8a86df11 100644 (file)
@@ -1677,40 +1677,36 @@ static u32 vx855_encode_pll(struct pll_config pll)
 u32 viafb_get_clk_value(int clk)
 {
        u32 value = 0;
-       int i = 0;
+       int i, best = 0;
 
-       while (i < NUM_TOTAL_PLL_TABLE && clk != pll_value[i].clk)
-               i++;
-
-       if (i == NUM_TOTAL_PLL_TABLE) {
-               printk(KERN_WARNING "viafb_get_clk_value: PLL lookup failed!");
-       } else {
-               switch (viaparinfo->chip_info->gfx_chip_name) {
-               case UNICHROME_CLE266:
-               case UNICHROME_K400:
-                       value = cle266_encode_pll(pll_value[i].cle266_pll);
-                       break;
-
-               case UNICHROME_K800:
-               case UNICHROME_PM800:
-               case UNICHROME_CN700:
-                       value = k800_encode_pll(pll_value[i].k800_pll);
-                       break;
-
-               case UNICHROME_CX700:
-               case UNICHROME_CN750:
-               case UNICHROME_K8M890:
-               case UNICHROME_P4M890:
-               case UNICHROME_P4M900:
-               case UNICHROME_VX800:
-                       value = k800_encode_pll(pll_value[i].cx700_pll);
-                       break;
+       for (i = 1; i < ARRAY_SIZE(pll_value); i++) {
+               if (abs(pll_value[i].clk - clk)
+                       < abs(pll_value[best].clk - clk))
+                       best = i;
+       }
 
-               case UNICHROME_VX855:
-               case UNICHROME_VX900:
-                       value = vx855_encode_pll(pll_value[i].vx855_pll);
-                       break;
-               }
+       switch (viaparinfo->chip_info->gfx_chip_name) {
+       case UNICHROME_CLE266:
+       case UNICHROME_K400:
+               value = cle266_encode_pll(pll_value[best].cle266_pll);
+               break;
+       case UNICHROME_K800:
+       case UNICHROME_PM800:
+       case UNICHROME_CN700:
+               value = k800_encode_pll(pll_value[best].k800_pll);
+               break;
+       case UNICHROME_CX700:
+       case UNICHROME_CN750:
+       case UNICHROME_K8M890:
+       case UNICHROME_P4M890:
+       case UNICHROME_P4M900:
+       case UNICHROME_VX800:
+               value = k800_encode_pll(pll_value[best].cx700_pll);
+               break;
+       case UNICHROME_VX855:
+       case UNICHROME_VX900:
+               value = vx855_encode_pll(pll_value[best].vx855_pll);
+               break;
        }
 
        return value;
index 668d534542ef31ba878bef01e9685fe525c678dd..7295263299f793c3d89c8194098bed7dd6a2f74a 100644 (file)
@@ -893,8 +893,6 @@ struct iga2_crtc_timing {
 /* VT3410 chipset*/
 #define VX900_FUNCTION3     0x3410
 
-#define NUM_TOTAL_PLL_TABLE ARRAY_SIZE(pll_value)
-
 struct IODATA {
        u8 Index;
        u8 Mask;