2 * Copyright 2008 Cavium Networks
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, Version 2, as
6 * published by the Free Software Foundation.
9 #include <linux/platform_device.h>
10 #include <linux/atomic.h>
11 #include <mach/cns3xxx.h>
14 static int cns3xxx_ehci_init(struct usb_hcd *hcd)
16 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
20 * EHCI and OHCI share the same clock and power,
21 * resetting twice would cause the 1st controller been reset.
22 * Therefore only do power up at the first up device, and
23 * power down at the last down device.
25 * Set USB AHB INCR length to 16
27 if (atomic_inc_return(&usb_pwr_ref) == 1) {
28 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
29 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
30 cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
31 __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
32 MISC_CHIP_CONFIG_REG);
35 ehci->caps = hcd->regs;
39 retval = ehci_setup(hcd);
43 ehci_port_power(ehci, 0);
48 static const struct hc_driver cns3xxx_ehci_hc_driver = {
49 .description = hcd_name,
50 .product_desc = "CNS3XXX EHCI Host Controller",
51 .hcd_priv_size = sizeof(struct ehci_hcd),
53 .flags = HCD_MEMORY | HCD_USB2,
54 .reset = cns3xxx_ehci_init,
57 .shutdown = ehci_shutdown,
58 .urb_enqueue = ehci_urb_enqueue,
59 .urb_dequeue = ehci_urb_dequeue,
60 .endpoint_disable = ehci_endpoint_disable,
61 .endpoint_reset = ehci_endpoint_reset,
62 .get_frame_number = ehci_get_frame,
63 .hub_status_data = ehci_hub_status_data,
64 .hub_control = ehci_hub_control,
66 .bus_suspend = ehci_bus_suspend,
67 .bus_resume = ehci_bus_resume,
69 .relinquish_port = ehci_relinquish_port,
70 .port_handed_over = ehci_port_handed_over,
72 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
75 static int cns3xxx_ehci_probe(struct platform_device *pdev)
77 struct device *dev = &pdev->dev;
79 const struct hc_driver *driver = &cns3xxx_ehci_hc_driver;
87 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
89 dev_err(dev, "Found HC with no IRQ.\n");
94 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
98 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100 dev_err(dev, "Found HC with no register addr.\n");
105 hcd->rsrc_start = res->start;
106 hcd->rsrc_len = resource_size(res);
108 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
109 driver->description)) {
110 dev_dbg(dev, "controller already in use\n");
115 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
116 if (hcd->regs == NULL) {
117 dev_dbg(dev, "error mapping memory\n");
122 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
128 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
135 static int cns3xxx_ehci_remove(struct platform_device *pdev)
137 struct usb_hcd *hcd = platform_get_drvdata(pdev);
141 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
144 * EHCI and OHCI share the same clock and power,
145 * resetting twice would cause the 1st controller been reset.
146 * Therefore only do power up at the first up device, and
147 * power down at the last down device.
149 if (atomic_dec_return(&usb_pwr_ref) == 0)
150 cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
154 platform_set_drvdata(pdev, NULL);
159 MODULE_ALIAS("platform:cns3xxx-ehci");
161 static struct platform_driver cns3xxx_ehci_driver = {
162 .probe = cns3xxx_ehci_probe,
163 .remove = cns3xxx_ehci_remove,
165 .name = "cns3xxx-ehci",