2 * SAMSUNG EXYNOS USB HOST OHCI Controller
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/clk.h>
16 #include <linux/platform_device.h>
17 #include <mach/ohci.h>
18 #include <plat/usb-phy.h>
20 struct exynos_ohci_hcd
{
26 static int ohci_exynos_start(struct usb_hcd
*hcd
)
28 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
31 ohci_dbg(ohci
, "ohci_exynos_start, ohci:%p", ohci
);
33 ret
= ohci_init(ohci
);
39 dev_err(hcd
->self
.controller
, "can't start %s\n",
48 static const struct hc_driver exynos_ohci_hc_driver
= {
49 .description
= hcd_name
,
50 .product_desc
= "EXYNOS OHCI Host Controller",
51 .hcd_priv_size
= sizeof(struct ohci_hcd
),
54 .flags
= HCD_MEMORY
|HCD_USB11
,
56 .start
= ohci_exynos_start
,
58 .shutdown
= ohci_shutdown
,
60 .get_frame_number
= ohci_get_frame
,
62 .urb_enqueue
= ohci_urb_enqueue
,
63 .urb_dequeue
= ohci_urb_dequeue
,
64 .endpoint_disable
= ohci_endpoint_disable
,
66 .hub_status_data
= ohci_hub_status_data
,
67 .hub_control
= ohci_hub_control
,
69 .bus_suspend
= ohci_bus_suspend
,
70 .bus_resume
= ohci_bus_resume
,
72 .start_port_reset
= ohci_start_port_reset
,
75 static u64 ohci_exynos_dma_mask
= DMA_BIT_MASK(32);
77 static int __devinit
exynos_ohci_probe(struct platform_device
*pdev
)
79 struct exynos4_ohci_platdata
*pdata
;
80 struct exynos_ohci_hcd
*exynos_ohci
;
82 struct ohci_hcd
*ohci
;
87 pdata
= pdev
->dev
.platform_data
;
89 dev_err(&pdev
->dev
, "No platform data defined\n");
94 * Right now device-tree probed devices don't get dma_mask set.
95 * Since shared usb code relies on it, set it here for now.
96 * Once we move to full device tree support this will vanish off.
98 if (!pdev
->dev
.dma_mask
)
99 pdev
->dev
.dma_mask
= &ohci_exynos_dma_mask
;
100 if (!pdev
->dev
.coherent_dma_mask
)
101 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
103 exynos_ohci
= devm_kzalloc(&pdev
->dev
, sizeof(struct exynos_ohci_hcd
),
108 exynos_ohci
->dev
= &pdev
->dev
;
110 hcd
= usb_create_hcd(&exynos_ohci_hc_driver
, &pdev
->dev
,
111 dev_name(&pdev
->dev
));
113 dev_err(&pdev
->dev
, "Unable to create HCD\n");
117 exynos_ohci
->hcd
= hcd
;
118 exynos_ohci
->clk
= clk_get(&pdev
->dev
, "usbhost");
120 if (IS_ERR(exynos_ohci
->clk
)) {
121 dev_err(&pdev
->dev
, "Failed to get usbhost clock\n");
122 err
= PTR_ERR(exynos_ohci
->clk
);
126 err
= clk_enable(exynos_ohci
->clk
);
130 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
132 dev_err(&pdev
->dev
, "Failed to get I/O memory\n");
137 hcd
->rsrc_start
= res
->start
;
138 hcd
->rsrc_len
= resource_size(res
);
139 hcd
->regs
= devm_ioremap(&pdev
->dev
, res
->start
, hcd
->rsrc_len
);
141 dev_err(&pdev
->dev
, "Failed to remap I/O memory\n");
146 irq
= platform_get_irq(pdev
, 0);
148 dev_err(&pdev
->dev
, "Failed to get IRQ\n");
154 pdata
->phy_init(pdev
, S5P_USB_PHY_HOST
);
156 ohci
= hcd_to_ohci(hcd
);
159 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
161 dev_err(&pdev
->dev
, "Failed to add USB HCD\n");
165 platform_set_drvdata(pdev
, exynos_ohci
);
170 clk_disable(exynos_ohci
->clk
);
172 clk_put(exynos_ohci
->clk
);
178 static int __devexit
exynos_ohci_remove(struct platform_device
*pdev
)
180 struct exynos4_ohci_platdata
*pdata
= pdev
->dev
.platform_data
;
181 struct exynos_ohci_hcd
*exynos_ohci
= platform_get_drvdata(pdev
);
182 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
186 if (pdata
&& pdata
->phy_exit
)
187 pdata
->phy_exit(pdev
, S5P_USB_PHY_HOST
);
189 clk_disable(exynos_ohci
->clk
);
190 clk_put(exynos_ohci
->clk
);
197 static void exynos_ohci_shutdown(struct platform_device
*pdev
)
199 struct exynos_ohci_hcd
*exynos_ohci
= platform_get_drvdata(pdev
);
200 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
202 if (hcd
->driver
->shutdown
)
203 hcd
->driver
->shutdown(hcd
);
207 static int exynos_ohci_suspend(struct device
*dev
)
209 struct exynos_ohci_hcd
*exynos_ohci
= dev_get_drvdata(dev
);
210 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
211 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
212 struct platform_device
*pdev
= to_platform_device(dev
);
213 struct exynos4_ohci_platdata
*pdata
= pdev
->dev
.platform_data
;
218 * Root hub was already suspended. Disable irq emission and
219 * mark HW unaccessible, bail out if RH has been resumed. Use
220 * the spinlock to properly synchronize with possible pending
221 * RH suspend or resume activity.
223 spin_lock_irqsave(&ohci
->lock
, flags
);
224 if (ohci
->rh_state
!= OHCI_RH_SUSPENDED
&&
225 ohci
->rh_state
!= OHCI_RH_HALTED
) {
230 clear_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
232 if (pdata
&& pdata
->phy_exit
)
233 pdata
->phy_exit(pdev
, S5P_USB_PHY_HOST
);
235 clk_disable(exynos_ohci
->clk
);
238 spin_unlock_irqrestore(&ohci
->lock
, flags
);
243 static int exynos_ohci_resume(struct device
*dev
)
245 struct exynos_ohci_hcd
*exynos_ohci
= dev_get_drvdata(dev
);
246 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
247 struct platform_device
*pdev
= to_platform_device(dev
);
248 struct exynos4_ohci_platdata
*pdata
= pdev
->dev
.platform_data
;
250 clk_enable(exynos_ohci
->clk
);
252 if (pdata
&& pdata
->phy_init
)
253 pdata
->phy_init(pdev
, S5P_USB_PHY_HOST
);
255 /* Mark hardware accessible again as we are out of D3 state by now */
256 set_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
258 ohci_finish_controller_resume(hcd
);
263 #define exynos_ohci_suspend NULL
264 #define exynos_ohci_resume NULL
267 static const struct dev_pm_ops exynos_ohci_pm_ops
= {
268 .suspend
= exynos_ohci_suspend
,
269 .resume
= exynos_ohci_resume
,
273 static const struct of_device_id exynos_ohci_match
[] = {
274 { .compatible
= "samsung,exynos-ohci" },
277 MODULE_DEVICE_TABLE(of
, exynos_ohci_match
);
280 static struct platform_driver exynos_ohci_driver
= {
281 .probe
= exynos_ohci_probe
,
282 .remove
= __devexit_p(exynos_ohci_remove
),
283 .shutdown
= exynos_ohci_shutdown
,
285 .name
= "exynos-ohci",
286 .owner
= THIS_MODULE
,
287 .pm
= &exynos_ohci_pm_ops
,
288 .of_match_table
= of_match_ptr(exynos_ohci_match
),
292 MODULE_ALIAS("platform:exynos-ohci");
293 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");