lxfb_ops.c 14 KB

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