s3c2440 devices usb改为host usb 小记

来源:互联网 发布:java写接口连接数据库 编辑:程序博客网 时间:2024/05/15 02:13


将arm板上的usb设备端改为主设备端:

修改linux-2.6.18.2/drivers/usb/host/Kconfig,末尾添加:

/********************add begin************************/
........

config MAX_ROOT_PORTS

    int "Maximum port(s) of RootHub"

    depends on USB_OHCI_HCD && ARCH_S3C2410

    default 1

    ---help---

    pls select usb host number,default one host and one     device.so We select one normally


/********************add end************************/


    修改/linux-2.6.18.2/drivers/usb/host/ohci-s3c2410.c


/********************add begin************************/

#include <asm/arch/regs-gpio.h>


    static int usb_hcd_s3c2410_probe (const struct hc_driver *driver, struct platform_device *dev)

    {

       struct usb_hcd *hcd = NULL;

       int retval;

//add by guo

       unsigned long tmp;

#if CONFIG_MAX_ROOT_PORTS < 2

 /* 1 host port, 1 slave port*/

          tmp = __raw_readl(S3C2410_MISCCR);

          tmp &= ~S3C2410_MISCCR_USBHOST;

           __raw_writel(tmp, S3C2410_MISCCR);

          s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);

#else

 /* 2 host port */

        tmp = __raw_readl(S3C2410_MISCCR);

        tmp |= S3C2410_MISCCR_USBHOST;

        __raw_writel(tmp, S3C2410_MISCCR);

        s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);

        s3c2410_usb_set_power(dev->dev.platform_data, 2, 1);

#endif

    //s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);

    //s3c2410_usb_set_power(dev->dev.platform_data, 2, 1);

    ......

/********************add end************************/


修改/linux-2.6.18.2/drivers/usb/core/hub.c

    static int hub_configure(struct usb_hub *hub,

    struct usb_endpoint_descriptor *endpoint)

    {

       struct usb_device *hdev = hub->hdev;

       struct device *hub_dev = hub->intfdev;

       u16 hubstatus, hubchange;

       u16 wHubCharacteristics;

       unsigned int pipe;

       int maxp, ret;

       char *message;


       hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL,

            &hub->buffer_dma);

       if (!hub->buffer) {

          message = "can't allocate hub irq buffer";

          ret = -ENOMEM;

          goto fail;

       }


       hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL);

       if (!hub->status) {

          message = "can't kmalloc hub status buffer";

          ret = -ENOMEM;

          goto fail;

       }

      mutex_init(&hub->status_mutex);


      hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);

      if (!hub->descriptor) {

          message = "can't kmalloc hub descriptor";

          ret = -ENOMEM;

          goto fail;

      }


    /* Request the entire hub descriptor.

     * hub->descriptor can handle USB_MAXCHILDREN ports,

     * but the hub can/will return fewer bytes here.

     */

    ret = get_hub_descriptor(hdev, hub->descriptor,

            sizeof(*hub->descriptor));

    if (ret < 0) {

        message = "can't read hub descriptor";

        goto fail;

    } else if (hub->descriptor->bNbrPorts > USB_MAXCHILDREN) {

        message = "hub has too many ports!";

        ret = -ENODEV;

        goto fail;

    }


/*********************add begin**********************/

/*add by guo */

#ifdef CONFIG_ARCH_S3C2410

    if ((hdev->devnum == 1) // Root Hub

    && hub->descriptor->bNbrPorts > CONFIG_MAX_ROOT_PORTS) {

    int j;

    for (j=hub->descriptor->bNbrPorts-1; j>=0; j--) {

        printk("port #%d ", j);

        if (j > CONFIG_MAX_ROOT_PORTS-1) {

        printk("suspened!/n");

        } else {

        printk("alived!/n");

        }

    }

    hub->descriptor->bNbrPorts = CONFIG_MAX_ROOT_PORTS;

    }

#endif

/********************add end*************************/


内核配置:

 Device Drivers  --->
  USB support  --->
   <*> Support for Host-side USB
   [*]   USB device filesystem

          <*>   OHCI HCD support                                                                                     
                 <*>   SL811HS HCD support                                                                                  
                 (2) Maximum port(s) of RootHub

 

原创粉丝点击