1
2
3
4
5
6
7
8
9
10
11#include <linux/fb.h>
12#include <linux/delay.h>
13#include <asm/io.h>
14#include <asm/delay.h>
15
16#include "geodefb.h"
17#include "video_cs5530.h"
18
19
20
21
22
23struct cs5530_pll_entry {
24 long pixclock;
25 u32 pll_value;
26};
27
28static const struct cs5530_pll_entry cs5530_pll_table[] = {
29 { 39721, 0x31C45801, },
30 { 35308, 0x20E36802, },
31 { 31746, 0x33915801, },
32 { 27777, 0x31EC4801, },
33 { 26666, 0x21E22801, },
34 { 25000, 0x33088801, },
35 { 22271, 0x33E22801, },
36 { 20202, 0x336C4801, },
37 { 20000, 0x23088801, },
38 { 19860, 0x23088801, },
39 { 18518, 0x3708A801, },
40 { 17777, 0x23E36802, },
41 { 17733, 0x23E36802, },
42 { 17653, 0x23E36802, },
43 { 16949, 0x37C45801, },
44 { 15873, 0x23EC4801, },
45 { 15384, 0x37911801, },
46 { 14814, 0x37963803, },
47 { 14124, 0x37058803, },
48 { 13888, 0x3710C805, },
49 { 13333, 0x37E22801, },
50 { 12698, 0x27915801, },
51 { 12500, 0x37D8D802, },
52 { 11135, 0x27588802, },
53 { 10582, 0x27EC4802, },
54 { 10101, 0x27AC6803, },
55 { 10000, 0x27088801, },
56 { 9259, 0x2710C805, },
57 { 8888, 0x27E36802, },
58 { 7692, 0x27C58803, },
59 { 7407, 0x27316803, },
60 { 6349, 0x2F915801, },
61 { 6172, 0x2F08A801, },
62 { 5714, 0x2FB11802, },
63 { 5291, 0x2FEC4802, },
64 { 4950, 0x2F963803, },
65 { 4310, 0x2FB1B802, },
66};
67
68static void cs5530_set_dclk_frequency(struct fb_info *info)
69{
70 struct geodefb_par *par = info->par;
71 int i;
72 u32 value;
73 long min, diff;
74
75
76 value = cs5530_pll_table[0].pll_value;
77 min = cs5530_pll_table[0].pixclock - info->var.pixclock;
78 if (min < 0) min = -min;
79 for (i = 1; i < ARRAY_SIZE(cs5530_pll_table); i++) {
80 diff = cs5530_pll_table[i].pixclock - info->var.pixclock;
81 if (diff < 0L) diff = -diff;
82 if (diff < min) {
83 min = diff;
84 value = cs5530_pll_table[i].pll_value;
85 }
86 }
87
88 writel(value, par->vid_regs + CS5530_DOT_CLK_CONFIG);
89 writel(value | 0x80000100, par->vid_regs + CS5530_DOT_CLK_CONFIG);
90 udelay(500);
91 writel(value & 0x7FFFFFFF, par->vid_regs + CS5530_DOT_CLK_CONFIG);
92 writel(value & 0x7FFFFEFF, par->vid_regs + CS5530_DOT_CLK_CONFIG);
93}
94
95static void cs5530_configure_display(struct fb_info *info)
96{
97 struct geodefb_par *par = info->par;
98 u32 dcfg;
99
100 dcfg = readl(par->vid_regs + CS5530_DISPLAY_CONFIG);
101
102
103 dcfg &= ~(CS5530_DCFG_CRT_SYNC_SKW_MASK | CS5530_DCFG_PWR_SEQ_DLY_MASK
104 | CS5530_DCFG_CRT_HSYNC_POL | CS5530_DCFG_CRT_VSYNC_POL
105 | CS5530_DCFG_FP_PWR_EN | CS5530_DCFG_FP_DATA_EN
106 | CS5530_DCFG_DAC_PWR_EN | CS5530_DCFG_VSYNC_EN
107 | CS5530_DCFG_HSYNC_EN);
108
109
110 dcfg |= (CS5530_DCFG_CRT_SYNC_SKW_INIT | CS5530_DCFG_PWR_SEQ_DLY_INIT
111 | CS5530_DCFG_GV_PAL_BYP);
112
113
114 if (par->enable_crt) {
115 dcfg |= CS5530_DCFG_DAC_PWR_EN;
116 dcfg |= CS5530_DCFG_HSYNC_EN | CS5530_DCFG_VSYNC_EN;
117 }
118
119 if (par->panel_x > 0) {
120 dcfg |= CS5530_DCFG_FP_PWR_EN;
121 dcfg |= CS5530_DCFG_FP_DATA_EN;
122 }
123
124
125 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
126 dcfg |= CS5530_DCFG_CRT_HSYNC_POL;
127 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
128 dcfg |= CS5530_DCFG_CRT_VSYNC_POL;
129
130 writel(dcfg, par->vid_regs + CS5530_DISPLAY_CONFIG);
131}
132
133static int cs5530_blank_display(struct fb_info *info, int blank_mode)
134{
135 struct geodefb_par *par = info->par;
136 u32 dcfg;
137 int blank, hsync, vsync;
138
139 switch (blank_mode) {
140 case FB_BLANK_UNBLANK:
141 blank = 0; hsync = 1; vsync = 1;
142 break;
143 case FB_BLANK_NORMAL:
144 blank = 1; hsync = 1; vsync = 1;
145 break;
146 case FB_BLANK_VSYNC_SUSPEND:
147 blank = 1; hsync = 1; vsync = 0;
148 break;
149 case FB_BLANK_HSYNC_SUSPEND:
150 blank = 1; hsync = 0; vsync = 1;
151 break;
152 case FB_BLANK_POWERDOWN:
153 blank = 1; hsync = 0; vsync = 0;
154 break;
155 default:
156 return -EINVAL;
157 }
158
159 dcfg = readl(par->vid_regs + CS5530_DISPLAY_CONFIG);
160
161 dcfg &= ~(CS5530_DCFG_DAC_BL_EN | CS5530_DCFG_DAC_PWR_EN
162 | CS5530_DCFG_HSYNC_EN | CS5530_DCFG_VSYNC_EN
163 | CS5530_DCFG_FP_DATA_EN | CS5530_DCFG_FP_PWR_EN);
164
165 if (par->enable_crt) {
166 if (!blank)
167 dcfg |= CS5530_DCFG_DAC_BL_EN | CS5530_DCFG_DAC_PWR_EN;
168 if (hsync)
169 dcfg |= CS5530_DCFG_HSYNC_EN;
170 if (vsync)
171 dcfg |= CS5530_DCFG_VSYNC_EN;
172 }
173 if (par->panel_x > 0) {
174 if (!blank)
175 dcfg |= CS5530_DCFG_FP_DATA_EN;
176 if (hsync && vsync)
177 dcfg |= CS5530_DCFG_FP_PWR_EN;
178 }
179
180 writel(dcfg, par->vid_regs + CS5530_DISPLAY_CONFIG);
181
182 return 0;
183}
184
185const struct geode_vid_ops cs5530_vid_ops = {
186 .set_dclk = cs5530_set_dclk_frequency,
187 .configure_display = cs5530_configure_display,
188 .blank_display = cs5530_blank_display,
189};
190