TTY: serial, move locking in uart_close
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / clps711xfb.c
blob99b354b8e2571db68f4a2d4f061829273d53de31
1 /*
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/mm.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/seq_file.h>
26 #include <linux/slab.h>
27 #include <linux/fb.h>
28 #include <linux/init.h>
29 #include <linux/proc_fs.h>
30 #include <linux/delay.h>
32 #include <mach/hardware.h>
33 #include <asm/mach-types.h>
34 #include <linux/uaccess.h>
36 #include <asm/hardware/clps7111.h>
37 #include <mach/syspld.h>
39 struct fb_info *cfb;
41 #define CMAP_MAX_SIZE 16
44 * LCD AC Prescale. This comes from the LCD panel manufacturers specifications.
45 * This determines how many clocks + 1 of CL1 before the M signal toggles.
46 * The number of lines on the display must not be divisible by this number.
48 static unsigned int lcd_ac_prescale = 13;
51 * Set a single color register. Return != 0 for invalid regno.
53 static int
54 clps7111fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
55 u_int transp, struct fb_info *info)
57 unsigned int level, mask, shift, pal;
59 if (regno >= (1 << info->var.bits_per_pixel))
60 return 1;
62 /* gray = 0.30*R + 0.58*G + 0.11*B */
63 level = (red * 77 + green * 151 + blue * 28) >> 20;
66 * On an LCD, a high value is dark, while a low value is light.
67 * So we invert the level.
69 * This isn't true on all machines, so we only do it on EDB7211.
70 * --rmk
72 if (machine_is_edb7211()) {
73 level = 15 - level;
76 shift = 4 * (regno & 7);
77 level <<= shift;
78 mask = 15 << shift;
79 level &= mask;
81 regno = regno < 8 ? PALLSW : PALMSW;
83 pal = clps_readl(regno);
84 pal = (pal & ~mask) | level;
85 clps_writel(pal, regno);
87 return 0;
91 * Validate the purposed mode.
92 */
93 static int
94 clps7111fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
96 var->transp.msb_right = 0;
97 var->transp.offset = 0;
98 var->transp.length = 0;
99 var->red.msb_right = 0;
100 var->red.offset = 0;
101 var->red.length = var->bits_per_pixel;
102 var->green = var->red;
103 var->blue = var->red;
105 if (var->bits_per_pixel > 4)
106 return -EINVAL;
108 return 0;
112 * Set the hardware state.
114 static int
115 clps7111fb_set_par(struct fb_info *info)
117 unsigned int lcdcon, syscon, pixclock;
119 switch (info->var.bits_per_pixel) {
120 case 1:
121 info->fix.visual = FB_VISUAL_MONO01;
122 break;
123 case 2:
124 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
125 break;
126 case 4:
127 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
128 break;
131 info->fix.line_length = info->var.xres_virtual * info->var.bits_per_pixel / 8;
133 lcdcon = (info->var.xres_virtual * info->var.yres_virtual * info->var.bits_per_pixel) / 128 - 1;
134 lcdcon |= ((info->var.xres_virtual / 16) - 1) << 13;
135 lcdcon |= lcd_ac_prescale << 25;
138 * Calculate pixel prescale value from the pixclock. This is:
139 * 36.864MHz / pixclock_mhz - 1.
140 * However, pixclock is in picoseconds, so this ends up being:
141 * 36864000 * pixclock_ps / 10^12 - 1
142 * and this will overflow the 32-bit math. We perform this as
143 * (9 * 4096000 == 36864000):
144 * pixclock_ps * 9 * (4096000 / 10^12) - 1
146 pixclock = 9 * info->var.pixclock / 244140 - 1;
147 lcdcon |= pixclock << 19;
149 if (info->var.bits_per_pixel == 4)
150 lcdcon |= LCDCON_GSMD;
151 if (info->var.bits_per_pixel >= 2)
152 lcdcon |= LCDCON_GSEN;
155 * LCDCON must only be changed while the LCD is disabled
157 syscon = clps_readl(SYSCON1);
158 clps_writel(syscon & ~SYSCON1_LCDEN, SYSCON1);
159 clps_writel(lcdcon, LCDCON);
160 clps_writel(syscon | SYSCON1_LCDEN, SYSCON1);
161 return 0;
164 static int clps7111fb_blank(int blank, struct fb_info *info)
166 if (blank) {
167 if (machine_is_edb7211()) {
168 /* Turn off the LCD backlight. */
169 clps_writeb(clps_readb(PDDR) & ~EDB_PD3_LCDBL, PDDR);
171 /* Power off the LCD DC-DC converter. */
172 clps_writeb(clps_readb(PDDR) & ~EDB_PD1_LCD_DC_DC_EN, PDDR);
174 /* Delay for a little while (half a second). */
175 udelay(100);
177 /* Power off the LCD panel. */
178 clps_writeb(clps_readb(PDDR) & ~EDB_PD2_LCDEN, PDDR);
180 /* Power off the LCD controller. */
181 clps_writel(clps_readl(SYSCON1) & ~SYSCON1_LCDEN,
182 SYSCON1);
184 } else {
185 if (machine_is_edb7211()) {
186 /* Power up the LCD controller. */
187 clps_writel(clps_readl(SYSCON1) | SYSCON1_LCDEN,
188 SYSCON1);
190 /* Power up the LCD panel. */
191 clps_writeb(clps_readb(PDDR) | EDB_PD2_LCDEN, PDDR);
193 /* Delay for a little while. */
194 udelay(100);
196 /* Power up the LCD DC-DC converter. */
197 clps_writeb(clps_readb(PDDR) | EDB_PD1_LCD_DC_DC_EN,
198 PDDR);
200 /* Turn on the LCD backlight. */
201 clps_writeb(clps_readb(PDDR) | EDB_PD3_LCDBL, PDDR);
204 return 0;
207 static struct fb_ops clps7111fb_ops = {
208 .owner = THIS_MODULE,
209 .fb_check_var = clps7111fb_check_var,
210 .fb_set_par = clps7111fb_set_par,
211 .fb_setcolreg = clps7111fb_setcolreg,
212 .fb_blank = clps7111fb_blank,
213 .fb_fillrect = cfb_fillrect,
214 .fb_copyarea = cfb_copyarea,
215 .fb_imageblit = cfb_imageblit,
218 static int backlight_proc_show(struct seq_file *m, void *v)
220 if (machine_is_edb7211()) {
221 seq_printf(m, "%d\n",
222 (clps_readb(PDDR) & EDB_PD3_LCDBL) ? 1 : 0);
225 return 0;
228 static int backlight_proc_open(struct inode *inode, struct file *file)
230 return single_open(file, backlight_proc_show, NULL);
233 static ssize_t backlight_proc_write(struct file *file, const char *buffer,
234 size_t count, loff_t *pos)
236 unsigned char char_value;
237 int value;
239 if (count < 1) {
240 return -EINVAL;
243 if (copy_from_user(&char_value, buffer, 1))
244 return -EFAULT;
246 value = char_value - '0';
248 if (machine_is_edb7211()) {
249 unsigned char port_d;
251 port_d = clps_readb(PDDR);
253 if (value) {
254 port_d |= EDB_PD3_LCDBL;
255 } else {
256 port_d &= ~EDB_PD3_LCDBL;
259 clps_writeb(port_d, PDDR);
262 return count;
265 static const struct file_operations backlight_proc_fops = {
266 .owner = THIS_MODULE,
267 .open = backlight_proc_open,
268 .read = seq_read,
269 .llseek = seq_lseek,
270 .release = single_release,
271 .write = backlight_proc_write,
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;
302 break;
304 case LCDCON_GSEN:
305 info->var.bits_per_pixel = 2;
306 break;
308 default:
309 info->var.bits_per_pixel = 1;
310 break;
314 * Decode xres/yres
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);
322 * Calculate pixclock
324 info->var.pixclock = (((lcdcon >> 19) & 0x3f) + 1) * 244140 / 9;
327 * Grab AC prescale
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
344 if (size <= 38400) {
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)
364 int err = -ENOMEM;
366 if (fb_get_options("clps711xfb", NULL))
367 return -ENODEV;
369 cfb = kzalloc(sizeof(*cfb), GFP_KERNEL);
370 if (!cfb)
371 goto out;
373 strcpy(cfb->fix.id, "clps711x");
375 cfb->fbops = &clps7111fb_ops;
376 cfb->flags = FBINFO_DEFAULT;
378 clps711x_guess_lcd_params(cfb);
380 fb_alloc_cmap(&cfb->cmap, CMAP_MAX_SIZE, 0);
382 if (!proc_create("backlight", 0444, NULL, &backlight_proc_fops)) {
383 printk("Couldn't create the /proc entry for the backlight.\n");
384 return -EINVAL;
388 * Power up the LCD
390 if (machine_is_p720t()) {
391 PLD_LCDEN = PLD_LCDEN_EN;
392 PLD_PWR |= (PLD_S4_ON|PLD_S3_ON|PLD_S2_ON|PLD_S1_ON);
395 if (machine_is_edb7211()) {
396 /* Power up the LCD panel. */
397 clps_writeb(clps_readb(PDDR) | EDB_PD2_LCDEN, PDDR);
399 /* Delay for a little while. */
400 udelay(100);
402 /* Power up the LCD DC-DC converter. */
403 clps_writeb(clps_readb(PDDR) | EDB_PD1_LCD_DC_DC_EN, PDDR);
405 /* Turn on the LCD backlight. */
406 clps_writeb(clps_readb(PDDR) | EDB_PD3_LCDBL, PDDR);
409 err = register_framebuffer(cfb);
411 out: return err;
414 static void __exit clps711xfb_exit(void)
416 unregister_framebuffer(cfb);
417 kfree(cfb);
420 * Power down the LCD
422 if (machine_is_p720t()) {
423 PLD_LCDEN = 0;
424 PLD_PWR &= ~(PLD_S4_ON|PLD_S3_ON|PLD_S2_ON|PLD_S1_ON);
428 module_init(clps711xfb_init);
429 module_exit(clps711xfb_exit);
431 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
432 MODULE_DESCRIPTION("CLPS711x framebuffer driver");
433 MODULE_LICENSE("GPL");