video_gx.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Geode GX video processor device.
  3. *
  4. * Copyright (C) 2006 Arcom Control Systems Ltd.
  5. *
  6. * Portions from AMD's original 2.4 driver:
  7. * Copyright (C) 2004 Advanced Micro Devices, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/fb.h>
  15. #include <linux/delay.h>
  16. #include <asm/io.h>
  17. #include <asm/delay.h>
  18. #include <asm/msr.h>
  19. #include "geodefb.h"
  20. #include "video_gx.h"
  21. /*
  22. * Tables of register settings for various DOTCLKs.
  23. */
  24. struct gx_pll_entry {
  25. long pixclock; /* ps */
  26. u32 sys_rstpll_bits;
  27. u32 dotpll_value;
  28. };
  29. #define POSTDIV3 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3)
  30. #define PREMULT2 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPREMULT2)
  31. #define PREDIV2 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3)
  32. static const struct gx_pll_entry gx_pll_table_48MHz[] = {
  33. { 40123, POSTDIV3, 0x00000BF2 }, /* 24.9230 */
  34. { 39721, 0, 0x00000037 }, /* 25.1750 */
  35. { 35308, POSTDIV3|PREMULT2, 0x00000B1A }, /* 28.3220 */
  36. { 31746, POSTDIV3, 0x000002D2 }, /* 31.5000 */
  37. { 27777, POSTDIV3|PREMULT2, 0x00000FE2 }, /* 36.0000 */
  38. { 26666, POSTDIV3, 0x0000057A }, /* 37.5000 */
  39. { 25000, POSTDIV3, 0x0000030A }, /* 40.0000 */
  40. { 22271, 0, 0x00000063 }, /* 44.9000 */
  41. { 20202, 0, 0x0000054B }, /* 49.5000 */
  42. { 20000, 0, 0x0000026E }, /* 50.0000 */
  43. { 19860, PREMULT2, 0x00000037 }, /* 50.3500 */
  44. { 18518, POSTDIV3|PREMULT2, 0x00000B0D }, /* 54.0000 */
  45. { 17777, 0, 0x00000577 }, /* 56.2500 */
  46. { 17733, 0, 0x000007F7 }, /* 56.3916 */
  47. { 17653, 0, 0x0000057B }, /* 56.6444 */
  48. { 16949, PREMULT2, 0x00000707 }, /* 59.0000 */
  49. { 15873, POSTDIV3|PREMULT2, 0x00000B39 }, /* 63.0000 */
  50. { 15384, POSTDIV3|PREMULT2, 0x00000B45 }, /* 65.0000 */
  51. { 14814, POSTDIV3|PREMULT2, 0x00000FC1 }, /* 67.5000 */
  52. { 14124, POSTDIV3, 0x00000561 }, /* 70.8000 */
  53. { 13888, POSTDIV3, 0x000007E1 }, /* 72.0000 */
  54. { 13426, PREMULT2, 0x00000F4A }, /* 74.4810 */
  55. { 13333, 0, 0x00000052 }, /* 75.0000 */
  56. { 12698, 0, 0x00000056 }, /* 78.7500 */
  57. { 12500, POSTDIV3|PREMULT2, 0x00000709 }, /* 80.0000 */
  58. { 11135, PREMULT2, 0x00000262 }, /* 89.8000 */
  59. { 10582, 0, 0x000002D2 }, /* 94.5000 */
  60. { 10101, PREMULT2, 0x00000B4A }, /* 99.0000 */
  61. { 10000, PREMULT2, 0x00000036 }, /* 100.0000 */
  62. { 9259, 0, 0x000007E2 }, /* 108.0000 */
  63. { 8888, 0, 0x000007F6 }, /* 112.5000 */
  64. { 7692, POSTDIV3|PREMULT2, 0x00000FB0 }, /* 130.0000 */
  65. { 7407, POSTDIV3|PREMULT2, 0x00000B50 }, /* 135.0000 */
  66. { 6349, 0, 0x00000055 }, /* 157.5000 */
  67. { 6172, 0, 0x000009C1 }, /* 162.0000 */
  68. { 5787, PREMULT2, 0x0000002D }, /* 172.798 */
  69. { 5698, 0, 0x000002C1 }, /* 175.5000 */
  70. { 5291, 0, 0x000002D1 }, /* 189.0000 */
  71. { 4938, 0, 0x00000551 }, /* 202.5000 */
  72. { 4357, 0, 0x0000057D }, /* 229.5000 */
  73. };
  74. static const struct gx_pll_entry gx_pll_table_14MHz[] = {
  75. { 39721, 0, 0x00000037 }, /* 25.1750 */
  76. { 35308, 0, 0x00000B7B }, /* 28.3220 */
  77. { 31746, 0, 0x000004D3 }, /* 31.5000 */
  78. { 27777, 0, 0x00000BE3 }, /* 36.0000 */
  79. { 26666, 0, 0x0000074F }, /* 37.5000 */
  80. { 25000, 0, 0x0000050B }, /* 40.0000 */
  81. { 22271, 0, 0x00000063 }, /* 44.9000 */
  82. { 20202, 0, 0x0000054B }, /* 49.5000 */
  83. { 20000, 0, 0x0000026E }, /* 50.0000 */
  84. { 19860, 0, 0x000007C3 }, /* 50.3500 */
  85. { 18518, 0, 0x000007E3 }, /* 54.0000 */
  86. { 17777, 0, 0x00000577 }, /* 56.2500 */
  87. { 17733, 0, 0x000002FB }, /* 56.3916 */
  88. { 17653, 0, 0x0000057B }, /* 56.6444 */
  89. { 16949, 0, 0x0000058B }, /* 59.0000 */
  90. { 15873, 0, 0x0000095E }, /* 63.0000 */
  91. { 15384, 0, 0x0000096A }, /* 65.0000 */
  92. { 14814, 0, 0x00000BC2 }, /* 67.5000 */
  93. { 14124, 0, 0x0000098A }, /* 70.8000 */
  94. { 13888, 0, 0x00000BE2 }, /* 72.0000 */
  95. { 13333, 0, 0x00000052 }, /* 75.0000 */
  96. { 12698, 0, 0x00000056 }, /* 78.7500 */
  97. { 12500, 0, 0x0000050A }, /* 80.0000 */
  98. { 11135, 0, 0x0000078E }, /* 89.8000 */
  99. { 10582, 0, 0x000002D2 }, /* 94.5000 */
  100. { 10101, 0, 0x000011F6 }, /* 99.0000 */
  101. { 10000, 0, 0x0000054E }, /* 100.0000 */
  102. { 9259, 0, 0x000007E2 }, /* 108.0000 */
  103. { 8888, 0, 0x000002FA }, /* 112.5000 */
  104. { 7692, 0, 0x00000BB1 }, /* 130.0000 */
  105. { 7407, 0, 0x00000975 }, /* 135.0000 */
  106. { 6349, 0, 0x00000055 }, /* 157.5000 */
  107. { 6172, 0, 0x000009C1 }, /* 162.0000 */
  108. { 5698, 0, 0x000002C1 }, /* 175.5000 */
  109. { 5291, 0, 0x00000539 }, /* 189.0000 */
  110. { 4938, 0, 0x00000551 }, /* 202.5000 */
  111. { 4357, 0, 0x0000057D }, /* 229.5000 */
  112. };
  113. static void gx_set_dclk_frequency(struct fb_info *info)
  114. {
  115. const struct gx_pll_entry *pll_table;
  116. int pll_table_len;
  117. int i, best_i;
  118. long min, diff;
  119. u64 dotpll, sys_rstpll;
  120. int timeout = 1000;
  121. /* Rev. 1 Geode GXs use a 14 MHz reference clock instead of 48 MHz. */
  122. if (cpu_data->x86_mask == 1) {
  123. pll_table = gx_pll_table_14MHz;
  124. pll_table_len = ARRAY_SIZE(gx_pll_table_14MHz);
  125. } else {
  126. pll_table = gx_pll_table_48MHz;
  127. pll_table_len = ARRAY_SIZE(gx_pll_table_48MHz);
  128. }
  129. /* Search the table for the closest pixclock. */
  130. best_i = 0;
  131. min = abs(pll_table[0].pixclock - info->var.pixclock);
  132. for (i = 1; i < pll_table_len; i++) {
  133. diff = abs(pll_table[i].pixclock - info->var.pixclock);
  134. if (diff < min) {
  135. min = diff;
  136. best_i = i;
  137. }
  138. }
  139. rdmsrl(MSR_GLCP_SYS_RSTPLL, sys_rstpll);
  140. rdmsrl(MSR_GLCP_DOTPLL, dotpll);
  141. /* Program new M, N and P. */
  142. dotpll &= 0x00000000ffffffffull;
  143. dotpll |= (u64)pll_table[best_i].dotpll_value << 32;
  144. dotpll |= MSR_GLCP_DOTPLL_DOTRESET;
  145. dotpll &= ~MSR_GLCP_DOTPLL_BYPASS;
  146. wrmsrl(MSR_GLCP_DOTPLL, dotpll);
  147. /* Program dividers. */
  148. sys_rstpll &= ~( MSR_GLCP_SYS_RSTPLL_DOTPREDIV2
  149. | MSR_GLCP_SYS_RSTPLL_DOTPREMULT2
  150. | MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3 );
  151. sys_rstpll |= pll_table[best_i].sys_rstpll_bits;
  152. wrmsrl(MSR_GLCP_SYS_RSTPLL, sys_rstpll);
  153. /* Clear reset bit to start PLL. */
  154. dotpll &= ~(MSR_GLCP_DOTPLL_DOTRESET);
  155. wrmsrl(MSR_GLCP_DOTPLL, dotpll);
  156. /* Wait for LOCK bit. */
  157. do {
  158. rdmsrl(MSR_GLCP_DOTPLL, dotpll);
  159. } while (timeout-- && !(dotpll & MSR_GLCP_DOTPLL_LOCK));
  160. }
  161. static void gx_configure_display(struct fb_info *info)
  162. {
  163. struct geodefb_par *par = info->par;
  164. u32 dcfg, fp_pm;
  165. dcfg = readl(par->vid_regs + GX_DCFG);
  166. /* Clear bits from existing mode. */
  167. dcfg &= ~(GX_DCFG_CRT_SYNC_SKW_MASK
  168. | GX_DCFG_CRT_HSYNC_POL | GX_DCFG_CRT_VSYNC_POL
  169. | GX_DCFG_VSYNC_EN | GX_DCFG_HSYNC_EN);
  170. /* Set default sync skew. */
  171. dcfg |= GX_DCFG_CRT_SYNC_SKW_DFLT;
  172. /* Enable hsync and vsync. */
  173. dcfg |= GX_DCFG_HSYNC_EN | GX_DCFG_VSYNC_EN;
  174. /* Sync polarities. */
  175. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
  176. dcfg |= GX_DCFG_CRT_HSYNC_POL;
  177. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
  178. dcfg |= GX_DCFG_CRT_VSYNC_POL;
  179. writel(dcfg, par->vid_regs + GX_DCFG);
  180. /* Power on flat panel. */
  181. fp_pm = readl(par->vid_regs + GX_FP_PM);
  182. fp_pm |= GX_FP_PM_P;
  183. writel(fp_pm, par->vid_regs + GX_FP_PM);
  184. }
  185. static int gx_blank_display(struct fb_info *info, int blank_mode)
  186. {
  187. struct geodefb_par *par = info->par;
  188. u32 dcfg, fp_pm;
  189. int blank, hsync, vsync;
  190. /* CRT power saving modes. */
  191. switch (blank_mode) {
  192. case FB_BLANK_UNBLANK:
  193. blank = 0; hsync = 1; vsync = 1;
  194. break;
  195. case FB_BLANK_NORMAL:
  196. blank = 1; hsync = 1; vsync = 1;
  197. break;
  198. case FB_BLANK_VSYNC_SUSPEND:
  199. blank = 1; hsync = 1; vsync = 0;
  200. break;
  201. case FB_BLANK_HSYNC_SUSPEND:
  202. blank = 1; hsync = 0; vsync = 1;
  203. break;
  204. case FB_BLANK_POWERDOWN:
  205. blank = 1; hsync = 0; vsync = 0;
  206. break;
  207. default:
  208. return -EINVAL;
  209. }
  210. dcfg = readl(par->vid_regs + GX_DCFG);
  211. dcfg &= ~(GX_DCFG_DAC_BL_EN
  212. | GX_DCFG_HSYNC_EN | GX_DCFG_VSYNC_EN);
  213. if (!blank)
  214. dcfg |= GX_DCFG_DAC_BL_EN;
  215. if (hsync)
  216. dcfg |= GX_DCFG_HSYNC_EN;
  217. if (vsync)
  218. dcfg |= GX_DCFG_VSYNC_EN;
  219. writel(dcfg, par->vid_regs + GX_DCFG);
  220. /* Power on/off flat panel. */
  221. fp_pm = readl(par->vid_regs + GX_FP_PM);
  222. if (blank_mode == FB_BLANK_POWERDOWN)
  223. fp_pm &= ~GX_FP_PM_P;
  224. else
  225. fp_pm |= GX_FP_PM_P;
  226. writel(fp_pm, par->vid_regs + GX_FP_PM);
  227. return 0;
  228. }
  229. struct geode_vid_ops gx_vid_ops = {
  230. .set_dclk = gx_set_dclk_frequency,
  231. .configure_display = gx_configure_display,
  232. .blank_display = gx_blank_display,
  233. };