- static void s3c2410_udc_enable(struct s3c2410_udc *dev)
- {
- int i;
- dprintk(DEBUG_NORMAL, "s3c2410_udc_enable called\n");
- /* dev->gadget.speed = USB_SPEED_UNKNOWN; */
- dev->gadget.speed = USB_SPEED_FULL;
- /* Set MAXP for all endpoints */
- for (i = 0; i < S3C2410_ENDPOINTS; i++) {
- udc_write(i, S3C2410_UDC_INDEX_REG);
- udc_write((dev->ep[i].ep.maxpacket & 0x7ff) >> 3,
- S3C2410_UDC_MAXP_REG);
- }
- /* Set default power state */
- udc_write(DEFAULT_POWER_STATE, S3C2410_UDC_PWR_REG);
- /* Enable reset and suspend interrupt interrupts */
- udc_write(S3C2410_UDC_USBINT_RESET | S3C2410_UDC_USBINT_SUSPEND,
- S3C2410_UDC_USB_INT_EN_REG);
- /* Enable ep0 interrupt */
- udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG);
- /* time to say "hello, world" */
- if (udc_info && udc_info->udc_command) {
- udc_info->udc_command(S3C2410_UDC_P_ENABLE);
- }
- }
- static struct s3c2410_udc_mach_info *udc_info;
- struct s3c2410_udc_mach_info {
- void (*udc_command)(enum s3c2410_udc_cmd_e);
- void (*vbus_draw)(unsigned int ma);
- unsigned int vbus_pin;
- unsigned char vbus_pin_inverted;
- };
- udc_info = pdev->dev.platform_data;
- static void s3c2410_udc_pullup(enum s3c2410_udc_cmd_e cmd)
- {
- switch (cmd) {
- case S3C2410_UDC_P_ENABLE :
- s3c2410_gpio_cfgpin(S3C2410_GPC(5), S3C2410_GPIO_OUTPUT); //参考评论增加的代码
- s3c2410_gpio_setpin(S3C2410_GPC(5), 1);
- break;
- case S3C2410_UDC_P_DISABLE :
- s3c2410_gpio_setpin(S3C2410_GPC(5), 0);
- break;
- case S3C2410_UDC_P_RESET :
- break;
- default:
- break;
- }
- }
- static struct s3c2410_udc_mach_info s3c2410_udc_cfg __initdata = {
- .udc_command = s3c2410_udc_pullup,
- };
修改mini2440_machine_init函数,增加s3c24xx_udc_set_platdata(&s3c2410_udc_cfg);如下
- static void __init mini2440_machine_init(void)
- {
- #if defined (LCD_WIDTH)
- s3c24xx_fb_set_platdata(&mini2440_fb_info);
- #endif
- s3c_i2c0_set_platdata(NULL);
- s3c2410_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
- s3c_device_nand.dev.platform_data = &friendly_arm_nand_info;
- s3c_device_sdi.dev.platform_data = &mini2440_mmc_cfg;
- s3c24xx_udc_set_platdata(&s3c2410_udc_cfg); //增加的代码
- platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
- s3c_pm_init();
- }
- void __init s3c24xx_udc_set_platdata(struct s3c2410_udc_mach_info *pd)
- {
- struct s3c2410_udc_mach_info *npd;
- npd = kmalloc(sizeof(*npd), GFP_KERNEL);
- if (npd) {
- memcpy(npd, pd, sizeof(*npd));
- s3c_device_usbgadget.dev.platform_data = npd;
- } else {
- printk(KERN_ERR "no memory for udc platform data\n");
- }
- }
- int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
- {
- struct s3c2410_udc *udc = the_controller;
- if (!udc)
- return -ENODEV;
- if (!driver || driver != udc->driver || !driver->unbind)
- return -EINVAL;
- dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n",
- driver->driver.name);
- driver->disconnect(&udc->gadget);
- //此处为新加语句,这条语句调用 composite_disconnect,然后使得cdev->config为NULL
- driver->unbind(&udc->gadget);
- //这里就是composite_unbind
- device_del(&udc->gadget.dev);
- udc->driver = NULL;
- /* Disable udc */
- s3c2410_udc_disable(udc);
- return 0;
- }
Bus 005 Device 023: ID 0525:a4a0 Netchip Technology, Inc. Linux-USB "Gadget Zero"
卸载g_zero.ko后,新设备就会消失。这样基本的USB Gadget驱动功能就开启了。类似的还可以测试其他的USB Gagget。