⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pxafb.c

📁 LINUX下PXA的LCD驱动程序原代码,值得一看,
💻 C
📖 第 1 页 / 共 3 页
字号:
	 * setup is based on type of panel supported	 */	lccr0 = fbi->lccr0;	/* 4 bit interface */	if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))	{		// bits 58-61		GPDR1 |= (0xf << 26);		GAFR1_U = (GAFR1_U & ~(0xff << 20)) | (0xaa << 20);		// bits 74-77		GPDR2 |= (0xf << 10);                GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);	}        /* 8 bit interface */        else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||                 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))        {		// bits 58-65                GPDR1 |= (0x3f << 26);                GPDR2 |= (0x3);                GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);                GAFR2_L = (GAFR2_L & ~0xf) | (0xa);                // bits 74-77                GPDR2 |= (0xf << 10);                GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);        }        /* 16 bit interface */        else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))        {		// bits 58-77                GPDR1 |= (0x3f << 26);                GPDR2 |= 0x00003fff;                GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);                GAFR2_L = (GAFR2_L & 0xf0000000) | 0x0aaaaaaa;        }	else	{		printk( KERN_ERR "pxafb_setup_gpio: unable to determine bits per pixel\n");	}}static void pxafb_enable_controller(struct pxafb_info *fbi){	DPRINTK("Enabling LCD controller\n");	/* Sequence from 11.7.10 */	LCCR3 = fbi->reg_lccr3;	LCCR2 = fbi->reg_lccr2;	LCCR1 = fbi->reg_lccr1;	LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB;	/* FIXME we used to have LCD power control here */	FDADR0 = fbi->fdadr0;	FDADR1 = fbi->fdadr1;	LCCR0 |= LCCR0_ENB;	DPRINTK("FDADR0 = 0x%08x\n", (unsigned int)FDADR0);	DPRINTK("FDADR1 = 0x%08x\n", (unsigned int)FDADR1);	DPRINTK("LCCR0 = 0x%08x\n", (unsigned int)LCCR0);	DPRINTK("LCCR1 = 0x%08x\n", (unsigned int)LCCR1);	DPRINTK("LCCR2 = 0x%08x\n", (unsigned int)LCCR2);	DPRINTK("LCCR3 = 0x%08x\n", (unsigned int)LCCR3);}static void pxafb_disable_controller(struct pxafb_info *fbi){	DECLARE_WAITQUEUE(wait, current);	DPRINTK("Disabling LCD controller\n");	/* FIXME add power down GPIO stuff here */	add_wait_queue(&fbi->ctrlr_wait, &wait);	set_current_state(TASK_UNINTERRUPTIBLE);	LCSR = 0xffffffff;	/* Clear LCD Status Register *///	LCCR0 &= ~LCCR0_LDM;	/* Enable LCD Disable Done Interrupt *///	enable_irq(IRQ_LCD);	/* Enable LCD IRQ */	LCCR0 &= ~LCCR0_ENB;	/* Disable LCD Controller */	schedule_timeout(20 * HZ / 1000);	current->state = TASK_RUNNING;	remove_wait_queue(&fbi->ctrlr_wait, &wait);}/* *  pxafb_handle_irq: Handle 'LCD DONE' interrupts. */static void pxafb_handle_irq(int irq, void *dev_id, struct pt_regs *regs){	struct pxafb_info *fbi = dev_id;	unsigned int lcsr = LCSR;	if (lcsr & LCSR_LDD) {		LCCR0 |= LCCR0_LDM;		wake_up(&fbi->ctrlr_wait);	}	LCSR = lcsr;}/* * This function must be called from task context only, since it will * sleep when disabling the LCD controller, or if we get two contending * processes trying to alter state. */static void set_ctrlr_state(struct pxafb_info *fbi, u_int state){	u_int old_state;	down(&fbi->ctrlr_sem);	old_state = fbi->state;	switch (state) {#if 0	case C_DISABLE_CLKCHANGE:		/*		 * Disable controller for clock change.  If the		 * controller is already disabled, then do nothing.		 */		if (old_state != C_DISABLE) {			fbi->state = state;			pxafb_disable_controller(fbi);		}		break;	case C_DISABLE:		/*		 * Disable controller		 */		if (old_state != C_DISABLE) {			fbi->state = state;			pxafb_backlight_off(fbi);			if (old_state != C_DISABLE_CLKCHANGE)				pxafb_disable_controller(fbi);			pxafb_power_down_lcd(fbi);		}		break;#endif	case C_ENABLE_CLKCHANGE:		/*		 * Enable the controller after clock change.  Only		 * do this if we were disabled for the clock change.		 */		if (old_state == C_DISABLE_CLKCHANGE) {			fbi->state = C_ENABLE;			pxafb_enable_controller(fbi);		}		break;#if 0	case C_REENABLE:		/*		 * Re-enable the controller only if it was already		 * enabled.  This is so we reprogram the control		 * registers.		 */		if (old_state == C_ENABLE) {			pxafb_disable_controller(fbi);			pxafb_setup_gpio(fbi);			pxafb_enable_controller(fbi);		}		break;#endif	case C_ENABLE:		/*		 * Power up the LCD screen, enable controller, and		 * turn on the backlight.		 */		if (old_state != C_ENABLE) {			fbi->state = C_ENABLE;			pxafb_setup_gpio(fbi);			pxafb_power_up_lcd(fbi);			pxafb_enable_controller(fbi);			pxafb_backlight_on(fbi);		}		break;	}	up(&fbi->ctrlr_sem);}/* * Our LCD controller task (which is called when we blank or unblank) * via keventd. */static void pxafb_task(void *dummy){	struct pxafb_info *fbi = dummy;	u_int state = xchg(&fbi->task_state, -1);	set_ctrlr_state(fbi, state);}#ifdef CONFIG_CPU_FREQ/* * CPU clock speed change handler.  We need to adjust the LCD timing * parameters when the CPU clock is adjusted by the power management * subsystem. */static intpxafb_clkchg_notifier(struct notifier_block *nb, unsigned long val,			 void *data){	struct pxafb_info *fbi = TO_INF(nb, clockchg);	u_int pcd;	switch (val) {	case CPUFREQ_MINMAX:		/* todo: fill in min/max values */		break;	case CPUFREQ_PRECHANGE:		set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);		break;	case CPUFREQ_POSTCHANGE:		pcd = get_pcd(fbi->fb.var.pixclock);		fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);		set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);		break;	}	return 0;}#endif#ifdef CONFIG_PM/* * Power management hook.  Note that we won't be called from IRQ context, * unlike the blank functions above, so we may sleep. */static intpxafb_pm_callback(struct pm_dev *pm_dev, pm_request_t req, void *data){	struct pxafb_info *fbi = pm_dev->data;	DPRINTK("pm_callback: %d\n", req);	if (req == PM_SUSPEND || req == PM_RESUME) {		int state = (int)data;		if (state == 0) {			/* Enter D0. */			set_ctrlr_state(fbi, C_ENABLE);		} else {			/* Enter D1-D3.  Disable the LCD controller.  */			set_ctrlr_state(fbi, C_DISABLE);		}	}	DPRINTK("done\n");	return 0;}#endif/* * pxafb_map_video_memory(): *      Allocates the DRAM memory for the frame buffer.  This buffer is   *	remapped into a non-cached, non-buffered, memory region to   *      allow palette and pixel writes to occur without flushing the  *      cache.  Once this area is remapped, all virtual memory *      access to the video memory should occur at the new region. */static int __init pxafb_map_video_memory(struct pxafb_info *fbi){	u_long palette_mem_size;	/*	 * We reserve one page for the palette, plus the size	 * of the framebuffer.	 *	 * layout of stuff in memory	 *	 *                fblow descriptor	 *                fbhigh descriptor	 *                palette descriptor	 *                palette	 *   page boundary->	 *                frame buffer	 */	fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);	fbi->map_cpu = consistent_alloc(GFP_KERNEL, fbi->map_size,					&fbi->map_dma);	if (fbi->map_cpu) {		fbi->screen_cpu = fbi->map_cpu + PAGE_SIZE;		fbi->screen_dma = fbi->map_dma + PAGE_SIZE;		fbi->fb.fix.smem_start = fbi->screen_dma;		fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;		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;	}	return fbi->map_cpu ? 0 : -ENOMEM;}/* Fake monspecs to fill in fbinfo structure */static struct fb_monspecs monspecs __initdata = {	30000, 70000, 50, 65, 0	/* Generic */};static struct pxafb_info * __init pxafb_init_fbinfo(void){	struct pxafb_mach_info *inf;	struct pxafb_info *fbi;	fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(struct display) +		      sizeof(u16) * 16, GFP_KERNEL);	if (!fbi)		return NULL;	memset(fbi, 0, sizeof(struct pxafb_info) + sizeof(struct display));	fbi->currcon		= -1;	strcpy(fbi->fb.fix.id, PXA_NAME);	fbi->fb.fix.type	= FB_TYPE_PACKED_PIXELS;	fbi->fb.fix.type_aux	= 0;	fbi->fb.fix.xpanstep	= 0;	fbi->fb.fix.ypanstep	= 0;	fbi->fb.fix.ywrapstep	= 0;	fbi->fb.fix.accel	= FB_ACCEL_NONE;	fbi->fb.var.nonstd	= 0;	fbi->fb.var.activate	= FB_ACTIVATE_NOW;	fbi->fb.var.height	= -1;	fbi->fb.var.width	= -1;	fbi->fb.var.accel_flags	= 0;	fbi->fb.var.vmode	= FB_VMODE_NONINTERLACED;	strcpy(fbi->fb.modename, PXA_NAME);	strcpy(fbi->fb.fontname, "Acorn8x8");	fbi->fb.fbops		= &pxafb_ops;	fbi->fb.changevar	= NULL;	fbi->fb.switch_con	= pxafb_switch;	fbi->fb.updatevar	= pxafb_updatevar;	fbi->fb.blank		= pxafb_blank;	fbi->fb.flags		= FBINFO_FLAG_DEFAULT;	fbi->fb.node		= -1;	fbi->fb.monspecs	= monspecs;	fbi->fb.disp		= (struct display *)(fbi + 1);	fbi->fb.pseudo_palette	= (void *)(fbi->fb.disp + 1);	fbi->rgb[RGB_8]		= &rgb_8;	fbi->rgb[RGB_16]	= &def_rgb_16;	inf = pxafb_get_machine_info(fbi);	fbi->max_xres			= inf->xres;	fbi->fb.var.xres		= inf->xres;	fbi->fb.var.xres_virtual	= inf->xres;	fbi->max_yres			= inf->yres;	fbi->fb.var.yres		= inf->yres;	fbi->fb.var.yres_virtual	= inf->yres;	fbi->max_bpp			= inf->bpp;	fbi->fb.var.bits_per_pixel	= inf->bpp;	fbi->fb.var.pixclock		= inf->pixclock;	fbi->fb.var.hsync_len		= inf->hsync_len;	fbi->fb.var.left_margin		= inf->left_margin;	fbi->fb.var.right_margin	= inf->right_margin;	fbi->fb.var.vsync_len		= inf->vsync_len;	fbi->fb.var.upper_margin	= inf->upper_margin;	fbi->fb.var.lower_margin	= inf->lower_margin;	fbi->fb.var.sync		= inf->sync;	fbi->fb.var.grayscale		= inf->cmap_greyscale;	fbi->cmap_inverse		= inf->cmap_inverse;	fbi->cmap_static		= inf->cmap_static;	fbi->lccr0			= inf->lccr0;	fbi->lccr3			= inf->lccr3;	fbi->state			= C_DISABLE;	fbi->task_state			= (u_char)-1;	fbi->fb.fix.smem_len		= fbi->max_xres * fbi->max_yres *					  fbi->max_bpp / 8;	init_waitqueue_head(&fbi->ctrlr_wait);	INIT_TQUEUE(&fbi->task, pxafb_task, fbi);	init_MUTEX(&fbi->ctrlr_sem);	return fbi;}int __init pxafb_init(void){	struct pxafb_info *fbi;	int ret;	printk("PXA LCD FrameBuffer Driver modified by Michael <ningbo1120@163.com>\n");	fbi = pxafb_init_fbinfo();	ret = -ENOMEM;	if (!fbi)		goto failed;	/* Initialize video memory */	ret = pxafb_map_video_memory(fbi);	if (ret)		goto failed;//	ret = request_irq(IRQ_LCD, pxafb_handle_irq, SA_INTERRUPT,//			  "LCD", fbi);//	if (ret) {//		printk(KERN_ERR "pxafb: failed in request_irq: %d\n", ret);//		goto failed;//	}	pxafb_set_var(&fbi->fb.var, -1, &fbi->fb);	ret = register_framebuffer(&fbi->fb);	if (ret < 0)		goto failed;#ifdef CONFIG_PM	/*	 * Note that the console registers this as well, but we want to	 * power down the display prior to sleeping.	 */	fbi->pm = pm_register(PM_SYS_DEV, PM_SYS_VGA, pxafb_pm_callback);	if (fbi->pm)		fbi->pm->data = fbi;#endif#ifdef CONFIG_CPU_FREQ	fbi->clockchg.notifier_call = pxafb_clkchg_notifier;	cpufreq_register_notifier(&fbi->clockchg);#endif	/*	 * Ok, now enable the LCD controller	 */	set_ctrlr_state(fbi, C_ENABLE);	/* This driver cannot be unloaded at the moment */	MOD_INC_USE_COUNT;	return 0;failed:	if (fbi)		kfree(fbi);	return ret;}int __init pxafb_setup(char *options){#if 0	char *this_opt;	if (!options || !*options)		return 0;	for (this_opt = strtok(options, ","); this_opt;	     this_opt = strtok(NULL, ",")) {		if (!strncmp(this_opt, "bpp:", 4))			current_par.max_bpp =			    simple_strtoul(this_opt + 4, NULL, 0);		if (!strncmp(this_opt, "lccr0:", 6))			lcd_shadow.lccr0 =			    simple_strtoul(this_opt + 6, NULL, 0);		if (!strncmp(this_opt, "lccr1:", 6)) {			lcd_shadow.lccr1 =			    simple_strtoul(this_opt + 6, NULL, 0);			current_par.max_xres =			    (lcd_shadow.lccr1 & 0x3ff) + 16;		}		if (!strncmp(this_opt, "lccr2:", 6)) {			lcd_shadow.lccr2 =			    simple_strtoul(this_opt + 6, NULL, 0);			current_par.max_yres =			    (lcd_shadow.			     lccr0 & LCCR0_SDS) ? ((lcd_shadow.						    lccr2 & 0x3ff) +						   1) *			    2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);		}		if (!strncmp(this_opt, "lccr3:", 6))			lcd_shadow.lccr3 =			    simple_strtoul(this_opt + 6, NULL, 0);	}#endif	return 0;}

⌨️ 快捷键说明

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