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

📄 sgivwfb.c

📁 S3C44B0X下的LCD (framebuffer)驱动资料与相关代码
💻 C
📖 第 1 页 / 共 2 页
字号:
}static void sgivwfb_encode_fix(struct fb_fix_screeninfo *fix,			       struct fb_var_screeninfo *var){  memset(fix, 0, sizeof(struct fb_fix_screeninfo));  strcpy(fix->id, sgivwfb_name);  fix->smem_start = sgivwfb_mem_phys;  fix->smem_len = sgivwfb_mem_size;  fix->type = FB_TYPE_PACKED_PIXELS;  fix->type_aux = 0;  switch (var->bits_per_pixel) {  case 8:    fix->visual = FB_VISUAL_PSEUDOCOLOR;    break;  default:    fix->visual = FB_VISUAL_TRUECOLOR;    break;  }  fix->ywrapstep = ywrap;  fix->xpanstep = 0;  fix->ypanstep = ypan;  fix->line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);  fix->mmio_start = DBE_REG_PHYS;  fix->mmio_len = DBE_REG_SIZE;}/* *  Read a single color register and split it into *  colors/transparent. Return != 0 for invalid regno. */static int sgivwfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,                             u_int *transp, struct fb_info *info){  if (regno > 255)    return 1;  *red =   palette[regno].red << 8;  *green = palette[regno].green << 8;  *blue =  palette[regno].blue << 8;  *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 sgivwfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,                             u_int transp, struct fb_info *info){  if (regno > 255)    return 1;  red >>= 8;  green >>= 8;  blue >>= 8;  palette[regno].red = red;  palette[regno].green = green;  palette[regno].blue = blue;  /* wait for the color map FIFO to have a free entry */  while (cmap_fifo == 0)    cmap_fifo = regs->cm_fifo;  regs->cmap[regno] = (red << 24) | (green << 16) | (blue << 8);  cmap_fifo--;			/* assume FIFO is filling up */  return 0;}static void do_install_cmap(int con, struct fb_info *info){    if (con != currcon)	return;    if (fb_display[con].cmap.len)	fb_set_cmap(&fb_display[con].cmap, 1, sgivwfb_setcolreg, info);    else	fb_set_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), 1,		    sgivwfb_setcolreg, info);}/* ---------------------------------------------------- *//* *  Get the Fixed Part of the Display */static int sgivwfb_get_fix(struct fb_fix_screeninfo *fix, int con,			   struct fb_info *info){  struct fb_var_screeninfo *var;  if (con == -1)    var = &par_current.var;  else    var = &fb_display[con].var;  sgivwfb_encode_fix(fix, var);  return 0;}/* *  Get the User Defined Part of the Display. If a real par get it form there */static int sgivwfb_get_var(struct fb_var_screeninfo *var, int con,			   struct fb_info *info){  if (con == -1)    *var = par_current.var;  else    *var = fb_display[con].var;  return 0;}/* *  Set the User Defined Part of the Display. Again if par use it to get *  real video mode. */static int sgivwfb_set_var(struct fb_var_screeninfo *var, int con,			   struct fb_info *info){  int err, activate = var->activate;  int oldxres, oldyres, oldvxres, oldvyres, oldbpp;  u_long line_length;  u_long min_mode;  int req_dot;  int test_mode;  struct dbe_timing_info *timing;  struct display *display;  if (con >= 0)    display = &fb_display[con];  else    display = &disp;	/* used during initialization */  /*   *  FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!   *  as FB_VMODE_SMOOTH_XPAN is only used internally   */  if (var->vmode & FB_VMODE_CONUPDATE) {    var->vmode |= FB_VMODE_YWRAP;    var->xoffset = display->var.xoffset;    var->yoffset = display->var.yoffset;  }  /* XXX FIXME - forcing var's */  var->xoffset = 0;  var->yoffset = 0;  /* Limit bpp to 8, 16, and 32 */  if (var->bits_per_pixel <= 8)    var->bits_per_pixel = 8;  else if (var->bits_per_pixel <= 16)    var->bits_per_pixel = 16;  else if (var->bits_per_pixel <= 32)    var->bits_per_pixel = 32;  else    return -EINVAL;  var->grayscale = 0;           /* No grayscale for now */  /* determine valid resolution and timing */  for (min_mode=0; min_mode<DBE_VT_SIZE; min_mode++) {    if (dbeVTimings[min_mode].width >= var->xres &&        dbeVTimings[min_mode].height >= var->yres)      break;  }  if (min_mode == DBE_VT_SIZE)    return -EINVAL;             /* Resolution to high */  /* XXX FIXME - should try to pick best refresh rate */  /* for now, pick closest dot-clock within 3MHz*/#error "Floating point not allowed in kernel"    req_dot = (int)((1.0e3/1.0e6) / (1.0e-12 * (float)var->pixclock));  printk(KERN_INFO "sgivwfb: requested pixclock=%d ps (%d KHz)\n", var->pixclock,	 req_dot);  test_mode=min_mode;  while (dbeVTimings[min_mode].width == dbeVTimings[test_mode].width) {    if (dbeVTimings[test_mode].cfreq+3000 > req_dot)      break;    test_mode++;  }  if (dbeVTimings[min_mode].width != dbeVTimings[test_mode].width)    test_mode--;  min_mode = test_mode;  timing = &dbeVTimings[min_mode];  printk(KERN_INFO "sgivwfb: granted dot-clock=%d KHz\n", timing->cfreq);  /* Adjust virtual resolution, if necessary */  if (var->xres > var->xres_virtual || (!ywrap && !ypan))    var->xres_virtual = var->xres;  if (var->yres > var->yres_virtual || (!ywrap && !ypan))    var->yres_virtual = var->yres;  /*   *  Memory limit   */  line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);  if (line_length*var->yres_virtual > sgivwfb_mem_size)    return -ENOMEM;             /* Virtual resolution to high */  switch (var->bits_per_pixel)    {    case 8:      var->red.offset = 0;      var->red.length = 8;      var->green.offset = 0;      var->green.length = 8;      var->blue.offset = 0;      var->blue.length = 8;      var->transp.offset = 0;      var->transp.length = 0;      break;    case 16:	/* RGBA 5551 */      var->red.offset = 11;      var->red.length = 5;      var->green.offset = 6;      var->green.length = 5;      var->blue.offset = 1;      var->blue.length = 5;      var->transp.offset = 0;      var->transp.length = 0;      break;    case 32:	/* RGB 8888 */      var->red.offset = 0;      var->red.length = 8;      var->green.offset = 8;      var->green.length = 8;      var->blue.offset = 16;      var->blue.length = 8;      var->transp.offset = 24;      var->transp.length = 8;      break;    }  var->red.msb_right = 0;  var->green.msb_right = 0;  var->blue.msb_right = 0;  var->transp.msb_right = 0;  /* set video timing information */  var->pixclock = (__u32)(1.0e+9/(float)timing->cfreq);  var->left_margin = timing->htotal - timing->hsync_end;  var->right_margin = timing->hsync_start - timing->width;  var->upper_margin = timing->vtotal - timing->vsync_end;  var->lower_margin = timing->vsync_start - timing->height;  var->hsync_len = timing->hsync_end - timing->hsync_start;  var->vsync_len = timing->vsync_end -  timing->vsync_start;  if ((activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {    oldxres = display->var.xres;    oldyres = display->var.yres;    oldvxres = display->var.xres_virtual;    oldvyres = display->var.yres_virtual;    oldbpp = display->var.bits_per_pixel;    display->var = *var;    par_current.var = *var;    par_current.timing_num = min_mode;    if (oldxres != var->xres || oldyres != var->yres ||	oldvxres != var->xres_virtual || oldvyres != var->yres_virtual ||	oldbpp != var->bits_per_pixel || !par_current.valid) {      struct fb_fix_screeninfo fix;      printk(KERN_INFO "sgivwfb: new video mode xres=%d yres=%d bpp=%d\n",	     var->xres, var->yres, var->bits_per_pixel);      printk(KERN_INFO "         vxres=%d vyres=%d\n",	     var->xres_virtual, var->yres_virtual);      activate_par(&par_current);      sgivwfb_encode_fix(&fix, var);      display->screen_base = (char *)fbmem;      display->visual = fix.visual;      display->type = fix.type;      display->type_aux = fix.type_aux;      display->ypanstep = fix.ypanstep;      display->ywrapstep = fix.ywrapstep;      display->line_length = fix.line_length;      display->can_soft_blank = 1;      display->inverse = 0;      if (oldbpp != var->bits_per_pixel || !par_current.valid) {	if ((err = fb_alloc_cmap(&display->cmap, 0, 0)))	  return err;	do_install_cmap(con, info);      }      switch (var->bits_per_pixel) {#ifdef FBCON_HAS_CFB8      case 8:	display->dispsw = &fbcon_cfb8;	break;#endif#ifdef FBCON_HAS_CFB16      case 16:	display->dispsw = &fbcon_cfb16;	display->dispsw_data = fbcon_cmap.cfb16;	break;#endif#ifdef FBCON_HAS_CFB32      case 32:	display->dispsw = &fbcon_cfb32;	display->dispsw_data = fbcon_cmap.cfb32;	break;#endif      default:	display->dispsw = &fbcon_dummy;	break;      }      par_current.valid = 1;      if (fb_info.changevar)	(*fb_info.changevar)(con);    }  }  return 0;}/* *  Get the Colormap */static int sgivwfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,			    struct fb_info *info){  if (con == currcon) /* current console? */    return fb_get_cmap(cmap, kspc, sgivwfb_getcolreg, info);  else if (fb_display[con].cmap.len) /* non default colormap? */    fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);  else    fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),		 cmap, kspc ? 0 : 2);  return 0;}/* *  Set the Colormap */static int sgivwfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,			    struct fb_info *info){  int err;  if (!fb_display[con].cmap.len) {	/* no colormap allocated? */    int size = fb_display[con].var.bits_per_pixel == 16 ? 32 : 256;    if ((err = fb_alloc_cmap(&fb_display[con].cmap, size, 0)))      return err;  }  if (con == currcon)			/* current console? */    return fb_set_cmap(cmap, kspc, sgivwfb_setcolreg, info);  else    fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);  return 0;}static int sgivwfb_mmap(struct fb_info *info, struct file *file,                        struct vm_area_struct *vma){  unsigned long size = vma->vm_end - vma->vm_start;  unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;  if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))	return -EINVAL;  if (offset+size > sgivwfb_mem_size)    return -EINVAL;  offset += sgivwfb_mem_phys;  pgprot_val(vma->vm_page_prot) = pgprot_val(vma->vm_page_prot) | _PAGE_PCD;  if (remap_page_range(vma->vm_start, offset, size, vma->vm_page_prot))    return -EAGAIN;  vma->vm_file = file;  printk(KERN_DEBUG "sgivwfb: mmap framebuffer P(%lx)->V(%lx)\n", offset, vma->vm_start);  return 0;}int __init sgivwfb_setup(char *options){  char *this_opt;  fb_info.fontname[0] = '\0';  if (!options || !*options)    return 0;  while ((this_opt = strsep(&options, ",")) != NULL) {    if (!strncmp(this_opt, "font:", 5))      strcpy(fb_info.fontname, this_opt+5);  }  return 0;}/* *  Initialisation */int __init sgivwfb_init(void){  printk(KERN_INFO "sgivwfb: framebuffer at 0x%lx, size %ldk\n",	 sgivwfb_mem_phys, sgivwfb_mem_size/1024);  regs = (asregs*)ioremap_nocache(DBE_REG_PHYS, DBE_REG_SIZE);  if (!regs) {    printk(KERN_ERR "sgivwfb: couldn't ioremap registers\n");    goto fail_ioremap_regs;  }#ifdef CONFIG_MTRR  mtrr_add((unsigned long)sgivwfb_mem_phys, sgivwfb_mem_size, MTRR_TYPE_WRCOMB, 1);#endif  strcpy(fb_info.modename, sgivwfb_name);  fb_info.changevar = NULL;  fb_info.node = -1;  fb_info.fbops = &sgivwfb_ops;  fb_info.disp = &disp;  fb_info.switch_con = &sgivwfbcon_switch;  fb_info.updatevar = &sgivwfbcon_updatevar;  fb_info.blank = &sgivwfbcon_blank;  fb_info.flags = FBINFO_FLAG_DEFAULT;  fbmem = ioremap_nocache((unsigned long)sgivwfb_mem_phys, sgivwfb_mem_size);  if (!fbmem) {    printk(KERN_ERR "sgivwfb: couldn't ioremap fbmem\n");    goto fail_ioremap_fbmem;  }  /* turn on default video mode */  sgivwfb_set_var(&par_current.var, -1, &fb_info);  if (register_framebuffer(&fb_info) < 0) {    printk(KERN_ERR "sgivwfb: couldn't register framebuffer\n");    goto fail_register_framebuffer;  }  printk(KERN_INFO "fb%d: Virtual frame buffer device, using %ldK of video memory\n",	 GET_FB_IDX(fb_info.node), sgivwfb_mem_size>>10);  return 0; fail_register_framebuffer:  iounmap((char*)fbmem); fail_ioremap_fbmem:  iounmap(regs); fail_ioremap_regs:  return -ENXIO;}static int sgivwfbcon_switch(int con, struct fb_info *info){  /* Do we have to save the colormap? */  if (fb_display[currcon].cmap.len)    fb_get_cmap(&fb_display[currcon].cmap, 1, sgivwfb_getcolreg, info);  currcon = con;  /* Install new colormap */  do_install_cmap(con, info);  return 0;}/* *  Update the `var' structure (called by fbcon.c) */static int sgivwfbcon_updatevar(int con, struct fb_info *info){    /* Nothing */    return 0;}/* *  Blank the display. */static void sgivwfbcon_blank(int blank, struct fb_info *info){    /* Nothing */}#ifdef MODULEMODULE_LICENSE("GPL");int init_module(void){  return sgivwfb_init();}void cleanup_module(void){  unregister_framebuffer(&fb_info);  dbe_TurnOffDma();  iounmap(regs);  iounmap(fbmem);}#endif /* MODULE */

⌨️ 快捷键说明

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