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 */
64 .activate = FB_ACTIVATE_NOW,
74 .vmode = FB_VMODE_NONINTERLACED,
78 * Interface used by the world
80 int tx3912fb_init(void);
82 static int tx3912fb_setcolreg(u_int regno, u_int red, u_int green,
83 u_int blue, u_int transp,
84 struct fb_info *info);
89 #define get_line_length(xres_virtual, bpp) \
90 (u_long) (((int) xres_virtual * (int) bpp + 7) >> 3)
93 * Frame buffer operations structure used by console driver
95 static struct fb_ops tx3912fb_ops = {
97 .fb_setcolreg = tx3912fb_setcolreg,
98 .fb_fillrect = cfb_fillrect,
99 .fb_copyarea = cfb_copyarea,
100 .fb_imageblit = cfb_imageblit,
101 .fb_cursor = soft_cursor,
104 static int tx3912fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
110 get_line_length(var->xres_virtual, var->bits_per_pixel);
111 if ((line_length * var->yres_virtual) > info->fix.smem_len)
117 static int tx3912fb_set_par(struct fb_info *info)
119 u_long tx3912fb_paddr = 0;
121 /* Disable the video logic */
122 outl(inl(TX3912_VIDEO_CTRL1) &
123 ~(TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
127 /* Set start address for DMA transfer */
128 outl(tx3912fb_paddr, TX3912_VIDEO_CTRL3);
130 /* Set end address for DMA transfer */
131 outl((tx3912fb_paddr + tx3912fb_fix.smem_len + 1), TX3912_VIDEO_CTRL4);
133 /* Set the pixel depth */
134 switch (info->var.bits_per_pixel) {
137 outl(inl(TX3912_VIDEO_CTRL1) &
138 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
139 info->fix.visual = FB_VISUAL_MONO10;
143 outl(inl(TX3912_VIDEO_CTRL1) &
144 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
145 outl(inl(TX3912_VIDEO_CTRL1) |
146 TX3912_VIDEO_CTRL1_BITSEL_4BIT_GRAY,
148 info->fix.visual = FB_VISUAL_TRUECOLOR;
152 outl(inl(TX3912_VIDEO_CTRL1) &
153 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
154 outl(inl(TX3912_VIDEO_CTRL1) |
155 TX3912_VIDEO_CTRL1_BITSEL_8BIT_COLOR,
157 info->fix.visual = FB_VISUAL_TRUECOLOR;
162 outl(inl(TX3912_VIDEO_CTRL1) &
163 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
164 outl(inl(TX3912_VIDEO_CTRL1) |
165 TX3912_VIDEO_CTRL1_BITSEL_2BIT_GRAY,
167 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
171 /* Enable the video clock */
172 outl(inl(TX3912_CLK_CTRL) | TX3912_CLK_CTRL_ENVIDCLK,
175 /* Unfreeze video logic and enable DF toggle */
176 outl(inl(TX3912_VIDEO_CTRL1) &
177 ~(TX3912_VIDEO_CTRL1_ENFREEZEFRAME |
178 TX3912_VIDEO_CTRL1_DFMODE)
179 , TX3912_VIDEO_CTRL1);
182 /* Enable the video logic */
183 outl(inl(TX3912_VIDEO_CTRL1) |
184 (TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
187 info->fix.line_length = get_line_length(var->xres_virtual,
188 var->bits_per_pixel);
192 * Set a single color register
194 static int tx3912fb_setcolreg(u_int regno, u_int red, u_int green,
195 u_int blue, u_int transp,
196 struct fb_info *info)
202 ((u32 *)(info->pseudo_palette))[regno] = ((red & 0xe000) >> 8)
203 | ((green & 0xe000) >> 11)
204 | ((blue & 0xc000) >> 14);
209 * Initialization of the framebuffer
211 int __init tx3912fb_init(void)
213 u_long tx3912fb_paddr = 0;
214 int size = (info->var.bits_per_pixel == 8) ? 256 : 16;
216 /* Disable the video logic */
217 outl(inl(TX3912_VIDEO_CTRL1) &
218 ~(TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
222 /* Set start address for DMA transfer */
223 outl(tx3912fb_paddr, TX3912_VIDEO_CTRL3);
225 /* Set end address for DMA transfer */
226 outl((tx3912fb_paddr + tx3912fb_fix.smem_len + 1), TX3912_VIDEO_CTRL4);
228 /* Set the pixel depth */
229 switch (tx3912fb_var.bits_per_pixel) {
232 outl(inl(TX3912_VIDEO_CTRL1) &
233 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
234 tx3912fb_fix.visual = FB_VISUAL_MONO10;
238 outl(inl(TX3912_VIDEO_CTRL1) &
239 ~TX3912_VIDEO_CTRL1_BITSEL_MASK, TX3912_VIDEO_CTRL1);
240 outl(inl(TX3912_VIDEO_CTRL1) |
241 TX3912_VIDEO_CTRL1_BITSEL_4BIT_GRAY,
243 tx3912fb_fix.visual = FB_VISUAL_TRUECOLOR;
244 tx3912fb_fix.grayscale = 1;
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_8BIT_COLOR,
253 tx3912fb_fix.visual = FB_VISUAL_TRUECOLOR;
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_2BIT_GRAY,
263 tx3912fb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
264 tx3912fb_fix.grayscale = 1;
268 /* Enable the video clock */
269 outl(inl(TX3912_CLK_CTRL) | TX3912_CLK_CTRL_ENVIDCLK,
272 /* Unfreeze video logic and enable DF toggle */
273 outl(inl(TX3912_VIDEO_CTRL1) &
274 ~(TX3912_VIDEO_CTRL1_ENFREEZEFRAME | TX3912_VIDEO_CTRL1_DFMODE),
278 /* Clear the framebuffer */
279 memset((void *) tx3912fb_fix.smem_start, 0xff, tx3912fb_fix.smem_len);
282 /* Enable the video logic */
283 outl(inl(TX3912_VIDEO_CTRL1) |
284 (TX3912_VIDEO_CTRL1_ENVID | TX3912_VIDEO_CTRL1_DISPON),
290 tx3912fb_fix.line_length =
291 get_line_length(tx3912fb_var.xres_virtual, tx3912fb_var.bits_per_pixel);
292 if ((tx3912fb_fix.line_length * tx3912fb_var.yres_virtual) > tx3912fb_fix.smem_len)
295 fb_info.fbops = &tx3912fb_ops;
296 fb_info.var = tx3912fb_var;
297 fb_info.fix = tx3912fb_fix;
298 fb_info.pseudo_palette = pseudo_palette;
299 fb_info.flags = FBINFO_FLAG_DEFAULT;
301 /* Clear the framebuffer */
302 memset((void *) fb_info.fix.smem_start, 0xff, fb_info.fix.smem_len);
305 fb_alloc_cmap(&info->cmap, size, 0);
307 if (register_framebuffer(&fb_info) < 0)
310 printk(KERN_INFO "fb%d: TX3912 frame buffer using %uKB.\n",
311 fb_info.node, (u_int) (fb_info.fix.smem_len >> 10));
315 int __init tx3912fb_setup(char *options)
319 if (!options || !*options)
322 while ((this_opt = strsep(&options, ","))) {
323 if (!strncmp(options, "bpp:", 4))
324 tx3912fb_var.bits_per_pixel = simple_strtoul(options+4, NULL, 0);
329 MODULE_LICENSE("GPL");