Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Generic platform ohci driver
  4 *
  5 * Copyright 2007 Michael Buesch <m@bues.ch>
  6 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
  7 * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
  8 *
  9 * Derived from the OCHI-SSB driver
 10 * Derived from the OHCI-PCI driver
 11 * Copyright 1999 Roman Weissgaerber
 12 * Copyright 2000-2002 David Brownell
 13 * Copyright 1999 Linus Torvalds
 14 * Copyright 1999 Gregory P. Smith
 
 
 15 */
 16
 17#include <linux/clk.h>
 18#include <linux/dma-mapping.h>
 19#include <linux/hrtimer.h>
 20#include <linux/io.h>
 21#include <linux/kernel.h>
 22#include <linux/module.h>
 23#include <linux/err.h>
 24#include <linux/of.h>
 25#include <linux/platform_device.h>
 26#include <linux/pm_runtime.h>
 27#include <linux/reset.h>
 28#include <linux/usb/ohci_pdriver.h>
 29#include <linux/usb.h>
 30#include <linux/usb/hcd.h>
 31#include <linux/usb/of.h>
 32
 33#include "ohci.h"
 34
 35#define DRIVER_DESC "OHCI generic platform driver"
 36#define OHCI_MAX_CLKS 3
 
 37#define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
 38
 39struct ohci_platform_priv {
 40	struct clk *clks[OHCI_MAX_CLKS];
 41	struct reset_control *resets;
 
 
 42};
 43
 
 
 44static int ohci_platform_power_on(struct platform_device *dev)
 45{
 46	struct usb_hcd *hcd = platform_get_drvdata(dev);
 47	struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
 48	int clk, ret;
 49
 50	for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
 51		ret = clk_prepare_enable(priv->clks[clk]);
 52		if (ret)
 53			goto err_disable_clks;
 54	}
 55
 
 
 
 
 
 
 
 
 
 
 
 56	return 0;
 57
 
 
 
 
 
 58err_disable_clks:
 59	while (--clk >= 0)
 60		clk_disable_unprepare(priv->clks[clk]);
 61
 62	return ret;
 63}
 64
 65static void ohci_platform_power_off(struct platform_device *dev)
 66{
 67	struct usb_hcd *hcd = platform_get_drvdata(dev);
 68	struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
 69	int clk;
 
 
 
 
 
 70
 71	for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
 72		if (priv->clks[clk])
 73			clk_disable_unprepare(priv->clks[clk]);
 74}
 75
 76static struct hc_driver __read_mostly ohci_platform_hc_driver;
 77
 78static const struct ohci_driver_overrides platform_overrides __initconst = {
 79	.product_desc =		"Generic Platform OHCI controller",
 80	.extra_priv_size =	sizeof(struct ohci_platform_priv),
 81};
 82
 83static struct usb_ohci_pdata ohci_platform_defaults = {
 84	.power_on =		ohci_platform_power_on,
 85	.power_suspend =	ohci_platform_power_off,
 86	.power_off =		ohci_platform_power_off,
 87};
 88
 89static int ohci_platform_probe(struct platform_device *dev)
 90{
 91	struct usb_hcd *hcd;
 92	struct resource *res_mem;
 93	struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
 94	struct ohci_platform_priv *priv;
 95	struct ohci_hcd *ohci;
 96	int err, irq, clk = 0;
 97
 98	if (usb_disabled())
 99		return -ENODEV;
100
101	/*
102	 * Use reasonable defaults so platforms don't have to provide these
103	 * with DT probing on ARM.
104	 */
105	if (!pdata)
106		pdata = &ohci_platform_defaults;
107
108	err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
109	if (err)
110		return err;
111
112	irq = platform_get_irq(dev, 0);
113	if (irq < 0)
 
114		return irq;
 
115
116	hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
117			dev_name(&dev->dev));
118	if (!hcd)
119		return -ENOMEM;
120
121	platform_set_drvdata(dev, hcd);
122	dev->dev.platform_data = pdata;
123	priv = hcd_to_ohci_priv(hcd);
124	ohci = hcd_to_ohci(hcd);
125
126	if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
127		if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
128			ohci->flags |= OHCI_QUIRK_BE_MMIO;
129
130		if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
131			ohci->flags |= OHCI_QUIRK_BE_DESC;
132
133		if (of_property_read_bool(dev->dev.of_node, "big-endian"))
134			ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
135
136		if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no"))
137			ohci->flags |= OHCI_QUIRK_FRAME_NO;
138
139		if (of_property_read_bool(dev->dev.of_node,
140					  "remote-wakeup-connected"))
141			ohci->hc_control = OHCI_CTRL_RWC;
142
143		of_property_read_u32(dev->dev.of_node, "num-ports",
144				     &ohci->num_ports);
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146		for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
147			priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
148			if (IS_ERR(priv->clks[clk])) {
149				err = PTR_ERR(priv->clks[clk]);
150				if (err == -EPROBE_DEFER)
151					goto err_put_clks;
152				priv->clks[clk] = NULL;
153				break;
154			}
155		}
156
157		priv->resets = devm_reset_control_array_get_optional_shared(
158								&dev->dev);
159		if (IS_ERR(priv->resets)) {
160			err = PTR_ERR(priv->resets);
161			goto err_put_clks;
 
 
 
 
 
 
 
 
162		}
163
164		err = reset_control_deassert(priv->resets);
165		if (err)
166			goto err_put_clks;
167	}
168
169	if (pdata->big_endian_desc)
170		ohci->flags |= OHCI_QUIRK_BE_DESC;
171	if (pdata->big_endian_mmio)
172		ohci->flags |= OHCI_QUIRK_BE_MMIO;
173	if (pdata->no_big_frame_no)
174		ohci->flags |= OHCI_QUIRK_FRAME_NO;
175	if (pdata->num_ports)
176		ohci->num_ports = pdata->num_ports;
177
178#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
179	if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
180		dev_err(&dev->dev,
181			"Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n");
182		err = -EINVAL;
183		goto err_reset;
184	}
185#endif
186#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC
187	if (ohci->flags & OHCI_QUIRK_BE_DESC) {
188		dev_err(&dev->dev,
189			"Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n");
190		err = -EINVAL;
191		goto err_reset;
192	}
193#endif
194
195	pm_runtime_set_active(&dev->dev);
196	pm_runtime_enable(&dev->dev);
197	if (pdata->power_on) {
198		err = pdata->power_on(dev);
199		if (err < 0)
200			goto err_reset;
201	}
202
203	res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
204	hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
205	if (IS_ERR(hcd->regs)) {
206		err = PTR_ERR(hcd->regs);
207		goto err_power;
208	}
209	hcd->rsrc_start = res_mem->start;
210	hcd->rsrc_len = resource_size(res_mem);
211
212	hcd->tpl_support = of_usb_host_tpl_support(dev->dev.of_node);
213
214	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
215	if (err)
216		goto err_power;
217
218	device_wakeup_enable(hcd->self.controller);
219
220	platform_set_drvdata(dev, hcd);
221
222	return err;
223
224err_power:
225	if (pdata->power_off)
226		pdata->power_off(dev);
227err_reset:
228	pm_runtime_disable(&dev->dev);
229	reset_control_assert(priv->resets);
230err_put_clks:
231	while (--clk >= 0)
232		clk_put(priv->clks[clk]);
233
234	if (pdata == &ohci_platform_defaults)
235		dev->dev.platform_data = NULL;
236
237	usb_put_hcd(hcd);
238
239	return err;
240}
241
242static int ohci_platform_remove(struct platform_device *dev)
243{
244	struct usb_hcd *hcd = platform_get_drvdata(dev);
245	struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
246	struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
247	int clk;
248
249	pm_runtime_get_sync(&dev->dev);
250	usb_remove_hcd(hcd);
251
252	if (pdata->power_off)
253		pdata->power_off(dev);
254
255	reset_control_assert(priv->resets);
 
256
257	for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
258		clk_put(priv->clks[clk]);
259
260	usb_put_hcd(hcd);
261
262	pm_runtime_put_sync(&dev->dev);
263	pm_runtime_disable(&dev->dev);
264
265	if (pdata == &ohci_platform_defaults)
266		dev->dev.platform_data = NULL;
267
268	return 0;
269}
270
271#ifdef CONFIG_PM_SLEEP
272static int ohci_platform_suspend(struct device *dev)
273{
274	struct usb_hcd *hcd = dev_get_drvdata(dev);
275	struct usb_ohci_pdata *pdata = dev->platform_data;
276	struct platform_device *pdev = to_platform_device(dev);
277	bool do_wakeup = device_may_wakeup(dev);
278	int ret;
279
280	ret = ohci_suspend(hcd, do_wakeup);
281	if (ret)
282		return ret;
283
284	if (pdata->power_suspend)
285		pdata->power_suspend(pdev);
286
287	return ret;
288}
289
290static int ohci_platform_resume_common(struct device *dev, bool hibernated)
291{
292	struct usb_hcd *hcd = dev_get_drvdata(dev);
293	struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
294	struct platform_device *pdev = to_platform_device(dev);
295
296	if (pdata->power_on) {
297		int err = pdata->power_on(pdev);
298		if (err < 0)
299			return err;
300	}
301
302	ohci_resume(hcd, hibernated);
303
304	pm_runtime_disable(dev);
305	pm_runtime_set_active(dev);
306	pm_runtime_enable(dev);
307
308	return 0;
309}
310
311static int ohci_platform_resume(struct device *dev)
312{
313	return ohci_platform_resume_common(dev, false);
314}
315
316static int ohci_platform_restore(struct device *dev)
317{
318	return ohci_platform_resume_common(dev, true);
319}
320#endif /* CONFIG_PM_SLEEP */
321
322static const struct of_device_id ohci_platform_ids[] = {
323	{ .compatible = "generic-ohci", },
324	{ .compatible = "cavium,octeon-6335-ohci", },
325	{ .compatible = "ti,ohci-omap3", },
326	{ }
327};
328MODULE_DEVICE_TABLE(of, ohci_platform_ids);
329
330static const struct platform_device_id ohci_platform_table[] = {
331	{ "ohci-platform", 0 },
332	{ }
333};
334MODULE_DEVICE_TABLE(platform, ohci_platform_table);
335
336#ifdef CONFIG_PM_SLEEP
337static const struct dev_pm_ops ohci_platform_pm_ops = {
338	.suspend = ohci_platform_suspend,
339	.resume = ohci_platform_resume,
340	.freeze = ohci_platform_suspend,
341	.thaw = ohci_platform_resume,
342	.poweroff = ohci_platform_suspend,
343	.restore = ohci_platform_restore,
344};
345#endif
346
347static struct platform_driver ohci_platform_driver = {
348	.id_table	= ohci_platform_table,
349	.probe		= ohci_platform_probe,
350	.remove		= ohci_platform_remove,
351	.shutdown	= usb_hcd_platform_shutdown,
352	.driver		= {
353		.name	= "ohci-platform",
354#ifdef CONFIG_PM_SLEEP
355		.pm	= &ohci_platform_pm_ops,
356#endif
357		.of_match_table = ohci_platform_ids,
358		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
359	}
360};
361
362static int __init ohci_platform_init(void)
363{
364	if (usb_disabled())
365		return -ENODEV;
 
 
366
367	ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
368	return platform_driver_register(&ohci_platform_driver);
369}
370module_init(ohci_platform_init);
371
372static void __exit ohci_platform_cleanup(void)
373{
374	platform_driver_unregister(&ohci_platform_driver);
375}
376module_exit(ohci_platform_cleanup);
377
378MODULE_DESCRIPTION(DRIVER_DESC);
379MODULE_AUTHOR("Hauke Mehrtens");
380MODULE_AUTHOR("Alan Stern");
381MODULE_LICENSE("GPL");
v4.10.11
 
  1/*
  2 * Generic platform ohci driver
  3 *
  4 * Copyright 2007 Michael Buesch <m@bues.ch>
  5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
  6 * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
  7 *
  8 * Derived from the OCHI-SSB driver
  9 * Derived from the OHCI-PCI driver
 10 * Copyright 1999 Roman Weissgaerber
 11 * Copyright 2000-2002 David Brownell
 12 * Copyright 1999 Linus Torvalds
 13 * Copyright 1999 Gregory P. Smith
 14 *
 15 * Licensed under the GNU/GPL. See COPYING for details.
 16 */
 17
 18#include <linux/clk.h>
 19#include <linux/dma-mapping.h>
 20#include <linux/hrtimer.h>
 21#include <linux/io.h>
 22#include <linux/kernel.h>
 23#include <linux/module.h>
 24#include <linux/err.h>
 25#include <linux/phy/phy.h>
 26#include <linux/platform_device.h>
 
 27#include <linux/reset.h>
 28#include <linux/usb/ohci_pdriver.h>
 29#include <linux/usb.h>
 30#include <linux/usb/hcd.h>
 
 31
 32#include "ohci.h"
 33
 34#define DRIVER_DESC "OHCI generic platform driver"
 35#define OHCI_MAX_CLKS 3
 36#define OHCI_MAX_RESETS 2
 37#define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
 38
 39struct ohci_platform_priv {
 40	struct clk *clks[OHCI_MAX_CLKS];
 41	struct reset_control *resets[OHCI_MAX_RESETS];
 42	struct phy **phys;
 43	int num_phys;
 44};
 45
 46static const char hcd_name[] = "ohci-platform";
 47
 48static int ohci_platform_power_on(struct platform_device *dev)
 49{
 50	struct usb_hcd *hcd = platform_get_drvdata(dev);
 51	struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
 52	int clk, ret, phy_num;
 53
 54	for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
 55		ret = clk_prepare_enable(priv->clks[clk]);
 56		if (ret)
 57			goto err_disable_clks;
 58	}
 59
 60	for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
 61		ret = phy_init(priv->phys[phy_num]);
 62		if (ret)
 63			goto err_exit_phy;
 64		ret = phy_power_on(priv->phys[phy_num]);
 65		if (ret) {
 66			phy_exit(priv->phys[phy_num]);
 67			goto err_exit_phy;
 68		}
 69	}
 70
 71	return 0;
 72
 73err_exit_phy:
 74	while (--phy_num >= 0) {
 75		phy_power_off(priv->phys[phy_num]);
 76		phy_exit(priv->phys[phy_num]);
 77	}
 78err_disable_clks:
 79	while (--clk >= 0)
 80		clk_disable_unprepare(priv->clks[clk]);
 81
 82	return ret;
 83}
 84
 85static void ohci_platform_power_off(struct platform_device *dev)
 86{
 87	struct usb_hcd *hcd = platform_get_drvdata(dev);
 88	struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
 89	int clk, phy_num;
 90
 91	for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
 92		phy_power_off(priv->phys[phy_num]);
 93		phy_exit(priv->phys[phy_num]);
 94	}
 95
 96	for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
 97		if (priv->clks[clk])
 98			clk_disable_unprepare(priv->clks[clk]);
 99}
100
101static struct hc_driver __read_mostly ohci_platform_hc_driver;
102
103static const struct ohci_driver_overrides platform_overrides __initconst = {
104	.product_desc =		"Generic Platform OHCI controller",
105	.extra_priv_size =	sizeof(struct ohci_platform_priv),
106};
107
108static struct usb_ohci_pdata ohci_platform_defaults = {
109	.power_on =		ohci_platform_power_on,
110	.power_suspend =	ohci_platform_power_off,
111	.power_off =		ohci_platform_power_off,
112};
113
114static int ohci_platform_probe(struct platform_device *dev)
115{
116	struct usb_hcd *hcd;
117	struct resource *res_mem;
118	struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
119	struct ohci_platform_priv *priv;
120	struct ohci_hcd *ohci;
121	int err, irq, phy_num, clk = 0, rst = 0;
122
123	if (usb_disabled())
124		return -ENODEV;
125
126	/*
127	 * Use reasonable defaults so platforms don't have to provide these
128	 * with DT probing on ARM.
129	 */
130	if (!pdata)
131		pdata = &ohci_platform_defaults;
132
133	err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
134	if (err)
135		return err;
136
137	irq = platform_get_irq(dev, 0);
138	if (irq < 0) {
139		dev_err(&dev->dev, "no irq provided");
140		return irq;
141	}
142
143	hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
144			dev_name(&dev->dev));
145	if (!hcd)
146		return -ENOMEM;
147
148	platform_set_drvdata(dev, hcd);
149	dev->dev.platform_data = pdata;
150	priv = hcd_to_ohci_priv(hcd);
151	ohci = hcd_to_ohci(hcd);
152
153	if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
154		if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
155			ohci->flags |= OHCI_QUIRK_BE_MMIO;
156
157		if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
158			ohci->flags |= OHCI_QUIRK_BE_DESC;
159
160		if (of_property_read_bool(dev->dev.of_node, "big-endian"))
161			ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
162
163		if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no"))
164			ohci->flags |= OHCI_QUIRK_FRAME_NO;
165
 
 
 
 
166		of_property_read_u32(dev->dev.of_node, "num-ports",
167				     &ohci->num_ports);
168
169		priv->num_phys = of_count_phandle_with_args(dev->dev.of_node,
170				"phys", "#phy-cells");
171
172		if (priv->num_phys > 0) {
173			priv->phys = devm_kcalloc(&dev->dev, priv->num_phys,
174					    sizeof(struct phy *), GFP_KERNEL);
175			if (!priv->phys)
176				return -ENOMEM;
177		} else
178			priv->num_phys = 0;
179
180		for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
181			priv->phys[phy_num] = devm_of_phy_get_by_index(
182					&dev->dev, dev->dev.of_node, phy_num);
183			if (IS_ERR(priv->phys[phy_num])) {
184				err = PTR_ERR(priv->phys[phy_num]);
185				goto err_put_hcd;
186			}
187		}
188
189		for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
190			priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
191			if (IS_ERR(priv->clks[clk])) {
192				err = PTR_ERR(priv->clks[clk]);
193				if (err == -EPROBE_DEFER)
194					goto err_put_clks;
195				priv->clks[clk] = NULL;
196				break;
197			}
198		}
199		for (rst = 0; rst < OHCI_MAX_RESETS; rst++) {
200			priv->resets[rst] =
201				devm_reset_control_get_shared_by_index(
202								&dev->dev, rst);
203			if (IS_ERR(priv->resets[rst])) {
204				err = PTR_ERR(priv->resets[rst]);
205				if (err == -EPROBE_DEFER)
206					goto err_reset;
207				priv->resets[rst] = NULL;
208				break;
209			}
210			err = reset_control_deassert(priv->resets[rst]);
211			if (err)
212				goto err_reset;
213		}
 
 
 
 
214	}
215
216	if (pdata->big_endian_desc)
217		ohci->flags |= OHCI_QUIRK_BE_DESC;
218	if (pdata->big_endian_mmio)
219		ohci->flags |= OHCI_QUIRK_BE_MMIO;
220	if (pdata->no_big_frame_no)
221		ohci->flags |= OHCI_QUIRK_FRAME_NO;
222	if (pdata->num_ports)
223		ohci->num_ports = pdata->num_ports;
224
225#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
226	if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
227		dev_err(&dev->dev,
228			"Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n");
229		err = -EINVAL;
230		goto err_reset;
231	}
232#endif
233#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC
234	if (ohci->flags & OHCI_QUIRK_BE_DESC) {
235		dev_err(&dev->dev,
236			"Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n");
237		err = -EINVAL;
238		goto err_reset;
239	}
240#endif
241
 
 
242	if (pdata->power_on) {
243		err = pdata->power_on(dev);
244		if (err < 0)
245			goto err_reset;
246	}
247
248	res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
249	hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
250	if (IS_ERR(hcd->regs)) {
251		err = PTR_ERR(hcd->regs);
252		goto err_power;
253	}
254	hcd->rsrc_start = res_mem->start;
255	hcd->rsrc_len = resource_size(res_mem);
256
 
 
257	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
258	if (err)
259		goto err_power;
260
261	device_wakeup_enable(hcd->self.controller);
262
263	platform_set_drvdata(dev, hcd);
264
265	return err;
266
267err_power:
268	if (pdata->power_off)
269		pdata->power_off(dev);
270err_reset:
271	while (--rst >= 0)
272		reset_control_assert(priv->resets[rst]);
273err_put_clks:
274	while (--clk >= 0)
275		clk_put(priv->clks[clk]);
276err_put_hcd:
277	if (pdata == &ohci_platform_defaults)
278		dev->dev.platform_data = NULL;
279
280	usb_put_hcd(hcd);
281
282	return err;
283}
284
285static int ohci_platform_remove(struct platform_device *dev)
286{
287	struct usb_hcd *hcd = platform_get_drvdata(dev);
288	struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
289	struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
290	int clk, rst;
291
 
292	usb_remove_hcd(hcd);
293
294	if (pdata->power_off)
295		pdata->power_off(dev);
296
297	for (rst = 0; rst < OHCI_MAX_RESETS && priv->resets[rst]; rst++)
298		reset_control_assert(priv->resets[rst]);
299
300	for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
301		clk_put(priv->clks[clk]);
302
303	usb_put_hcd(hcd);
304
 
 
 
305	if (pdata == &ohci_platform_defaults)
306		dev->dev.platform_data = NULL;
307
308	return 0;
309}
310
311#ifdef CONFIG_PM_SLEEP
312static int ohci_platform_suspend(struct device *dev)
313{
314	struct usb_hcd *hcd = dev_get_drvdata(dev);
315	struct usb_ohci_pdata *pdata = dev->platform_data;
316	struct platform_device *pdev = to_platform_device(dev);
317	bool do_wakeup = device_may_wakeup(dev);
318	int ret;
319
320	ret = ohci_suspend(hcd, do_wakeup);
321	if (ret)
322		return ret;
323
324	if (pdata->power_suspend)
325		pdata->power_suspend(pdev);
326
327	return ret;
328}
329
330static int ohci_platform_resume(struct device *dev)
331{
332	struct usb_hcd *hcd = dev_get_drvdata(dev);
333	struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
334	struct platform_device *pdev = to_platform_device(dev);
335
336	if (pdata->power_on) {
337		int err = pdata->power_on(pdev);
338		if (err < 0)
339			return err;
340	}
341
342	ohci_resume(hcd, false);
 
 
 
 
 
343	return 0;
344}
 
 
 
 
 
 
 
 
 
 
345#endif /* CONFIG_PM_SLEEP */
346
347static const struct of_device_id ohci_platform_ids[] = {
348	{ .compatible = "generic-ohci", },
349	{ .compatible = "cavium,octeon-6335-ohci", },
 
350	{ }
351};
352MODULE_DEVICE_TABLE(of, ohci_platform_ids);
353
354static const struct platform_device_id ohci_platform_table[] = {
355	{ "ohci-platform", 0 },
356	{ }
357};
358MODULE_DEVICE_TABLE(platform, ohci_platform_table);
359
360static SIMPLE_DEV_PM_OPS(ohci_platform_pm_ops, ohci_platform_suspend,
361	ohci_platform_resume);
 
 
 
 
 
 
 
 
362
363static struct platform_driver ohci_platform_driver = {
364	.id_table	= ohci_platform_table,
365	.probe		= ohci_platform_probe,
366	.remove		= ohci_platform_remove,
367	.shutdown	= usb_hcd_platform_shutdown,
368	.driver		= {
369		.name	= "ohci-platform",
 
370		.pm	= &ohci_platform_pm_ops,
 
371		.of_match_table = ohci_platform_ids,
 
372	}
373};
374
375static int __init ohci_platform_init(void)
376{
377	if (usb_disabled())
378		return -ENODEV;
379
380	pr_info("%s: " DRIVER_DESC "\n", hcd_name);
381
382	ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
383	return platform_driver_register(&ohci_platform_driver);
384}
385module_init(ohci_platform_init);
386
387static void __exit ohci_platform_cleanup(void)
388{
389	platform_driver_unregister(&ohci_platform_driver);
390}
391module_exit(ohci_platform_cleanup);
392
393MODULE_DESCRIPTION(DRIVER_DESC);
394MODULE_AUTHOR("Hauke Mehrtens");
395MODULE_AUTHOR("Alan Stern");
396MODULE_LICENSE("GPL");