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
;
36 ehci
->regs
= hcd
->regs
37 + HC_LENGTH(ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
38 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
43 retval
= ehci_init(hcd
);
47 ehci_port_power(ehci
, 0);
52 static const struct hc_driver cns3xxx_ehci_hc_driver
= {
53 .description
= hcd_name
,
54 .product_desc
= "CNS3XXX EHCI Host Controller",
55 .hcd_priv_size
= sizeof(struct ehci_hcd
),
57 .flags
= HCD_MEMORY
| HCD_USB2
,
58 .reset
= cns3xxx_ehci_init
,
61 .shutdown
= ehci_shutdown
,
62 .urb_enqueue
= ehci_urb_enqueue
,
63 .urb_dequeue
= ehci_urb_dequeue
,
64 .endpoint_disable
= ehci_endpoint_disable
,
65 .endpoint_reset
= ehci_endpoint_reset
,
66 .get_frame_number
= ehci_get_frame
,
67 .hub_status_data
= ehci_hub_status_data
,
68 .hub_control
= ehci_hub_control
,
70 .bus_suspend
= ehci_bus_suspend
,
71 .bus_resume
= ehci_bus_resume
,
73 .relinquish_port
= ehci_relinquish_port
,
74 .port_handed_over
= ehci_port_handed_over
,
76 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
79 static int cns3xxx_ehci_probe(struct platform_device
*pdev
)
81 struct device
*dev
= &pdev
->dev
;
83 const struct hc_driver
*driver
= &cns3xxx_ehci_hc_driver
;
91 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
93 dev_err(dev
, "Found HC with no IRQ.\n");
98 hcd
= usb_create_hcd(driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
102 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
104 dev_err(dev
, "Found HC with no register addr.\n");
109 hcd
->rsrc_start
= res
->start
;
110 hcd
->rsrc_len
= res
->end
- res
->start
+ 1;
112 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
,
113 driver
->description
)) {
114 dev_dbg(dev
, "controller already in use\n");
119 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
120 if (hcd
->regs
== NULL
) {
121 dev_dbg(dev
, "error mapping memory\n");
126 retval
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
132 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
139 static int cns3xxx_ehci_remove(struct platform_device
*pdev
)
141 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
145 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
148 * EHCI and OHCI share the same clock and power,
149 * resetting twice would cause the 1st controller been reset.
150 * Therefore only do power up at the first up device, and
151 * power down at the last down device.
153 if (atomic_dec_return(&usb_pwr_ref
) == 0)
154 cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST
);
158 platform_set_drvdata(pdev
, NULL
);
163 MODULE_ALIAS("platform:cns3xxx-ehci");
165 static struct platform_driver cns3xxx_ehci_driver
= {
166 .probe
= cns3xxx_ehci_probe
,
167 .remove
= cns3xxx_ehci_remove
,
169 .name
= "cns3xxx-ehci",