lxfb_ops.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /* Geode LX framebuffer driver
  2. *
  3. * Copyright (C) 2006-2007, Advanced Micro Devices,Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/fb.h>
  13. #include <linux/uaccess.h>
  14. #include <linux/delay.h>
  15. #include <asm/geode.h>
  16. #include "lxfb.h"
  17. /* TODO
  18. * Support panel scaling
  19. * Add acceleration
  20. * Add support for interlacing (TV out)
  21. * Support compression
  22. */
  23. /* This is the complete list of PLL frequencies that we can set -
  24. * we will choose the closest match to the incoming clock.
  25. * freq is the frequency of the dotclock * 1000 (for example,
  26. * 24823 = 24.983 Mhz).
  27. * pllval is the corresponding PLL value
  28. */
  29. static const struct {
  30. unsigned int pllval;
  31. unsigned int freq;
  32. } pll_table[] = {
  33. { 0x000131AC, 6231 },
  34. { 0x0001215D, 6294 },
  35. { 0x00011087, 6750 },
  36. { 0x0001216C, 7081 },
  37. { 0x0001218D, 7140 },
  38. { 0x000110C9, 7800 },
  39. { 0x00013147, 7875 },
  40. { 0x000110A7, 8258 },
  41. { 0x00012159, 8778 },
  42. { 0x00014249, 8875 },
  43. { 0x00010057, 9000 },
  44. { 0x0001219A, 9472 },
  45. { 0x00012158, 9792 },
  46. { 0x00010045, 10000 },
  47. { 0x00010089, 10791 },
  48. { 0x000110E7, 11225 },
  49. { 0x00012136, 11430 },
  50. { 0x00013207, 12375 },
  51. { 0x00012187, 12500 },
  52. { 0x00014286, 14063 },
  53. { 0x000110E5, 15016 },
  54. { 0x00014214, 16250 },
  55. { 0x00011105, 17045 },
  56. { 0x000131E4, 18563 },
  57. { 0x00013183, 18750 },
  58. { 0x00014284, 19688 },
  59. { 0x00011104, 20400 },
  60. { 0x00016363, 23625 },
  61. { 0x000031AC, 24923 },
  62. { 0x0000215D, 25175 },
  63. { 0x00001087, 27000 },
  64. { 0x0000216C, 28322 },
  65. { 0x0000218D, 28560 },
  66. { 0x000010C9, 31200 },
  67. { 0x00003147, 31500 },
  68. { 0x000010A7, 33032 },
  69. { 0x00002159, 35112 },
  70. { 0x00004249, 35500 },
  71. { 0x00000057, 36000 },
  72. { 0x0000219A, 37889 },
  73. { 0x00002158, 39168 },
  74. { 0x00000045, 40000 },
  75. { 0x00000089, 43163 },
  76. { 0x000010E7, 44900 },
  77. { 0x00002136, 45720 },
  78. { 0x00003207, 49500 },
  79. { 0x00002187, 50000 },
  80. { 0x00004286, 56250 },
  81. { 0x000010E5, 60065 },
  82. { 0x00004214, 65000 },
  83. { 0x00001105, 68179 },
  84. { 0x000031E4, 74250 },
  85. { 0x00003183, 75000 },
  86. { 0x00004284, 78750 },
  87. { 0x00001104, 81600 },
  88. { 0x00006363, 94500 },
  89. { 0x00005303, 97520 },
  90. { 0x00002183, 100187 },
  91. { 0x00002122, 101420 },
  92. { 0x00001081, 108000 },
  93. { 0x00006201, 113310 },
  94. { 0x00000041, 119650 },
  95. { 0x000041A1, 129600 },
  96. { 0x00002182, 133500 },
  97. { 0x000041B1, 135000 },
  98. { 0x00000051, 144000 },
  99. { 0x000041E1, 148500 },
  100. { 0x000062D1, 157500 },
  101. { 0x000031A1, 162000 },
  102. { 0x00000061, 169203 },
  103. { 0x00004231, 172800 },
  104. { 0x00002151, 175500 },
  105. { 0x000052E1, 189000 },
  106. { 0x00000071, 192000 },
  107. { 0x00003201, 198000 },
  108. { 0x00004291, 202500 },
  109. { 0x00001101, 204750 },
  110. { 0x00007481, 218250 },
  111. { 0x00004170, 229500 },
  112. { 0x00006210, 234000 },
  113. { 0x00003140, 251182 },
  114. { 0x00006250, 261000 },
  115. { 0x000041C0, 278400 },
  116. { 0x00005220, 280640 },
  117. { 0x00000050, 288000 },
  118. { 0x000041E0, 297000 },
  119. { 0x00002130, 320207 }
  120. };
  121. static void lx_set_dotpll(u32 pllval)
  122. {
  123. u32 dotpll_lo, dotpll_hi;
  124. int i;
  125. rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  126. if ((dotpll_lo & MSR_GLCP_DOTPLL_LOCK) && (dotpll_hi == pllval))
  127. return;
  128. dotpll_hi = pllval;
  129. dotpll_lo &= ~(MSR_GLCP_DOTPLL_BYPASS | MSR_GLCP_DOTPLL_HALFPIX);
  130. dotpll_lo |= MSR_GLCP_DOTPLL_DOTRESET;
  131. wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  132. /* Wait 100us for the PLL to lock */
  133. udelay(100);
  134. /* Now, loop for the lock bit */
  135. for (i = 0; i < 1000; i++) {
  136. rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  137. if (dotpll_lo & MSR_GLCP_DOTPLL_LOCK)
  138. break;
  139. }
  140. /* Clear the reset bit */
  141. dotpll_lo &= ~MSR_GLCP_DOTPLL_DOTRESET;
  142. wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  143. }
  144. /* Set the clock based on the frequency specified by the current mode */
  145. static void lx_set_clock(struct fb_info *info)
  146. {
  147. unsigned int diff, min, best = 0;
  148. unsigned int freq, i;
  149. freq = (unsigned int) (1000000000 / info->var.pixclock);
  150. min = abs(pll_table[0].freq - freq);
  151. for (i = 0; i < ARRAY_SIZE(pll_table); i++) {
  152. diff = abs(pll_table[i].freq - freq);
  153. if (diff < min) {
  154. min = diff;
  155. best = i;
  156. }
  157. }
  158. lx_set_dotpll(pll_table[best].pllval & 0x00017FFF);
  159. }
  160. static void lx_graphics_disable(struct fb_info *info)
  161. {
  162. struct lxfb_par *par = info->par;
  163. unsigned int val, gcfg;
  164. /* Note: This assumes that the video is in a quitet state */
  165. write_vp(par, VP_A1T, 0);
  166. write_vp(par, VP_A2T, 0);
  167. write_vp(par, VP_A3T, 0);
  168. /* Turn off the VGA and video enable */
  169. val = read_dc(par, DC_GENERAL_CFG) & ~(DC_GENERAL_CFG_VGAE |
  170. DC_GENERAL_CFG_VIDE);
  171. write_dc(par, DC_GENERAL_CFG, val);
  172. val = read_vp(par, VP_VCFG) & ~VP_VCFG_VID_EN;
  173. write_vp(par, VP_VCFG, val);
  174. write_dc(par, DC_IRQ, DC_IRQ_MASK | DC_IRQ_VIP_VSYNC_LOSS_IRQ_MASK |
  175. DC_IRQ_STATUS | DC_IRQ_VIP_VSYNC_IRQ_STATUS);
  176. val = read_dc(par, DC_GENLK_CTL) & ~DC_GENLK_CTL_GENLK_EN;
  177. write_dc(par, DC_GENLK_CTL, val);
  178. val = read_dc(par, DC_CLR_KEY);
  179. write_dc(par, DC_CLR_KEY, val & ~DC_CLR_KEY_CLR_KEY_EN);
  180. /* turn off the panel */
  181. write_fp(par, FP_PM, read_fp(par, FP_PM) & ~FP_PM_P);
  182. val = read_vp(par, VP_MISC) | VP_MISC_DACPWRDN;
  183. write_vp(par, VP_MISC, val);
  184. /* Turn off the display */
  185. val = read_vp(par, VP_DCFG);
  186. write_vp(par, VP_DCFG, val & ~(VP_DCFG_CRT_EN | VP_DCFG_HSYNC_EN |
  187. VP_DCFG_VSYNC_EN | VP_DCFG_DAC_BL_EN));
  188. gcfg = read_dc(par, DC_GENERAL_CFG);
  189. gcfg &= ~(DC_GENERAL_CFG_CMPE | DC_GENERAL_CFG_DECE);
  190. write_dc(par, DC_GENERAL_CFG, gcfg);
  191. /* Turn off the TGEN */
  192. val = read_dc(par, DC_DISPLAY_CFG);
  193. val &= ~DC_DISPLAY_CFG_TGEN;
  194. write_dc(par, DC_DISPLAY_CFG, val);
  195. /* Wait 1000 usecs to ensure that the TGEN is clear */
  196. udelay(1000);
  197. /* Turn off the FIFO loader */
  198. gcfg &= ~DC_GENERAL_CFG_DFLE;
  199. write_dc(par, DC_GENERAL_CFG, gcfg);
  200. /* Lastly, wait for the GP to go idle */
  201. do {
  202. val = read_gp(par, GP_BLT_STATUS);
  203. } while ((val & GP_BLT_STATUS_PB) || !(val & GP_BLT_STATUS_CE));
  204. }
  205. static void lx_graphics_enable(struct fb_info *info)
  206. {
  207. struct lxfb_par *par = info->par;
  208. u32 temp, config;
  209. /* Set the video request register */
  210. write_vp(par, VP_VRR, 0);
  211. /* Set up the polarities */
  212. config = read_vp(par, VP_DCFG);
  213. config &= ~(VP_DCFG_CRT_SYNC_SKW | VP_DCFG_PWR_SEQ_DELAY |
  214. VP_DCFG_CRT_HSYNC_POL | VP_DCFG_CRT_VSYNC_POL);
  215. config |= (VP_DCFG_CRT_SYNC_SKW_DEFAULT | VP_DCFG_PWR_SEQ_DELAY_DEFAULT
  216. | VP_DCFG_GV_GAM);
  217. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
  218. config |= VP_DCFG_CRT_HSYNC_POL;
  219. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
  220. config |= VP_DCFG_CRT_VSYNC_POL;
  221. if (par->output & OUTPUT_PANEL) {
  222. u32 msrlo, msrhi;
  223. write_fp(par, FP_PT1, 0);
  224. write_fp(par, FP_PT2, FP_PT2_SCRC);
  225. write_fp(par, FP_DFC, FP_DFC_BC);
  226. msrlo = MSR_LX_MSR_PADSEL_TFT_SEL_LOW;
  227. msrhi = MSR_LX_MSR_PADSEL_TFT_SEL_HIGH;
  228. wrmsr(MSR_LX_MSR_PADSEL, msrlo, msrhi);
  229. }
  230. if (par->output & OUTPUT_CRT) {
  231. config |= VP_DCFG_CRT_EN | VP_DCFG_HSYNC_EN |
  232. VP_DCFG_VSYNC_EN | VP_DCFG_DAC_BL_EN;
  233. }
  234. write_vp(par, VP_DCFG, config);
  235. /* Turn the CRT dacs back on */
  236. if (par->output & OUTPUT_CRT) {
  237. temp = read_vp(par, VP_MISC);
  238. temp &= ~(VP_MISC_DACPWRDN | VP_MISC_APWRDN);
  239. write_vp(par, VP_MISC, temp);
  240. }
  241. /* Turn the panel on (if it isn't already) */
  242. if (par->output & OUTPUT_PANEL)
  243. write_fp(par, FP_PM, read_fp(par, FP_PM) | FP_PM_P);
  244. }
  245. unsigned int lx_framebuffer_size(void)
  246. {
  247. unsigned int val;
  248. if (!geode_has_vsa2()) {
  249. uint32_t hi, lo;
  250. /* The number of pages is (PMAX - PMIN)+1 */
  251. rdmsr(MSR_GLIU_P2D_RO0, lo, hi);
  252. /* PMAX */
  253. val = ((hi & 0xff) << 12) | ((lo & 0xfff00000) >> 20);
  254. /* PMIN */
  255. val -= (lo & 0x000fffff);
  256. val += 1;
  257. /* The page size is 4k */
  258. return (val << 12);
  259. }
  260. /* The frame buffer size is reported by a VSM in VSA II */
  261. /* Virtual Register Class = 0x02 */
  262. /* VG_MEM_SIZE (1MB units) = 0x00 */
  263. outw(VSA_VR_UNLOCK, VSA_VRC_INDEX);
  264. outw(VSA_VR_MEM_SIZE, VSA_VRC_INDEX);
  265. val = (unsigned int)(inw(VSA_VRC_DATA)) & 0xFE;
  266. return (val << 20);
  267. }
  268. void lx_set_mode(struct fb_info *info)
  269. {
  270. struct lxfb_par *par = info->par;
  271. u64 msrval;
  272. unsigned int max, dv, val, size;
  273. unsigned int gcfg, dcfg;
  274. int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
  275. int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
  276. /* Unlock the DC registers */
  277. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  278. lx_graphics_disable(info);
  279. lx_set_clock(info);
  280. /* Set output mode */
  281. rdmsrl(MSR_LX_GLD_MSR_CONFIG, msrval);
  282. msrval &= ~MSR_LX_GLD_MSR_CONFIG_FMT;
  283. if (par->output & OUTPUT_PANEL) {
  284. msrval |= MSR_LX_GLD_MSR_CONFIG_FMT_FP;
  285. if (par->output & OUTPUT_CRT)
  286. msrval |= MSR_LX_GLD_MSR_CONFIG_FPC;
  287. else
  288. msrval &= ~MSR_LX_GLD_MSR_CONFIG_FPC;
  289. } else
  290. msrval |= MSR_LX_GLD_MSR_CONFIG_FMT_CRT;
  291. wrmsrl(MSR_LX_GLD_MSR_CONFIG, msrval);
  292. /* Clear the various buffers */
  293. /* FIXME: Adjust for panning here */
  294. write_dc(par, DC_FB_ST_OFFSET, 0);
  295. write_dc(par, DC_CB_ST_OFFSET, 0);
  296. write_dc(par, DC_CURS_ST_OFFSET, 0);
  297. /* FIXME: Add support for interlacing */
  298. /* FIXME: Add support for scaling */
  299. val = read_dc(par, DC_GENLK_CTL);
  300. val &= ~(DC_GENLK_CTL_ALPHA_FLICK_EN | DC_GENLK_CTL_FLICK_EN |
  301. DC_GENLK_CTL_FLICK_SEL_MASK);
  302. /* Default scaling params */
  303. write_dc(par, DC_GFX_SCALE, (0x4000 << 16) | 0x4000);
  304. write_dc(par, DC_IRQ_FILT_CTL, 0);
  305. write_dc(par, DC_GENLK_CTL, val);
  306. /* FIXME: Support compression */
  307. if (info->fix.line_length > 4096)
  308. dv = DC_DV_CTL_DV_LINE_SIZE_8K;
  309. else if (info->fix.line_length > 2048)
  310. dv = DC_DV_CTL_DV_LINE_SIZE_4K;
  311. else if (info->fix.line_length > 1024)
  312. dv = DC_DV_CTL_DV_LINE_SIZE_2K;
  313. else
  314. dv = DC_DV_CTL_DV_LINE_SIZE_1K;
  315. max = info->fix.line_length * info->var.yres;
  316. max = (max + 0x3FF) & 0xFFFFFC00;
  317. write_dc(par, DC_DV_TOP, max | DC_DV_TOP_DV_TOP_EN);
  318. val = read_dc(par, DC_DV_CTL) & ~DC_DV_CTL_DV_LINE_SIZE;
  319. write_dc(par, DC_DV_CTL, val | dv);
  320. size = info->var.xres * (info->var.bits_per_pixel >> 3);
  321. write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3);
  322. write_dc(par, DC_LINE_SIZE, (size + 7) >> 3);
  323. /* Set default watermark values */
  324. rdmsrl(MSR_LX_SPARE_MSR, msrval);
  325. msrval &= ~(MSR_LX_SPARE_MSR_DIS_CFIFO_HGO
  326. | MSR_LX_SPARE_MSR_VFIFO_ARB_SEL
  327. | MSR_LX_SPARE_MSR_LOAD_WM_LPEN_M
  328. | MSR_LX_SPARE_MSR_WM_LPEN_OVRD);
  329. msrval |= MSR_LX_SPARE_MSR_DIS_VIFO_WM |
  330. MSR_LX_SPARE_MSR_DIS_INIT_V_PRI;
  331. wrmsrl(MSR_LX_SPARE_MSR, msrval);
  332. gcfg = DC_GENERAL_CFG_DFLE; /* Display fifo enable */
  333. gcfg |= (0x6 << DC_GENERAL_CFG_DFHPSL_SHIFT) | /* default priority */
  334. (0xb << DC_GENERAL_CFG_DFHPEL_SHIFT);
  335. gcfg |= DC_GENERAL_CFG_FDTY; /* Set the frame dirty mode */
  336. dcfg = DC_DISPLAY_CFG_VDEN; /* Enable video data */
  337. dcfg |= DC_DISPLAY_CFG_GDEN; /* Enable graphics */
  338. dcfg |= DC_DISPLAY_CFG_TGEN; /* Turn on the timing generator */
  339. dcfg |= DC_DISPLAY_CFG_TRUP; /* Update timings immediately */
  340. dcfg |= DC_DISPLAY_CFG_PALB; /* Palette bypass in > 8 bpp modes */
  341. dcfg |= DC_DISPLAY_CFG_VISL;
  342. dcfg |= DC_DISPLAY_CFG_DCEN; /* Always center the display */
  343. /* Set the current BPP mode */
  344. switch (info->var.bits_per_pixel) {
  345. case 8:
  346. dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP;
  347. break;
  348. case 16:
  349. dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP;
  350. break;
  351. case 32:
  352. case 24:
  353. dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP;
  354. break;
  355. }
  356. /* Now - set up the timings */
  357. hactive = info->var.xres;
  358. hblankstart = hactive;
  359. hsyncstart = hblankstart + info->var.right_margin;
  360. hsyncend = hsyncstart + info->var.hsync_len;
  361. hblankend = hsyncend + info->var.left_margin;
  362. htotal = hblankend;
  363. vactive = info->var.yres;
  364. vblankstart = vactive;
  365. vsyncstart = vblankstart + info->var.lower_margin;
  366. vsyncend = vsyncstart + info->var.vsync_len;
  367. vblankend = vsyncend + info->var.upper_margin;
  368. vtotal = vblankend;
  369. write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) | ((htotal - 1) << 16));
  370. write_dc(par, DC_H_BLANK_TIMING,
  371. (hblankstart - 1) | ((hblankend - 1) << 16));
  372. write_dc(par, DC_H_SYNC_TIMING,
  373. (hsyncstart - 1) | ((hsyncend - 1) << 16));
  374. write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) | ((vtotal - 1) << 16));
  375. write_dc(par, DC_V_BLANK_TIMING,
  376. (vblankstart - 1) | ((vblankend - 1) << 16));
  377. write_dc(par, DC_V_SYNC_TIMING,
  378. (vsyncstart - 1) | ((vsyncend - 1) << 16));
  379. write_dc(par, DC_FB_ACTIVE,
  380. (info->var.xres - 1) << 16 | (info->var.yres - 1));
  381. /* And re-enable the graphics output */
  382. lx_graphics_enable(info);
  383. /* Write the two main configuration registers */
  384. write_dc(par, DC_DISPLAY_CFG, dcfg);
  385. write_dc(par, DC_ARB_CFG, 0);
  386. write_dc(par, DC_GENERAL_CFG, gcfg);
  387. /* Lock the DC registers */
  388. write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
  389. }
  390. void lx_set_palette_reg(struct fb_info *info, unsigned regno,
  391. unsigned red, unsigned green, unsigned blue)
  392. {
  393. struct lxfb_par *par = info->par;
  394. int val;
  395. /* Hardware palette is in RGB 8-8-8 format. */
  396. val = (red << 8) & 0xff0000;
  397. val |= (green) & 0x00ff00;
  398. val |= (blue >> 8) & 0x0000ff;
  399. write_dc(par, DC_PAL_ADDRESS, regno);
  400. write_dc(par, DC_PAL_DATA, val);
  401. }
  402. int lx_blank_display(struct fb_info *info, int blank_mode)
  403. {
  404. struct lxfb_par *par = info->par;
  405. u32 dcfg, misc, fp_pm;
  406. int blank, hsync, vsync;
  407. /* CRT power saving modes. */
  408. switch (blank_mode) {
  409. case FB_BLANK_UNBLANK:
  410. blank = 0; hsync = 1; vsync = 1;
  411. break;
  412. case FB_BLANK_NORMAL:
  413. blank = 1; hsync = 1; vsync = 1;
  414. break;
  415. case FB_BLANK_VSYNC_SUSPEND:
  416. blank = 1; hsync = 1; vsync = 0;
  417. break;
  418. case FB_BLANK_HSYNC_SUSPEND:
  419. blank = 1; hsync = 0; vsync = 1;
  420. break;
  421. case FB_BLANK_POWERDOWN:
  422. blank = 1; hsync = 0; vsync = 0;
  423. break;
  424. default:
  425. return -EINVAL;
  426. }
  427. dcfg = read_vp(par, VP_DCFG);
  428. dcfg &= ~(VP_DCFG_DAC_BL_EN | VP_DCFG_HSYNC_EN | VP_DCFG_VSYNC_EN |
  429. VP_DCFG_CRT_EN);
  430. if (!blank)
  431. dcfg |= VP_DCFG_DAC_BL_EN | VP_DCFG_CRT_EN;
  432. if (hsync)
  433. dcfg |= VP_DCFG_HSYNC_EN;
  434. if (vsync)
  435. dcfg |= VP_DCFG_VSYNC_EN;
  436. write_vp(par, VP_DCFG, dcfg);
  437. misc = read_vp(par, VP_MISC);
  438. if (vsync && hsync)
  439. misc &= ~VP_MISC_DACPWRDN;
  440. else
  441. misc |= VP_MISC_DACPWRDN;
  442. write_vp(par, VP_MISC, misc);
  443. /* Power on/off flat panel */
  444. if (par->output & OUTPUT_PANEL) {
  445. fp_pm = read_fp(par, FP_PM);
  446. if (blank_mode == FB_BLANK_POWERDOWN)
  447. fp_pm &= ~FP_PM_P;
  448. else
  449. fp_pm |= FP_PM_P;
  450. write_fp(par, FP_PM, fp_pm);
  451. }
  452. return 0;
  453. }
  454. #ifdef CONFIG_PM
  455. static void lx_save_regs(struct lxfb_par *par)
  456. {
  457. uint32_t filt;
  458. int i;
  459. /* wait for the BLT engine to stop being busy */
  460. do {
  461. i = read_gp(par, GP_BLT_STATUS);
  462. } while ((i & GP_BLT_STATUS_PB) || !(i & GP_BLT_STATUS_CE));
  463. /* save MSRs */
  464. rdmsrl(MSR_LX_MSR_PADSEL, par->msr.padsel);
  465. rdmsrl(MSR_GLCP_DOTPLL, par->msr.dotpll);
  466. rdmsrl(MSR_LX_GLD_MSR_CONFIG, par->msr.dfglcfg);
  467. rdmsrl(MSR_LX_SPARE_MSR, par->msr.dcspare);
  468. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  469. /* save registers */
  470. memcpy(par->gp, par->gp_regs, sizeof(par->gp));
  471. memcpy(par->dc, par->dc_regs, sizeof(par->dc));
  472. memcpy(par->vp, par->vp_regs, sizeof(par->vp));
  473. memcpy(par->fp, par->vp_regs + VP_FP_START, sizeof(par->fp));
  474. /* save the palette */
  475. write_dc(par, DC_PAL_ADDRESS, 0);
  476. for (i = 0; i < ARRAY_SIZE(par->pal); i++)
  477. par->pal[i] = read_dc(par, DC_PAL_DATA);
  478. /* save the horizontal filter coefficients */
  479. filt = par->dc[DC_IRQ_FILT_CTL] | DC_IRQ_FILT_CTL_H_FILT_SEL;
  480. for (i = 0; i < ARRAY_SIZE(par->hcoeff); i += 2) {
  481. write_dc(par, DC_IRQ_FILT_CTL, (filt & 0xffffff00) | i);
  482. par->hcoeff[i] = read_dc(par, DC_FILT_COEFF1);
  483. par->hcoeff[i + 1] = read_dc(par, DC_FILT_COEFF2);
  484. }
  485. /* save the vertical filter coefficients */
  486. filt &= ~DC_IRQ_FILT_CTL_H_FILT_SEL;
  487. for (i = 0; i < ARRAY_SIZE(par->vcoeff); i++) {
  488. write_dc(par, DC_IRQ_FILT_CTL, (filt & 0xffffff00) | i);
  489. par->vcoeff[i] = read_dc(par, DC_FILT_COEFF1);
  490. }
  491. /* save video coeff ram */
  492. memcpy(par->vp_coeff, par->vp_regs + VP_VCR, sizeof(par->vp_coeff));
  493. }
  494. static void lx_restore_gfx_proc(struct lxfb_par *par)
  495. {
  496. int i;
  497. /* a bunch of registers require GP_RASTER_MODE to be set first */
  498. write_gp(par, GP_RASTER_MODE, par->gp[GP_RASTER_MODE]);
  499. for (i = 0; i < ARRAY_SIZE(par->gp); i++) {
  500. switch (i) {
  501. case GP_RASTER_MODE:
  502. case GP_VECTOR_MODE:
  503. case GP_BLT_MODE:
  504. case GP_BLT_STATUS:
  505. case GP_HST_SRC:
  506. /* FIXME: restore LUT data */
  507. case GP_LUT_INDEX:
  508. case GP_LUT_DATA:
  509. /* don't restore these registers */
  510. break;
  511. default:
  512. write_gp(par, i, par->gp[i]);
  513. }
  514. }
  515. }
  516. static void lx_restore_display_ctlr(struct lxfb_par *par)
  517. {
  518. uint32_t filt;
  519. int i;
  520. wrmsrl(MSR_LX_SPARE_MSR, par->msr.dcspare);
  521. for (i = 0; i < ARRAY_SIZE(par->dc); i++) {
  522. switch (i) {
  523. case DC_UNLOCK:
  524. /* unlock the DC; runs first */
  525. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  526. break;
  527. case DC_GENERAL_CFG:
  528. case DC_DISPLAY_CFG:
  529. /* disable all while restoring */
  530. write_dc(par, i, 0);
  531. break;
  532. case DC_DV_CTL:
  533. /* set all ram to dirty */
  534. write_dc(par, i, par->dc[i] | DC_DV_CTL_CLEAR_DV_RAM);
  535. case DC_RSVD_1:
  536. case DC_RSVD_2:
  537. case DC_RSVD_3:
  538. case DC_LINE_CNT:
  539. case DC_PAL_ADDRESS:
  540. case DC_PAL_DATA:
  541. case DC_DFIFO_DIAG:
  542. case DC_CFIFO_DIAG:
  543. case DC_FILT_COEFF1:
  544. case DC_FILT_COEFF2:
  545. case DC_RSVD_4:
  546. case DC_RSVD_5:
  547. /* don't restore these registers */
  548. break;
  549. default:
  550. write_dc(par, i, par->dc[i]);
  551. }
  552. }
  553. /* restore the palette */
  554. write_dc(par, DC_PAL_ADDRESS, 0);
  555. for (i = 0; i < ARRAY_SIZE(par->pal); i++)
  556. write_dc(par, DC_PAL_DATA, par->pal[i]);
  557. /* restore the horizontal filter coefficients */
  558. filt = par->dc[DC_IRQ_FILT_CTL] | DC_IRQ_FILT_CTL_H_FILT_SEL;
  559. for (i = 0; i < ARRAY_SIZE(par->hcoeff); i += 2) {
  560. write_dc(par, DC_IRQ_FILT_CTL, (filt & 0xffffff00) | i);
  561. write_dc(par, DC_FILT_COEFF1, par->hcoeff[i]);
  562. write_dc(par, DC_FILT_COEFF2, par->hcoeff[i + 1]);
  563. }
  564. /* restore the vertical filter coefficients */
  565. filt &= ~DC_IRQ_FILT_CTL_H_FILT_SEL;
  566. for (i = 0; i < ARRAY_SIZE(par->vcoeff); i++) {
  567. write_dc(par, DC_IRQ_FILT_CTL, (filt & 0xffffff00) | i);
  568. write_dc(par, DC_FILT_COEFF1, par->vcoeff[i]);
  569. }
  570. }
  571. static void lx_restore_video_proc(struct lxfb_par *par)
  572. {
  573. int i;
  574. wrmsrl(MSR_LX_GLD_MSR_CONFIG, par->msr.dfglcfg);
  575. wrmsrl(MSR_LX_MSR_PADSEL, par->msr.padsel);
  576. for (i = 0; i < ARRAY_SIZE(par->vp); i++) {
  577. switch (i) {
  578. case VP_VCFG:
  579. case VP_DCFG:
  580. case VP_PAR:
  581. case VP_PDR:
  582. case VP_CCS:
  583. case VP_RSVD_0:
  584. /* case VP_VDC: */ /* why should this not be restored? */
  585. case VP_RSVD_1:
  586. case VP_CRC32:
  587. /* don't restore these registers */
  588. break;
  589. default:
  590. write_vp(par, i, par->vp[i]);
  591. }
  592. }
  593. /* restore video coeff ram */
  594. memcpy(par->vp_regs + VP_VCR, par->vp_coeff, sizeof(par->vp_coeff));
  595. }
  596. static void lx_restore_regs(struct lxfb_par *par)
  597. {
  598. int i;
  599. lx_set_dotpll((u32) (par->msr.dotpll >> 32));
  600. lx_restore_gfx_proc(par);
  601. lx_restore_display_ctlr(par);
  602. lx_restore_video_proc(par);
  603. /* Flat Panel */
  604. for (i = 0; i < ARRAY_SIZE(par->fp); i++) {
  605. switch (i) {
  606. case FP_PM:
  607. case FP_RSVD_0:
  608. case FP_RSVD_1:
  609. case FP_RSVD_2:
  610. case FP_RSVD_3:
  611. case FP_RSVD_4:
  612. /* don't restore these registers */
  613. break;
  614. default:
  615. write_fp(par, i, par->fp[i]);
  616. }
  617. }
  618. /* control the panel */
  619. if (par->fp[FP_PM] & FP_PM_P) {
  620. /* power on the panel if not already power{ed,ing} on */
  621. if (!(read_fp(par, FP_PM) &
  622. (FP_PM_PANEL_ON|FP_PM_PANEL_PWR_UP)))
  623. write_fp(par, FP_PM, par->fp[FP_PM]);
  624. } else {
  625. /* power down the panel if not already power{ed,ing} down */
  626. if (!(read_fp(par, FP_PM) &
  627. (FP_PM_PANEL_OFF|FP_PM_PANEL_PWR_DOWN)))
  628. write_fp(par, FP_PM, par->fp[FP_PM]);
  629. }
  630. /* turn everything on */
  631. write_vp(par, VP_VCFG, par->vp[VP_VCFG]);
  632. write_vp(par, VP_DCFG, par->vp[VP_DCFG]);
  633. write_dc(par, DC_DISPLAY_CFG, par->dc[DC_DISPLAY_CFG]);
  634. /* do this last; it will enable the FIFO load */
  635. write_dc(par, DC_GENERAL_CFG, par->dc[DC_GENERAL_CFG]);
  636. /* lock the door behind us */
  637. write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
  638. }
  639. int lx_powerdown(struct fb_info *info)
  640. {
  641. struct lxfb_par *par = info->par;
  642. if (par->powered_down)
  643. return 0;
  644. lx_save_regs(par);
  645. lx_graphics_disable(info);
  646. par->powered_down = 1;
  647. return 0;
  648. }
  649. int lx_powerup(struct fb_info *info)
  650. {
  651. struct lxfb_par *par = info->par;
  652. if (!par->powered_down)
  653. return 0;
  654. lx_restore_regs(par);
  655. par->powered_down = 0;
  656. return 0;
  657. }
  658. #endif