新路程------imx6 lvds ioctl

最近有个需求,做一些接口给上层应用调用

于是看了一下驱动,linux有一套标准的framebuffer机制让我们做接口,就是fb_ioctl

首先看对应的framebuffer驱动,在之前的ldb.c中,确实配置了对应的fb_info结构体,但是要修改这个结构体的参数并不需要在ldb.c中做,在mxc_ipuv3_fb.c里

static struct fb_ops mxcfb_ops = {
	.owner = THIS_MODULE,
	.fb_set_par = mxcfb_set_par,
	.fb_check_var = mxcfb_check_var,
	.fb_setcolreg = mxcfb_setcolreg,
	.fb_pan_display = mxcfb_pan_display,
	.fb_ioctl = mxcfb_ioctl,
	.fb_mmap = mxcfb_mmap,
	.fb_fillrect = cfb_fillrect,
	.fb_copyarea = cfb_copyarea,
	.fb_imageblit = cfb_imageblit,
	.fb_blank = mxcfb_blank,
};
这里实现了自己特定的
fb_ioctl 

看看有哪些现成的cmd

/*
 * Function to handle custom ioctls for MXC framebuffer.
 *
 * @param       inode   inode struct
 *
 * @param       file    file struct
 *
 * @param       cmd     Ioctl command to handle
 *
 * @param       arg     User pointer to command arguments
 *
 * @param       fbi     framebuffer information pointer
 */
static int mxcfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)  //上层调用的时候就会把fbi也就是/dev/fb0之类的参数传入,
arg是要写入的数据的首地址
{int retval = 0;int __user *argp = (void __user *)arg;struct mxcfb_info *mxc_fbi = (struct mxcfb_info *)fbi->par;//fbi是linux通用标准结构体,但是不同的ic需要自己特定的framebuffer结构体
//add by matthew_xuan int matt_bpp=0; int matt_res[2]=0; // struct fb_var_screeninfo *matt_var=fbi->var;//switch (cmd) {case MXCFB_SET_LOC_ALPHA:{struct mxcfb_loc_alpha la;if (copy_from_user(&la, (void *)arg, sizeof(la))) { //获取传入的设置数据retval = -EFAULT;break;}if (ipu_disp_set_global_alpha(mxc_fbi->ipu, mxc_fbi->ipu_ch,  
//这个ipu:整个IPU挂接在AXI与AHB总线上面,通过总线,它可以与ARM,VPU,GPU和RAM等模块通信。
//通过LDB控制到LVDS屏,直接控制LCD屏,并且可以通过HDMI或者MIPI来显示。
						      !(bool)la.enable, 0)) {
				retval = -EINVAL;
				break;
			}

			if (la.enable && !la.alpha_in_pixel) {
				struct fb_info *fbi_tmp;
				ipu_channel_t ipu_ch;

				mxc_fbi->alpha_chan_en = true;

				if (mxc_fbi->ipu_ch == MEM_FG_SYNC)
					ipu_ch = MEM_BG_SYNC;
				else if (mxc_fbi->ipu_ch == MEM_BG_SYNC)
					ipu_ch = MEM_FG_SYNC;
				else {
					retval = -EINVAL;
					break;
				}

				fbi_tmp = found_registered_fb(ipu_ch, mxc_fbi->ipu_id);
				if (fbi_tmp)
					((struct mxcfb_info *)(fbi_tmp->par))->alpha_chan_en = false;
			} else
				mxc_fbi->alpha_chan_en = false;

			fbi->var.activate = (fbi->var.activate & ~FB_ACTIVATE_MASK) |
						FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
			mxcfb_set_par(fbi);  //这里把新设置的fbi参数传给notifier去处理

			la.alpha_phy_addr0 = mxc_fbi->alpha_phy_addr0;
			la.alpha_phy_addr1 = mxc_fbi->alpha_phy_addr1;
			if (copy_to_user((void *)arg, &la, sizeof(la))) {
				retval = -EFAULT;
				break;
			}

			if (la.enable)
				dev_dbg(fbi->device,
					"Enable DP local alpha for %s\n",
					fbi->fix.id);
			break;
		}
	
	case MXCFB_GET_FB_BLANK:
		{
			struct mxcfb_info *mxc_fbi =
				(struct mxcfb_info *)fbi->par;

			if (put_user(mxc_fbi->cur_blank, argp))
				return -EFAULT;
			break;
		}
	case MXCFB_SET_DIFMT:
		{
			struct mxcfb_info *mxc_fbi =
				(struct mxcfb_info *)fbi->par;

			if (get_user(mxc_fbi->ipu_di_pix_fmt, argp))
				return -EFAULT;

			break;
		}
	//add by matthew_xuan
	case MXCFB_SET_XRES_YRES:
		{
			
			if (copy_from_user(&matt_res, (void *)arg, sizeof(matt_res))) {
							retval = -EFAULT;
							break;
						}
			fbi->var->xres=matt_res[0];
			fbi->var->yres=matt_res[1];
			mxcfb_set_par(fbi);
		}
	
	default:
		retval = -EINVAL;
	}
	return retval;
}


这里的
#define MXCFB_CSC_UPDATE _IOW('F', 0x2D, struct mxcfb_csc_matrix)
//add by matthew_xuan
#define MXCFB_SET_XRES_YRES   _IOW('F', 0x2E, int struct mxcfb_matt_res)
可以参考这篇文章  http://blog.chinaunix.net/uid-20754793-id-177774.html
接下来看
static int mxcfb_set_par(struct fb_info *fbi)
{
mxcfb_set_fix(fbi);设置了fix结构体
_setup_disp_channel1(fbi); 重新定义输出屏幕的格式
_setup_disp_channel1(fbi);这里启动之后,上层应用调用输出才会成功
}
再看看
static int _setup_disp_channel2(struct fb_info *fbi)
{
retval = ipu_init_channel_buffer(mxc_fbi->ipu,
mxc_fbi->ipu_ch, IPU_INPUT_BUFFER,
fbi_to_pixfmt(fbi),
fbi->var.xres, fbi->var.yres,
fb_stride,
fbi->var.rotate,
base,
base,
fbi->var.accel_flags &
FB_ACCEL_DOUBLE_FLAG ? 0 : base,
0, 0);
}
整个大概的过程就是这样哦

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值