为了方便测试应用程序,需要开发linux从USB端口的驱动,为S3C2410硬件实现模拟U盘的功能,查了很多资料,得知利用linux USB gadget驱动可以实现这一功能,于是便开始修改内核代码,添加linux USB gadget驱动: 1.根据如下电路,需要将S3C2410的GPG9端口拉高 修改arch/arm/mach-s3c2410/mach-smdk2410.c,添加如下代码: static void smdk2410_udc_pullup(enum s3c2410_udc_cmd_e cmd) { u8 *s3c2410_pullup_info[] = { " ", "Pull-up enable", "Pull-up disable", "UDC reset, in case of" }; printk("smdk2410_udc: %s\n",s3c2410_pullup_info[cmd]); s3c2410_gpio_cfgpin(S3C2410_GPG9, S3C2410_GPG9_OUTP); switch (cmd) { case S3C2410_UDC_P_ENABLE : s3c2410_gpio_setpin(S3C2410_GPG9, 1); //set gpg9 output HIGH break; case S3C2410_UDC_P_DISABLE : s3c2410_gpio_setpin(S3C2410_GPG9, 0); //set gpg9 output LOW break; case S3C2410_UDC_P_RESET : //FIXME!!! break; default: break; } } static struct s3c2410_udc_mach_info smdk2410_udc_cfg __initdata = { .udc_command = smdk2410_udc_pullup, }; static struct platform_device *smdk2410_devices[] __initdata = { …, &s3c_device_usbgadget, /*USB gadget device设备登记*/ }; static void __init sdmk2410_init(void) { u32 upll_value; set_s3c2410fb_info(&smdk2410_lcdcfg); s3c24xx_udc_set_platdata(&smdk2410_udc_cfg); /* 初始化*/ s3c_device_sdi.dev.platform_data = &smdk2410_mmc_cfg; /* Turn off suspend on both USB ports, and switch the * selectable USB port to USB device mode. */ } 2..修改drivers/usb/gadget/file_storage.c static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, struct usb_request *req, int *pbusy, enum fsg_buffer_state *state) { int rc; udelay(800); …… } 3.配置内核支持U盘模拟 USB Gadget Support ---> USB Peripheral Controller (S3C2410 USB Device Controller) ---> S3C2410 USB Device Controller [*] S3C2410 udc debug messages USB Gadget Drivers File-backed Storage Gadget 注意,在USB Gadget Support下,所有选项都要配制成模块【M】, 然后#make zImage 然后再#make modules,会在...../drivers/usb/gadget下生成g_file_storage.ko和s3c2410_udc.ko模块。 4.在文件系统中的/etc/init.d/rcS文件中,添加: #insmod /lib/modules/s3c2410_udc.ko #insmod /lib/modules/g_file_storage.ko 5.用USB数据线将目标板和PC机连接,再重启内核,发现PC机中出现目标板的盘符,表明移植成功。 参考资料:(1)Linux usb gadget 驱动 (2)linux2.6内核 linux USB gadget驱动移植 来源:
阅读(1436) | 评论(1) | 转发(0) |