2 * drivers/usb/host/ehci-pxa168.c
4 * Tanmay Upadhyay <tanmay.upadhyay@einfochips.com>
6 * Based on drivers/usb/host/ehci-orion.c
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/clk.h>
17 #include <mach/pxa168.h>
19 #define USB_PHY_CTRL_REG 0x4
20 #define USB_PHY_PLL_REG 0x8
21 #define USB_PHY_TX_REG 0xc
32 #define PLLCALI12_SHIFT 25
38 #define PLLVDD12_SHIFT 27
44 #define PLLVDD18_SHIFT 29
51 #define PLL_READY (1 << 23)
52 #define VCOCAL_START (1 << 21)
53 #define REG_RCAL_START (1 << 12)
55 struct pxa168_usb_drv_data
{
57 struct clk
*pxa168_usb_clk
;
58 struct resource
*usb_phy_res
;
59 void __iomem
*usb_phy_reg_base
;
62 static int ehci_pxa168_setup(struct usb_hcd
*hcd
)
64 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
68 retval
= ehci_halt(ehci
);
75 retval
= ehci_init(hcd
);
81 ehci_port_power(ehci
, 0);
86 static const struct hc_driver ehci_pxa168_hc_driver
= {
87 .description
= hcd_name
,
88 .product_desc
= "Marvell PXA168 EHCI",
89 .hcd_priv_size
= sizeof(struct pxa168_usb_drv_data
),
92 * generic hardware linkage
95 .flags
= HCD_MEMORY
| HCD_USB2
,
98 * basic lifecycle operations
100 .reset
= ehci_pxa168_setup
,
103 .shutdown
= ehci_shutdown
,
106 * managing i/o requests and associated device resources
108 .urb_enqueue
= ehci_urb_enqueue
,
109 .urb_dequeue
= ehci_urb_dequeue
,
110 .endpoint_disable
= ehci_endpoint_disable
,
111 .endpoint_reset
= ehci_endpoint_reset
,
116 .get_frame_number
= ehci_get_frame
,
121 .hub_status_data
= ehci_hub_status_data
,
122 .hub_control
= ehci_hub_control
,
123 .bus_suspend
= ehci_bus_suspend
,
124 .bus_resume
= ehci_bus_resume
,
125 .relinquish_port
= ehci_relinquish_port
,
126 .port_handed_over
= ehci_port_handed_over
,
128 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
131 static int pxa168_usb_phy_init(struct platform_device
*pdev
)
133 struct resource
*res
;
134 void __iomem
*usb_phy_reg_base
;
135 struct pxa168_usb_pdata
*pdata
;
136 struct pxa168_usb_drv_data
*drv_data
;
137 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
138 unsigned long reg_val
;
139 int pll_retry_cont
= 10000, err
= 0;
141 drv_data
= (struct pxa168_usb_drv_data
*)hcd
->hcd_priv
;
142 pdata
= (struct pxa168_usb_pdata
*)pdev
->dev
.platform_data
;
144 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
147 "Found HC with no PHY register addr. Check %s setup!\n",
148 dev_name(&pdev
->dev
));
152 if (!request_mem_region(res
->start
, resource_size(res
),
153 ehci_pxa168_hc_driver
.description
)) {
154 dev_dbg(&pdev
->dev
, "controller already in use\n");
158 usb_phy_reg_base
= ioremap(res
->start
, resource_size(res
));
159 if (usb_phy_reg_base
== NULL
) {
160 dev_dbg(&pdev
->dev
, "error mapping memory\n");
164 drv_data
->usb_phy_reg_base
= usb_phy_reg_base
;
165 drv_data
->usb_phy_res
= res
;
167 /* If someone wants to init USB phy in board specific way */
168 if (pdata
&& pdata
->phy_init
)
169 return pdata
->phy_init(usb_phy_reg_base
);
171 /* Power up the PHY and PLL */
172 writel(readl(usb_phy_reg_base
+ USB_PHY_CTRL_REG
) | 0x3,
173 usb_phy_reg_base
+ USB_PHY_CTRL_REG
);
175 /* Configure PHY PLL */
176 reg_val
= readl(usb_phy_reg_base
+ USB_PHY_PLL_REG
) & ~(0x7e03ffff);
177 reg_val
|= (VDD18_22
<< PLLVDD18_SHIFT
| VDD12_12
<< PLLVDD12_SHIFT
|
178 CALI12_11
<< PLLCALI12_SHIFT
| 3 << KVCO_SHIFT
|
179 ICP_15
<< ICP_SHIFT
| 0xee << FBDIV_SHIFT
| 0xb);
180 writel(reg_val
, usb_phy_reg_base
+ USB_PHY_PLL_REG
);
182 /* Make sure PHY PLL is ready */
183 while (!(readl(usb_phy_reg_base
+ USB_PHY_PLL_REG
) & PLL_READY
)) {
184 if (!(pll_retry_cont
--)) {
185 dev_dbg(&pdev
->dev
, "USB PHY PLL not ready\n");
191 /* Toggle VCOCAL_START bit of U2PLL for PLL calibration */
193 writel(readl(usb_phy_reg_base
+ USB_PHY_PLL_REG
) | VCOCAL_START
,
194 usb_phy_reg_base
+ USB_PHY_PLL_REG
);
196 writel(readl(usb_phy_reg_base
+ USB_PHY_PLL_REG
) & ~VCOCAL_START
,
197 usb_phy_reg_base
+ USB_PHY_PLL_REG
);
199 /* Toggle REG_RCAL_START bit of U2PTX for impedance calibration */
201 writel(readl(usb_phy_reg_base
+ USB_PHY_TX_REG
) | REG_RCAL_START
,
202 usb_phy_reg_base
+ USB_PHY_TX_REG
);
204 writel(readl(usb_phy_reg_base
+ USB_PHY_TX_REG
) & ~REG_RCAL_START
,
205 usb_phy_reg_base
+ USB_PHY_TX_REG
);
207 /* Make sure PHY PLL is ready again */
209 while (!(readl(usb_phy_reg_base
+ USB_PHY_PLL_REG
) & PLL_READY
)) {
210 if (!(pll_retry_cont
--)) {
211 dev_dbg(&pdev
->dev
, "USB PHY PLL not ready\n");
219 iounmap(usb_phy_reg_base
);
221 release_mem_region(res
->start
, resource_size(res
));
225 static int __devinit
ehci_pxa168_drv_probe(struct platform_device
*pdev
)
227 struct resource
*res
;
229 struct ehci_hcd
*ehci
;
230 struct pxa168_usb_drv_data
*drv_data
;
237 pr_debug("Initializing pxa168-SoC USB Host Controller\n");
239 irq
= platform_get_irq(pdev
, 0);
242 "Found HC with no IRQ. Check %s setup!\n",
243 dev_name(&pdev
->dev
));
248 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
251 "Found HC with no register addr. Check %s setup!\n",
252 dev_name(&pdev
->dev
));
257 if (!request_mem_region(res
->start
, resource_size(res
),
258 ehci_pxa168_hc_driver
.description
)) {
259 dev_dbg(&pdev
->dev
, "controller already in use\n");
264 regs
= ioremap(res
->start
, resource_size(res
));
266 dev_dbg(&pdev
->dev
, "error mapping memory\n");
271 hcd
= usb_create_hcd(&ehci_pxa168_hc_driver
,
272 &pdev
->dev
, dev_name(&pdev
->dev
));
278 drv_data
= (struct pxa168_usb_drv_data
*)hcd
->hcd_priv
;
280 /* Enable USB clock */
281 drv_data
->pxa168_usb_clk
= clk_get(&pdev
->dev
, "PXA168-USBCLK");
282 if (IS_ERR(drv_data
->pxa168_usb_clk
)) {
283 dev_err(&pdev
->dev
, "Couldn't get USB clock\n");
284 err
= PTR_ERR(drv_data
->pxa168_usb_clk
);
287 clk_enable(drv_data
->pxa168_usb_clk
);
289 err
= pxa168_usb_phy_init(pdev
);
291 dev_err(&pdev
->dev
, "USB PHY initialization failed\n");
295 hcd
->rsrc_start
= res
->start
;
296 hcd
->rsrc_len
= resource_size(res
);
299 ehci
= hcd_to_ehci(hcd
);
300 ehci
->caps
= hcd
->regs
+ 0x100;
301 ehci
->regs
= hcd
->regs
+ 0x100 +
302 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
303 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
307 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
| IRQF_DISABLED
);
314 clk_disable(drv_data
->pxa168_usb_clk
);
315 clk_put(drv_data
->pxa168_usb_clk
);
321 release_mem_region(res
->start
, resource_size(res
));
323 dev_err(&pdev
->dev
, "init %s fail, %d\n",
324 dev_name(&pdev
->dev
), err
);
329 static int __exit
ehci_pxa168_drv_remove(struct platform_device
*pdev
)
331 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
332 struct pxa168_usb_drv_data
*drv_data
=
333 (struct pxa168_usb_drv_data
*)hcd
->hcd_priv
;
337 /* Power down PHY & PLL */
338 writel(readl(drv_data
->usb_phy_reg_base
+ USB_PHY_CTRL_REG
) & (~0x3),
339 drv_data
->usb_phy_reg_base
+ USB_PHY_CTRL_REG
);
341 clk_disable(drv_data
->pxa168_usb_clk
);
342 clk_put(drv_data
->pxa168_usb_clk
);
345 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
347 iounmap(drv_data
->usb_phy_reg_base
);
348 release_mem_region(drv_data
->usb_phy_res
->start
,
349 resource_size(drv_data
->usb_phy_res
));
356 MODULE_ALIAS("platform:pxa168-ehci");
358 static struct platform_driver ehci_pxa168_driver
= {
359 .probe
= ehci_pxa168_drv_probe
,
360 .remove
= __exit_p(ehci_pxa168_drv_remove
),
361 .shutdown
= usb_hcd_platform_shutdown
,
362 .driver
.name
= "pxa168-ehci",