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

📄 sbusfb.c

📁 S3C44B0X下的LCD (framebuffer)驱动资料与相关代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    /*     *  Read a single color register and split it into     *  colors/transparent. Return != 0 for invalid regno.     */static int sbusfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,			  u_int *transp, struct fb_info *info){	struct fb_info_sbusfb *fb = sbusfbinfo(info);	if (!fb->color_map || regno > 255)		return 1;	*red = (fb->color_map CM(regno, 0)<<8) | fb->color_map CM(regno, 0);	*green = (fb->color_map CM(regno, 1)<<8) | fb->color_map CM(regno, 1);	*blue = (fb->color_map CM(regno, 2)<<8) | fb->color_map CM(regno, 2);	*transp = 0;	return 0;}    /*     *  Set a single color register. The values supplied are already     *  rounded down to the hardware's capabilities (according to the     *  entries in the var structure). Return != 0 for invalid regno.     */static int sbusfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,			    u_int transp, struct fb_info *info){	struct fb_info_sbusfb *fb = sbusfbinfo(info);	if (!fb->color_map || regno > 255)		return 1;	red >>= 8;	green >>= 8;	blue >>= 8;	fb->color_map CM(regno, 0) = red;	fb->color_map CM(regno, 1) = green;	fb->color_map CM(regno, 2) = blue;	return 0;}static void do_install_cmap(int con, struct fb_info *info){	struct fb_info_sbusfb *fb = sbusfbinfo(info);		if (con != currcon)		return;	if (fb_display[con].cmap.len)		fb_set_cmap(&fb_display[con].cmap, 1, sbusfb_setcolreg, info);	else		fb_set_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),			    1, sbusfb_setcolreg, info);	if (fb->loadcmap)		(*fb->loadcmap)(fb, &fb_display[con], 0, 256);}static int sbusfb_set_font(struct display *p, int width, int height){	int margin;	int w = p->var.xres_virtual, h = p->var.yres_virtual;	int depth = p->var.bits_per_pixel;	struct fb_info_sbusfb *fb = sbusfbinfod(p);	int x_margin, y_margin;		if (depth > 8) depth = 8;	x_margin = 0;	y_margin = 0;	if (defx_margin < 0 || defy_margin < 0) {		for (margin = 0; def_margins[margin].depth; margin++)			if (w == def_margins[margin].xres &&			    h == def_margins[margin].yres &&			    depth == def_margins[margin].depth) {				x_margin = def_margins[margin].x_margin;				y_margin = def_margins[margin].y_margin;				break;			}	} else {		x_margin = defx_margin;		y_margin = defy_margin;	}	x_margin += ((w - 2*x_margin) % width) / 2;	y_margin += ((h - 2*y_margin) % height) / 2;	p->var.xres = w - 2*x_margin;	p->var.yres = h - 2*y_margin;		fb->cursor.mode |= CURSOR_SHAPE;		if (fb->margins)		fb->margins(fb, p, x_margin, y_margin);	if (fb->x_margin != x_margin || fb->y_margin != y_margin) {		fb->x_margin = x_margin; fb->y_margin = y_margin;		sbusfb_clear_margin(p, 0);	}	return 1;}void sbusfb_palette(int enter){	int i;	struct display *p;		for (i = 0; i < MAX_NR_CONSOLES; i++) {		p = &fb_display[i];		if (p->dispsw && p->dispsw->setup == sbusfb_disp_setup &&		    p->fb_info->display_fg &&		    p->fb_info->display_fg->vc_num == i) {			struct fb_info_sbusfb *fb = sbusfbinfod(p);			if (fb->restore_palette) {				if (enter)					fb->restore_palette(fb);				else if (vt_cons[i]->vc_mode != KD_GRAPHICS)				         vc_cons[i].d->vc_sw->con_set_palette(vc_cons[i].d, color_table);			}		}	}}    /*     *  Initialisation     */     extern void (*prom_palette)(int);static void __init sbusfb_init_fb(int node, int parent, int fbtype,				  struct sbus_dev *sbdp){	struct fb_fix_screeninfo *fix;	struct fb_var_screeninfo *var;	struct display *disp;	struct fb_info_sbusfb *fb;	struct fbtype *type;	int linebytes, w, h, depth;	char *p = NULL;	int margin;	fb = kmalloc(sizeof(struct fb_info_sbusfb), GFP_ATOMIC);	if (!fb) {		prom_printf("Could not allocate sbusfb structure\n");		return;	}		if (!prom_palette)		prom_palette = sbusfb_palette;		memset(fb, 0, sizeof(struct fb_info_sbusfb));	fix = &fb->fix;	var = &fb->var;	disp = &fb->disp;	type = &fb->type;		spin_lock_init(&fb->lock);	fb->prom_node = node;	fb->prom_parent = parent;	fb->sbdp = sbdp;	if (sbdp)		fb->iospace = sbdp->reg_addrs[0].which_io;	type->fb_type = fbtype;	memset(&fb->emulations, 0xff, sizeof(fb->emulations));	fb->emulations[0] = fbtype;	#ifndef __sparc_v9__	disp->screen_base = (unsigned char *)prom_getintdefault(node, "address", 0);#endif		type->fb_height = h = prom_getintdefault(node, "height", 900);	type->fb_width  = w = prom_getintdefault(node, "width", 1152);sizechange:	type->fb_depth  = depth = (fbtype == FBTYPE_SUN2BW) ? 1 : 8;	linebytes = prom_getintdefault(node, "linebytes", w * depth / 8);	type->fb_size   = PAGE_ALIGN((linebytes) * h);		if (defx_margin < 0 || defy_margin < 0) {		for (margin = 0; def_margins[margin].depth; margin++)			if (w == def_margins[margin].xres &&			    h == def_margins[margin].yres &&			    depth == def_margins[margin].depth) {				fb->x_margin = def_margins[margin].x_margin;				fb->y_margin = def_margins[margin].y_margin;				break;			}	} else {		fb->x_margin = defx_margin;		fb->y_margin = defy_margin;	}	fb->x_margin += ((w - 2*fb->x_margin) & 7) / 2;	fb->y_margin += ((h - 2*fb->y_margin) & 15) / 2;	var->xres_virtual = w;	var->yres_virtual = h;	var->xres = w - 2*fb->x_margin;	var->yres = h - 2*fb->y_margin;		var->bits_per_pixel = depth;	var->height = var->width = -1;	var->pixclock = 10000;	var->vmode = FB_VMODE_NONINTERLACED;	var->red.length = var->green.length = var->blue.length = 8;	fix->line_length = linebytes;	fix->smem_len = type->fb_size;	fix->type = FB_TYPE_PACKED_PIXELS;	fix->visual = FB_VISUAL_PSEUDOCOLOR;		fb->info.node = -1;	fb->info.fbops = &sbusfb_ops;	fb->info.disp = disp;	strcpy(fb->info.fontname, fontname);	fb->info.changevar = NULL;	fb->info.switch_con = &sbusfbcon_switch;	fb->info.updatevar = &sbusfbcon_updatevar;	fb->info.blank = &sbusfbcon_blank;	fb->info.flags = FBINFO_FLAG_DEFAULT;		fb->cursor.hwsize.fbx = 32;	fb->cursor.hwsize.fby = 32;		if (depth > 1 && !fb->color_map)		fb->color_map = kmalloc(256 * 3, GFP_ATOMIC);			switch(fbtype) {#ifdef CONFIG_FB_CREATOR	case FBTYPE_CREATOR:		p = creatorfb_init(fb); break;#endif#ifdef CONFIG_FB_CGSIX	case FBTYPE_SUNFAST_COLOR:		p = cgsixfb_init(fb); break;#endif#ifdef CONFIG_FB_CGTHREE	case FBTYPE_SUN3COLOR:		p = cgthreefb_init(fb); break;#endif#ifdef CONFIG_FB_TCX	case FBTYPE_TCXCOLOR:		p = tcxfb_init(fb); break;#endif#ifdef CONFIG_FB_LEO	case FBTYPE_SUNLEO:		p = leofb_init(fb); break;#endif#ifdef CONFIG_FB_BWTWO	case FBTYPE_SUN2BW:		p = bwtwofb_init(fb); break;#endif#ifdef CONFIG_FB_CGFOURTEEN	case FBTYPE_MDICOLOR:		p = cgfourteenfb_init(fb); break;#endif#ifdef CONFIG_FB_P9100	case FBTYPE_P9100COLOR:		/* Temporary crock. For now we are a cg3 */		p = p9100fb_init(fb); type->fb_type = FBTYPE_SUN3COLOR; break;#endif	}		if (!p) {		if (fb->color_map)			kfree(fb->color_map);		kfree(fb);		return;	}		if (p == SBUSFBINIT_SIZECHANGE)		goto sizechange;	disp->dispsw = &fb->dispsw;	if (fb->setcursor) {		fb->dispsw.cursor = sbusfb_cursor;		if (curblink) {			fb->cursor.blink_rate = DEFAULT_CURSOR_BLINK_RATE;			init_timer(&fb->cursor.timer);			fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;			fb->cursor.timer.data = (unsigned long)fb;			fb->cursor.timer.function = sbusfb_cursor_timer_handler;			add_timer(&fb->cursor.timer);		}	}	fb->cursor.mode = CURSOR_SHAPE;	fb->dispsw.set_font = sbusfb_set_font;	fb->setup = fb->dispsw.setup;	fb->dispsw.setup = sbusfb_disp_setup;	fb->dispsw.clear_margins = NULL;	disp->var = *var;	disp->visual = fix->visual;	disp->type = fix->type;	disp->type_aux = fix->type_aux;	disp->line_length = fix->line_length;		if (fb->blank)		disp->can_soft_blank = 1;	sbusfb_set_var(var, -1, &fb->info);	if (register_framebuffer(&fb->info) < 0) {		if (fb->color_map)			kfree(fb->color_map);		kfree(fb);		return;	}	printk(KERN_INFO "fb%d: %s\n", GET_FB_IDX(fb->info.node), p);}static inline int known_card(char *name){	char *p;	for (p = name; *p && *p != ','; p++);	if (*p == ',') name = p + 1;	if (!strcmp(name, "cgsix") || !strcmp(name, "cgthree+"))		return FBTYPE_SUNFAST_COLOR;	if (!strcmp(name, "cgthree") || !strcmp(name, "cgRDI"))		return FBTYPE_SUN3COLOR;	if (!strcmp(name, "cgfourteen"))		return FBTYPE_MDICOLOR;	if (!strcmp(name, "leo"))		return FBTYPE_SUNLEO;	if (!strcmp(name, "bwtwo"))		return FBTYPE_SUN2BW;	if (!strcmp(name, "tcx"))		return FBTYPE_TCXCOLOR;	if (!strcmp(name, "p9100"))		return FBTYPE_P9100COLOR;	return FBTYPE_NOTYPE;}#ifdef CONFIG_FB_CREATORstatic void creator_fb_scan_siblings(int root){	int node, child;	child = prom_getchild(root);	for (node = prom_searchsiblings(child, "SUNW,ffb"); node;	     node = prom_searchsiblings(prom_getsibling(node), "SUNW,ffb"))		sbusfb_init_fb(node, root, FBTYPE_CREATOR, NULL);	for (node = prom_searchsiblings(child, "SUNW,afb"); node;	     node = prom_searchsiblings(prom_getsibling(node), "SUNW,afb"))		sbusfb_init_fb(node, root, FBTYPE_CREATOR, NULL);}static void creator_fb_scan(void){	int root;	creator_fb_scan_siblings(prom_root_node);	root = prom_getchild(prom_root_node);	for (root = prom_searchsiblings(root, "upa"); root;	     root = prom_searchsiblings(prom_getsibling(root), "upa"))		creator_fb_scan_siblings(root);}#endifint __init sbusfb_init(void){	int type;	struct sbus_dev *sbdp;	struct sbus_bus *sbus;	char prom_name[40];	extern int con_is_present(void);		if (!con_is_present()) return -ENXIO;	#ifdef CONFIG_FB_CREATOR	creator_fb_scan();#endif#ifdef CONFIG_SUN4	sbusfb_init_fb(0, 0, FBTYPE_SUN2BW, NULL);#endif#if defined(CONFIG_FB_CGFOURTEEN) && !defined(__sparc_v9__)	{		int root, node;		root = prom_getchild(prom_root_node);		root = prom_searchsiblings(root, "obio");		if (root && 		    (node = prom_searchsiblings(prom_getchild(root), "cgfourteen"))) {			sbusfb_init_fb(node, root, FBTYPE_MDICOLOR, NULL);		}	}#endif	if (sbus_root == NULL)		return 0;	for_all_sbusdev(sbdp, sbus) {		type = known_card(sbdp->prom_name);		if (type == FBTYPE_NOTYPE)			continue;		if (prom_getproperty(sbdp->prom_node, "emulation",				     prom_name, sizeof(prom_name)) > 0) {			type = known_card(prom_name);			if (type == FBTYPE_NOTYPE)				type = known_card(sbdp->prom_name);		}		sbusfb_init_fb(sbdp->prom_node, sbdp->bus->prom_node, type, sbdp);	}	return 0;}MODULE_LICENSE("GPL");	

⌨️ 快捷键说明

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