Collection Driver (2)

Source: Internet
Author: User

Happy shrimp

Http://blog.csdn.net/lights_joy/

Lights@hb165.com

This article applies

ADSP-BF561

Uclinux-2008r1.5-rc3 (smp patch)

Visual DSP ++ 5.0 (Update 5)

BF561-EZKIT

Reprinted, but keep the author information

 

In this paper, we only do a simple learning for BF561-EZKIT video acquisition.

1.1 Overall Structure
To achieve Video Acquisition first in the hardware to use a Video Acquisition chip to complete the analog signal to digital signal conversion, In the BF561-EZKIT using adv7183. This chip can be configured through the I2C bus, so the kernel must provide a driver for it, which is implemented by the drivers/Media/Video/Blackfin/adv7183b. c file. Note that this driver is only used by bfin camera, and does not register anything with the kernel, nor does the kernel feel the existence of this driver.

After a collection chip is available, it must be connected to 561, usually the PPI interface. Because different collection chips can be used, the kernel abstracts them, all called camera, and then packs them into a driver named "Blackfin CMOS Camera" to register with the v4l module. This driver is implemented by drivers/Media/Video/Blackfin/blackfin_cam.c.

After the video collection hardware is available, the kernel provides users with a virtual device/dev/video4linux, Which is packaged with various hardware, provides a unified video operation interface, also known as v4l.

1.2 adv7183 driver
This driver is driven by drivers/Media/Video/Blackfin/adv7183b. c file implementation, but looking at the entire file, there is no definition like module_init, that is to say, this module will not be directly initialized when the kernel is started. But at the end of the file, we can find such code:

 

Static struct bcap_camera_ops adv7183b_ops = {

. Cam_control = adv7183b_cam_control,

. Create_sysfs = adv7183b_create_sysfs,

. Power = adv7183b_power,

};

 

Struct bcap_camera_ops * get_camops (void)

{

Printk (kern_info "Driver for adv7183b get_camops/N ");

Return (& adv7183b_ops );

 

}

You can easily find the get_camops function. This function is provided in multiple files in the drivers/Media/Video/Blackfin/directory and called in blackfin_cam.c. Therefore, it can be confirmed that the driver of the 7183 or other Blackfin acquisition chip provides a unified interface to blackfin_cam.c through struct bcap_camera_ops.

The entire file shows that most of the functions are directly returned. Only the initialization functions are interesting:

Static int adv7183b_init (struct i2c_client * client, u32 Arg)

{

 

Printk (kern_info "Driver for adv7183b init/N ");

If (adv7183b_probe (client )){

Return-enodev;

}

 

/* Configuration example, taken from datasheet adv7183b */

 

/* Examples using 27 MHz clock

* Mode 1 CVBS input (composite video on ain5)

* All standards are supported through autodetect, 8-bit, ITU-R bt.656 output on p15 to P8.

*/

Adv7183b_write_byte (client, 0x00, 0x04);/* CVBS input on ain5 .*/

Adv7183b_write_byte (client, 0x15, 0x00);/* slow down digital clamps .*/

Adv7183b_write_byte (client, 0x17, 0x41);/* Set CSFM to sh1 .*/

Adv7183b_write_byte (client, 0x3a, 0x16);/* power down ADC 1 and ADC 2 .*/

Adv7183b_write_byte (client, 0x50, 0x04);/* Set DNR threshold to 4 for flat response .*/

Adv7183b_write_byte (client, 0x0e, 0x80);/* Adi recommended programming sequence .*/

/* This sequence must be followed exactly when setting up the decoder .*/

Adv7183b_write_byte (client, 0x50, 0x20);/* recommended setting .*/

Adv7183b_write_byte (client, 0x52, 0x18);/* recommended setting .*/

Adv7183b_write_byte (client, 0x58, 0xed);/* recommended setting .*/

Adv7183b_write_byte (client, 0x77, 0xc5);/* recommended setting .*/

Adv7183b_write_byte (client, 0x7c, 0x93);/* recommended setting .*/

Adv7183b_write_byte (client, 0x7d, 0x00);/* recommended setting .*/

Adv7183b_write_byte (client, 0xd0, 0x48);/* recommended setting .*/

Adv7183b_write_byte (client, 0xd5, 0xa0);/* recommended setting .*/

Adv7183b_write_byte (client, 0xd7, 0xea);/* recommended setting .*/

Adv7183b_write_byte (client, 0xe4, 0x3e);/* recommended setting .*/

Adv7183b_write_byte (client, 0xe9, 0x3e);/* recommended setting .*/

Adv7183b_write_byte (client, 0xea, 0x0f);/* recommended setting .*/

Adv7183b_write_byte (client, 0x0e, 0x00);/* recommended setting .*/

 

Return 0;

 

}

This function will be called in blackfin_cam.c.

1.3 Blackfin CMOS camera driver
The kernel defines a unified interface for the video capture device connected to the PPI interface, and then uses a driver called Blackfin CMOS camera to represent this type of device. The implementation of this driver is completed by blackfin_cam.c.

First, let's take a look at its initialization:

 

Static _ init int bcap_init (void)

{

Int err;

Struct bcap_camera_ops * OPS;

...............

 

Err = i2c_add_driver (& sensor_driver );

................

 

Err = setup_pin_mux (1 );

...............

}

This initialization function is mainly called in two ways. i2c_add_driver is used to register an I2C device, and setup_pin_mux is used to configure the reusable gpio/PPI pins.

When registering the I2C driver, it will eventually call the sensor_attach_adapter function:

Static int sensor_attach_adapter (struct i2c_adapter * adapter)

{

Int I;

Bug_on (adapter = NULL );

Pr_debug ("% s: Starting probe for adapter % s (0x % x)/n", Sensor_Name,

Adapter-> name, adapter-> ID );

I = i2c_probe (adapter, & addr_data, & sensor_detect_client );

Return I;

}

Under i2c_probe, execute the sensor_detect_client function:

Static int sensor_detect_client (struct i2c_adapter * adapter, int address,

Int kind)

{

Int err;

Struct i2c_client * new_client;

Struct sensor_data * data;

2010tmp = 0;

 

....................

Err = data-> cam_ops-> cam_control (new_client, cam_cmd_init, 1 );

 

If (ERR)

Goto error_out;

 

Data-> cam_ops-> cam_control (new_client, cam_pai_set_pixfmt,

Default_palette (force_palette ));

 

Err = bcap_init_v4l (data );

................

}

One of the two main functions of this function is to call the initialization function of the adv7183 driver and configure it. The other is to prepare a unified interface for the driver of the/dev/video virtual device, this task is completed by bcap_init_v4l:

Static int bcap_init_v4l (struct sensor_data * Data)

{

Int err, I;

.....................

Memcpy (bcap_dev-> videodev, & bcap_template, sizeof (bcap_template ));

Bcap_dev-> frame_count = 0;

Err = video_register_device (bcap_dev-> videodev, vfl_type_grabber, 0 );

If (ERR ){

Printk (kern_notice

"Unable to register video4linux driver for % s/n ",

Bcap_dev-> videodev-> name );

Goto error_out_video;

}

..............

 

Bcap_create_sysfs (bcap_dev );

...............

}

This function first constructs a standard interface for use by the/dev/vedio4linux driver, and then calls video_register_device to register this interface to the/dev/video driver, finally, calling bcap_create_sysfs gave adv7183 a chance to create a device node in VFS. Of course, 7183 gave up this opportunity.

1.4 vedio4linux driver
This driver is implemented by the drivers/Media/Video/videodev. c file to check its initialization process:

 

Static int _ init videodev_init (void)

{

Int ret;

 

Printk (kern_info "Linux video capture interface: v2.00/N ");

If (register_chrdev (video_major, video_name, & video_fops )){

Printk (kern_warning "video_dev: Unable to get Major % d/N", video_major );

Return-EIO;

}

 

Ret = class_register (& video_class );

If (Ret <0 ){

Unregister_chrdev (video_major, video_name );

Printk (kern_warning "video_dev: class_register failed/N ");

Return-EIO;

}

 

Return 0;

}

An ordinary initialization process. What is interesting here is the initial value of video_fops:

Static const struct file_operations video_fops =

{

. Owner = this_module,

. Llseek = no_llseek,

. Open = video_open,

};

It only implements one open function! So how can we read videos or configure parameters? Let's look at video_open:

/*

* Open a video device-fixme: obsoleted

*/

Static int video_open (struct inode * inode, struct file * file)

{

Unsigned int minor = iminor (inode );

Int err = 0;

Struct video_device * VFL;

Const struct file_operations * old_fops;

.......................

Old_fops = file-> f_op;

File-> f_op = fops_get (vfl-> FoPs );

If (file-> f_op-> open)

Err = file-> f_op-> open (inode, file );

If (ERR ){

Fops_put (file-> f_op );

File-> f_op = fops_get (old_fops );

}

........................

}

Originally, file-> f_op was replaced here! The VFL here comes directly from the pointer passed in blackfin_cam.c. For adv7183, it will point:

Static struct file_operations bcap_fops = {

. Owner = this_module,

. Open = bcap_open,

. Release = bcap_close,

. IOCTL = bcap_ioctl,

. Compat_ioctl = (void *) v4l_ioctl,

. Llseek = no_llseek,

. Read = bcap_read,

. MMAP = bcap_mmap,

};

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/lights_joy/archive/2009/07/02/4316334.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.