2 * linux/drivers/video/clps711xfb.c
4 * Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
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.
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.
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
20 * Framebuffer driver for the CLPS7111 and EP7212 processors.
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
26 #include <linux/init.h>
27 #include <linux/proc_fs.h>
28 #include <linux/delay.h>
30 #include <asm/hardware.h>
31 #include <asm/mach-types.h>
32 #include <asm/uaccess.h>
34 #include <asm/hardware/clps7111.h>
35 #include <asm/arch/syspld.h>
39 #define CMAP_MAX_SIZE 16
41 /* The /proc entry for the backlight. */
42 static struct proc_dir_entry
*clps7111fb_backlight_proc_entry
= NULL
;
44 static int clps7111fb_proc_backlight_read(char *page
, char **start
, off_t off
,
45 int count
, int *eof
, void *data
);
46 static int clps7111fb_proc_backlight_write(struct file
*file
,
47 const char *buffer
, unsigned long count
, void *data
);
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.
54 static unsigned int lcd_ac_prescale
= 13;
57 * Set a single color register. Return != 0 for invalid regno.
60 clps7111fb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
61 u_int transp
, struct fb_info
*info
)
63 unsigned int level
, mask
, shift
, pal
;
65 if (regno
>= (1 << info
->var
.bits_per_pixel
))
68 /* gray = 0.30*R + 0.58*G + 0.11*B */
69 level
= (red
* 77 + green
* 151 + blue
* 28) >> 20;
72 * On an LCD, a high value is dark, while a low value is light.
73 * So we invert the level.
75 * This isn't true on all machines, so we only do it on EDB7211.
78 if (machine_is_edb7211()) {
82 shift
= 4 * (regno
& 7);
87 regno
= regno
< 8 ? PALLSW
: PALMSW
;
89 pal
= clps_readl(regno
);
90 pal
= (pal
& ~mask
) | level
;
91 clps_writel(pal
, regno
);
97 * Validate the purposed mode.
100 clps7111fb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
102 var
->transp
.msb_right
= 0;
103 var
->transp
.offset
= 0;
104 var
->transp
.length
= 0;
105 var
->red
.msb_right
= 0;
107 var
->red
.length
= var
->bits_per_pixel
;
108 var
->green
= var
->red
;
109 var
->blue
= var
->red
;
111 if (var
->bits_per_pixel
> 4)
118 * Set the hardware state.
121 clps7111fb_set_par(struct fb_info
*info
)
123 unsigned int lcdcon
, syscon
, pixclock
;
125 switch (info
->var
.bits_per_pixel
) {
127 info
->fix
.visual
= FB_VISUAL_MONO01
;
130 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
133 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
137 info
->fix
.line_length
= info
->var
.xres_virtual
* info
->var
.bits_per_pixel
/ 8;
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;
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
152 pixclock
= 9 * info
->var
.pixclock
/ 244140 - 1;
153 lcdcon
|= pixclock
<< 19;
155 if (info
->var
.bits_per_pixel
== 4)
156 lcdcon
|= LCDCON_GSMD
;
157 if (info
->var
.bits_per_pixel
>= 2)
158 lcdcon
|= LCDCON_GSEN
;
161 * LCDCON must only be changed while the LCD is disabled
163 syscon
= clps_readl(SYSCON1
);
164 clps_writel(syscon
& ~SYSCON1_LCDEN
, SYSCON1
);
165 clps_writel(lcdcon
, LCDCON
);
166 clps_writel(syscon
| SYSCON1_LCDEN
, SYSCON1
);
170 static int clps7111fb_blank(int blank
, struct fb_info
*info
)
173 if (machine_is_edb7211()) {
174 /* Turn off the LCD backlight. */
175 clps_writeb(clps_readb(PDDR
) & ~EDB_PD3_LCDBL
, PDDR
);
177 /* Power off the LCD DC-DC converter. */
178 clps_writeb(clps_readb(PDDR
) & ~EDB_PD1_LCD_DC_DC_EN
, PDDR
);
180 /* Delay for a little while (half a second). */
183 /* Power off the LCD panel. */
184 clps_writeb(clps_readb(PDDR
) & ~EDB_PD2_LCDEN
, PDDR
);
186 /* Power off the LCD controller. */
187 clps_writel(clps_readl(SYSCON1
) & ~SYSCON1_LCDEN
,
191 if (machine_is_edb7211()) {
192 /* Power up the LCD controller. */
193 clps_writel(clps_readl(SYSCON1
) | SYSCON1_LCDEN
,
196 /* Power up the LCD panel. */
197 clps_writeb(clps_readb(PDDR
) | EDB_PD2_LCDEN
, PDDR
);
199 /* Delay for a little while. */
202 /* Power up the LCD DC-DC converter. */
203 clps_writeb(clps_readb(PDDR
) | EDB_PD1_LCD_DC_DC_EN
,
206 /* Turn on the LCD backlight. */
207 clps_writeb(clps_readb(PDDR
) | EDB_PD3_LCDBL
, PDDR
);
213 static 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
,
225 clps7111fb_proc_backlight_read(char *page
, char **start
, off_t off
,
226 int count
, int *eof
, void *data
)
228 /* We need at least two characters, one for the digit, and one for
229 * the terminating NULL. */
233 if (machine_is_edb7211()) {
234 return sprintf(page
, "%d\n",
235 (clps_readb(PDDR
) & EDB_PD3_LCDBL
) ? 1 : 0);
242 clps7111fb_proc_backlight_write(struct file
*file
, const char *buffer
,
243 unsigned long count
, void *data
)
245 unsigned char char_value
;
252 if (copy_from_user(&char_value
, buffer
, 1))
255 value
= char_value
- '0';
257 if (machine_is_edb7211()) {
258 unsigned char port_d
;
260 port_d
= clps_readb(PDDR
);
263 port_d
|= EDB_PD3_LCDBL
;
265 port_d
&= ~EDB_PD3_LCDBL
;
268 clps_writeb(port_d
, PDDR
);
274 static void __init
clps711x_guess_lcd_params(struct fb_info
*info
)
276 unsigned int lcdcon
, syscon
, size
;
277 unsigned long phys_base
= PAGE_OFFSET
;
278 void *virt_base
= (void *)PAGE_OFFSET
;
280 info
->var
.xres_virtual
= 640;
281 info
->var
.yres_virtual
= 240;
282 info
->var
.bits_per_pixel
= 4;
283 info
->var
.activate
= FB_ACTIVATE_NOW
;
284 info
->var
.height
= -1;
285 info
->var
.width
= -1;
286 info
->var
.pixclock
= 93006; /* 10.752MHz pixel clock */
289 * If the LCD controller is already running, decode the values
290 * in LCDCON to xres/yres/bpp/pixclock/acprescale
292 syscon
= clps_readl(SYSCON1
);
293 if (syscon
& SYSCON1_LCDEN
) {
294 lcdcon
= clps_readl(LCDCON
);
297 * Decode GSMD and GSEN bits to bits per pixel
299 switch (lcdcon
& (LCDCON_GSMD
| LCDCON_GSEN
)) {
300 case LCDCON_GSMD
| LCDCON_GSEN
:
301 info
->var
.bits_per_pixel
= 4;
305 info
->var
.bits_per_pixel
= 2;
309 info
->var
.bits_per_pixel
= 1;
316 info
->var
.xres_virtual
= (((lcdcon
>> 13) & 0x3f) + 1) * 16;
317 info
->var
.yres_virtual
= (((lcdcon
& 0x1fff) + 1) * 128) /
318 (info
->var
.xres_virtual
*
319 info
->var
.bits_per_pixel
);
324 info
->var
.pixclock
= (((lcdcon
>> 19) & 0x3f) + 1) * 244140 / 9;
329 lcd_ac_prescale
= (lcdcon
>> 25) & 0x1f;
332 info
->var
.xres
= info
->var
.xres_virtual
;
333 info
->var
.yres
= info
->var
.yres_virtual
;
334 info
->var
.grayscale
= info
->var
.bits_per_pixel
> 1;
336 size
= info
->var
.xres
* info
->var
.yres
* info
->var
.bits_per_pixel
/ 8;
339 * Might be worth checking to see if we can use the on-board
340 * RAM if size here...
341 * CLPS7110 - no on-board SRAM
342 * EP7212 - 38400 bytes
345 printk(KERN_INFO
"CLPS711xFB: could use on-board SRAM?\n");
348 if ((syscon
& SYSCON1_LCDEN
) == 0) {
350 * The display isn't running. Ensure that
351 * the display memory is empty.
353 memset(virt_base
, 0, size
);
356 info
->screen_base
= virt_base
;
357 info
->fix
.smem_start
= phys_base
;
358 info
->fix
.smem_len
= PAGE_ALIGN(size
);
359 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
362 int __init
clps711xfb_init(void)
366 if (fb_get_options("clps711xfb", NULL
))
369 cfb
= kmalloc(sizeof(*cfb
), GFP_KERNEL
);
373 memset(cfb
, 0, sizeof(*cfb
));
374 strcpy(cfb
->fix
.id
, "clps711x");
376 cfb
->fbops
= &clps7111fb_ops
;
377 cfb
->flags
= FBINFO_DEFAULT
;
379 clps711x_guess_lcd_params(cfb
);
381 fb_alloc_cmap(&cfb
->cmap
, CMAP_MAX_SIZE
, 0);
383 /* Register the /proc entries. */
384 clps7111fb_backlight_proc_entry
= create_proc_entry("backlight", 0444,
386 if (clps7111fb_backlight_proc_entry
== NULL
) {
387 printk("Couldn't create the /proc entry for the backlight.\n");
391 clps7111fb_backlight_proc_entry
->read_proc
=
392 &clps7111fb_proc_backlight_read
;
393 clps7111fb_backlight_proc_entry
->write_proc
=
394 &clps7111fb_proc_backlight_write
;
399 if (machine_is_p720t()) {
400 PLD_LCDEN
= PLD_LCDEN_EN
;
401 PLD_PWR
|= (PLD_S4_ON
|PLD_S3_ON
|PLD_S2_ON
|PLD_S1_ON
);
404 if (machine_is_edb7211()) {
405 /* Power up the LCD panel. */
406 clps_writeb(clps_readb(PDDR
) | EDB_PD2_LCDEN
, PDDR
);
408 /* Delay for a little while. */
411 /* Power up the LCD DC-DC converter. */
412 clps_writeb(clps_readb(PDDR
) | EDB_PD1_LCD_DC_DC_EN
, PDDR
);
414 /* Turn on the LCD backlight. */
415 clps_writeb(clps_readb(PDDR
) | EDB_PD3_LCDBL
, PDDR
);
418 err
= register_framebuffer(cfb
);
423 static void __exit
clps711xfb_exit(void)
425 unregister_framebuffer(cfb
);
431 if (machine_is_p720t()) {
433 PLD_PWR
&= ~(PLD_S4_ON
|PLD_S3_ON
|PLD_S2_ON
|PLD_S1_ON
);
437 module_init(clps711xfb_init
);
438 module_exit(clps711xfb_exit
);
440 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
441 MODULE_DESCRIPTION("CLPS711x framebuffer driver");
442 MODULE_LICENSE("GPL");