当前位置: 技术问答>linux和unix
zc301驱动zc0301_core.c的zc0301_usb_init 函数调用后,没有调用驱动对应的zc0301_usb_ probe 函数是怎么回事
来源: 互联网 发布时间:2017-05-12
本文导语: 这个问题我弄很久了,希望大神能够帮帮忙。按网上的说法是自动创建节点video0,不需要自动创建,但是还是没有video0. 我后来发现zc0301_core.c中的probe函数都没有运行。 。。。。。。。。。。。。。。。。。。。。...
这个问题我弄很久了,希望大神能够帮帮忙。按网上的说法是自动创建节点video0,不需要自动创建,但是还是没有video0. 我后来发现zc0301_core.c中的probe函数都没有运行。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
其中一部分代码。。:
static int
zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
{
struct usb_device *udev = interface_to_usbdev(intf);
struct zc0301_device* cam;
static unsigned int dev_nr;
unsigned int i;
int err = 0;
printk("sssssssssssssssssssssssssssssssssssssssssssss");
if (!(cam = kzalloc(sizeof(struct zc0301_device), GFP_KERNEL)))
return -ENOMEM;
cam->usbdev = udev;
if (!(cam->control_buffer = kzalloc(4, GFP_KERNEL))) {
DBG(1, "kmalloc() failed");
err = -ENOMEM;
goto fail;
}
if (!(cam->v4ldev = video_device_alloc())) {
DBG(1, "video_device_alloc() failed");
err = -ENOMEM;
goto fail;
}
DBG(2, "ZC0301[P] Image Processor and Control Chip detected "
"(vid/pid 0x%04X:0x%04X)",id->idVendor, id->idProduct);
for (i = 0; zc0301_sensor_table[i]; i++) {
err = zc0301_sensor_table[i](cam);
if (!err)
break;
}
if (!err)
DBG(2, "%s image sensor detected", cam->sensor.name);
else {
DBG(1, "No supported image sensor detected");
err = -ENODEV;
goto fail;
}
if (zc0301_init(cam)) {
DBG(1, "Initialization failed. I will retry on open().");
cam->state |= DEV_MISCONFIGURED;
}
strcpy(cam->v4ldev->name, "ZC0301[P] PC Camera");
cam->v4ldev->fops = &zc0301_fops;
cam->v4ldev->minor = video_nr[dev_nr];
cam->v4ldev->release = video_device_release;
cam->v4ldev->parent = &udev->dev;
video_set_drvdata(cam->v4ldev, cam);
init_completion(&cam->probe);
err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
video_nr[dev_nr]);
if (err) {
DBG(1, "V4L2 device registration failed");
if (err == -ENFILE && video_nr[dev_nr] == -1)
DBG(1, "Free /dev/videoX node not found");
video_nr[dev_nr] = -1;
dev_nr = (dev_nr probe);
goto fail;
}
DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->num);
cam->module_param.force_munmap = force_munmap[dev_nr];
cam->module_param.frame_timeout = frame_timeout[dev_nr];
dev_nr = (dev_nr kref);
usb_get_dev(cam->usbdev);
complete_all(&cam->probe);
return 0;
fail:
if (cam) {
kfree(cam->control_buffer);
if (cam->v4ldev)
video_device_release(cam->v4ldev);
kfree(cam);
}
return err;
}
static void zc0301_usb_disconnect(struct usb_interface* intf)
{
struct zc0301_device* cam;
down_write(&zc0301_dev_lock);
cam = usb_get_intfdata(intf);
DBG(2, "Disconnecting %s...", cam->v4ldev->name);
if (cam->users) {
DBG(2, "Device /dev/video%d is open! Deregistration and "
"memory deallocation are deferred.",
cam->v4ldev->num);
cam->state |= DEV_MISCONFIGURED;
zc0301_stop_transfer(cam);
cam->state |= DEV_DISCONNECTED;
wake_up_interruptible(&cam->wait_frame);
wake_up(&cam->wait_stream);
} else
cam->state |= DEV_DISCONNECTED;
wake_up_interruptible_all(&cam->wait_open);
kref_put(&cam->kref, zc0301_release_resources);
up_write(&zc0301_dev_lock);
}
static struct usb_driver zc0301_usb_driver = {
.name = "zc0301",
.id_table = zc0301_id_table,
.probe = zc0301_usb_probe,
.disconnect = zc0301_usb_disconnect,
};
/*****************************************************************************/
static int __init zc0301_module_init(void)
{
int err = 0;
printk("initkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
KDBG(2, ZC0301_MODULE_NAME " v" ZC0301_MODULE_VERSION);
KDBG(3, ZC0301_MODULE_AUTHOR);
if ((err = usb_register(&zc0301_usb_driver)))
KDBG(1, "usb_register() failed");
return err;
}
static void __exit zc0301_module_exit(void)
{
usb_deregister(&zc0301_usb_driver);
}
module_init(zc0301_module_init);
module_exit(zc0301_module_exit);
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
其中一部分代码。。:
static int
zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
{
struct usb_device *udev = interface_to_usbdev(intf);
struct zc0301_device* cam;
static unsigned int dev_nr;
unsigned int i;
int err = 0;
printk("sssssssssssssssssssssssssssssssssssssssssssss");
if (!(cam = kzalloc(sizeof(struct zc0301_device), GFP_KERNEL)))
return -ENOMEM;
cam->usbdev = udev;
if (!(cam->control_buffer = kzalloc(4, GFP_KERNEL))) {
DBG(1, "kmalloc() failed");
err = -ENOMEM;
goto fail;
}
if (!(cam->v4ldev = video_device_alloc())) {
DBG(1, "video_device_alloc() failed");
err = -ENOMEM;
goto fail;
}
DBG(2, "ZC0301[P] Image Processor and Control Chip detected "
"(vid/pid 0x%04X:0x%04X)",id->idVendor, id->idProduct);
for (i = 0; zc0301_sensor_table[i]; i++) {
err = zc0301_sensor_table[i](cam);
if (!err)
break;
}
if (!err)
DBG(2, "%s image sensor detected", cam->sensor.name);
else {
DBG(1, "No supported image sensor detected");
err = -ENODEV;
goto fail;
}
if (zc0301_init(cam)) {
DBG(1, "Initialization failed. I will retry on open().");
cam->state |= DEV_MISCONFIGURED;
}
strcpy(cam->v4ldev->name, "ZC0301[P] PC Camera");
cam->v4ldev->fops = &zc0301_fops;
cam->v4ldev->minor = video_nr[dev_nr];
cam->v4ldev->release = video_device_release;
cam->v4ldev->parent = &udev->dev;
video_set_drvdata(cam->v4ldev, cam);
init_completion(&cam->probe);
err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
video_nr[dev_nr]);
if (err) {
DBG(1, "V4L2 device registration failed");
if (err == -ENFILE && video_nr[dev_nr] == -1)
DBG(1, "Free /dev/videoX node not found");
video_nr[dev_nr] = -1;
dev_nr = (dev_nr probe);
goto fail;
}
DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->num);
cam->module_param.force_munmap = force_munmap[dev_nr];
cam->module_param.frame_timeout = frame_timeout[dev_nr];
dev_nr = (dev_nr kref);
usb_get_dev(cam->usbdev);
complete_all(&cam->probe);
return 0;
fail:
if (cam) {
kfree(cam->control_buffer);
if (cam->v4ldev)
video_device_release(cam->v4ldev);
kfree(cam);
}
return err;
}
static void zc0301_usb_disconnect(struct usb_interface* intf)
{
struct zc0301_device* cam;
down_write(&zc0301_dev_lock);
cam = usb_get_intfdata(intf);
DBG(2, "Disconnecting %s...", cam->v4ldev->name);
if (cam->users) {
DBG(2, "Device /dev/video%d is open! Deregistration and "
"memory deallocation are deferred.",
cam->v4ldev->num);
cam->state |= DEV_MISCONFIGURED;
zc0301_stop_transfer(cam);
cam->state |= DEV_DISCONNECTED;
wake_up_interruptible(&cam->wait_frame);
wake_up(&cam->wait_stream);
} else
cam->state |= DEV_DISCONNECTED;
wake_up_interruptible_all(&cam->wait_open);
kref_put(&cam->kref, zc0301_release_resources);
up_write(&zc0301_dev_lock);
}
static struct usb_driver zc0301_usb_driver = {
.name = "zc0301",
.id_table = zc0301_id_table,
.probe = zc0301_usb_probe,
.disconnect = zc0301_usb_disconnect,
};
/*****************************************************************************/
static int __init zc0301_module_init(void)
{
int err = 0;
printk("initkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
KDBG(2, ZC0301_MODULE_NAME " v" ZC0301_MODULE_VERSION);
KDBG(3, ZC0301_MODULE_AUTHOR);
if ((err = usb_register(&zc0301_usb_driver)))
KDBG(1, "usb_register() failed");
return err;
}
static void __exit zc0301_module_exit(void)
{
usb_deregister(&zc0301_usb_driver);
}
module_init(zc0301_module_init);
module_exit(zc0301_module_exit);
|
zc0301_id_table这个需要和device matched。 才会调probe, 你没有这个设备?
const struct usb_device_id *usb_match_id(
struct usb_interface *interface,
const -struct usb_device_id *id)
{
/* proc_connectinfo in devio.c may call us with id == NULL. */
if (id == NULL)
return NULL;
/* It is important to check that id->driver_info is nonzero,
since an entry that is all zeroes except for a nonzero
id->driver_info is the way to create an entry that
indicates that the driver want to examine every
device and interface. */
for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass ||
id->driver_info; id++) {
if (usb_match_one_id(interface, id))
return id;
}
return NULL;
}
|
usb_register调用probe之前, 会调用usb总线match函数, 判断总线初始化扫描得到的device id是否与你给出的一致. 你可以看看/sys/bus/usb/devices/
|
lsusb -v 看看有那个设备么.
|
“1d6b”= “Linux Foundation”,“0001” = “1.1 root hub”
usb驱动, 没有枚举出设备.
usb驱动, 没有枚举出设备.
|
这个不是zc301p驱动的问题, 是内核中usb总线扫描时根本就没有识别你这个设备.
你断开/连接设备或其它的USB口, dmesg会有什么打印?
你断开/连接设备或其它的USB口, dmesg会有什么打印?
|
usb 1-1: device descriptor read/64, error -62
是这个原因么?
http://sunnyshineboy.blog.163.com/blog/static/2028151182012580123731/
是这个原因么?
http://sunnyshineboy.blog.163.com/blog/static/2028151182012580123731/
|
我给你讲一下原理, 你的usb摄像头连接后, usb host controller驱动会读取设备的descriptor, 这个你可以看usb的specification, 会保存在usb_bus的device链表的device设备结构中.
这时加载驱动, video_register_device会调用usb_bus的match函数比较驱动提供的ID和已经读出的设备ID, 如果匹配, 调用驱动probe函数.
usb 1-1: device descriptor read/64, error -62
这个根本就是没有读出设备ID.
这时加载驱动, video_register_device会调用usb_bus的match函数比较驱动提供的ID和已经读出的设备ID, 如果匹配, 调用驱动probe函数.
usb 1-1: device descriptor read/64, error -62
这个根本就是没有读出设备ID.
|
LZ是驱动中星微的摄像头么?
数据编解码自己写的还是?
数据编解码自己写的还是?