【1】camera端设备驱动api
__ccic_cam_cmd(pxa910_camera.c)--> command-->> ov5640_mipi_command(供host端调用的接口ov5640_mipi.c)-- >
switch case
{
case v4l2定义的ioctl:
调用camera操作函数(通过i2c)
}
【2】camera控制器驱动
struct ccic_camera
{
int irq;
struct platform_device *pdev;
struct video_device v4ldev;//重要
struct i2c_adapter i2c_adapter;
struct i2c_client *sensor;
struct i2c_client *sensors[SENSOR_MAX];//重要
unsigned int bus_type[SENSOR_MAX]; /* parrallel or MIPI */
unsigned char __iomem *regs;
struct list_head dev_list; /* link to other devices */
................
};
static int pxa910_camera_probe(struct platform_device *pdev)
{
struct ccic_camera *cam;
cam = kzalloc(sizeof(struct ccic_camera), GFP_KERNEL);
tasklet_init(&cam->s_tasklet, ccic_frame_tasklet, (unsigned long) cam);
cam->regs = ioremap(res->start, SZ_4K);
ret = request_irq(cam->irq, ccic_irq, IRQF_SHARED, "pxa910-camera", cam);
ccic_ctlr_init(cam);
cam->v4ldev = ccic_v4l_template;//!!!!
video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1);
ccic_alloc_dma_bufs(cam, 1)
}
static struct video_device ccic_v4l_template =
{
.name = "pxa910-camera",
.fops = &ccic_v4l_fops,
.ioctl_ops = &ccic_ioctl_ops,
};
static const struct v4l2_file_operations ccic_v4l_fops =
{
.owner = THIS_MODULE,
.open = ccic_v4l_open,
.release = ccic_v4l_realease,
.poll = ccic_v4l_poll,
.mmap = ccic_v4l_mmap,
.ioctl = ccic_v4l_ioctl,
};
struct v4l2_ioctl_ops ccic_ioctl_ops =
{
........
}
static int __video_register_device(struct video_device *vdev, int type, int nr, int warn_if_nr_in_use)
{
vdev->cdev = cdev_alloc();
vdev->cdev->ops = &v4l2_fops;
cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1);
vdev->dev.class = &video_class;
device_register(&vdev->dev);
}
static const struct file_operations v4l2_fops =
{
.read = v4l2_read,
.write = v4l2_write,
.open = v4l2_open,
.mmap = v4l2_mmap,
.ioctl = v4l2_ioctl,
.poll = v4l2_poll,
}
static ssize_t v4l2_read(xxxx)
{
struct video_device *vdev = video_devdata(filp);
vdev->fops->read(filp, buf, sz, off);
}
static int v4l2_ioctl(xxx)
{
struct video_device *vdev = video_devdata(filp);
vdev->fops->ioctl->(filp, cmd, arg);// ccic_v4l_fops.ccic_v4l_ioctl->video_ioctl2(file, cmd, arg)->__video_do_ioctl(file, cmd, arg)->ccic_v4l_template->ccic_ioctl_ops;然后进行switch (case)各个接口函数,各个接口在调用__ccic_cam_cmd去操作camera设备
}
【3】向host添加camera设备的函数
int ccic_sensor_attach(struct i2c_client *client)
{
struct ccic_camera *cam;
cam->sensors[SENSOR_HIGH] = client;
}