LINUX驱动学习——内核USB驱动编写八USB的OTG驱动2(转载)(3)
- UID
- 1029342
- 性别
- 男
|
LINUX驱动学习——内核USB驱动编写八USB的OTG驱动2(转载)(3)
调用fsl_otg_probe函数,函数参数platform_device *pdev,就是我们上面注册进系统的platform_device结构,现在由系统赋值调用fsl_otg_probe
static int __init fsl_otg_probe(struct platform_device *pdev)
{
int status;
struct fsl_usb2_platform_data *pdata;
DBG("pdev=0x%p\n", pdev);
if (!pdev)
return -ENODEV;
/*判断是否有设备自己的数据,就是检查我们上面定义的3的过程*/
if (!pdev->dev.platform_data)
return -ENOMEM;
pdata = pdev->dev.platform_data;
/* configure the OTG */
status = fsl_otg_conf(pdev);
if (status) {
printk(KERN_INFO "Couldn't init OTG module\n");
return -status;
}
/* start OTG */
status = usb_otg_start(pdev);
if (register_chrdev(FSL_OTG_MAJOR, FSL_OTG_NAME, &otg_fops)) {
printk(KERN_WARNING FSL_OTG_NAME
": unable to register FSL OTG device\n");
return -EIO;
}
create_proc_file();
return status;
}
|
上面函数中调用了fsl_otg_conf,我们来看看他干了什么。
static int fsl_otg_conf(struct platform_device *pdev)
{
int status;
struct fsl_otg *fsl_otg_tc;
struct fsl_usb2_platform_data *pdata;
pdata = pdev->dev.platform_data;
DBG();
/**************************************************************/
struct fsl_otg {
struct otg_transceiver otg;
struct otg_fsm fsm;
struct usb_dr_mmap *dr_mem_map;
struct delayed_work otg_event;
/*used for usb host */
struct work_struct work_wq;
u8 host_working;
int irq;
};
/**************************************************************/
if (fsl_otg_dev)
return 0;
/* allocate space to fsl otg device */
fsl_otg_tc = kzalloc(sizeof(struct fsl_otg), GFP_KERNEL);
if (!fsl_otg_tc)
return -ENODEV;
INIT_DELAYED_WORK(&fsl_otg_tc->otg_event, fsl_otg_event);
INIT_LIST_HEAD(&active_timers);
status = fsl_otg_init_timers(&fsl_otg_tc->fsm);
if (status) {
printk(KERN_INFO "Couldn't init OTG timers\n");
fsl_otg_uninit_timers();
kfree(fsl_otg_tc);
return status;
}
spin_lock_init(&fsl_otg_tc->fsm.lock); |
|
|
|
|
|