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/config.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/tty.h>
19 #include <linux/delay.h>
20 #include <linux/interrupt.h>
21 #include <linux/init.h>
25 #include <asm/bootinfo.h>
26 #include <asm/uaccess.h>
27 #include <asm/tx3912.h>
28 #include <video/tx3912.h>
31 * Frame buffer, palette and console structures
33 static struct fb_info fb_info
;
36 static struct fb_fix_screeninfo tx3912fb_fix __initdata
= {
38 #ifdef CONFIG_NINO_16MB
39 .smem_len
= (240 * 320),
41 .smem_len
= ((240 * 320)/2),
43 .type
= FB_TYPE_PACKED_PIXELS
,
44 .visual
= FB_VISUAL_TRUECOLOR
,
48 .accel
= FB_ACCEL_NONE
,
51 static struct fb_var_screeninfo tx3912fb_var
= {
56 #ifdef CONFIG_NINO_16MB
58 .red
= { 5, 3, 0 }, /* RGB 332 */
63 .red
= { 0, 4, 0 }, /* ??? */
67 .activate
= FB_ACTIVATE_NOW
,
77 .vmode
= FB_VMODE_NONINTERLACED
,
81 * Interface used by the world
83 int tx3912fb_init(void);
85 static int tx3912fb_setcolreg(u_int regno
, u_int red
, u_int green
,
86 u_int blue
, u_int transp
,
87 struct fb_info
*info
);
92 #define get_line_length(xres_virtual, bpp) \
93 (u_long) (((int) xres_virtual * (int) bpp + 7) >> 3)
96 * Frame buffer operations structure used by console driver
98 static struct fb_ops tx3912fb_ops
= {
100 .fb_setcolreg
= tx3912fb_setcolreg
,
101 .fb_fillrect
= cfb_fillrect
,
102 .fb_copyarea
= cfb_copyarea
,
103 .fb_imageblit
= cfb_imageblit
,
104 .fb_cursor
= soft_cursor
,
107 static int tx3912fb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
113 get_line_length(var
->xres_virtual
, var
->bits_per_pixel
);
114 if ((line_length
* var
->yres_virtual
) > info
->fix
.smem_len
)
120 static int tx3912fb_set_par(struct fb_info
*info
)
122 u_long tx3912fb_paddr
= 0;
124 /* Disable the video logic */
125 outl(inl(TX3912_VIDEO_CTRL1
) &
126 ~(TX3912_VIDEO_CTRL1_ENVID
| TX3912_VIDEO_CTRL1_DISPON
),
130 /* Set start address for DMA transfer */
131 outl(tx3912fb_paddr
, TX3912_VIDEO_CTRL3
);
133 /* Set end address for DMA transfer */
134 outl((tx3912fb_paddr
+ tx3912fb_fix
.smem_len
+ 1), TX3912_VIDEO_CTRL4
);
136 /* Set the pixel depth */
137 switch (info
->var
.bits_per_pixel
) {
140 outl(inl(TX3912_VIDEO_CTRL1
) &
141 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
142 info
->fix
.visual
= FB_VISUAL_MONO10
;
146 outl(inl(TX3912_VIDEO_CTRL1
) &
147 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
148 outl(inl(TX3912_VIDEO_CTRL1
) |
149 TX3912_VIDEO_CTRL1_BITSEL_4BIT_GRAY
,
151 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
155 outl(inl(TX3912_VIDEO_CTRL1
) &
156 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
157 outl(inl(TX3912_VIDEO_CTRL1
) |
158 TX3912_VIDEO_CTRL1_BITSEL_8BIT_COLOR
,
160 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
165 outl(inl(TX3912_VIDEO_CTRL1
) &
166 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
167 outl(inl(TX3912_VIDEO_CTRL1
) |
168 TX3912_VIDEO_CTRL1_BITSEL_2BIT_GRAY
,
170 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
174 /* Enable the video clock */
175 outl(inl(TX3912_CLK_CTRL
) | TX3912_CLK_CTRL_ENVIDCLK
,
178 /* Unfreeze video logic and enable DF toggle */
179 outl(inl(TX3912_VIDEO_CTRL1
) &
180 ~(TX3912_VIDEO_CTRL1_ENFREEZEFRAME
|
181 TX3912_VIDEO_CTRL1_DFMODE
)
182 , TX3912_VIDEO_CTRL1
);
185 /* Enable the video logic */
186 outl(inl(TX3912_VIDEO_CTRL1
) |
187 (TX3912_VIDEO_CTRL1_ENVID
| TX3912_VIDEO_CTRL1_DISPON
),
190 info
->fix
.line_length
= get_line_length(var
->xres_virtual
,
191 var
->bits_per_pixel
);
195 * Set a single color register
197 static int tx3912fb_setcolreg(u_int regno
, u_int red
, u_int green
,
198 u_int blue
, u_int transp
,
199 struct fb_info
*info
)
205 ((u32
*)(info
->pseudo_palette
))[regno
] = ((red
& 0xe000) >> 8)
206 | ((green
& 0xe000) >> 11)
207 | ((blue
& 0xc000) >> 14);
211 int __init
tx3912fb_setup(char *options
);
214 * Initialization of the framebuffer
216 int __init
tx3912fb_init(void)
218 u_long tx3912fb_paddr
= 0;
219 int size
= (info
->var
.bits_per_pixel
== 8) ? 256 : 16;
222 if (fb_get_options("tx3912fb", &option
))
224 tx3912fb_setup(option
);
226 /* Disable the video logic */
227 outl(inl(TX3912_VIDEO_CTRL1
) &
228 ~(TX3912_VIDEO_CTRL1_ENVID
| TX3912_VIDEO_CTRL1_DISPON
),
232 /* Set start address for DMA transfer */
233 outl(tx3912fb_paddr
, TX3912_VIDEO_CTRL3
);
235 /* Set end address for DMA transfer */
236 outl((tx3912fb_paddr
+ tx3912fb_fix
.smem_len
+ 1), TX3912_VIDEO_CTRL4
);
238 /* Set the pixel depth */
239 switch (tx3912fb_var
.bits_per_pixel
) {
242 outl(inl(TX3912_VIDEO_CTRL1
) &
243 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
244 tx3912fb_fix
.visual
= FB_VISUAL_MONO10
;
248 outl(inl(TX3912_VIDEO_CTRL1
) &
249 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
250 outl(inl(TX3912_VIDEO_CTRL1
) |
251 TX3912_VIDEO_CTRL1_BITSEL_4BIT_GRAY
,
253 tx3912fb_fix
.visual
= FB_VISUAL_TRUECOLOR
;
254 tx3912fb_fix
.grayscale
= 1;
258 outl(inl(TX3912_VIDEO_CTRL1
) &
259 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
260 outl(inl(TX3912_VIDEO_CTRL1
) |
261 TX3912_VIDEO_CTRL1_BITSEL_8BIT_COLOR
,
263 tx3912fb_fix
.visual
= FB_VISUAL_TRUECOLOR
;
268 outl(inl(TX3912_VIDEO_CTRL1
) &
269 ~TX3912_VIDEO_CTRL1_BITSEL_MASK
, TX3912_VIDEO_CTRL1
);
270 outl(inl(TX3912_VIDEO_CTRL1
) |
271 TX3912_VIDEO_CTRL1_BITSEL_2BIT_GRAY
,
273 tx3912fb_fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
274 tx3912fb_fix
.grayscale
= 1;
278 /* Enable the video clock */
279 outl(inl(TX3912_CLK_CTRL
) | TX3912_CLK_CTRL_ENVIDCLK
,
282 /* Unfreeze video logic and enable DF toggle */
283 outl(inl(TX3912_VIDEO_CTRL1
) &
284 ~(TX3912_VIDEO_CTRL1_ENFREEZEFRAME
| TX3912_VIDEO_CTRL1_DFMODE
),
288 /* Clear the framebuffer */
289 memset((void *) tx3912fb_fix
.smem_start
, 0xff, tx3912fb_fix
.smem_len
);
292 /* Enable the video logic */
293 outl(inl(TX3912_VIDEO_CTRL1
) |
294 (TX3912_VIDEO_CTRL1_ENVID
| TX3912_VIDEO_CTRL1_DISPON
),
300 tx3912fb_fix
.line_length
=
301 get_line_length(tx3912fb_var
.xres_virtual
, tx3912fb_var
.bits_per_pixel
);
302 if ((tx3912fb_fix
.line_length
* tx3912fb_var
.yres_virtual
) > tx3912fb_fix
.smem_len
)
305 fb_info
.fbops
= &tx3912fb_ops
;
306 fb_info
.var
= tx3912fb_var
;
307 fb_info
.fix
= tx3912fb_fix
;
308 fb_info
.pseudo_palette
= pseudo_palette
;
309 fb_info
.flags
= FBINFO_DEFAULT
;
311 /* Clear the framebuffer */
312 memset((void *) fb_info
.fix
.smem_start
, 0xff, fb_info
.fix
.smem_len
);
315 fb_alloc_cmap(&info
->cmap
, size
, 0);
317 if (register_framebuffer(&fb_info
) < 0)
320 printk(KERN_INFO
"fb%d: TX3912 frame buffer using %uKB.\n",
321 fb_info
.node
, (u_int
) (fb_info
.fix
.smem_len
>> 10));
325 int __init
tx3912fb_setup(char *options
)
329 if (!options
|| !*options
)
332 while ((this_opt
= strsep(&options
, ","))) {
333 if (!strncmp(options
, "bpp:", 4))
334 tx3912fb_var
.bits_per_pixel
= simple_strtoul(options
+4, NULL
, 0);
339 module_init(tx3912fb_init
);
340 MODULE_LICENSE("GPL");