aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/clps711xfb.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/video/clps711xfb.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/video/clps711xfb.c')
-rw-r--r--drivers/video/clps711xfb.c443
1 files changed, 443 insertions, 0 deletions
diff --git a/drivers/video/clps711xfb.c b/drivers/video/clps711xfb.c
new file mode 100644
index 000000000000..8692e002986b
--- /dev/null
+++ b/drivers/video/clps711xfb.c
@@ -0,0 +1,443 @@
1/*
2 * linux/drivers/video/clps711xfb.c
3 *
4 * Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Framebuffer driver for the CLPS7111 and EP7212 processors.
21 */
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/slab.h>
25#include <linux/fb.h>
26#include <linux/init.h>
27#include <linux/proc_fs.h>
28#include <linux/delay.h>
29
30#include <asm/hardware.h>
31#include <asm/mach-types.h>
32#include <asm/uaccess.h>
33
34#include <asm/hardware/clps7111.h>
35#include <asm/arch/syspld.h>
36
37struct fb_info *cfb;
38
39#define CMAP_MAX_SIZE 16
40
41/* The /proc entry for the backlight. */
42static struct proc_dir_entry *clps7111fb_backlight_proc_entry = NULL;
43
44static int clps7111fb_proc_backlight_read(char *page, char **start, off_t off,
45 int count, int *eof, void *data);
46static int clps7111fb_proc_backlight_write(struct file *file,
47 const char *buffer, unsigned long count, void *data);
48
49/*
50 * LCD AC Prescale. This comes from the LCD panel manufacturers specifications.
51 * This determines how many clocks + 1 of CL1 before the M signal toggles.
52 * The number of lines on the display must not be divisible by this number.
53 */
54static unsigned int lcd_ac_prescale = 13;
55
56/*
57 * Set a single color register. Return != 0 for invalid regno.
58 */
59static int
60clps7111fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
61 u_int transp, struct fb_info *info)
62{
63 unsigned int level, mask, shift, pal;
64
65 if (regno >= (1 << info->var.bits_per_pixel))
66 return 1;
67
68 /* gray = 0.30*R + 0.58*G + 0.11*B */
69 level = (red * 77 + green * 151 + blue * 28) >> 20;
70
71 /*
72 * On an LCD, a high value is dark, while a low value is light.
73 * So we invert the level.
74 *
75 * This isn't true on all machines, so we only do it on EDB7211.
76 * --rmk
77 */
78 if (machine_is_edb7211()) {
79 level = 15 - level;
80 }
81
82 shift = 4 * (regno & 7);
83 level <<= shift;
84 mask = 15 << shift;
85 level &= mask;
86
87 regno = regno < 8 ? PALLSW : PALMSW;
88
89 pal = clps_readl(regno);
90 pal = (pal & ~mask) | level;
91 clps_writel(pal, regno);
92
93 return 0;
94}
95
96/*
97 * Validate the purposed mode.
98 */
99static int
100clps7111fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
101{
102 var->transp.msb_right = 0;
103 var->transp.offset = 0;
104 var->transp.length = 0;
105 var->red.msb_right = 0;
106 var->red.offset = 0;
107 var->red.length = var->bits_per_pixel;
108 var->green = var->red;
109 var->blue = var->red;
110
111 if (var->bits_per_pixel > 4)
112 return -EINVAL;
113
114 return 0;
115}
116
117/*
118 * Set the hardware state.
119 */
120static int
121clps7111fb_set_par(struct fb_info *info)
122{
123 unsigned int lcdcon, syscon, pixclock;
124
125 switch (info->var.bits_per_pixel) {
126 case 1:
127 info->fix.visual = FB_VISUAL_MONO01;
128 break;
129 case 2:
130 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
131 break;
132 case 4:
133 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
134 break;
135 }
136
137 info->fix.line_length = info->var.xres_virtual * info->var.bits_per_pixel / 8;
138
139 lcdcon = (info->var.xres_virtual * info->var.yres_virtual * info->var.bits_per_pixel) / 128 - 1;
140 lcdcon |= ((info->var.xres_virtual / 16) - 1) << 13;
141 lcdcon |= lcd_ac_prescale << 25;
142
143 /*
144 * Calculate pixel prescale value from the pixclock. This is:
145 * 36.864MHz / pixclock_mhz - 1.
146 * However, pixclock is in picoseconds, so this ends up being:
147 * 36864000 * pixclock_ps / 10^12 - 1
148 * and this will overflow the 32-bit math. We perform this as
149 * (9 * 4096000 == 36864000):
150 * pixclock_ps * 9 * (4096000 / 10^12) - 1
151 */
152 pixclock = 9 * info->var.pixclock / 244140 - 1;
153 lcdcon |= pixclock << 19;
154
155 if (info->var.bits_per_pixel == 4)
156 lcdcon |= LCDCON_GSMD;
157 if (info->var.bits_per_pixel >= 2)
158 lcdcon |= LCDCON_GSEN;
159
160 /*
161 * LCDCON must only be changed while the LCD is disabled
162 */
163 syscon = clps_readl(SYSCON1);
164 clps_writel(syscon & ~SYSCON1_LCDEN, SYSCON1);
165 clps_writel(lcdcon, LCDCON);
166 clps_writel(syscon | SYSCON1_LCDEN, SYSCON1);
167 return 0;
168}
169
170static int clps7111fb_blank(int blank, struct fb_info *info)
171{
172 if (blank) {
173 if (machine_is_edb7211()) {
174 /* Turn off the LCD backlight. */
175 clps_writeb(clps_readb(PDDR) & ~EDB_PD3_LCDBL, PDDR);
176
177 /* Power off the LCD DC-DC converter. */
178 clps_writeb(clps_readb(PDDR) & ~EDB_PD1_LCD_DC_DC_EN, PDDR);
179
180 /* Delay for a little while (half a second). */
181 udelay(100);
182
183 /* Power off the LCD panel. */
184 clps_writeb(clps_readb(PDDR) & ~EDB_PD2_LCDEN, PDDR);
185
186 /* Power off the LCD controller. */
187 clps_writel(clps_readl(SYSCON1) & ~SYSCON1_LCDEN,
188 SYSCON1);
189 }
190 } else {
191 if (machine_is_edb7211()) {
192 /* Power up the LCD controller. */
193 clps_writel(clps_readl(SYSCON1) | SYSCON1_LCDEN,
194 SYSCON1);
195
196 /* Power up the LCD panel. */
197 clps_writeb(clps_readb(PDDR) | EDB_PD2_LCDEN, PDDR);
198
199 /* Delay for a little while. */
200 udelay(100);
201
202 /* Power up the LCD DC-DC converter. */
203 clps_writeb(clps_readb(PDDR) | EDB_PD1_LCD_DC_DC_EN,
204 PDDR);
205
206 /* Turn on the LCD backlight. */
207 clps_writeb(clps_readb(PDDR) | EDB_PD3_LCDBL, PDDR);
208 }
209 }
210 return 0;
211}
212
213static struct fb_ops clps7111fb_ops = {
214 .owner = THIS_MODULE,
215 .fb_check_var = clps7111fb_check_var,
216 .fb_set_par = clps7111fb_set_par,
217 .fb_setcolreg = clps7111fb_setcolreg,
218 .fb_blank = clps7111fb_blank,
219 .fb_fillrect = cfb_fillrect,
220 .fb_copyarea = cfb_copyarea,
221 .fb_imageblit = cfb_imageblit,
222 .fb_cursor = soft_cursor,
223};
224
225static int
226clps7111fb_proc_backlight_read(char *page, char **start, off_t off,
227 int count, int *eof, void *data)
228{
229 /* We need at least two characters, one for the digit, and one for
230 * the terminating NULL. */
231 if (count < 2)
232 return -EINVAL;
233
234 if (machine_is_edb7211()) {
235 return sprintf(page, "%d\n",
236 (clps_readb(PDDR) & EDB_PD3_LCDBL) ? 1 : 0);
237 }
238
239 return 0;
240}
241
242static int
243clps7111fb_proc_backlight_write(struct file *file, const char *buffer,
244 unsigned long count, void *data)
245{
246 unsigned char char_value;
247 int value;
248
249 if (count < 1) {
250 return -EINVAL;
251 }
252
253 if (copy_from_user(&char_value, buffer, 1))
254 return -EFAULT;
255
256 value = char_value - '0';
257
258 if (machine_is_edb7211()) {
259 unsigned char port_d;
260
261 port_d = clps_readb(PDDR);
262
263 if (value) {
264 port_d |= EDB_PD3_LCDBL;
265 } else {
266 port_d &= ~EDB_PD3_LCDBL;
267 }
268
269 clps_writeb(port_d, PDDR);
270 }
271
272 return count;
273}
274
275static void __init clps711x_guess_lcd_params(struct fb_info *info)
276{
277 unsigned int lcdcon, syscon, size;
278 unsigned long phys_base = PAGE_OFFSET;
279 void *virt_base = (void *)PAGE_OFFSET;
280
281 info->var.xres_virtual = 640;
282 info->var.yres_virtual = 240;
283 info->var.bits_per_pixel = 4;
284 info->var.activate = FB_ACTIVATE_NOW;
285 info->var.height = -1;
286 info->var.width = -1;
287 info->var.pixclock = 93006; /* 10.752MHz pixel clock */
288
289 /*
290 * If the LCD controller is already running, decode the values
291 * in LCDCON to xres/yres/bpp/pixclock/acprescale
292 */
293 syscon = clps_readl(SYSCON1);
294 if (syscon & SYSCON1_LCDEN) {
295 lcdcon = clps_readl(LCDCON);
296
297 /*
298 * Decode GSMD and GSEN bits to bits per pixel
299 */
300 switch (lcdcon & (LCDCON_GSMD | LCDCON_GSEN)) {
301 case LCDCON_GSMD | LCDCON_GSEN:
302 info->var.bits_per_pixel = 4;
303 break;
304
305 case LCDCON_GSEN:
306 info->var.bits_per_pixel = 2;
307 break;
308
309 default:
310 info->var.bits_per_pixel = 1;
311 break;
312 }
313
314 /*
315 * Decode xres/yres
316 */
317 info->var.xres_virtual = (((lcdcon >> 13) & 0x3f) + 1) * 16;
318 info->var.yres_virtual = (((lcdcon & 0x1fff) + 1) * 128) /
319 (info->var.xres_virtual *
320 info->var.bits_per_pixel);
321
322 /*
323 * Calculate pixclock
324 */
325 info->var.pixclock = (((lcdcon >> 19) & 0x3f) + 1) * 244140 / 9;
326
327 /*
328 * Grab AC prescale
329 */
330 lcd_ac_prescale = (lcdcon >> 25) & 0x1f;
331 }
332
333 info->var.xres = info->var.xres_virtual;
334 info->var.yres = info->var.yres_virtual;
335 info->var.grayscale = info->var.bits_per_pixel > 1;
336
337 size = info->var.xres * info->var.yres * info->var.bits_per_pixel / 8;
338
339 /*
340 * Might be worth checking to see if we can use the on-board
341 * RAM if size here...
342 * CLPS7110 - no on-board SRAM
343 * EP7212 - 38400 bytes
344 */
345 if (size <= 38400) {
346 printk(KERN_INFO "CLPS711xFB: could use on-board SRAM?\n");
347 }
348
349 if ((syscon & SYSCON1_LCDEN) == 0) {
350 /*
351 * The display isn't running. Ensure that
352 * the display memory is empty.
353 */
354 memset(virt_base, 0, size);
355 }
356
357 info->screen_base = virt_base;
358 info->fix.smem_start = phys_base;
359 info->fix.smem_len = PAGE_ALIGN(size);
360 info->fix.type = FB_TYPE_PACKED_PIXELS;
361}
362
363int __init clps711xfb_init(void)
364{
365 int err = -ENOMEM;
366
367 if (fb_get_options("clps711xfb", NULL))
368 return -ENODEV;
369
370 cfb = kmalloc(sizeof(*cfb), GFP_KERNEL);
371 if (!cfb)
372 goto out;
373
374 memset(cfb, 0, sizeof(*cfb));
375 strcpy(cfb->fix.id, "clps711x");
376
377 cfb->fbops = &clps7111fb_ops;
378 cfb->flags = FBINFO_DEFAULT;
379
380 clps711x_guess_lcd_params(cfb);
381
382 fb_alloc_cmap(&cfb->cmap, CMAP_MAX_SIZE, 0);
383
384 /* Register the /proc entries. */
385 clps7111fb_backlight_proc_entry = create_proc_entry("backlight", 0444,
386 &proc_root);
387 if (clps7111fb_backlight_proc_entry == NULL) {
388 printk("Couldn't create the /proc entry for the backlight.\n");
389 return -EINVAL;
390 }
391
392 clps7111fb_backlight_proc_entry->read_proc =
393 &clps7111fb_proc_backlight_read;
394 clps7111fb_backlight_proc_entry->write_proc =
395 &clps7111fb_proc_backlight_write;
396
397 /*
398 * Power up the LCD
399 */
400 if (machine_is_p720t()) {
401 PLD_LCDEN = PLD_LCDEN_EN;
402 PLD_PWR |= (PLD_S4_ON|PLD_S3_ON|PLD_S2_ON|PLD_S1_ON);
403 }
404
405 if (machine_is_edb7211()) {
406 /* Power up the LCD panel. */
407 clps_writeb(clps_readb(PDDR) | EDB_PD2_LCDEN, PDDR);
408
409 /* Delay for a little while. */
410 udelay(100);
411
412 /* Power up the LCD DC-DC converter. */
413 clps_writeb(clps_readb(PDDR) | EDB_PD1_LCD_DC_DC_EN, PDDR);
414
415 /* Turn on the LCD backlight. */
416 clps_writeb(clps_readb(PDDR) | EDB_PD3_LCDBL, PDDR);
417 }
418
419 err = register_framebuffer(cfb);
420
421out: return err;
422}
423
424static void __exit clps711xfb_exit(void)
425{
426 unregister_framebuffer(cfb);
427 kfree(cfb);
428
429 /*
430 * Power down the LCD
431 */
432 if (machine_is_p720t()) {
433 PLD_LCDEN = 0;
434 PLD_PWR &= ~(PLD_S4_ON|PLD_S3_ON|PLD_S2_ON|PLD_S1_ON);
435 }
436}
437
438module_init(clps711xfb_init);
439module_exit(clps711xfb_exit);
440
441MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
442MODULE_DESCRIPTION("CLPS711x framebuffer driver");
443MODULE_LICENSE("GPL");