1 /* Geode LX framebuffer driver
3 * Copyright (C) 2006-2007, Advanced Micro Devices,Inc.
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.
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
14 #include <linux/uaccess.h>
15 #include <linux/delay.h>
16 #include <asm/geode.h>
21 * Support panel scaling
23 * Add support for interlacing (TV out)
27 /* This is the complete list of PLL frequencies that we can set -
28 * we will choose the closest match to the incoming clock.
29 * freq is the frequency of the dotclock * 1000 (for example,
30 * 24823 = 24.983 Mhz).
31 * pllval is the corresponding PLL value
38 { 0x000031AC, 24923 },
39 { 0x0000215D, 25175 },
40 { 0x00001087, 27000 },
41 { 0x0000216C, 28322 },
42 { 0x0000218D, 28560 },
43 { 0x000010C9, 31200 },
44 { 0x00003147, 31500 },
45 { 0x000010A7, 33032 },
46 { 0x00002159, 35112 },
47 { 0x00004249, 35500 },
48 { 0x00000057, 36000 },
49 { 0x0000219A, 37889 },
50 { 0x00002158, 39168 },
51 { 0x00000045, 40000 },
52 { 0x00000089, 43163 },
53 { 0x000010E7, 44900 },
54 { 0x00002136, 45720 },
55 { 0x00003207, 49500 },
56 { 0x00002187, 50000 },
57 { 0x00004286, 56250 },
58 { 0x000010E5, 60065 },
59 { 0x00004214, 65000 },
60 { 0x00001105, 68179 },
61 { 0x000031E4, 74250 },
62 { 0x00003183, 75000 },
63 { 0x00004284, 78750 },
64 { 0x00001104, 81600 },
65 { 0x00006363, 94500 },
66 { 0x00005303, 97520 },
67 { 0x00002183, 100187 },
68 { 0x00002122, 101420 },
69 { 0x00001081, 108000 },
70 { 0x00006201, 113310 },
71 { 0x00000041, 119650 },
72 { 0x000041A1, 129600 },
73 { 0x00002182, 133500 },
74 { 0x000041B1, 135000 },
75 { 0x00000051, 144000 },
76 { 0x000041E1, 148500 },
77 { 0x000062D1, 157500 },
78 { 0x000031A1, 162000 },
79 { 0x00000061, 169203 },
80 { 0x00004231, 172800 },
81 { 0x00002151, 175500 },
82 { 0x000052E1, 189000 },
83 { 0x00000071, 192000 },
84 { 0x00003201, 198000 },
85 { 0x00004291, 202500 },
86 { 0x00001101, 204750 },
87 { 0x00007481, 218250 },
88 { 0x00004170, 229500 },
89 { 0x00006210, 234000 },
90 { 0x00003140, 251182 },
91 { 0x00006250, 261000 },
92 { 0x000041C0, 278400 },
93 { 0x00005220, 280640 },
94 { 0x00000050, 288000 },
95 { 0x000041E0, 297000 },
96 { 0x00002130, 320207 }
100 static void lx_set_dotpll(u32 pllval)
102 u32 dotpll_lo, dotpll_hi;
105 rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
107 if ((dotpll_lo & GLCP_DOTPLL_LOCK) && (dotpll_hi == pllval))
111 dotpll_lo &= ~(GLCP_DOTPLL_BYPASS | GLCP_DOTPLL_HALFPIX);
112 dotpll_lo |= GLCP_DOTPLL_RESET;
114 wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
116 /* Wait 100us for the PLL to lock */
120 /* Now, loop for the lock bit */
122 for (i = 0; i < 1000; i++) {
123 rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
124 if (dotpll_lo & GLCP_DOTPLL_LOCK)
128 /* Clear the reset bit */
130 dotpll_lo &= ~GLCP_DOTPLL_RESET;
131 wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
134 /* Set the clock based on the frequency specified by the current mode */
136 static void lx_set_clock(struct fb_info *info)
138 unsigned int diff, min, best = 0;
139 unsigned int freq, i;
141 freq = (unsigned int) (0x3b9aca00 / info->var.pixclock);
143 min = abs(pll_table[0].freq - freq);
145 for (i = 0; i < ARRAY_SIZE(pll_table); i++) {
146 diff = abs(pll_table[i].freq - freq);
153 lx_set_dotpll(pll_table[best].pllval & 0x7FFF);
156 static void lx_graphics_disable(struct fb_info *info)
158 struct lxfb_par *par = info->par;
159 unsigned int val, gcfg;
161 /* Note: This assumes that the video is in a quitet state */
163 writel(0, par->df_regs + DF_ALPHA_CONTROL_1);
164 writel(0, par->df_regs + DF_ALPHA_CONTROL_1 + 32);
165 writel(0, par->df_regs + DF_ALPHA_CONTROL_1 + 64);
167 /* Turn off the VGA and video enable */
168 val = readl (par->dc_regs + DC_GENERAL_CFG) &
169 ~(DC_GCFG_VGAE | DC_GCFG_VIDE);
171 writel(val, par->dc_regs + DC_GENERAL_CFG);
173 val = readl(par->df_regs + DF_VIDEO_CFG) & ~DF_VCFG_VID_EN;
174 writel(val, par->df_regs + DF_VIDEO_CFG);
176 writel( DC_IRQ_MASK | DC_VSYNC_IRQ_MASK |
177 DC_IRQ_STATUS | DC_VSYNC_IRQ_STATUS,
178 par->dc_regs + DC_IRQ);
180 val = readl(par->dc_regs + DC_GENLCK_CTRL) & ~DC_GENLCK_ENABLE;
181 writel(val, par->dc_regs + DC_GENLCK_CTRL);
183 val = readl(par->dc_regs + DC_COLOR_KEY) & ~DC_CLR_KEY_ENABLE;
184 writel(val & ~DC_CLR_KEY_ENABLE, par->dc_regs + DC_COLOR_KEY);
186 /* We don't actually blank the panel, due to the long latency
187 involved with bringing it back */
189 val = readl(par->df_regs + DF_MISC) | DF_MISC_DAC_PWRDN;
190 writel(val, par->df_regs + DF_MISC);
192 /* Turn off the display */
194 val = readl(par->df_regs + DF_DISPLAY_CFG);
195 writel(val & ~(DF_DCFG_CRT_EN | DF_DCFG_HSYNC_EN | DF_DCFG_VSYNC_EN |
196 DF_DCFG_DAC_BL_EN), par->df_regs + DF_DISPLAY_CFG);
198 gcfg = readl(par->dc_regs + DC_GENERAL_CFG);
199 gcfg &= ~(DC_GCFG_CMPE | DC_GCFG_DECE);
200 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
202 /* Turn off the TGEN */
203 val = readl(par->dc_regs + DC_DISPLAY_CFG);
204 val &= ~DC_DCFG_TGEN;
205 writel(val, par->dc_regs + DC_DISPLAY_CFG);
207 /* Wait 1000 usecs to ensure that the TGEN is clear */
210 /* Turn off the FIFO loader */
212 gcfg &= ~DC_GCFG_DFLE;
213 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
215 /* Lastly, wait for the GP to go idle */
218 val = readl(par->gp_regs + GP_BLT_STATUS);
219 } while ((val & GP_BS_BLT_BUSY) || !(val & GP_BS_CB_EMPTY));
222 static void lx_graphics_enable(struct fb_info *info)
224 struct lxfb_par *par = info->par;
227 /* Set the video request register */
228 writel(0, par->df_regs + DF_VIDEO_REQUEST);
230 /* Set up the polarities */
232 config = readl(par->df_regs + DF_DISPLAY_CFG);
234 config &= ~(DF_DCFG_CRT_SYNC_SKW_MASK | DF_DCFG_PWR_SEQ_DLY_MASK |
235 DF_DCFG_CRT_HSYNC_POL | DF_DCFG_CRT_VSYNC_POL);
237 config |= (DF_DCFG_CRT_SYNC_SKW_INIT | DF_DCFG_PWR_SEQ_DLY_INIT |
240 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
241 config |= DF_DCFG_CRT_HSYNC_POL;
243 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
244 config |= DF_DCFG_CRT_VSYNC_POL;
246 if (par->output & OUTPUT_PANEL) {
249 writel(DF_DEFAULT_TFT_PMTIM1,
250 par->df_regs + DF_PANEL_TIM1);
251 writel(DF_DEFAULT_TFT_PMTIM2,
252 par->df_regs + DF_PANEL_TIM2);
253 writel(DF_DEFAULT_TFT_DITHCTL,
254 par->df_regs + DF_DITHER_CONTROL);
256 msrlo = DF_DEFAULT_TFT_PAD_SEL_LOW;
257 msrhi = DF_DEFAULT_TFT_PAD_SEL_HIGH;
259 wrmsr(MSR_LX_MSR_PADSEL, msrlo, msrhi);
262 if (par->output & OUTPUT_CRT) {
263 config |= DF_DCFG_CRT_EN | DF_DCFG_HSYNC_EN |
264 DF_DCFG_VSYNC_EN | DF_DCFG_DAC_BL_EN;
267 writel(config, par->df_regs + DF_DISPLAY_CFG);
269 /* Turn the CRT dacs back on */
271 if (par->output & OUTPUT_CRT) {
272 temp = readl(par->df_regs + DF_MISC);
273 temp &= ~(DF_MISC_DAC_PWRDN | DF_MISC_A_PWRDN);
274 writel(temp, par->df_regs + DF_MISC);
277 /* Turn the panel on (if it isn't already) */
279 if (par->output & OUTPUT_PANEL) {
280 temp = readl(par->df_regs + DF_FP_PM);
283 writel(temp | DF_FP_PM_P, par->df_regs + DF_FP_PM);
286 temp = readl(par->df_regs + DF_MISC);
287 temp = readl(par->df_regs + DF_DISPLAY_CFG);
290 unsigned int lx_framebuffer_size(void)
294 /* The frame buffer size is reported by a VSM in VSA II */
295 /* Virtual Register Class = 0x02 */
296 /* VG_MEM_SIZE (1MB units) = 0x00 */
298 outw(0xFC53, 0xAC1C);
299 outw(0x0200, 0xAC1C);
301 val = (unsigned int)(inw(0xAC1E)) & 0xFE;
305 void lx_set_mode(struct fb_info *info)
307 struct lxfb_par *par = info->par;
310 unsigned int max, dv, val, size;
312 unsigned int gcfg, dcfg;
313 int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
314 int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
316 /* Unlock the DC registers */
317 writel(DC_UNLOCK_CODE, par->dc_regs + DC_UNLOCK);
319 lx_graphics_disable(info);
323 /* Set output mode */
325 rdmsrl(MSR_LX_GLD_MSR_CONFIG, msrval);
326 msrval &= ~DF_CONFIG_OUTPUT_MASK;
328 if (par->output & OUTPUT_PANEL) {
329 msrval |= DF_OUTPUT_PANEL;
331 if (par->output & OUTPUT_CRT)
332 msrval |= DF_SIMULTANEOUS_CRT_AND_FP;
334 msrval &= ~DF_SIMULTANEOUS_CRT_AND_FP;
336 msrval |= DF_OUTPUT_CRT;
339 wrmsrl(MSR_LX_GLD_MSR_CONFIG, msrval);
341 /* Clear the various buffers */
342 /* FIXME: Adjust for panning here */
344 writel(0, par->dc_regs + DC_FB_START);
345 writel(0, par->dc_regs + DC_CB_START);
346 writel(0, par->dc_regs + DC_CURSOR_START);
348 /* FIXME: Add support for interlacing */
349 /* FIXME: Add support for scaling */
351 val = readl(par->dc_regs + DC_GENLCK_CTRL);
352 val &= ~(DC_GC_ALPHA_FLICK_ENABLE |
353 DC_GC_FLICKER_FILTER_ENABLE | DC_GC_FLICKER_FILTER_MASK);
355 /* Default scaling params */
357 writel((0x4000 << 16) | 0x4000, par->dc_regs + DC_GFX_SCALE);
358 writel(0, par->dc_regs + DC_IRQ_FILT_CTL);
359 writel(val, par->dc_regs + DC_GENLCK_CTRL);
361 /* FIXME: Support compression */
363 if (info->fix.line_length > 4096)
364 dv = DC_DV_LINE_SIZE_8192;
365 else if (info->fix.line_length > 2048)
366 dv = DC_DV_LINE_SIZE_4096;
367 else if (info->fix.line_length > 1024)
368 dv = DC_DV_LINE_SIZE_2048;
370 dv = DC_DV_LINE_SIZE_1024;
372 max = info->fix.line_length * info->var.yres;
373 max = (max + 0x3FF) & 0xFFFFFC00;
375 writel(max | DC_DV_TOP_ENABLE, par->dc_regs + DC_DV_TOP);
377 val = readl(par->dc_regs + DC_DV_CTL) & ~DC_DV_LINE_SIZE_MASK;
378 writel(val | dv, par->dc_regs + DC_DV_CTL);
380 size = info->var.xres * (info->var.bits_per_pixel >> 3);
382 writel(info->fix.line_length >> 3, par->dc_regs + DC_GRAPHICS_PITCH);
383 writel((size + 7) >> 3, par->dc_regs + DC_LINE_SIZE);
385 /* Set default watermark values */
387 rdmsrl(MSR_LX_SPARE_MSR, msrval);
389 msrval &= ~(DC_SPARE_DISABLE_CFIFO_HGO | DC_SPARE_VFIFO_ARB_SELECT |
390 DC_SPARE_LOAD_WM_LPEN_MASK | DC_SPARE_WM_LPEN_OVRD |
391 DC_SPARE_DISABLE_INIT_VID_PRI | DC_SPARE_DISABLE_VFIFO_WM);
392 msrval |= DC_SPARE_DISABLE_VFIFO_WM | DC_SPARE_DISABLE_INIT_VID_PRI;
393 wrmsrl(MSR_LX_SPARE_MSR, msrval);
395 gcfg = DC_GCFG_DFLE; /* Display fifo enable */
396 gcfg |= 0xB600; /* Set default priority */
397 gcfg |= DC_GCFG_FDTY; /* Set the frame dirty mode */
399 dcfg = DC_DCFG_VDEN; /* Enable video data */
400 dcfg |= DC_DCFG_GDEN; /* Enable graphics */
401 dcfg |= DC_DCFG_TGEN; /* Turn on the timing generator */
402 dcfg |= DC_DCFG_TRUP; /* Update timings immediately */
403 dcfg |= DC_DCFG_PALB; /* Palette bypass in > 8 bpp modes */
404 dcfg |= DC_DCFG_VISL;
405 dcfg |= DC_DCFG_DCEN; /* Always center the display */
407 /* Set the current BPP mode */
409 switch (info->var.bits_per_pixel) {
411 dcfg |= DC_DCFG_DISP_MODE_8BPP;
415 dcfg |= DC_DCFG_DISP_MODE_16BPP | DC_DCFG_16BPP;
420 dcfg |= DC_DCFG_DISP_MODE_24BPP;
424 /* Now - set up the timings */
426 hactive = info->var.xres;
427 hblankstart = hactive;
428 hsyncstart = hblankstart + info->var.right_margin;
429 hsyncend = hsyncstart + info->var.hsync_len;
430 hblankend = hsyncend + info->var.left_margin;
433 vactive = info->var.yres;
434 vblankstart = vactive;
435 vsyncstart = vblankstart + info->var.lower_margin;
436 vsyncend = vsyncstart + info->var.vsync_len;
437 vblankend = vsyncend + info->var.upper_margin;
440 writel((hactive - 1) | ((htotal - 1) << 16),
441 par->dc_regs + DC_H_ACTIVE_TIMING);
442 writel((hblankstart - 1) | ((hblankend - 1) << 16),
443 par->dc_regs + DC_H_BLANK_TIMING);
444 writel((hsyncstart - 1) | ((hsyncend - 1) << 16),
445 par->dc_regs + DC_H_SYNC_TIMING);
447 writel((vactive - 1) | ((vtotal - 1) << 16),
448 par->dc_regs + DC_V_ACTIVE_TIMING);
450 writel((vblankstart - 1) | ((vblankend - 1) << 16),
451 par->dc_regs + DC_V_BLANK_TIMING);
453 writel((vsyncstart - 1) | ((vsyncend - 1) << 16),
454 par->dc_regs + DC_V_SYNC_TIMING);
456 writel( (info->var.xres - 1) << 16 | (info->var.yres - 1),
457 par->dc_regs + DC_FB_ACTIVE);
459 /* And re-enable the graphics output */
460 lx_graphics_enable(info);
462 /* Write the two main configuration registers */
463 writel(dcfg, par->dc_regs + DC_DISPLAY_CFG);
464 writel(0, par->dc_regs + DC_ARB_CFG);
465 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
467 /* Lock the DC registers */
468 writel(0, par->dc_regs + DC_UNLOCK);
471 void lx_set_palette_reg(struct fb_info *info, unsigned regno,
472 unsigned red, unsigned green, unsigned blue)
474 struct lxfb_par *par = info->par;
477 /* Hardware palette is in RGB 8-8-8 format. */
479 val = (red << 8) & 0xff0000;
480 val |= (green) & 0x00ff00;
481 val |= (blue >> 8) & 0x0000ff;
483 writel(regno, par->dc_regs + DC_PAL_ADDRESS);
484 writel(val, par->dc_regs + DC_PAL_DATA);
487 int lx_blank_display(struct fb_info *info, int blank_mode)
489 struct lxfb_par *par = info->par;
491 int blank, hsync, vsync;
493 /* CRT power saving modes. */
494 switch (blank_mode) {
495 case FB_BLANK_UNBLANK:
496 blank = 0; hsync = 1; vsync = 1;
498 case FB_BLANK_NORMAL:
499 blank = 1; hsync = 1; vsync = 1;
501 case FB_BLANK_VSYNC_SUSPEND:
502 blank = 1; hsync = 1; vsync = 0;
504 case FB_BLANK_HSYNC_SUSPEND:
505 blank = 1; hsync = 0; vsync = 1;
507 case FB_BLANK_POWERDOWN:
508 blank = 1; hsync = 0; vsync = 0;
514 dcfg = readl(par->df_regs + DF_DISPLAY_CFG);
515 dcfg &= ~(DF_DCFG_DAC_BL_EN
516 | DF_DCFG_HSYNC_EN | DF_DCFG_VSYNC_EN);
518 dcfg |= DF_DCFG_DAC_BL_EN;
520 dcfg |= DF_DCFG_HSYNC_EN;
522 dcfg |= DF_DCFG_VSYNC_EN;
523 writel(dcfg, par->df_regs + DF_DISPLAY_CFG);
525 /* Power on/off flat panel */
527 if (par->output & OUTPUT_PANEL) {
528 fp_pm = readl(par->df_regs + DF_FP_PM);
529 if (blank_mode == FB_BLANK_POWERDOWN)
530 fp_pm &= ~DF_FP_PM_P;
533 writel(fp_pm, par->df_regs + DF_FP_PM);