lxfb_ops.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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 "lxfb.h"
  16. /* TODO
  17. * Support panel scaling
  18. * Add acceleration
  19. * Add support for interlacing (TV out)
  20. * Support compression
  21. */
  22. /* This is the complete list of PLL frequencies that we can set -
  23. * we will choose the closest match to the incoming clock.
  24. * freq is the frequency of the dotclock * 1000 (for example,
  25. * 24823 = 24.983 Mhz).
  26. * pllval is the corresponding PLL value
  27. */
  28. static const struct {
  29. unsigned int pllval;
  30. unsigned int freq;
  31. } pll_table[] = {
  32. { 0x000031AC, 24923 },
  33. { 0x0000215D, 25175 },
  34. { 0x00001087, 27000 },
  35. { 0x0000216C, 28322 },
  36. { 0x0000218D, 28560 },
  37. { 0x000010C9, 31200 },
  38. { 0x00003147, 31500 },
  39. { 0x000010A7, 33032 },
  40. { 0x00002159, 35112 },
  41. { 0x00004249, 35500 },
  42. { 0x00000057, 36000 },
  43. { 0x0000219A, 37889 },
  44. { 0x00002158, 39168 },
  45. { 0x00000045, 40000 },
  46. { 0x00000089, 43163 },
  47. { 0x000010E7, 44900 },
  48. { 0x00002136, 45720 },
  49. { 0x00003207, 49500 },
  50. { 0x00002187, 50000 },
  51. { 0x00004286, 56250 },
  52. { 0x000010E5, 60065 },
  53. { 0x00004214, 65000 },
  54. { 0x00001105, 68179 },
  55. { 0x000031E4, 74250 },
  56. { 0x00003183, 75000 },
  57. { 0x00004284, 78750 },
  58. { 0x00001104, 81600 },
  59. { 0x00006363, 94500 },
  60. { 0x00005303, 97520 },
  61. { 0x00002183, 100187 },
  62. { 0x00002122, 101420 },
  63. { 0x00001081, 108000 },
  64. { 0x00006201, 113310 },
  65. { 0x00000041, 119650 },
  66. { 0x000041A1, 129600 },
  67. { 0x00002182, 133500 },
  68. { 0x000041B1, 135000 },
  69. { 0x00000051, 144000 },
  70. { 0x000041E1, 148500 },
  71. { 0x000062D1, 157500 },
  72. { 0x000031A1, 162000 },
  73. { 0x00000061, 169203 },
  74. { 0x00004231, 172800 },
  75. { 0x00002151, 175500 },
  76. { 0x000052E1, 189000 },
  77. { 0x00000071, 192000 },
  78. { 0x00003201, 198000 },
  79. { 0x00004291, 202500 },
  80. { 0x00001101, 204750 },
  81. { 0x00007481, 218250 },
  82. { 0x00004170, 229500 },
  83. { 0x00006210, 234000 },
  84. { 0x00003140, 251182 },
  85. { 0x00006250, 261000 },
  86. { 0x000041C0, 278400 },
  87. { 0x00005220, 280640 },
  88. { 0x00000050, 288000 },
  89. { 0x000041E0, 297000 },
  90. { 0x00002130, 320207 }
  91. };
  92. static void lx_set_dotpll(u32 pllval)
  93. {
  94. u32 dotpll_lo, dotpll_hi;
  95. int i;
  96. rdmsr(MSR_LX_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  97. if ((dotpll_lo & GLCP_DOTPLL_LOCK) && (dotpll_hi == pllval))
  98. return;
  99. dotpll_hi = pllval;
  100. dotpll_lo &= ~(GLCP_DOTPLL_BYPASS | GLCP_DOTPLL_HALFPIX);
  101. dotpll_lo |= GLCP_DOTPLL_RESET;
  102. wrmsr(MSR_LX_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  103. /* Wait 100us for the PLL to lock */
  104. udelay(100);
  105. /* Now, loop for the lock bit */
  106. for (i = 0; i < 1000; i++) {
  107. rdmsr(MSR_LX_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  108. if (dotpll_lo & GLCP_DOTPLL_LOCK)
  109. break;
  110. }
  111. /* Clear the reset bit */
  112. dotpll_lo &= ~GLCP_DOTPLL_RESET;
  113. wrmsr(MSR_LX_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
  114. }
  115. /* Set the clock based on the frequency specified by the current mode */
  116. static void lx_set_clock(struct fb_info *info)
  117. {
  118. unsigned int diff, min, best = 0;
  119. unsigned int freq, i;
  120. freq = (unsigned int) (0x3b9aca00 / info->var.pixclock);
  121. min = abs(pll_table[0].freq - freq);
  122. for (i = 0; i < ARRAY_SIZE(pll_table); i++) {
  123. diff = abs(pll_table[i].freq - freq);
  124. if (diff < min) {
  125. min = diff;
  126. best = i;
  127. }
  128. }
  129. lx_set_dotpll(pll_table[best].pllval & 0x7FFF);
  130. }
  131. static void lx_graphics_disable(struct fb_info *info)
  132. {
  133. struct lxfb_par *par = info->par;
  134. unsigned int val, gcfg;
  135. /* Note: This assumes that the video is in a quitet state */
  136. writel(0, par->df_regs + DF_ALPHA_CONTROL_1);
  137. writel(0, par->df_regs + DF_ALPHA_CONTROL_1 + 32);
  138. writel(0, par->df_regs + DF_ALPHA_CONTROL_1 + 64);
  139. /* Turn off the VGA and video enable */
  140. val = readl (par->dc_regs + DC_GENERAL_CFG) &
  141. ~(DC_GCFG_VGAE | DC_GCFG_VIDE);
  142. writel(val, par->dc_regs + DC_GENERAL_CFG);
  143. val = readl(par->df_regs + DF_VIDEO_CFG) & ~DF_VCFG_VID_EN;
  144. writel(val, par->df_regs + DF_VIDEO_CFG);
  145. writel( DC_IRQ_MASK | DC_VSYNC_IRQ_MASK |
  146. DC_IRQ_STATUS | DC_VSYNC_IRQ_STATUS,
  147. par->dc_regs + DC_IRQ);
  148. val = readl(par->dc_regs + DC_GENLCK_CTRL) & ~DC_GENLCK_ENABLE;
  149. writel(val, par->dc_regs + DC_GENLCK_CTRL);
  150. val = readl(par->dc_regs + DC_COLOR_KEY) & ~DC_CLR_KEY_ENABLE;
  151. writel(val & ~DC_CLR_KEY_ENABLE, par->dc_regs + DC_COLOR_KEY);
  152. /* We don't actually blank the panel, due to the long latency
  153. involved with bringing it back */
  154. val = readl(par->df_regs + DF_MISC) | DF_MISC_DAC_PWRDN;
  155. writel(val, par->df_regs + DF_MISC);
  156. /* Turn off the display */
  157. val = readl(par->df_regs + DF_DISPLAY_CFG);
  158. writel(val & ~(DF_DCFG_CRT_EN | DF_DCFG_HSYNC_EN | DF_DCFG_VSYNC_EN |
  159. DF_DCFG_DAC_BL_EN), par->df_regs + DF_DISPLAY_CFG);
  160. gcfg = readl(par->dc_regs + DC_GENERAL_CFG);
  161. gcfg &= ~(DC_GCFG_CMPE | DC_GCFG_DECE);
  162. writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
  163. /* Turn off the TGEN */
  164. val = readl(par->dc_regs + DC_DISPLAY_CFG);
  165. val &= ~DC_DCFG_TGEN;
  166. writel(val, par->dc_regs + DC_DISPLAY_CFG);
  167. /* Wait 1000 usecs to ensure that the TGEN is clear */
  168. udelay(1000);
  169. /* Turn off the FIFO loader */
  170. gcfg &= ~DC_GCFG_DFLE;
  171. writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
  172. /* Lastly, wait for the GP to go idle */
  173. do {
  174. val = readl(par->gp_regs + GP_BLT_STATUS);
  175. } while ((val & GP_BS_BLT_BUSY) || !(val & GP_BS_CB_EMPTY));
  176. }
  177. static void lx_graphics_enable(struct fb_info *info)
  178. {
  179. struct lxfb_par *par = info->par;
  180. u32 temp, config;
  181. /* Set the video request register */
  182. writel(0, par->df_regs + DF_VIDEO_REQUEST);
  183. /* Set up the polarities */
  184. config = readl(par->df_regs + DF_DISPLAY_CFG);
  185. config &= ~(DF_DCFG_CRT_SYNC_SKW_MASK | DF_DCFG_PWR_SEQ_DLY_MASK |
  186. DF_DCFG_CRT_HSYNC_POL | DF_DCFG_CRT_VSYNC_POL);
  187. config |= (DF_DCFG_CRT_SYNC_SKW_INIT | DF_DCFG_PWR_SEQ_DLY_INIT |
  188. DF_DCFG_GV_PAL_BYP);
  189. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
  190. config |= DF_DCFG_CRT_HSYNC_POL;
  191. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
  192. config |= DF_DCFG_CRT_VSYNC_POL;
  193. if (par->output & OUTPUT_PANEL) {
  194. u32 msrlo, msrhi;
  195. writel(DF_DEFAULT_TFT_PMTIM1,
  196. par->df_regs + DF_PANEL_TIM1);
  197. writel(DF_DEFAULT_TFT_PMTIM2,
  198. par->df_regs + DF_PANEL_TIM2);
  199. writel(DF_DEFAULT_TFT_DITHCTL,
  200. par->df_regs + DF_DITHER_CONTROL);
  201. msrlo = DF_DEFAULT_TFT_PAD_SEL_LOW;
  202. msrhi = DF_DEFAULT_TFT_PAD_SEL_HIGH;
  203. wrmsr(MSR_LX_DF_PADSEL, msrlo, msrhi);
  204. }
  205. if (par->output & OUTPUT_CRT) {
  206. config |= DF_DCFG_CRT_EN | DF_DCFG_HSYNC_EN |
  207. DF_DCFG_VSYNC_EN | DF_DCFG_DAC_BL_EN;
  208. }
  209. writel(config, par->df_regs + DF_DISPLAY_CFG);
  210. /* Turn the CRT dacs back on */
  211. if (par->output & OUTPUT_CRT) {
  212. temp = readl(par->df_regs + DF_MISC);
  213. temp &= ~(DF_MISC_DAC_PWRDN | DF_MISC_A_PWRDN);
  214. writel(temp, par->df_regs + DF_MISC);
  215. }
  216. /* Turn the panel on (if it isn't already) */
  217. if (par->output & OUTPUT_PANEL) {
  218. temp = readl(par->df_regs + DF_FP_PM);
  219. if (!(temp & 0x09))
  220. writel(temp | DF_FP_PM_P, par->df_regs + DF_FP_PM);
  221. }
  222. temp = readl(par->df_regs + DF_MISC);
  223. temp = readl(par->df_regs + DF_DISPLAY_CFG);
  224. }
  225. unsigned int lx_framebuffer_size(void)
  226. {
  227. unsigned int val;
  228. /* The frame buffer size is reported by a VSM in VSA II */
  229. /* Virtual Register Class = 0x02 */
  230. /* VG_MEM_SIZE (1MB units) = 0x00 */
  231. outw(0xFC53, 0xAC1C);
  232. outw(0x0200, 0xAC1C);
  233. val = (unsigned int)(inw(0xAC1E)) & 0xFE;
  234. return (val << 20);
  235. }
  236. void lx_set_mode(struct fb_info *info)
  237. {
  238. struct lxfb_par *par = info->par;
  239. u64 msrval;
  240. unsigned int max, dv, val, size;
  241. unsigned int gcfg, dcfg;
  242. int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
  243. int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
  244. /* Unlock the DC registers */
  245. writel(DC_UNLOCK_CODE, par->dc_regs + DC_UNLOCK);
  246. lx_graphics_disable(info);
  247. lx_set_clock(info);
  248. /* Set output mode */
  249. rdmsrl(MSR_LX_DF_GLCONFIG, msrval);
  250. msrval &= ~DF_CONFIG_OUTPUT_MASK;
  251. if (par->output & OUTPUT_PANEL) {
  252. msrval |= DF_OUTPUT_PANEL;
  253. if (par->output & OUTPUT_CRT)
  254. msrval |= DF_SIMULTANEOUS_CRT_AND_FP;
  255. else
  256. msrval &= ~DF_SIMULTANEOUS_CRT_AND_FP;
  257. } else {
  258. msrval |= DF_OUTPUT_CRT;
  259. }
  260. wrmsrl(MSR_LX_DF_GLCONFIG, msrval);
  261. /* Clear the various buffers */
  262. /* FIXME: Adjust for panning here */
  263. writel(0, par->dc_regs + DC_FB_START);
  264. writel(0, par->dc_regs + DC_CB_START);
  265. writel(0, par->dc_regs + DC_CURSOR_START);
  266. /* FIXME: Add support for interlacing */
  267. /* FIXME: Add support for scaling */
  268. val = readl(par->dc_regs + DC_GENLCK_CTRL);
  269. val &= ~(DC_GC_ALPHA_FLICK_ENABLE |
  270. DC_GC_FLICKER_FILTER_ENABLE | DC_GC_FLICKER_FILTER_MASK);
  271. /* Default scaling params */
  272. writel((0x4000 << 16) | 0x4000, par->dc_regs + DC_GFX_SCALE);
  273. writel(0, par->dc_regs + DC_IRQ_FILT_CTL);
  274. writel(val, par->dc_regs + DC_GENLCK_CTRL);
  275. /* FIXME: Support compression */
  276. if (info->fix.line_length > 4096)
  277. dv = DC_DV_LINE_SIZE_8192;
  278. else if (info->fix.line_length > 2048)
  279. dv = DC_DV_LINE_SIZE_4096;
  280. else if (info->fix.line_length > 1024)
  281. dv = DC_DV_LINE_SIZE_2048;
  282. else
  283. dv = DC_DV_LINE_SIZE_1024;
  284. max = info->fix.line_length * info->var.yres;
  285. max = (max + 0x3FF) & 0xFFFFFC00;
  286. writel(max | DC_DV_TOP_ENABLE, par->dc_regs + DC_DV_TOP);
  287. val = readl(par->dc_regs + DC_DV_CTL) & ~DC_DV_LINE_SIZE_MASK;
  288. writel(val | dv, par->dc_regs + DC_DV_CTL);
  289. size = info->var.xres * (info->var.bits_per_pixel >> 3);
  290. writel(info->fix.line_length >> 3, par->dc_regs + DC_GRAPHICS_PITCH);
  291. writel((size + 7) >> 3, par->dc_regs + DC_LINE_SIZE);
  292. /* Set default watermark values */
  293. rdmsrl(MSR_LX_DC_SPARE, msrval);
  294. msrval &= ~(DC_SPARE_DISABLE_CFIFO_HGO | DC_SPARE_VFIFO_ARB_SELECT |
  295. DC_SPARE_LOAD_WM_LPEN_MASK | DC_SPARE_WM_LPEN_OVRD |
  296. DC_SPARE_DISABLE_INIT_VID_PRI | DC_SPARE_DISABLE_VFIFO_WM);
  297. msrval |= DC_SPARE_DISABLE_VFIFO_WM | DC_SPARE_DISABLE_INIT_VID_PRI;
  298. wrmsrl(MSR_LX_DC_SPARE, msrval);
  299. gcfg = DC_GCFG_DFLE; /* Display fifo enable */
  300. gcfg |= 0xB600; /* Set default priority */
  301. gcfg |= DC_GCFG_FDTY; /* Set the frame dirty mode */
  302. dcfg = DC_DCFG_VDEN; /* Enable video data */
  303. dcfg |= DC_DCFG_GDEN; /* Enable graphics */
  304. dcfg |= DC_DCFG_TGEN; /* Turn on the timing generator */
  305. dcfg |= DC_DCFG_TRUP; /* Update timings immediately */
  306. dcfg |= DC_DCFG_PALB; /* Palette bypass in > 8 bpp modes */
  307. dcfg |= DC_DCFG_VISL;
  308. dcfg |= DC_DCFG_DCEN; /* Always center the display */
  309. /* Set the current BPP mode */
  310. switch (info->var.bits_per_pixel) {
  311. case 8:
  312. dcfg |= DC_DCFG_DISP_MODE_8BPP;
  313. break;
  314. case 16:
  315. dcfg |= DC_DCFG_DISP_MODE_16BPP | DC_DCFG_16BPP;
  316. break;
  317. case 32:
  318. case 24:
  319. dcfg |= DC_DCFG_DISP_MODE_24BPP;
  320. break;
  321. }
  322. /* Now - set up the timings */
  323. hactive = info->var.xres;
  324. hblankstart = hactive;
  325. hsyncstart = hblankstart + info->var.right_margin;
  326. hsyncend = hsyncstart + info->var.hsync_len;
  327. hblankend = hsyncend + info->var.left_margin;
  328. htotal = hblankend;
  329. vactive = info->var.yres;
  330. vblankstart = vactive;
  331. vsyncstart = vblankstart + info->var.lower_margin;
  332. vsyncend = vsyncstart + info->var.vsync_len;
  333. vblankend = vsyncend + info->var.upper_margin;
  334. vtotal = vblankend;
  335. writel((hactive - 1) | ((htotal - 1) << 16),
  336. par->dc_regs + DC_H_ACTIVE_TIMING);
  337. writel((hblankstart - 1) | ((hblankend - 1) << 16),
  338. par->dc_regs + DC_H_BLANK_TIMING);
  339. writel((hsyncstart - 1) | ((hsyncend - 1) << 16),
  340. par->dc_regs + DC_H_SYNC_TIMING);
  341. writel((vactive - 1) | ((vtotal - 1) << 16),
  342. par->dc_regs + DC_V_ACTIVE_TIMING);
  343. writel((vblankstart - 1) | ((vblankend - 1) << 16),
  344. par->dc_regs + DC_V_BLANK_TIMING);
  345. writel((vsyncstart - 1) | ((vsyncend - 1) << 16),
  346. par->dc_regs + DC_V_SYNC_TIMING);
  347. writel( (info->var.xres - 1) << 16 | (info->var.yres - 1),
  348. par->dc_regs + DC_FB_ACTIVE);
  349. /* And re-enable the graphics output */
  350. lx_graphics_enable(info);
  351. /* Write the two main configuration registers */
  352. writel(dcfg, par->dc_regs + DC_DISPLAY_CFG);
  353. writel(0, par->dc_regs + DC_ARB_CFG);
  354. writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
  355. /* Lock the DC registers */
  356. writel(0, par->dc_regs + DC_UNLOCK);
  357. }
  358. void lx_set_palette_reg(struct fb_info *info, unsigned regno,
  359. unsigned red, unsigned green, unsigned blue)
  360. {
  361. struct lxfb_par *par = info->par;
  362. int val;
  363. /* Hardware palette is in RGB 8-8-8 format. */
  364. val = (red << 8) & 0xff0000;
  365. val |= (green) & 0x00ff00;
  366. val |= (blue >> 8) & 0x0000ff;
  367. writel(regno, par->dc_regs + DC_PAL_ADDRESS);
  368. writel(val, par->dc_regs + DC_PAL_DATA);
  369. }
  370. int lx_blank_display(struct fb_info *info, int blank_mode)
  371. {
  372. struct lxfb_par *par = info->par;
  373. u32 dcfg, fp_pm;
  374. int blank, hsync, vsync;
  375. /* CRT power saving modes. */
  376. switch (blank_mode) {
  377. case FB_BLANK_UNBLANK:
  378. blank = 0; hsync = 1; vsync = 1;
  379. break;
  380. case FB_BLANK_NORMAL:
  381. blank = 1; hsync = 1; vsync = 1;
  382. break;
  383. case FB_BLANK_VSYNC_SUSPEND:
  384. blank = 1; hsync = 1; vsync = 0;
  385. break;
  386. case FB_BLANK_HSYNC_SUSPEND:
  387. blank = 1; hsync = 0; vsync = 1;
  388. break;
  389. case FB_BLANK_POWERDOWN:
  390. blank = 1; hsync = 0; vsync = 0;
  391. break;
  392. default:
  393. return -EINVAL;
  394. }
  395. dcfg = readl(par->df_regs + DF_DISPLAY_CFG);
  396. dcfg &= ~(DF_DCFG_DAC_BL_EN
  397. | DF_DCFG_HSYNC_EN | DF_DCFG_VSYNC_EN);
  398. if (!blank)
  399. dcfg |= DF_DCFG_DAC_BL_EN;
  400. if (hsync)
  401. dcfg |= DF_DCFG_HSYNC_EN;
  402. if (vsync)
  403. dcfg |= DF_DCFG_VSYNC_EN;
  404. writel(dcfg, par->df_regs + DF_DISPLAY_CFG);
  405. /* Power on/off flat panel */
  406. if (par->output & OUTPUT_PANEL) {
  407. fp_pm = readl(par->df_regs + DF_FP_PM);
  408. if (blank_mode == FB_BLANK_POWERDOWN)
  409. fp_pm &= ~DF_FP_PM_P;
  410. else
  411. fp_pm |= DF_FP_PM_P;
  412. writel(fp_pm, par->df_regs + DF_FP_PM);
  413. }
  414. return 0;
  415. }