OS:Linux-2.6.34
CPU:s3c2440
1、配置内核
内核配置如下:
Usb gadget Support 必须选中
USB Peripheral Controller 选择 S3C2410 USB Device Controller
选中USB Gadget Drivers 与File-backed Storage Gadget为模块模式
2、修改arch/arm/mach-s3c2440/mach-smdk2440.c文件
添加如下内容:
/*添加必要的头文件*/
#include <plat/udc.h>
#include <linux/gpio.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
/*设置udc回调函数udc_pullup()用于使能/禁止UDC上拉电阻*/
/*udc*/
static void udc_pullup(enum s3c2410_udc_cmd_e cmd)
{
switch(cmd)
{
case S3C2410_UDC_P_ENABLE:
s3c2410_gpio_setpin(S3C2410_GPG(12),1);
break;
case S3C2410_UDC_P_DISABLE:
s3c2410_gpio_setpin(S3C2410_GPG(12),0);
break;
case S3C2410_UDC_P_RESET:
break;
default:
break;
}
}
static struct s3c2410_udc_mach_info udc_machine = {
.udc_command = udc_pullup,
};
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_usbgadget, /*添加s3c_device_usbgadget(usb gadget设备),即:初始化usb gadget到内核*/
};
static void __init smdk2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&smdk2440_fb_info);
s3c_i2c0_set_platdata(NULL);
/*开机禁止UDC上拉电阻、设置GPG12管脚为输出、完善s3c_device_usbgadget结构*/
s3c2410_gpio_setpin(S3C2410_GPG(12),0);
s3c2410_gpio_cfgpin(S3C2410_GPG(12),S3C2410_GPIO_OUTPUT);
s3c24xx_udc_set_platdata(&udc_machine);
platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices));
smdk_machine_init();
}
3、修改driver/usb/gadget/s3c2410_udc.c
添加如下内容:
#include <mach/regs-gpio.h>
修改函数
static int s3c2410_udc_probe(struct platform_device *pdev)
{
struct s3c2410_udc *udc = &memory;
struct device *dev = &pdev->dev;
int retval;
int irq;
unsigned long misccr;
misccr = __raw_readl(S3C2410_MISCCR);
misccr &= ~(S3C2410_MISCCR_USBSUSPND0 |
S3C2410_MISCCR_USBSUSPND1 |
S3C2410_MISCCR_USBHOST);
__raw_writel(misccr,S3C2410_MISCCR);
修改函数
static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
{
struct s3c2410_request *req;
int is_in = ep->bEndpointAddress & USB_DIR_IN;
u32 ep_csr1;
u32 idx;
handle_ep_again: //2011-3-9 13:48:03 add byliu
。。。。。。。
if ((ep_csr1 & S3C2410_UDC_OCSR1_PKTRDY) && req) {
s3c2410_udc_read_fifo(ep,req);
if (s3c2410_udc_fifo_count_out())
goto handle_ep_again; //2011-3-9 13:48:03 add byliu
}
4、修改drivers/usb/gadget/file_storage.c
修改函数
static int fsg_setup(struct usb_gadget *gadget,
const struct usb_ctrlrequest *ctrl)
{。。。。。
//fsg->ep0req->zero = rc < w_length;
fsg->ep0req->zero = rc < w_length
&& (rc % gadget->ep0->maxpacket) == 0;//2011-3-9 13:47:03 add byliu
fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
5、编译内核与模块
[root@lby linux-2.6.34]# make modules SUBDIR=drivers/usb/gadget
[root@lby linux-2.6.34]# make zImage
6、加载模块
加入将CF卡作为U盘
[root@lby linux-2.6.34]# insmod g_file_storage.ko file=/dev/hda1 stall=0 removable=1
参考: http://bbs.embedsky.net/archiver/?tid-1690.html