1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/spinlock.h>
16#include <linux/fb.h>
17#include <linux/delay.h>
18#include <asm/io.h>
19#include <asm/div64.h>
20#include <asm/delay.h>
21
22#include "geodefb.h"
23#include "display_gx1.h"
24
25static DEFINE_SPINLOCK(gx1_conf_reg_lock);
26
27static u8 gx1_read_conf_reg(u8 reg)
28{
29 u8 val, ccr3;
30 unsigned long flags;
31
32 spin_lock_irqsave(&gx1_conf_reg_lock, flags);
33
34 outb(CONFIG_CCR3, 0x22);
35 ccr3 = inb(0x23);
36 outb(CONFIG_CCR3, 0x22);
37 outb(ccr3 | CONFIG_CCR3_MAPEN, 0x23);
38 outb(reg, 0x22);
39 val = inb(0x23);
40 outb(CONFIG_CCR3, 0x22);
41 outb(ccr3, 0x23);
42
43 spin_unlock_irqrestore(&gx1_conf_reg_lock, flags);
44
45 return val;
46}
47
48unsigned gx1_gx_base(void)
49{
50 return (gx1_read_conf_reg(CONFIG_GCR) & 0x03) << 30;
51}
52
53int gx1_frame_buffer_size(void)
54{
55 void __iomem *mc_regs;
56 u32 bank_cfg;
57 int d;
58 unsigned dram_size = 0, fb_base;
59
60 mc_regs = ioremap(gx1_gx_base() + 0x8400, 0x100);
61 if (!mc_regs)
62 return -ENOMEM;
63
64
65
66 bank_cfg = readl(mc_regs + MC_BANK_CFG);
67
68 for (d = 0; d < 2; d++) {
69 if ((bank_cfg & MC_BCFG_DIMM0_PG_SZ_MASK) != MC_BCFG_DIMM0_PG_SZ_NO_DIMM)
70 dram_size += 0x400000 << ((bank_cfg & MC_BCFG_DIMM0_SZ_MASK) >> 8);
71 bank_cfg >>= 16;
72 }
73
74 fb_base = (readl(mc_regs + MC_GBASE_ADD) & MC_GADD_GBADD_MASK) << 19;
75
76 iounmap(mc_regs);
77
78 return dram_size - fb_base;
79}
80
81static void gx1_set_mode(struct fb_info *info)
82{
83 struct geodefb_par *par = info->par;
84 u32 gcfg, tcfg, ocfg, dclk_div, val;
85 int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
86 int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
87
88
89 readl(par->dc_regs + DC_UNLOCK);
90 writel(DC_UNLOCK_CODE, par->dc_regs + DC_UNLOCK);
91
92 gcfg = readl(par->dc_regs + DC_GENERAL_CFG);
93 tcfg = readl(par->dc_regs + DC_TIMING_CFG);
94
95
96 tcfg &= ~(DC_TCFG_BLKE | DC_TCFG_TGEN);
97 writel(tcfg, par->dc_regs + DC_TIMING_CFG);
98
99
100 udelay(100);
101
102
103 gcfg &= ~(DC_GCFG_DFLE | DC_GCFG_CMPE | DC_GCFG_DECE);
104 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
105
106
107 gcfg &= ~DC_GCFG_DCLK_MASK;
108 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
109
110 par->vid_ops->set_dclk(info);
111
112 dclk_div = DC_GCFG_DCLK_DIV_1;
113 gcfg |= dclk_div;
114 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
115
116
117
118
119 udelay(1000);
120
121
122
123
124
125
126 gcfg = DC_GCFG_VRDY | dclk_div;
127
128
129
130 gcfg |= (6 << DC_GCFG_DFHPEL_POS) | (5 << DC_GCFG_DFHPSL_POS) | DC_GCFG_DFLE;
131
132
133
134
135 writel(0, par->dc_regs + DC_FB_ST_OFFSET);
136
137
138 writel(info->fix.line_length >> 2, par->dc_regs + DC_LINE_DELTA);
139 writel(((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2,
140 par->dc_regs + DC_BUF_SIZE);
141
142
143 ocfg = DC_OCFG_PCKE | DC_OCFG_PDEL | DC_OCFG_PDEH;
144 if (info->var.bits_per_pixel == 8) ocfg |= DC_OCFG_8BPP;
145
146
147 tcfg = DC_TCFG_FPPE | DC_TCFG_HSYE | DC_TCFG_VSYE | DC_TCFG_BLKE
148 | DC_TCFG_TGEN;
149
150
151 hactive = info->var.xres;
152 hblankstart = hactive;
153 hsyncstart = hblankstart + info->var.right_margin;
154 hsyncend = hsyncstart + info->var.hsync_len;
155 hblankend = hsyncend + info->var.left_margin;
156 htotal = hblankend;
157
158 vactive = info->var.yres;
159 vblankstart = vactive;
160 vsyncstart = vblankstart + info->var.lower_margin;
161 vsyncend = vsyncstart + info->var.vsync_len;
162 vblankend = vsyncend + info->var.upper_margin;
163 vtotal = vblankend;
164
165 val = (hactive - 1) | ((htotal - 1) << 16);
166 writel(val, par->dc_regs + DC_H_TIMING_1);
167 val = (hblankstart - 1) | ((hblankend - 1) << 16);
168 writel(val, par->dc_regs + DC_H_TIMING_2);
169 val = (hsyncstart - 1) | ((hsyncend - 1) << 16);
170 writel(val, par->dc_regs + DC_H_TIMING_3);
171 writel(val, par->dc_regs + DC_FP_H_TIMING);
172 val = (vactive - 1) | ((vtotal - 1) << 16);
173 writel(val, par->dc_regs + DC_V_TIMING_1);
174 val = (vblankstart - 1) | ((vblankend - 1) << 16);
175 writel(val, par->dc_regs + DC_V_TIMING_2);
176 val = (vsyncstart - 1) | ((vsyncend - 1) << 16);
177 writel(val, par->dc_regs + DC_V_TIMING_3);
178 val = (vsyncstart - 2) | ((vsyncend - 2) << 16);
179 writel(val, par->dc_regs + DC_FP_V_TIMING);
180
181
182 writel(ocfg, par->dc_regs + DC_OUTPUT_CFG);
183 writel(tcfg, par->dc_regs + DC_TIMING_CFG);
184 udelay(1000);
185 writel(gcfg, par->dc_regs + DC_GENERAL_CFG);
186
187 par->vid_ops->configure_display(info);
188
189
190 writel(0, par->dc_regs + DC_UNLOCK);
191
192
193
194}
195
196static void gx1_set_hw_palette_reg(struct fb_info *info, unsigned regno,
197 unsigned red, unsigned green, unsigned blue)
198{
199 struct geodefb_par *par = info->par;
200 int val;
201
202
203 val = (red << 2) & 0x3f000;
204 val |= (green >> 4) & 0x00fc0;
205 val |= (blue >> 10) & 0x0003f;
206
207 writel(regno, par->dc_regs + DC_PAL_ADDRESS);
208 writel(val, par->dc_regs + DC_PAL_DATA);
209}
210
211struct geode_dc_ops gx1_dc_ops = {
212 .set_mode = gx1_set_mode,
213 .set_palette_reg = gx1_set_hw_palette_reg,
214};
215