video_gx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 <asm/geode.h>
  20. #include "geodefb.h"
  21. #include "video_gx.h"
  22. /*
  23. * Tables of register settings for various DOTCLKs.
  24. */
  25. struct gx_pll_entry {
  26. long pixclock; /* ps */
  27. u32 sys_rstpll_bits;
  28. u32 dotpll_value;
  29. };
  30. #define POSTDIV3 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3)
  31. #define PREMULT2 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPREMULT2)
  32. #define PREDIV2 ((u32)MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3)
  33. static const struct gx_pll_entry gx_pll_table_48MHz[] = {
  34. { 40123, POSTDIV3, 0x00000BF2 }, /* 24.9230 */
  35. { 39721, 0, 0x00000037 }, /* 25.1750 */
  36. { 35308, POSTDIV3|PREMULT2, 0x00000B1A }, /* 28.3220 */
  37. { 31746, POSTDIV3, 0x000002D2 }, /* 31.5000 */
  38. { 27777, POSTDIV3|PREMULT2, 0x00000FE2 }, /* 36.0000 */
  39. { 26666, POSTDIV3, 0x0000057A }, /* 37.5000 */
  40. { 25000, POSTDIV3, 0x0000030A }, /* 40.0000 */
  41. { 22271, 0, 0x00000063 }, /* 44.9000 */
  42. { 20202, 0, 0x0000054B }, /* 49.5000 */
  43. { 20000, 0, 0x0000026E }, /* 50.0000 */
  44. { 19860, PREMULT2, 0x00000037 }, /* 50.3500 */
  45. { 18518, POSTDIV3|PREMULT2, 0x00000B0D }, /* 54.0000 */
  46. { 17777, 0, 0x00000577 }, /* 56.2500 */
  47. { 17733, 0, 0x000007F7 }, /* 56.3916 */
  48. { 17653, 0, 0x0000057B }, /* 56.6444 */
  49. { 16949, PREMULT2, 0x00000707 }, /* 59.0000 */
  50. { 15873, POSTDIV3|PREMULT2, 0x00000B39 }, /* 63.0000 */
  51. { 15384, POSTDIV3|PREMULT2, 0x00000B45 }, /* 65.0000 */
  52. { 14814, POSTDIV3|PREMULT2, 0x00000FC1 }, /* 67.5000 */
  53. { 14124, POSTDIV3, 0x00000561 }, /* 70.8000 */
  54. { 13888, POSTDIV3, 0x000007E1 }, /* 72.0000 */
  55. { 13426, PREMULT2, 0x00000F4A }, /* 74.4810 */
  56. { 13333, 0, 0x00000052 }, /* 75.0000 */
  57. { 12698, 0, 0x00000056 }, /* 78.7500 */
  58. { 12500, POSTDIV3|PREMULT2, 0x00000709 }, /* 80.0000 */
  59. { 11135, PREMULT2, 0x00000262 }, /* 89.8000 */
  60. { 10582, 0, 0x000002D2 }, /* 94.5000 */
  61. { 10101, PREMULT2, 0x00000B4A }, /* 99.0000 */
  62. { 10000, PREMULT2, 0x00000036 }, /* 100.0000 */
  63. { 9259, 0, 0x000007E2 }, /* 108.0000 */
  64. { 8888, 0, 0x000007F6 }, /* 112.5000 */
  65. { 7692, POSTDIV3|PREMULT2, 0x00000FB0 }, /* 130.0000 */
  66. { 7407, POSTDIV3|PREMULT2, 0x00000B50 }, /* 135.0000 */
  67. { 6349, 0, 0x00000055 }, /* 157.5000 */
  68. { 6172, 0, 0x000009C1 }, /* 162.0000 */
  69. { 5787, PREMULT2, 0x0000002D }, /* 172.798 */
  70. { 5698, 0, 0x000002C1 }, /* 175.5000 */
  71. { 5291, 0, 0x000002D1 }, /* 189.0000 */
  72. { 4938, 0, 0x00000551 }, /* 202.5000 */
  73. { 4357, 0, 0x0000057D }, /* 229.5000 */
  74. };
  75. static const struct gx_pll_entry gx_pll_table_14MHz[] = {
  76. { 39721, 0, 0x00000037 }, /* 25.1750 */
  77. { 35308, 0, 0x00000B7B }, /* 28.3220 */
  78. { 31746, 0, 0x000004D3 }, /* 31.5000 */
  79. { 27777, 0, 0x00000BE3 }, /* 36.0000 */
  80. { 26666, 0, 0x0000074F }, /* 37.5000 */
  81. { 25000, 0, 0x0000050B }, /* 40.0000 */
  82. { 22271, 0, 0x00000063 }, /* 44.9000 */
  83. { 20202, 0, 0x0000054B }, /* 49.5000 */
  84. { 20000, 0, 0x0000026E }, /* 50.0000 */
  85. { 19860, 0, 0x000007C3 }, /* 50.3500 */
  86. { 18518, 0, 0x000007E3 }, /* 54.0000 */
  87. { 17777, 0, 0x00000577 }, /* 56.2500 */
  88. { 17733, 0, 0x000002FB }, /* 56.3916 */
  89. { 17653, 0, 0x0000057B }, /* 56.6444 */
  90. { 16949, 0, 0x0000058B }, /* 59.0000 */
  91. { 15873, 0, 0x0000095E }, /* 63.0000 */
  92. { 15384, 0, 0x0000096A }, /* 65.0000 */
  93. { 14814, 0, 0x00000BC2 }, /* 67.5000 */
  94. { 14124, 0, 0x0000098A }, /* 70.8000 */
  95. { 13888, 0, 0x00000BE2 }, /* 72.0000 */
  96. { 13333, 0, 0x00000052 }, /* 75.0000 */
  97. { 12698, 0, 0x00000056 }, /* 78.7500 */
  98. { 12500, 0, 0x0000050A }, /* 80.0000 */
  99. { 11135, 0, 0x0000078E }, /* 89.8000 */
  100. { 10582, 0, 0x000002D2 }, /* 94.5000 */
  101. { 10101, 0, 0x000011F6 }, /* 99.0000 */
  102. { 10000, 0, 0x0000054E }, /* 100.0000 */
  103. { 9259, 0, 0x000007E2 }, /* 108.0000 */
  104. { 8888, 0, 0x000002FA }, /* 112.5000 */
  105. { 7692, 0, 0x00000BB1 }, /* 130.0000 */
  106. { 7407, 0, 0x00000975 }, /* 135.0000 */
  107. { 6349, 0, 0x00000055 }, /* 157.5000 */
  108. { 6172, 0, 0x000009C1 }, /* 162.0000 */
  109. { 5698, 0, 0x000002C1 }, /* 175.5000 */
  110. { 5291, 0, 0x00000539 }, /* 189.0000 */
  111. { 4938, 0, 0x00000551 }, /* 202.5000 */
  112. { 4357, 0, 0x0000057D }, /* 229.5000 */
  113. };
  114. static void gx_set_dclk_frequency(struct fb_info *info)
  115. {
  116. const struct gx_pll_entry *pll_table;
  117. int pll_table_len;
  118. int i, best_i;
  119. long min, diff;
  120. u64 dotpll, sys_rstpll;
  121. int timeout = 1000;
  122. /* Rev. 1 Geode GXs use a 14 MHz reference clock instead of 48 MHz. */
  123. if (cpu_data(0).x86_mask == 1) {
  124. pll_table = gx_pll_table_14MHz;
  125. pll_table_len = ARRAY_SIZE(gx_pll_table_14MHz);
  126. } else {
  127. pll_table = gx_pll_table_48MHz;
  128. pll_table_len = ARRAY_SIZE(gx_pll_table_48MHz);
  129. }
  130. /* Search the table for the closest pixclock. */
  131. best_i = 0;
  132. min = abs(pll_table[0].pixclock - info->var.pixclock);
  133. for (i = 1; i < pll_table_len; i++) {
  134. diff = abs(pll_table[i].pixclock - info->var.pixclock);
  135. if (diff < min) {
  136. min = diff;
  137. best_i = i;
  138. }
  139. }
  140. rdmsrl(MSR_GLCP_SYS_RSTPLL, sys_rstpll);
  141. rdmsrl(MSR_GLCP_DOTPLL, dotpll);
  142. /* Program new M, N and P. */
  143. dotpll &= 0x00000000ffffffffull;
  144. dotpll |= (u64)pll_table[best_i].dotpll_value << 32;
  145. dotpll |= MSR_GLCP_DOTPLL_DOTRESET;
  146. dotpll &= ~MSR_GLCP_DOTPLL_BYPASS;
  147. wrmsrl(MSR_GLCP_DOTPLL, dotpll);
  148. /* Program dividers. */
  149. sys_rstpll &= ~( MSR_GLCP_SYS_RSTPLL_DOTPREDIV2
  150. | MSR_GLCP_SYS_RSTPLL_DOTPREMULT2
  151. | MSR_GLCP_SYS_RSTPLL_DOTPOSTDIV3 );
  152. sys_rstpll |= pll_table[best_i].sys_rstpll_bits;
  153. wrmsrl(MSR_GLCP_SYS_RSTPLL, sys_rstpll);
  154. /* Clear reset bit to start PLL. */
  155. dotpll &= ~(MSR_GLCP_DOTPLL_DOTRESET);
  156. wrmsrl(MSR_GLCP_DOTPLL, dotpll);
  157. /* Wait for LOCK bit. */
  158. do {
  159. rdmsrl(MSR_GLCP_DOTPLL, dotpll);
  160. } while (timeout-- && !(dotpll & MSR_GLCP_DOTPLL_LOCK));
  161. }
  162. static void
  163. gx_configure_tft(struct fb_info *info)
  164. {
  165. struct geodefb_par *par = info->par;
  166. unsigned long val;
  167. unsigned long fp;
  168. /* Set up the DF pad select MSR */
  169. rdmsrl(MSR_GX_MSR_PADSEL, val);
  170. val &= ~GX_VP_PAD_SELECT_MASK;
  171. val |= GX_VP_PAD_SELECT_TFT;
  172. wrmsrl(MSR_GX_MSR_PADSEL, val);
  173. /* Turn off the panel */
  174. fp = readl(par->vid_regs + GX_FP_PM);
  175. fp &= ~GX_FP_PM_P;
  176. writel(fp, par->vid_regs + GX_FP_PM);
  177. /* Set timing 1 */
  178. fp = readl(par->vid_regs + GX_FP_PT1);
  179. fp &= GX_FP_PT1_VSIZE_MASK;
  180. fp |= info->var.yres << GX_FP_PT1_VSIZE_SHIFT;
  181. writel(fp, par->vid_regs + GX_FP_PT1);
  182. /* Timing 2 */
  183. /* Set bits that are always on for TFT */
  184. fp = 0x0F100000;
  185. /* Configure sync polarity */
  186. if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
  187. fp |= GX_FP_PT2_VSP;
  188. if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
  189. fp |= GX_FP_PT2_HSP;
  190. writel(fp, par->vid_regs + GX_FP_PT2);
  191. /* Set the dither control */
  192. writel(0x70, par->vid_regs + GX_FP_DFC);
  193. /* Enable the FP data and power (in case the BIOS didn't) */
  194. fp = readl(par->vid_regs + GX_DCFG);
  195. fp |= GX_DCFG_FP_PWR_EN | GX_DCFG_FP_DATA_EN;
  196. writel(fp, par->vid_regs + GX_DCFG);
  197. /* Unblank the panel */
  198. fp = readl(par->vid_regs + GX_FP_PM);
  199. fp |= GX_FP_PM_P;
  200. writel(fp, par->vid_regs + GX_FP_PM);
  201. }
  202. static void gx_configure_display(struct fb_info *info)
  203. {
  204. struct geodefb_par *par = info->par;
  205. u32 dcfg, misc;
  206. /* Set up the MISC register */
  207. misc = readl(par->vid_regs + GX_MISC);
  208. /* Power up the DAC */
  209. misc &= ~(GX_MISC_A_PWRDN | GX_MISC_DAC_PWRDN);
  210. /* Disable gamma correction */
  211. misc |= GX_MISC_GAM_EN;
  212. writel(misc, par->vid_regs + GX_MISC);
  213. /* Write the display configuration */
  214. dcfg = readl(par->vid_regs + GX_DCFG);
  215. /* Disable hsync and vsync */
  216. dcfg &= ~(GX_DCFG_VSYNC_EN | GX_DCFG_HSYNC_EN);
  217. writel(dcfg, par->vid_regs + GX_DCFG);
  218. /* Clear bits from existing mode. */
  219. dcfg &= ~(GX_DCFG_CRT_SYNC_SKW_MASK
  220. | GX_DCFG_CRT_HSYNC_POL | GX_DCFG_CRT_VSYNC_POL
  221. | GX_DCFG_VSYNC_EN | GX_DCFG_HSYNC_EN);
  222. /* Set default sync skew. */
  223. dcfg |= GX_DCFG_CRT_SYNC_SKW_DFLT;
  224. /* Enable hsync and vsync. */
  225. dcfg |= GX_DCFG_HSYNC_EN | GX_DCFG_VSYNC_EN;
  226. /* Only change the sync polarities if we are running
  227. * in CRT mode. The FP polarities will be handled in
  228. * gxfb_configure_tft */
  229. if (par->enable_crt) {
  230. if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
  231. dcfg |= GX_DCFG_CRT_HSYNC_POL;
  232. if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
  233. dcfg |= GX_DCFG_CRT_VSYNC_POL;
  234. }
  235. /* Enable the display logic */
  236. /* Set up the DACS to blank normally */
  237. dcfg |= GX_DCFG_CRT_EN | GX_DCFG_DAC_BL_EN;
  238. /* Enable the external DAC VREF? */
  239. writel(dcfg, par->vid_regs + GX_DCFG);
  240. /* Set up the flat panel (if it is enabled) */
  241. if (par->enable_crt == 0)
  242. gx_configure_tft(info);
  243. }
  244. static int gx_blank_display(struct fb_info *info, int blank_mode)
  245. {
  246. struct geodefb_par *par = info->par;
  247. u32 dcfg, fp_pm;
  248. int blank, hsync, vsync;
  249. /* CRT power saving modes. */
  250. switch (blank_mode) {
  251. case FB_BLANK_UNBLANK:
  252. blank = 0; hsync = 1; vsync = 1;
  253. break;
  254. case FB_BLANK_NORMAL:
  255. blank = 1; hsync = 1; vsync = 1;
  256. break;
  257. case FB_BLANK_VSYNC_SUSPEND:
  258. blank = 1; hsync = 1; vsync = 0;
  259. break;
  260. case FB_BLANK_HSYNC_SUSPEND:
  261. blank = 1; hsync = 0; vsync = 1;
  262. break;
  263. case FB_BLANK_POWERDOWN:
  264. blank = 1; hsync = 0; vsync = 0;
  265. break;
  266. default:
  267. return -EINVAL;
  268. }
  269. dcfg = readl(par->vid_regs + GX_DCFG);
  270. dcfg &= ~(GX_DCFG_DAC_BL_EN
  271. | GX_DCFG_HSYNC_EN | GX_DCFG_VSYNC_EN);
  272. if (!blank)
  273. dcfg |= GX_DCFG_DAC_BL_EN;
  274. if (hsync)
  275. dcfg |= GX_DCFG_HSYNC_EN;
  276. if (vsync)
  277. dcfg |= GX_DCFG_VSYNC_EN;
  278. writel(dcfg, par->vid_regs + GX_DCFG);
  279. /* Power on/off flat panel. */
  280. if (par->enable_crt == 0) {
  281. fp_pm = readl(par->vid_regs + GX_FP_PM);
  282. if (blank_mode == FB_BLANK_POWERDOWN)
  283. fp_pm &= ~GX_FP_PM_P;
  284. else
  285. fp_pm |= GX_FP_PM_P;
  286. writel(fp_pm, par->vid_regs + GX_FP_PM);
  287. }
  288. return 0;
  289. }
  290. struct geode_vid_ops gx_vid_ops = {
  291. .set_dclk = gx_set_dclk_frequency,
  292. .configure_display = gx_configure_display,
  293. .blank_display = gx_blank_display,
  294. };