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 <linux/platform_data/usb-exynos.h>
18 #include <linux/usb/phy.h>
19 #include <linux/usb/samsung_usb_phy.h>
20 #include <plat/usb-phy.h>
22 struct exynos_ohci_hcd
{
28 struct exynos4_ohci_platdata
*pdata
;
31 static void exynos_ohci_phy_enable(struct exynos_ohci_hcd
*exynos_ohci
)
33 struct platform_device
*pdev
= to_platform_device(exynos_ohci
->dev
);
36 usb_phy_init(exynos_ohci
->phy
);
37 else if (exynos_ohci
->pdata
&& exynos_ohci
->pdata
->phy_init
)
38 exynos_ohci
->pdata
->phy_init(pdev
, USB_PHY_TYPE_HOST
);
41 static void exynos_ohci_phy_disable(struct exynos_ohci_hcd
*exynos_ohci
)
43 struct platform_device
*pdev
= to_platform_device(exynos_ohci
->dev
);
46 usb_phy_shutdown(exynos_ohci
->phy
);
47 else if (exynos_ohci
->pdata
&& exynos_ohci
->pdata
->phy_exit
)
48 exynos_ohci
->pdata
->phy_exit(pdev
, USB_PHY_TYPE_HOST
);
51 static int ohci_exynos_reset(struct usb_hcd
*hcd
)
53 return ohci_init(hcd_to_ohci(hcd
));
56 static int ohci_exynos_start(struct usb_hcd
*hcd
)
58 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
61 ohci_dbg(ohci
, "ohci_exynos_start, ohci:%p", ohci
);
65 dev_err(hcd
->self
.controller
, "can't start %s\n",
74 static const struct hc_driver exynos_ohci_hc_driver
= {
75 .description
= hcd_name
,
76 .product_desc
= "EXYNOS OHCI Host Controller",
77 .hcd_priv_size
= sizeof(struct ohci_hcd
),
80 .flags
= HCD_MEMORY
|HCD_USB11
,
82 .reset
= ohci_exynos_reset
,
83 .start
= ohci_exynos_start
,
85 .shutdown
= ohci_shutdown
,
87 .get_frame_number
= ohci_get_frame
,
89 .urb_enqueue
= ohci_urb_enqueue
,
90 .urb_dequeue
= ohci_urb_dequeue
,
91 .endpoint_disable
= ohci_endpoint_disable
,
93 .hub_status_data
= ohci_hub_status_data
,
94 .hub_control
= ohci_hub_control
,
96 .bus_suspend
= ohci_bus_suspend
,
97 .bus_resume
= ohci_bus_resume
,
99 .start_port_reset
= ohci_start_port_reset
,
102 static u64 ohci_exynos_dma_mask
= DMA_BIT_MASK(32);
104 static int exynos_ohci_probe(struct platform_device
*pdev
)
106 struct exynos4_ohci_platdata
*pdata
= pdev
->dev
.platform_data
;
107 struct exynos_ohci_hcd
*exynos_ohci
;
109 struct ohci_hcd
*ohci
;
110 struct resource
*res
;
116 * Right now device-tree probed devices don't get dma_mask set.
117 * Since shared usb code relies on it, set it here for now.
118 * Once we move to full device tree support this will vanish off.
120 if (!pdev
->dev
.dma_mask
)
121 pdev
->dev
.dma_mask
= &ohci_exynos_dma_mask
;
122 if (!pdev
->dev
.coherent_dma_mask
)
123 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
125 exynos_ohci
= devm_kzalloc(&pdev
->dev
, sizeof(struct exynos_ohci_hcd
),
130 if (of_device_is_compatible(pdev
->dev
.of_node
,
131 "samsung,exynos5440-ohci"))
134 phy
= devm_usb_get_phy(&pdev
->dev
, USB_PHY_TYPE_USB2
);
136 /* Fallback to pdata */
138 dev_warn(&pdev
->dev
, "no platform data or transceiver defined\n");
139 return -EPROBE_DEFER
;
141 exynos_ohci
->pdata
= pdata
;
144 exynos_ohci
->phy
= phy
;
145 exynos_ohci
->otg
= phy
->otg
;
150 exynos_ohci
->dev
= &pdev
->dev
;
152 hcd
= usb_create_hcd(&exynos_ohci_hc_driver
, &pdev
->dev
,
153 dev_name(&pdev
->dev
));
155 dev_err(&pdev
->dev
, "Unable to create HCD\n");
159 exynos_ohci
->hcd
= hcd
;
160 exynos_ohci
->clk
= devm_clk_get(&pdev
->dev
, "usbhost");
162 if (IS_ERR(exynos_ohci
->clk
)) {
163 dev_err(&pdev
->dev
, "Failed to get usbhost clock\n");
164 err
= PTR_ERR(exynos_ohci
->clk
);
168 err
= clk_prepare_enable(exynos_ohci
->clk
);
172 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
174 dev_err(&pdev
->dev
, "Failed to get I/O memory\n");
179 hcd
->rsrc_start
= res
->start
;
180 hcd
->rsrc_len
= resource_size(res
);
181 hcd
->regs
= devm_ioremap(&pdev
->dev
, res
->start
, hcd
->rsrc_len
);
183 dev_err(&pdev
->dev
, "Failed to remap I/O memory\n");
188 irq
= platform_get_irq(pdev
, 0);
190 dev_err(&pdev
->dev
, "Failed to get IRQ\n");
195 if (exynos_ohci
->otg
)
196 exynos_ohci
->otg
->set_host(exynos_ohci
->otg
,
197 &exynos_ohci
->hcd
->self
);
199 exynos_ohci_phy_enable(exynos_ohci
);
201 ohci
= hcd_to_ohci(hcd
);
204 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
206 dev_err(&pdev
->dev
, "Failed to add USB HCD\n");
210 platform_set_drvdata(pdev
, exynos_ohci
);
215 exynos_ohci_phy_disable(exynos_ohci
);
217 clk_disable_unprepare(exynos_ohci
->clk
);
223 static int exynos_ohci_remove(struct platform_device
*pdev
)
225 struct exynos_ohci_hcd
*exynos_ohci
= platform_get_drvdata(pdev
);
226 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
230 if (exynos_ohci
->otg
)
231 exynos_ohci
->otg
->set_host(exynos_ohci
->otg
,
232 &exynos_ohci
->hcd
->self
);
234 exynos_ohci_phy_disable(exynos_ohci
);
236 clk_disable_unprepare(exynos_ohci
->clk
);
243 static void exynos_ohci_shutdown(struct platform_device
*pdev
)
245 struct exynos_ohci_hcd
*exynos_ohci
= platform_get_drvdata(pdev
);
246 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
248 if (hcd
->driver
->shutdown
)
249 hcd
->driver
->shutdown(hcd
);
253 static int exynos_ohci_suspend(struct device
*dev
)
255 struct exynos_ohci_hcd
*exynos_ohci
= dev_get_drvdata(dev
);
256 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
257 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
262 * Root hub was already suspended. Disable irq emission and
263 * mark HW unaccessible, bail out if RH has been resumed. Use
264 * the spinlock to properly synchronize with possible pending
265 * RH suspend or resume activity.
267 spin_lock_irqsave(&ohci
->lock
, flags
);
268 if (ohci
->rh_state
!= OHCI_RH_SUSPENDED
&&
269 ohci
->rh_state
!= OHCI_RH_HALTED
) {
274 clear_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
276 if (exynos_ohci
->otg
)
277 exynos_ohci
->otg
->set_host(exynos_ohci
->otg
,
278 &exynos_ohci
->hcd
->self
);
280 exynos_ohci_phy_disable(exynos_ohci
);
282 clk_disable_unprepare(exynos_ohci
->clk
);
285 spin_unlock_irqrestore(&ohci
->lock
, flags
);
290 static int exynos_ohci_resume(struct device
*dev
)
292 struct exynos_ohci_hcd
*exynos_ohci
= dev_get_drvdata(dev
);
293 struct usb_hcd
*hcd
= exynos_ohci
->hcd
;
295 clk_prepare_enable(exynos_ohci
->clk
);
297 if (exynos_ohci
->otg
)
298 exynos_ohci
->otg
->set_host(exynos_ohci
->otg
,
299 &exynos_ohci
->hcd
->self
);
301 exynos_ohci_phy_enable(exynos_ohci
);
303 ohci_resume(hcd
, false);
308 #define exynos_ohci_suspend NULL
309 #define exynos_ohci_resume NULL
312 static const struct dev_pm_ops exynos_ohci_pm_ops
= {
313 .suspend
= exynos_ohci_suspend
,
314 .resume
= exynos_ohci_resume
,
318 static const struct of_device_id exynos_ohci_match
[] = {
319 { .compatible
= "samsung,exynos4210-ohci" },
320 { .compatible
= "samsung,exynos5440-ohci" },
323 MODULE_DEVICE_TABLE(of
, exynos_ohci_match
);
326 static struct platform_driver exynos_ohci_driver
= {
327 .probe
= exynos_ohci_probe
,
328 .remove
= exynos_ohci_remove
,
329 .shutdown
= exynos_ohci_shutdown
,
331 .name
= "exynos-ohci",
332 .owner
= THIS_MODULE
,
333 .pm
= &exynos_ohci_pm_ops
,
334 .of_match_table
= of_match_ptr(exynos_ohci_match
),
338 MODULE_ALIAS("platform:exynos-ohci");
339 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");