1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/mm.h>
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/slab.h>
26#include <linux/fb.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/platform_device.h>
30
31#include <mach/hardware.h>
32#include <asm/mach-types.h>
33#include <linux/uaccess.h>
34
35struct fb_info *cfb;
36
37#define CMAP_MAX_SIZE 16
38
39
40
41
42
43
44static unsigned int lcd_ac_prescale = 13;
45
46
47
48
49static int
50clps7111fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
51 u_int transp, struct fb_info *info)
52{
53 unsigned int level, mask, shift, pal;
54
55 if (regno >= (1 << info->var.bits_per_pixel))
56 return 1;
57
58
59 level = (red * 77 + green * 151 + blue * 28) >> 20;
60
61
62
63
64
65
66
67
68 if (machine_is_edb7211()) {
69 level = 15 - level;
70 }
71
72 shift = 4 * (regno & 7);
73 level <<= shift;
74 mask = 15 << shift;
75 level &= mask;
76
77 regno = regno < 8 ? PALLSW : PALMSW;
78
79 pal = clps_readl(regno);
80 pal = (pal & ~mask) | level;
81 clps_writel(pal, regno);
82
83 return 0;
84}
85
86
87
88
89static int
90clps7111fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
91{
92 var->transp.msb_right = 0;
93 var->transp.offset = 0;
94 var->transp.length = 0;
95 var->red.msb_right = 0;
96 var->red.offset = 0;
97 var->red.length = var->bits_per_pixel;
98 var->green = var->red;
99 var->blue = var->red;
100
101 if (var->bits_per_pixel > 4)
102 return -EINVAL;
103
104 return 0;
105}
106
107
108
109
110static int
111clps7111fb_set_par(struct fb_info *info)
112{
113 unsigned int lcdcon, syscon, pixclock;
114
115 switch (info->var.bits_per_pixel) {
116 case 1:
117 info->fix.visual = FB_VISUAL_MONO01;
118 break;
119 case 2:
120 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
121 break;
122 case 4:
123 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
124 break;
125 }
126
127 info->fix.line_length = info->var.xres_virtual * info->var.bits_per_pixel / 8;
128
129 lcdcon = (info->var.xres_virtual * info->var.yres_virtual * info->var.bits_per_pixel) / 128 - 1;
130 lcdcon |= ((info->var.xres_virtual / 16) - 1) << 13;
131 lcdcon |= lcd_ac_prescale << 25;
132
133
134
135
136
137
138
139
140
141
142 pixclock = 9 * info->var.pixclock / 244140 - 1;
143 lcdcon |= pixclock << 19;
144
145 if (info->var.bits_per_pixel == 4)
146 lcdcon |= LCDCON_GSMD;
147 if (info->var.bits_per_pixel >= 2)
148 lcdcon |= LCDCON_GSEN;
149
150
151
152
153 syscon = clps_readl(SYSCON1);
154 clps_writel(syscon & ~SYSCON1_LCDEN, SYSCON1);
155 clps_writel(lcdcon, LCDCON);
156 clps_writel(syscon | SYSCON1_LCDEN, SYSCON1);
157 return 0;
158}
159
160static int clps7111fb_blank(int blank, struct fb_info *info)
161{
162
163 if (blank)
164 clps_writel(clps_readl(SYSCON1) & ~SYSCON1_LCDEN, SYSCON1);
165 else
166 clps_writel(clps_readl(SYSCON1) | SYSCON1_LCDEN, SYSCON1);
167
168 return 0;
169}
170
171static struct fb_ops clps7111fb_ops = {
172 .owner = THIS_MODULE,
173 .fb_check_var = clps7111fb_check_var,
174 .fb_set_par = clps7111fb_set_par,
175 .fb_setcolreg = clps7111fb_setcolreg,
176 .fb_blank = clps7111fb_blank,
177 .fb_fillrect = cfb_fillrect,
178 .fb_copyarea = cfb_copyarea,
179 .fb_imageblit = cfb_imageblit,
180};
181
182static void clps711x_guess_lcd_params(struct fb_info *info)
183{
184 unsigned int lcdcon, syscon, size;
185 unsigned long phys_base = PAGE_OFFSET;
186 void *virt_base = (void *)PAGE_OFFSET;
187
188 info->var.xres_virtual = 640;
189 info->var.yres_virtual = 240;
190 info->var.bits_per_pixel = 4;
191 info->var.activate = FB_ACTIVATE_NOW;
192 info->var.height = -1;
193 info->var.width = -1;
194 info->var.pixclock = 93006;
195
196
197
198
199
200 syscon = clps_readl(SYSCON1);
201 if (syscon & SYSCON1_LCDEN) {
202 lcdcon = clps_readl(LCDCON);
203
204
205
206
207 switch (lcdcon & (LCDCON_GSMD | LCDCON_GSEN)) {
208 case LCDCON_GSMD | LCDCON_GSEN:
209 info->var.bits_per_pixel = 4;
210 break;
211
212 case LCDCON_GSEN:
213 info->var.bits_per_pixel = 2;
214 break;
215
216 default:
217 info->var.bits_per_pixel = 1;
218 break;
219 }
220
221
222
223
224 info->var.xres_virtual = (((lcdcon >> 13) & 0x3f) + 1) * 16;
225 info->var.yres_virtual = (((lcdcon & 0x1fff) + 1) * 128) /
226 (info->var.xres_virtual *
227 info->var.bits_per_pixel);
228
229
230
231
232 info->var.pixclock = (((lcdcon >> 19) & 0x3f) + 1) * 244140 / 9;
233
234
235
236
237 lcd_ac_prescale = (lcdcon >> 25) & 0x1f;
238 }
239
240 info->var.xres = info->var.xres_virtual;
241 info->var.yres = info->var.yres_virtual;
242 info->var.grayscale = info->var.bits_per_pixel > 1;
243
244 size = info->var.xres * info->var.yres * info->var.bits_per_pixel / 8;
245
246
247
248
249
250
251
252 if (size <= 38400) {
253 printk(KERN_INFO "CLPS711xFB: could use on-board SRAM?\n");
254 }
255
256 if ((syscon & SYSCON1_LCDEN) == 0) {
257
258
259
260
261 memset(virt_base, 0, size);
262 }
263
264 info->screen_base = virt_base;
265 info->fix.smem_start = phys_base;
266 info->fix.smem_len = PAGE_ALIGN(size);
267 info->fix.type = FB_TYPE_PACKED_PIXELS;
268}
269
270static int clps711x_fb_probe(struct platform_device *pdev)
271{
272 int err = -ENOMEM;
273
274 if (fb_get_options("clps711xfb", NULL))
275 return -ENODEV;
276
277 cfb = kzalloc(sizeof(*cfb), GFP_KERNEL);
278 if (!cfb)
279 goto out;
280
281 strcpy(cfb->fix.id, "clps711x");
282
283 cfb->fbops = &clps7111fb_ops;
284 cfb->flags = FBINFO_DEFAULT;
285
286 clps711x_guess_lcd_params(cfb);
287
288 fb_alloc_cmap(&cfb->cmap, CMAP_MAX_SIZE, 0);
289
290 err = register_framebuffer(cfb);
291
292out: return err;
293}
294
295static int clps711x_fb_remove(struct platform_device *pdev)
296{
297 unregister_framebuffer(cfb);
298 kfree(cfb);
299
300 return 0;
301}
302
303static struct platform_driver clps711x_fb_driver = {
304 .driver = {
305 .name = "video-clps711x",
306 .owner = THIS_MODULE,
307 },
308 .probe = clps711x_fb_probe,
309 .remove = clps711x_fb_remove,
310};
311module_platform_driver(clps711x_fb_driver);
312
313MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
314MODULE_DESCRIPTION("CLPS711X framebuffer driver");
315MODULE_LICENSE("GPL");
316