Exemplo n.º 1
0
static int sw_ehci_hcd_probe(struct platform_device *pdev)
{
	struct usb_hcd *hcd = NULL;
	struct ehci_hcd *ehci = NULL;
	struct sw_hci_hcd *sw_ehci = NULL;
	int ret = 0;

	if (pdev == NULL)
		return -EINVAL;

	/* if usb is disabled, can not probe */
	if (usb_disabled())
		return -ENODEV;

	sw_ehci = pdev->dev.platform_data;
	if (!sw_ehci)
		return -ENODATA;

	sw_ehci->pdev = pdev;
	g_sw_ehci[sw_ehci->usbc_no] = sw_ehci;

	pr_debug("[%s%d]: probe, pdev->name: %s, pdev->id: %d,"
		" sw_ehci: 0x%p\n",
		SW_EHCI_NAME, sw_ehci->usbc_no, pdev->name, pdev->id, sw_ehci);

	/* get io resource */
	sw_get_io_resource(pdev, sw_ehci);
	sw_ehci->ehci_base = sw_ehci->usb_vbase + SW_USB_EHCI_BASE_OFFSET;
	sw_ehci->ehci_reg_length = SW_USB_EHCI_LEN;

	/* creat a usb_hcd for the ehci controller */
	hcd = usb_create_hcd(&sw_ehci_hc_driver, &pdev->dev, SW_EHCI_NAME);
	if (!hcd) {
		pr_err("%s: failed to create hcd\n", __func__);
		ret = -ENOMEM;
		goto err_create_hcd;
	}

	hcd->rsrc_start = (u32) sw_ehci->ehci_base;
	hcd->rsrc_len = sw_ehci->ehci_reg_length;
	hcd->regs = sw_ehci->ehci_base;
	sw_ehci->hcd = hcd;

	/* echi start to work */
	sw_start_ehci(sw_ehci);

	ehci = hcd_to_ehci(hcd);
	ehci->caps = hcd->regs;
	ehci->regs =
	    hcd->regs + HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));

	/* cache this readonly data, minimize chip reads */
	ehci->hcs_params = readl(&ehci->caps->hcs_params);

	ret = usb_add_hcd(hcd, sw_ehci->irq_no, IRQF_DISABLED | IRQF_SHARED);
	if (ret != 0) {
		pr_err("%s: failed to add hcd, rc=%d\n", __func__, ret);
		goto err_add_hcd;
	}

	platform_set_drvdata(pdev, hcd);

	pr_debug("[%s]: probe, clock: 0x60(0x%x), 0xcc(0x%x);"
	     " usb: 0x800(0x%x), dram:(0x%x, 0x%x)\n",
	     sw_ehci->hci_name, (u32) USBC_Readl(sw_ehci->clock_vbase + 0x60),
	     (u32) USBC_Readl(sw_ehci->clock_vbase + 0xcc),
	     (u32) USBC_Readl(sw_ehci->usb_vbase + 0x800),
	     (u32) USBC_Readl(sw_ehci->sdram_vbase + SW_SDRAM_REG_HPCR_USB1),
	     (u32) USBC_Readl(sw_ehci->sdram_vbase + SW_SDRAM_REG_HPCR_USB2));

	sw_ehci->probe = 1;

	/* Disable ehci, when driver probe */
	if (sw_ehci->host_init_state == 0) {
		if (ehci_first_probe[sw_ehci->usbc_no]) {
			sw_usb_disable_ehci(sw_ehci->usbc_no);
			ehci_first_probe[sw_ehci->usbc_no]--;
		}
	}

	return 0;

err_add_hcd:
	usb_put_hcd(hcd);
err_create_hcd:
	sw_ehci->hcd = NULL;
	g_sw_ehci[sw_ehci->usbc_no] = NULL;
	return ret;
}
static int sw_ohci_hcd_probe(struct platform_device *pdev)
{
	int ret;
	struct usb_hcd *hcd = NULL;
	struct sw_hci_hcd *sw_ohci = NULL;

	if(pdev == NULL){
	    DMSG_PANIC("ERR: Argment is invaild\n");
	    return -1;
    }

    /* if usb is disabled, can not probe */
    if (usb_disabled()){
        DMSG_PANIC("ERR: usb hcd is disabled\n");
        return -ENODEV;
    }

	sw_ohci = pdev->dev.platform_data;
	if(!sw_ohci){
		DMSG_PANIC("ERR: sw_ohci is null\n");
		ret = -ENOMEM;
		goto ERR1;
	}

	sw_ohci->pdev = pdev;
	g_sw_ohci[sw_ohci->usbc_no] = sw_ohci;

	DMSG_INFO("[%s%d]: probe, pdev->name: %s, pdev->id: %d, sw_ohci: 0x%p\n",
		      ohci_name, sw_ohci->usbc_no, pdev->name, pdev->id, sw_ohci);

	/* get io resource */
	sw_get_io_resource(pdev, sw_ohci);
	sw_ohci->ohci_base 			= sw_ohci->usb_vbase + SW_USB_OHCI_BASE_OFFSET;
	sw_ohci->ohci_reg_length 	= SW_USB_OHCI_LEN;

    /*creat a usb_hcd for the ohci controller*/
	hcd = usb_create_hcd(&sw_ohci_hc_driver, &pdev->dev, ohci_name);
	if(!hcd){
        DMSG_PANIC("ERR: usb_ohci_create_hcd failed\n");
        ret = -ENOMEM;
		goto ERR2;
	}

  	hcd->rsrc_start = (u32)sw_ohci->ohci_base;
	hcd->rsrc_len 	= sw_ohci->ohci_reg_length;
	hcd->regs 		= sw_ohci->ohci_base;
	sw_ohci->hcd    = hcd;

	/* ochi start to work */
	sw_start_ohc(sw_ohci);

    ohci_hcd_init(hcd_to_ohci(hcd));

    ret = usb_add_hcd(hcd, sw_ohci->irq_no, IRQF_DISABLED | IRQF_SHARED);
    if(ret != 0){
        DMSG_PANIC("ERR: usb_add_hcd failed\n");
        ret = -ENOMEM;
        goto ERR3;
    }

    platform_set_drvdata(pdev, hcd);

#ifdef  SW_USB_OHCI_DEBUG
    DMSG_INFO("[%s]: probe, clock: 0x60(0x%x), 0xcc(0x%x); usb: 0x800(0x%x), dram:(0x%x, 0x%x)\n",
              sw_ohci->hci_name,
              (u32)USBC_Readl(sw_ohci->clock_vbase + 0x60),
              (u32)USBC_Readl(sw_ohci->clock_vbase + 0xcc),
              (u32)USBC_Readl(sw_ohci->usb_vbase + 0x800),
              (u32)USBC_Readl(sw_ohci->sdram_vbase + SW_SDRAM_REG_HPCR_USB1),
              (u32)USBC_Readl(sw_ohci->sdram_vbase + SW_SDRAM_REG_HPCR_USB2));
#endif

	sw_ohci->probe = 1;

    /* Disable ohci, when driver probe */
    if(sw_ohci->host_init_state == 0){
        if(ohci_first_probe[sw_ohci->usbc_no]){
            sw_usb_disable_ohci(sw_ohci->usbc_no);
            ohci_first_probe[sw_ohci->usbc_no]--;
        }
    }

    return 0;

ERR3:
	usb_put_hcd(hcd);

ERR2:
	sw_ohci->hcd = NULL;
	g_sw_ohci[sw_ohci->usbc_no] = NULL;

ERR1:

    return ret;
}