2 * drivers/video/tx3912fb.c
4 * Copyright (C) 1999 Harald Koerfgen
5 * Copyright (C) 2001 Steven Hill (sjhill@realitydiluted.com)
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
11 * Framebuffer for LCD controller in TMPR3912/05 and PR31700 processors
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include <linux/interrupt.h>
19 #include <linux/init.h>
23 #include <asm/bootinfo.h>
24 #include <asm/uaccess.h>
25 #include <asm/tx3912.h>
26 #include <video/tx3912.h>
29 * Frame buffer, palette and console structures
31 static struct fb_info fb_info;
34 static struct fb_fix_screeninfo tx3912fb_fix __initdata = {
36 .smem_len = ((240 * 320)/2),
37 .type = FB_TYPE_PACKED_PIXELS,
38 .visual = FB_VISUAL_TRUECOLOR,
42 .accel = FB_ACCEL_NONE,
45 static struct fb_var_screeninfo tx3912fb_var = {
51 .red = { 0, 4, 0 }, /* ??? */
54 .activate = FB_ACTIVATE_NOW,
64 .vmode = FB_VMODE_NONINTERLACED,
68 * Interface used by the world
70 int tx3912fb_init(void);
72 static int tx3912fb_setcolreg(u_int regno, u_int red, u_int green,
73 u_int blue, u_int transp,
74 struct fb_info *info);
79 #define get_line_length(xres_virtual, bpp) \
80 (u_long) (((int) xres_virtual * (int) bpp + 7) >> 3)
83 * Frame buffer operations structure used by console driver
85 static struct fb_ops tx3912fb_ops = {
87 .fb_setcolreg = tx3912fb_setcolreg,
88 .fb_fillrect = cfb_fillrect,
89 .fb_copyarea = cfb_copyarea,
90 .fb_imageblit = cfb_imageblit,
93 static int tx3912fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
99 get_line_length(var->xres_virtual, var->bits_per_pixel);
100 if ((line_length * var->yres_virtual) > info->fix.smem_len)
106 static int tx3912fb_set_par(struct fb_info *info)
108 u_long tx3912fb_paddr = 0;
110 /* Disable the video logic */
111 outl(inl(TX3912_VIDEO_CTRL1) &
112 ~(TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
116 /* Set start address for DMA transfer */
117 outl(tx3912fb_paddr, TX3912_VIDEO_CTRL3);
119 /* Set end address for DMA transfer */
120 outl((tx3912fb_paddr + tx3912fb_fix.smem_len + 1), TX3912_VIDEO_CTRL4);
122 /* Set the pixel depth */
123 switch (info->var.bits_per_pixel) {
126 outl(inl(TX3912_VIDEO_CTRL1) &
127 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
128 info->fix.visual = FB_VISUAL_MONO10;
132 outl(inl(TX3912_VIDEO_CTRL1) &
133 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
134 outl(inl(TX3912_VIDEO_CTRL1) |
135 TX3912_VIDEO_CTRL1_BITSEL_4BIT_GRAY,
137 info->fix.visual = FB_VISUAL_TRUECOLOR;
141 outl(inl(TX3912_VIDEO_CTRL1) &
142 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
143 outl(inl(TX3912_VIDEO_CTRL1) |
144 TX3912_VIDEO_CTRL1_BITSEL_8BIT_COLOR,
146 info->fix.visual = FB_VISUAL_TRUECOLOR;
151 outl(inl(TX3912_VIDEO_CTRL1) &
152 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
153 outl(inl(TX3912_VIDEO_CTRL1) |
154 TX3912_VIDEO_CTRL1_BITSEL_2BIT_GRAY,
156 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
160 /* Enable the video clock */
161 outl(inl(TX3912_CLK_CTRL) | TX3912_CLK_CTRL_ENVIDCLK,
164 /* Unfreeze video logic and enable DF toggle */
165 outl(inl(TX3912_VIDEO_CTRL1) &
166 ~(TX3912_VIDEO_CTRL1_ENFREEZEFRAME |
167 TX3912_VIDEO_CTRL1_DFMODE)
168 , TX3912_VIDEO_CTRL1);
171 /* Enable the video logic */
172 outl(inl(TX3912_VIDEO_CTRL1) |
173 (TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
176 info->fix.line_length = get_line_length(var->xres_virtual,
177 var->bits_per_pixel);
181 * Set a single color register
183 static int tx3912fb_setcolreg(u_int regno, u_int red, u_int green,
184 u_int blue, u_int transp,
185 struct fb_info *info)
191 ((u32 *)(info->pseudo_palette))[regno] = ((red & 0xe000) >> 8)
192 | ((green & 0xe000) >> 11)
193 | ((blue & 0xc000) >> 14);
197 int __init tx3912fb_setup(char *options);
200 * Initialization of the framebuffer
202 int __init tx3912fb_init(void)
204 u_long tx3912fb_paddr = 0;
205 int size = (info->var.bits_per_pixel == 8) ? 256 : 16;
208 if (fb_get_options("tx3912fb", &option))
210 tx3912fb_setup(option);
212 /* Disable the video logic */
213 outl(inl(TX3912_VIDEO_CTRL1) &
214 ~(TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
218 /* Set start address for DMA transfer */
219 outl(tx3912fb_paddr, TX3912_VIDEO_CTRL3);
221 /* Set end address for DMA transfer */
222 outl((tx3912fb_paddr + tx3912fb_fix.smem_len + 1), TX3912_VIDEO_CTRL4);
224 /* Set the pixel depth */
225 switch (tx3912fb_var.bits_per_pixel) {
228 outl(inl(TX3912_VIDEO_CTRL1) &
229 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
230 tx3912fb_fix.visual = FB_VISUAL_MONO10;
234 outl(inl(TX3912_VIDEO_CTRL1) &
235 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
236 outl(inl(TX3912_VIDEO_CTRL1) |
237 TX3912_VIDEO_CTRL1_BITSEL_4BIT_GRAY,
239 tx3912fb_fix.visual = FB_VISUAL_TRUECOLOR;
240 tx3912fb_fix.grayscale = 1;
244 outl(inl(TX3912_VIDEO_CTRL1) &
245 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
246 outl(inl(TX3912_VIDEO_CTRL1) |
247 TX3912_VIDEO_CTRL1_BITSEL_8BIT_COLOR,
249 tx3912fb_fix.visual = FB_VISUAL_TRUECOLOR;
254 outl(inl(TX3912_VIDEO_CTRL1) &
255 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
256 outl(inl(TX3912_VIDEO_CTRL1) |
257 TX3912_VIDEO_CTRL1_BITSEL_2BIT_GRAY,
259 tx3912fb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
260 tx3912fb_fix.grayscale = 1;
264 /* Enable the video clock */
265 outl(inl(TX3912_CLK_CTRL) | TX3912_CLK_CTRL_ENVIDCLK,
268 /* Unfreeze video logic and enable DF toggle */
269 outl(inl(TX3912_VIDEO_CTRL1) &
270 ~(TX3912_VIDEO_CTRL1_ENFREEZEFRAME | TX3912_VIDEO_CTRL1_DFMODE),
274 /* Clear the framebuffer */
275 memset((void *) tx3912fb_fix.smem_start, 0xff, tx3912fb_fix.smem_len);
278 /* Enable the video logic */
279 outl(inl(TX3912_VIDEO_CTRL1) |
280 (TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
286 tx3912fb_fix.line_length =
287 get_line_length(tx3912fb_var.xres_virtual, tx3912fb_var.bits_per_pixel);
288 if ((tx3912fb_fix.line_length * tx3912fb_var.yres_virtual) > tx3912fb_fix.smem_len)
291 fb_info.fbops = &tx3912fb_ops;
292 fb_info.var = tx3912fb_var;
293 fb_info.fix = tx3912fb_fix;
294 fb_info.pseudo_palette = pseudo_palette;
295 fb_info.flags = FBINFO_DEFAULT;
297 /* Clear the framebuffer */
298 memset((void *) fb_info.fix.smem_start, 0xff, fb_info.fix.smem_len);
301 fb_alloc_cmap(&info->cmap, size, 0);
303 if (register_framebuffer(&fb_info) < 0)
306 printk(KERN_INFO "fb%d: TX3912 frame buffer using %uKB.\n",
307 fb_info.node, (u_int) (fb_info.fix.smem_len >> 10));
311 int __init tx3912fb_setup(char *options)
315 if (!options || !*options)
318 while ((this_opt = strsep(&options, ","))) {
319 if (!strncmp(options, "bpp:", 4))
320 tx3912fb_var.bits_per_pixel = simple_strtoul(options+4, NULL, 0);
325 module_init(tx3912fb_init);
326 MODULE_LICENSE("GPL");