gxfb: replace FBSIZE config option with a module parameter
[linux-2.6.git] / drivers / video / geode / display_gx.c
blob8cd75725a31b6ce896a319ebc7b2f8990628d895
1 /*
2 * Geode GX display controller.
4 * Copyright (C) 2005 Arcom Control Systems Ltd.
6 * Portions from AMD's original 2.4 driver:
7 * Copyright (C) 2004 Advanced Micro Devices, Inc.
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.
14 #include <linux/spinlock.h>
15 #include <linux/fb.h>
16 #include <linux/delay.h>
17 #include <asm/io.h>
18 #include <asm/div64.h>
19 #include <asm/delay.h>
21 #include "geodefb.h"
22 #include "display_gx.h"
24 unsigned int gx_frame_buffer_size(void)
26 unsigned int val;
28 /* FB size is reported by a virtual register */
29 /* Virtual register class = 0x02 */
30 /* VG_MEM_SIZE(512Kb units) = 0x00 */
32 outw(0xFC53, 0xAC1C);
33 outw(0x0200, 0xAC1C);
35 val = (unsigned int)(inw(0xAC1E)) & 0xFFl;
36 return (val << 19);
39 int gx_line_delta(int xres, int bpp)
41 /* Must be a multiple of 8 bytes. */
42 return (xres * (bpp >> 3) + 7) & ~0x7;
45 static void gx_set_mode(struct fb_info *info)
47 struct geodefb_par *par = info->par;
48 u32 gcfg, dcfg;
49 int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
50 int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
52 /* Unlock the display controller registers. */
53 readl(par->dc_regs + DC_UNLOCK);
54 writel(DC_UNLOCK_CODE, par->dc_regs + DC_UNLOCK);
56 gcfg = readl(par->dc_regs + DC_GENERAL_CFG);
57 dcfg = readl(par->dc_regs + DC_DISPLAY_CFG);
59 /* Disable the timing generator. */
60 dcfg &= ~(DC_DCFG_TGEN);
61 writel(dcfg, par->dc_regs + DC_DISPLAY_CFG);
63 /* Wait for pending memory requests before disabling the FIFO load. */
64 udelay(100);
66 /* Disable FIFO load and compression. */
67 gcfg &= ~(DC_GCFG_DFLE | DC_GCFG_CMPE | DC_GCFG_DECE);
68 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
70 /* Setup DCLK and its divisor. */
71 par->vid_ops->set_dclk(info);
74 * Setup new mode.
77 /* Clear all unused feature bits. */
78 gcfg &= DC_GCFG_YUVM | DC_GCFG_VDSE;
79 dcfg = 0;
81 /* Set FIFO priority (default 6/5) and enable. */
82 /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
83 gcfg |= (6 << DC_GCFG_DFHPEL_POS) | (5 << DC_GCFG_DFHPSL_POS) | DC_GCFG_DFLE;
85 /* Framebuffer start offset. */
86 writel(0, par->dc_regs + DC_FB_ST_OFFSET);
88 /* Line delta and line buffer length. */
89 writel(info->fix.line_length >> 3, par->dc_regs + DC_GFX_PITCH);
90 writel(((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2,
91 par->dc_regs + DC_LINE_SIZE);
94 /* Enable graphics and video data and unmask address lines. */
95 dcfg |= DC_DCFG_GDEN | DC_DCFG_VDEN | DC_DCFG_A20M | DC_DCFG_A18M;
97 /* Set pixel format. */
98 switch (info->var.bits_per_pixel) {
99 case 8:
100 dcfg |= DC_DCFG_DISP_MODE_8BPP;
101 break;
102 case 16:
103 dcfg |= DC_DCFG_DISP_MODE_16BPP;
104 dcfg |= DC_DCFG_16BPP_MODE_565;
105 break;
106 case 32:
107 dcfg |= DC_DCFG_DISP_MODE_24BPP;
108 dcfg |= DC_DCFG_PALB;
109 break;
112 /* Enable timing generator. */
113 dcfg |= DC_DCFG_TGEN;
115 /* Horizontal and vertical timings. */
116 hactive = info->var.xres;
117 hblankstart = hactive;
118 hsyncstart = hblankstart + info->var.right_margin;
119 hsyncend = hsyncstart + info->var.hsync_len;
120 hblankend = hsyncend + info->var.left_margin;
121 htotal = hblankend;
123 vactive = info->var.yres;
124 vblankstart = vactive;
125 vsyncstart = vblankstart + info->var.lower_margin;
126 vsyncend = vsyncstart + info->var.vsync_len;
127 vblankend = vsyncend + info->var.upper_margin;
128 vtotal = vblankend;
130 writel((hactive - 1) | ((htotal - 1) << 16), par->dc_regs + DC_H_ACTIVE_TIMING);
131 writel((hblankstart - 1) | ((hblankend - 1) << 16), par->dc_regs + DC_H_BLANK_TIMING);
132 writel((hsyncstart - 1) | ((hsyncend - 1) << 16), par->dc_regs + DC_H_SYNC_TIMING);
134 writel((vactive - 1) | ((vtotal - 1) << 16), par->dc_regs + DC_V_ACTIVE_TIMING);
135 writel((vblankstart - 1) | ((vblankend - 1) << 16), par->dc_regs + DC_V_BLANK_TIMING);
136 writel((vsyncstart - 1) | ((vsyncend - 1) << 16), par->dc_regs + DC_V_SYNC_TIMING);
138 /* Write final register values. */
139 writel(dcfg, par->dc_regs + DC_DISPLAY_CFG);
140 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
142 par->vid_ops->configure_display(info);
144 /* Relock display controller registers */
145 writel(0, par->dc_regs + DC_UNLOCK);
148 static void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
149 unsigned red, unsigned green, unsigned blue)
151 struct geodefb_par *par = info->par;
152 int val;
154 /* Hardware palette is in RGB 8-8-8 format. */
155 val = (red << 8) & 0xff0000;
156 val |= (green) & 0x00ff00;
157 val |= (blue >> 8) & 0x0000ff;
159 writel(regno, par->dc_regs + DC_PAL_ADDRESS);
160 writel(val, par->dc_regs + DC_PAL_DATA);
163 struct geode_dc_ops gx_dc_ops = {
164 .set_mode = gx_set_mode,
165 .set_palette_reg = gx_set_hw_palette_reg,