pxafb.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,394 行 · 第 1/3 页

C
1,394
字号
/* *  linux/drivers/video/pxafb.c * *  Copyright (C) 1999 Eric A. Thomas. *  Copyright (C) 2004 Jean-Frederic Clere. *  Copyright (C) 2004 Ian Campbell. *  Copyright (C) 2004 Jeff Lackey. *   Based on sa1100fb.c Copyright (C) 1999 Eric A. Thomas *  which in turn is *   Based on acornfb.c Copyright (C) Russell King. * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive for * more details. * *	        Intel PXA250/210 LCD Controller Frame Buffer Driver * * Please direct your questions and comments on this driver to the following * email address: * *	linux-arm-kernel@lists.arm.linux.org.uk * */#include <linux/config.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/interrupt.h>#include <linux/slab.h>#include <linux/fb.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/ioport.h>#include <linux/cpufreq.h>#include <linux/device.h>#include <linux/dma-mapping.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/arch/pxa-regs.h>#include <asm/arch/bitfield.h>#include <asm/arch/pxafb.h>/* * Complain if VAR is out of range. */#define DEBUG_VAR 1#include "pxafb.h"/* Bits which should not be set in machine configuration structures */#define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM|LCCR0_BM|LCCR0_QDM|LCCR0_DIS|LCCR0_EFM|LCCR0_IUM|LCCR0_SFM|LCCR0_LDM|LCCR0_ENB)#define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP|LCCR3_VSP|LCCR3_PCD|LCCR3_BPP)static void (*pxafb_backlight_power)(int);static void (*pxafb_lcd_power)(int);static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *);static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);#ifdef CONFIG_FB_PXA_PARAMETERS#define PXAFB_OPTIONS_SIZE 256static char g_options[PXAFB_OPTIONS_SIZE] __initdata = "";#endifstatic inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state){	unsigned long flags;	local_irq_save(flags);	/*	 * We need to handle two requests being made at the same time.	 * There are two important cases:	 *  1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)	 *     We must perform the unblanking, which will do our REENABLE for us.	 *  2. When we are blanking, but immediately unblank before we have	 *     blanked.  We do the "REENABLE" thing here as well, just to be sure.	 */	if (fbi->task_state == C_ENABLE && state == C_REENABLE)		state = (u_int) -1;	if (fbi->task_state == C_DISABLE && state == C_ENABLE)		state = C_REENABLE;	if (state != (u_int)-1) {		fbi->task_state = state;		schedule_work(&fbi->task);	}	local_irq_restore(flags);}static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf){	chan &= 0xffff;	chan >>= 16 - bf->length;	return chan << bf->offset;}static intpxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,		       u_int trans, struct fb_info *info){	struct pxafb_info *fbi = (struct pxafb_info *)info;	u_int val, ret = 1;	if (regno < fbi->palette_size) {		if (fbi->fb.var.grayscale) {			val = ((blue >> 8) & 0x00ff);		} else {			val  = ((red   >>  0) & 0xf800);			val |= ((green >>  5) & 0x07e0);			val |= ((blue  >> 11) & 0x001f);		}		fbi->palette_cpu[regno] = val;		ret = 0;	}	return ret;}static intpxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,		   u_int trans, struct fb_info *info){	struct pxafb_info *fbi = (struct pxafb_info *)info;	unsigned int val;	int ret = 1;	/*	 * If inverse mode was selected, invert all the colours	 * rather than the register number.  The register number	 * is what you poke into the framebuffer to produce the	 * colour you requested.	 */	if (fbi->cmap_inverse) {		red   = 0xffff - red;		green = 0xffff - green;		blue  = 0xffff - blue;	}	/*	 * If greyscale is true, then we convert the RGB value	 * to greyscale no matter what visual we are using.	 */	if (fbi->fb.var.grayscale)		red = green = blue = (19595 * red + 38470 * green +					7471 * blue) >> 16;	switch (fbi->fb.fix.visual) {	case FB_VISUAL_TRUECOLOR:		/*		 * 16-bit True Colour.  We encode the RGB value		 * according to the RGB bitfield information.		 */		if (regno < 16) {			u32 *pal = fbi->fb.pseudo_palette;			val  = chan_to_field(red, &fbi->fb.var.red);			val |= chan_to_field(green, &fbi->fb.var.green);			val |= chan_to_field(blue, &fbi->fb.var.blue);			pal[regno] = val;			ret = 0;		}		break;	case FB_VISUAL_STATIC_PSEUDOCOLOR:	case FB_VISUAL_PSEUDOCOLOR:		ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);		break;	}	return ret;}/* *  pxafb_bpp_to_lccr3(): *    Convert a bits per pixel value to the correct bit pattern for LCCR3 */static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var){        int ret = 0;        switch (var->bits_per_pixel) {        case 1:  ret = LCCR3_1BPP; break;        case 2:  ret = LCCR3_2BPP; break;        case 4:  ret = LCCR3_4BPP; break;        case 8:  ret = LCCR3_8BPP; break;        case 16: ret = LCCR3_16BPP; break;        }        return ret;}#ifdef CONFIG_CPU_FREQ/* *  pxafb_display_dma_period() *    Calculate the minimum period (in picoseconds) between two DMA *    requests for the LCD controller.  If we hit this, it means we're *    doing nothing but LCD DMA. */static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var){       /*        * Period = pixclock * bits_per_byte * bytes_per_transfer        *              / memory_bits_per_pixel;        */       return var->pixclock * 8 * 16 / var->bits_per_pixel;}extern unsigned int get_clk_frequency_khz(int info);#endif/* *  pxafb_check_var(): *    Get the video params out of 'var'. If a value doesn't fit, round it up, *    if it's too big, return -EINVAL. * *    Round up in the following order: bits_per_pixel, xres, *    yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale, *    bitfields, horizontal timing, vertical timing. */static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){	struct pxafb_info *fbi = (struct pxafb_info *)info;	if (var->xres < MIN_XRES)		var->xres = MIN_XRES;	if (var->yres < MIN_YRES)		var->yres = MIN_YRES;	if (var->xres > fbi->max_xres)		var->xres = fbi->max_xres;	if (var->yres > fbi->max_yres)		var->yres = fbi->max_yres;	var->xres_virtual =		max(var->xres_virtual, var->xres);	var->yres_virtual =		max(var->yres_virtual, var->yres);        /*	 * Setup the RGB parameters for this display.	 *	 * The pixel packing format is described on page 7-11 of the	 * PXA2XX Developer's Manual.         */	if (var->bits_per_pixel == 16) {		var->red.offset   = 11; var->red.length   = 5;		var->green.offset = 5;  var->green.length = 6;		var->blue.offset  = 0;  var->blue.length  = 5;		var->transp.offset = var->transp.length = 0;	} else {		var->red.offset = var->green.offset = var->blue.offset = var->transp.offset = 0;		var->red.length   = 8;		var->green.length = 8;		var->blue.length  = 8;		var->transp.length = 0;	}#ifdef CONFIG_CPU_FREQ	DPRINTK("dma period = %d ps, clock = %d kHz\n",		pxafb_display_dma_period(var),		get_clk_frequency_khz(0));#endif	return 0;}static inline void pxafb_set_truecolor(u_int is_true_color){	DPRINTK("true_color = %d\n", is_true_color);	// do your machine-specific setup if needed}/* * pxafb_set_par(): *	Set the user defined part of the display for the specified console */static int pxafb_set_par(struct fb_info *info){	struct pxafb_info *fbi = (struct pxafb_info *)info;	struct fb_var_screeninfo *var = &info->var;	unsigned long palette_mem_size;	DPRINTK("set_par\n");	if (var->bits_per_pixel == 16)		fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;	else if (!fbi->cmap_static)		fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;	else {		/*		 * Some people have weird ideas about wanting static		 * pseudocolor maps.  I suspect their user space		 * applications are broken.		 */		fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;	}	fbi->fb.fix.line_length = var->xres_virtual *				  var->bits_per_pixel / 8;	if (var->bits_per_pixel == 16)		fbi->palette_size = 0;	else		fbi->palette_size = var->bits_per_pixel == 1 ? 4 : 1 << var->bits_per_pixel;	palette_mem_size = fbi->palette_size * sizeof(u16);	DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);	fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);	fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;	/*	 * Set (any) board control register to handle new color depth	 */	pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);	if (fbi->fb.var.bits_per_pixel == 16)		fb_dealloc_cmap(&fbi->fb.cmap);	else		fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);	pxafb_activate_var(var, fbi);	return 0;}/* * Formal definition of the VESA spec: *  On *  	This refers to the state of the display when it is in full operation *  Stand-By *  	This defines an optional operating state of minimal power reduction with *  	the shortest recovery time *  Suspend *  	This refers to a level of power management in which substantial power *  	reduction is achieved by the display.  The display can have a longer *  	recovery time from this state than from the Stand-by state *  Off *  	This indicates that the display is consuming the lowest level of power *  	and is non-operational. Recovery from this state may optionally require *  	the user to manually power on the monitor * *  Now, the fbdev driver adds an additional state, (blank), where they *  turn off the video (maybe by colormap tricks), but don't mess with the *  video itself: think of it semantically between on and Stand-By. * *  So here's what we should do in our fbdev blank routine: * *  	VESA_NO_BLANKING (mode 0)	Video on,  front/back light on *  	VESA_VSYNC_SUSPEND (mode 1)  	Video on,  front/back light off *  	VESA_HSYNC_SUSPEND (mode 2)  	Video on,  front/back light off *  	VESA_POWERDOWN (mode 3)		Video off, front/back light off * *  This will match the matrox implementation. *//* * pxafb_blank(): *	Blank the display by setting all palette values to zero.  Note, the * 	16 bpp mode does not really use the palette, so this will not *      blank the display in all modes. */static int pxafb_blank(int blank, struct fb_info *info){	struct pxafb_info *fbi = (struct pxafb_info *)info;	int i;	DPRINTK("pxafb_blank: blank=%d\n", blank);	switch (blank) {	case VESA_POWERDOWN:	case VESA_VSYNC_SUSPEND:	case VESA_HSYNC_SUSPEND:		if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||		    fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)			for (i = 0; i < fbi->palette_size; i++)				pxafb_setpalettereg(i, 0, 0, 0, 0, info);		pxafb_schedule_work(fbi, C_DISABLE);		//TODO if (pxafb_blank_helper) pxafb_blank_helper(blank);		break;	case VESA_NO_BLANKING:		//TODO if (pxafb_blank_helper) pxafb_blank_helper(blank);		if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||		    fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)			fb_set_cmap(&fbi->fb.cmap, info);		pxafb_schedule_work(fbi, C_ENABLE);	}	return 0;}static struct fb_ops pxafb_ops = {	.owner		= THIS_MODULE,	.fb_check_var	= pxafb_check_var,	.fb_set_par	= pxafb_set_par,	.fb_setcolreg	= pxafb_setcolreg,	.fb_fillrect	= cfb_fillrect,	.fb_copyarea	= cfb_copyarea,	.fb_imageblit	= cfb_imageblit,	.fb_blank	= pxafb_blank,	.fb_cursor	= soft_cursor,};/* * Calculate the PCD value from the clock rate (in picoseconds). * We take account of the PPCR clock setting. * From PXA Developer's Manual: * *   PixelClock =      LCLK *                ------------- *                2 ( PCD + 1 ) * *   PCD =      LCLK *         ------------- - 1 *         2(PixelClock) * * Where: *   LCLK = LCD/Memory Clock *   PCD = LCCR3[7:0] * * PixelClock here is in Hz while the pixclock argument given is the * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 ) * * The function get_lclk_frequency_10khz returns LCLK in units of * 10khz. Calling the result of this function lclk gives us the * following * *    PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 ) *          -------------------------------------- - 1 *                          2 * * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below. */static inline unsigned int get_pcd(unsigned int pixclock){	unsigned long long pcd;	/* FIXME: Need to take into account Double Pixel Clock mode         * (DPC) bit? or perhaps set it based on the various clock         * speeds */	pcd = (unsigned long long)get_lcdclk_frequency_10khz() * pixclock;	pcd /= 100000000 * 2;	/* no need for this, since we should subtract 1 anyway. they cancel */	/* pcd += 1; */ /* make up for integer math truncations */	return (unsigned int)pcd;}/* * pxafb_activate_var(): *	Configures LCD Controller based on entries in var parameter.  Settings are *	only written to the controller if changes were made. */static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *fbi){	struct pxafb_lcd_reg new_regs;	u_long flags;	u_int lines_per_panel, pcd = get_pcd(var->pixclock);	DPRINTK("Configuring PXA LCD\n");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?