Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (C) 2010 ST-Ericsson AB
  3 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
  4 *
  5 * Based on omap2430.c
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License as published by
  9 * the Free Software Foundation; either version 2 of the License, or
 10 * (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 20 */
 21
 22#include <linux/module.h>
 23#include <linux/kernel.h>
 24#include <linux/clk.h>
 25#include <linux/err.h>
 26#include <linux/io.h>
 27#include <linux/of.h>
 28#include <linux/platform_device.h>
 29#include <linux/usb/musb-ux500.h>
 30
 31#include "musb_core.h"
 32
 33static struct musb_hdrc_config ux500_musb_hdrc_config = {
 34	.multipoint	= true,
 35	.dyn_fifo	= true,
 36	.num_eps	= 16,
 37	.ram_bits	= 16,
 38};
 39
 40struct ux500_glue {
 41	struct device		*dev;
 42	struct platform_device	*musb;
 43	struct clk		*clk;
 44};
 45#define glue_to_musb(g)	platform_get_drvdata(g->musb)
 46
 47static void ux500_musb_set_vbus(struct musb *musb, int is_on)
 48{
 49	u8            devctl;
 50	unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 51	/* HDRC controls CPEN, but beware current surges during device
 52	 * connect.  They can trigger transient overcurrent conditions
 53	 * that must be ignored.
 54	 */
 55
 56	devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
 57
 58	if (is_on) {
 59		if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) {
 60			/* start the session */
 61			devctl |= MUSB_DEVCTL_SESSION;
 62			musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
 63			/*
 64			 * Wait for the musb to set as A device to enable the
 65			 * VBUS
 66			 */
 67			while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
 68
 69				if (time_after(jiffies, timeout)) {
 70					dev_err(musb->controller,
 71					"configured as A device timeout");
 72					break;
 73				}
 74			}
 75
 76		} else {
 77			musb->is_active = 1;
 78			musb->xceiv->otg->default_a = 1;
 79			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
 80			devctl |= MUSB_DEVCTL_SESSION;
 81			MUSB_HST_MODE(musb);
 82		}
 83	} else {
 84		musb->is_active = 0;
 85
 86		/* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping
 87		 * right to B_IDLE...
 88		 */
 89		musb->xceiv->otg->default_a = 0;
 90		devctl &= ~MUSB_DEVCTL_SESSION;
 91		MUSB_DEV_MODE(musb);
 92	}
 93	musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
 94
 95	/*
 96	 * Devctl values will be updated after vbus goes below
 97	 * session_valid. The time taken depends on the capacitance
 98	 * on VBUS line. The max discharge time can be upto 1 sec
 99	 * as per the spec. Typically on our platform, it is 200ms
100	 */
101	if (!is_on)
102		mdelay(200);
103
104	dev_dbg(musb->controller, "VBUS %s, devctl %02x\n",
105		usb_otg_state_string(musb->xceiv->otg->state),
106		musb_readb(musb->mregs, MUSB_DEVCTL));
107}
108
109static int musb_otg_notifications(struct notifier_block *nb,
110		unsigned long event, void *unused)
111{
112	struct musb *musb = container_of(nb, struct musb, nb);
113
114	dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n",
115			event, usb_otg_state_string(musb->xceiv->otg->state));
116
117	switch (event) {
118	case UX500_MUSB_ID:
119		dev_dbg(musb->controller, "ID GND\n");
120		ux500_musb_set_vbus(musb, 1);
121		break;
122	case UX500_MUSB_VBUS:
123		dev_dbg(musb->controller, "VBUS Connect\n");
124		break;
125	case UX500_MUSB_NONE:
126		dev_dbg(musb->controller, "VBUS Disconnect\n");
127		if (is_host_active(musb))
128			ux500_musb_set_vbus(musb, 0);
129		else
130			musb->xceiv->otg->state = OTG_STATE_B_IDLE;
131		break;
132	default:
133		dev_dbg(musb->controller, "ID float\n");
134		return NOTIFY_DONE;
135	}
136	return NOTIFY_OK;
137}
138
139static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
140{
141	unsigned long   flags;
142	irqreturn_t     retval = IRQ_NONE;
143	struct musb     *musb = __hci;
144
145	spin_lock_irqsave(&musb->lock, flags);
146
147	musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
148	musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
149	musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
150
151	if (musb->int_usb || musb->int_tx || musb->int_rx)
152		retval = musb_interrupt(musb);
153
154	spin_unlock_irqrestore(&musb->lock, flags);
155
156	return retval;
157}
158
159static int ux500_musb_init(struct musb *musb)
160{
161	int status;
162
163	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
164	if (IS_ERR_OR_NULL(musb->xceiv)) {
165		pr_err("HS USB OTG: no transceiver configured\n");
166		return -EPROBE_DEFER;
167	}
168
169	musb->nb.notifier_call = musb_otg_notifications;
170	status = usb_register_notifier(musb->xceiv, &musb->nb);
171	if (status < 0) {
172		dev_dbg(musb->controller, "notification register failed\n");
173		return status;
174	}
175
176	musb->isr = ux500_musb_interrupt;
177
178	return 0;
179}
180
181static int ux500_musb_exit(struct musb *musb)
182{
183	usb_unregister_notifier(musb->xceiv, &musb->nb);
184
185	usb_put_phy(musb->xceiv);
186
187	return 0;
188}
189
190static const struct musb_platform_ops ux500_ops = {
191	.quirks		= MUSB_DMA_UX500 | MUSB_INDEXED_EP,
192#ifdef CONFIG_USB_UX500_DMA
193	.dma_init	= ux500_dma_controller_create,
194	.dma_exit	= ux500_dma_controller_destroy,
195#endif
196	.init		= ux500_musb_init,
197	.exit		= ux500_musb_exit,
198	.fifo_mode	= 5,
199
200	.set_vbus	= ux500_musb_set_vbus,
201};
202
203static struct musb_hdrc_platform_data *
204ux500_of_probe(struct platform_device *pdev, struct device_node *np)
205{
206	struct musb_hdrc_platform_data *pdata;
207	const char *mode;
208	int strlen;
209
210	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
211	if (!pdata)
212		return NULL;
213
214	mode = of_get_property(np, "dr_mode", &strlen);
215	if (!mode) {
216		dev_err(&pdev->dev, "No 'dr_mode' property found\n");
217		return NULL;
218	}
219
220	if (strlen > 0) {
221		if (!strcmp(mode, "host"))
222			pdata->mode = MUSB_HOST;
223		if (!strcmp(mode, "otg"))
224			pdata->mode = MUSB_OTG;
225		if (!strcmp(mode, "peripheral"))
226			pdata->mode = MUSB_PERIPHERAL;
227	}
228
229	return pdata;
230}
231
232static int ux500_probe(struct platform_device *pdev)
233{
234	struct resource musb_resources[2];
235	struct musb_hdrc_platform_data	*pdata = dev_get_platdata(&pdev->dev);
236	struct device_node		*np = pdev->dev.of_node;
237	struct platform_device		*musb;
238	struct ux500_glue		*glue;
239	struct clk			*clk;
240	int				ret = -ENOMEM;
241
242	if (!pdata) {
243		if (np) {
244			pdata = ux500_of_probe(pdev, np);
245			if (!pdata)
246				goto err0;
247
248			pdev->dev.platform_data = pdata;
249		} else {
250			dev_err(&pdev->dev, "no pdata or device tree found\n");
251			goto err0;
252		}
253	}
254
255	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
256	if (!glue)
257		goto err0;
258
259	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
260	if (!musb) {
261		dev_err(&pdev->dev, "failed to allocate musb device\n");
262		goto err0;
263	}
264
265	clk = devm_clk_get(&pdev->dev, NULL);
266	if (IS_ERR(clk)) {
267		dev_err(&pdev->dev, "failed to get clock\n");
268		ret = PTR_ERR(clk);
269		goto err1;
270	}
271
272	ret = clk_prepare_enable(clk);
273	if (ret) {
274		dev_err(&pdev->dev, "failed to enable clock\n");
275		goto err1;
276	}
277
278	musb->dev.parent		= &pdev->dev;
279	musb->dev.dma_mask		= &pdev->dev.coherent_dma_mask;
280	musb->dev.coherent_dma_mask	= pdev->dev.coherent_dma_mask;
281
282	glue->dev			= &pdev->dev;
283	glue->musb			= musb;
284	glue->clk			= clk;
285
286	pdata->platform_ops		= &ux500_ops;
287	pdata->config 			= &ux500_musb_hdrc_config;
288
289	platform_set_drvdata(pdev, glue);
290
291	memset(musb_resources, 0x00, sizeof(*musb_resources) *
292			ARRAY_SIZE(musb_resources));
293
294	musb_resources[0].name = pdev->resource[0].name;
295	musb_resources[0].start = pdev->resource[0].start;
296	musb_resources[0].end = pdev->resource[0].end;
297	musb_resources[0].flags = pdev->resource[0].flags;
298
299	musb_resources[1].name = pdev->resource[1].name;
300	musb_resources[1].start = pdev->resource[1].start;
301	musb_resources[1].end = pdev->resource[1].end;
302	musb_resources[1].flags = pdev->resource[1].flags;
303
304	ret = platform_device_add_resources(musb, musb_resources,
305			ARRAY_SIZE(musb_resources));
306	if (ret) {
307		dev_err(&pdev->dev, "failed to add resources\n");
308		goto err2;
309	}
310
311	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
312	if (ret) {
313		dev_err(&pdev->dev, "failed to add platform_data\n");
314		goto err2;
315	}
316
317	ret = platform_device_add(musb);
318	if (ret) {
319		dev_err(&pdev->dev, "failed to register musb device\n");
320		goto err2;
321	}
322
323	return 0;
324
325err2:
326	clk_disable_unprepare(clk);
327
328err1:
329	platform_device_put(musb);
330
331err0:
332	return ret;
333}
334
335static int ux500_remove(struct platform_device *pdev)
336{
337	struct ux500_glue	*glue = platform_get_drvdata(pdev);
338
339	platform_device_unregister(glue->musb);
340	clk_disable_unprepare(glue->clk);
341
342	return 0;
343}
344
345#ifdef CONFIG_PM_SLEEP
346static int ux500_suspend(struct device *dev)
347{
348	struct ux500_glue	*glue = dev_get_drvdata(dev);
349	struct musb		*musb = glue_to_musb(glue);
350
351	if (musb)
352		usb_phy_set_suspend(musb->xceiv, 1);
353
354	clk_disable_unprepare(glue->clk);
355
356	return 0;
357}
358
359static int ux500_resume(struct device *dev)
360{
361	struct ux500_glue	*glue = dev_get_drvdata(dev);
362	struct musb		*musb = glue_to_musb(glue);
363	int			ret;
364
365	ret = clk_prepare_enable(glue->clk);
366	if (ret) {
367		dev_err(dev, "failed to enable clock\n");
368		return ret;
369	}
370
371	if (musb)
372		usb_phy_set_suspend(musb->xceiv, 0);
373
374	return 0;
375}
376#endif
377
378static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume);
379
380static const struct of_device_id ux500_match[] = {
381        { .compatible = "stericsson,db8500-musb", },
382        {}
383};
384
385MODULE_DEVICE_TABLE(of, ux500_match);
386
387static struct platform_driver ux500_driver = {
388	.probe		= ux500_probe,
389	.remove		= ux500_remove,
390	.driver		= {
391		.name	= "musb-ux500",
392		.pm	= &ux500_pm_ops,
393		.of_match_table = ux500_match,
394	},
395};
396
397MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
398MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
399MODULE_LICENSE("GPL v2");
400module_platform_driver(ux500_driver);
v5.9
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (C) 2010 ST-Ericsson AB
  4 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
  5 *
  6 * Based on omap2430.c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  7 */
  8
  9#include <linux/module.h>
 10#include <linux/kernel.h>
 11#include <linux/clk.h>
 12#include <linux/err.h>
 13#include <linux/io.h>
 14#include <linux/of.h>
 15#include <linux/platform_device.h>
 16#include <linux/usb/musb-ux500.h>
 17
 18#include "musb_core.h"
 19
 20static const struct musb_hdrc_config ux500_musb_hdrc_config = {
 21	.multipoint	= true,
 22	.dyn_fifo	= true,
 23	.num_eps	= 16,
 24	.ram_bits	= 16,
 25};
 26
 27struct ux500_glue {
 28	struct device		*dev;
 29	struct platform_device	*musb;
 30	struct clk		*clk;
 31};
 32#define glue_to_musb(g)	platform_get_drvdata(g->musb)
 33
 34static void ux500_musb_set_vbus(struct musb *musb, int is_on)
 35{
 36	u8            devctl;
 37	unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 38	/* HDRC controls CPEN, but beware current surges during device
 39	 * connect.  They can trigger transient overcurrent conditions
 40	 * that must be ignored.
 41	 */
 42
 43	devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
 44
 45	if (is_on) {
 46		if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) {
 47			/* start the session */
 48			devctl |= MUSB_DEVCTL_SESSION;
 49			musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
 50			/*
 51			 * Wait for the musb to set as A device to enable the
 52			 * VBUS
 53			 */
 54			while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
 55
 56				if (time_after(jiffies, timeout)) {
 57					dev_err(musb->controller,
 58					"configured as A device timeout");
 59					break;
 60				}
 61			}
 62
 63		} else {
 64			musb->is_active = 1;
 
 65			musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
 66			devctl |= MUSB_DEVCTL_SESSION;
 67			MUSB_HST_MODE(musb);
 68		}
 69	} else {
 70		musb->is_active = 0;
 71
 72		/* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping
 73		 * right to B_IDLE...
 74		 */
 
 75		devctl &= ~MUSB_DEVCTL_SESSION;
 76		MUSB_DEV_MODE(musb);
 77	}
 78	musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
 79
 80	/*
 81	 * Devctl values will be updated after vbus goes below
 82	 * session_valid. The time taken depends on the capacitance
 83	 * on VBUS line. The max discharge time can be upto 1 sec
 84	 * as per the spec. Typically on our platform, it is 200ms
 85	 */
 86	if (!is_on)
 87		mdelay(200);
 88
 89	dev_dbg(musb->controller, "VBUS %s, devctl %02x\n",
 90		usb_otg_state_string(musb->xceiv->otg->state),
 91		musb_readb(musb->mregs, MUSB_DEVCTL));
 92}
 93
 94static int musb_otg_notifications(struct notifier_block *nb,
 95		unsigned long event, void *unused)
 96{
 97	struct musb *musb = container_of(nb, struct musb, nb);
 98
 99	dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n",
100			event, usb_otg_state_string(musb->xceiv->otg->state));
101
102	switch (event) {
103	case UX500_MUSB_ID:
104		dev_dbg(musb->controller, "ID GND\n");
105		ux500_musb_set_vbus(musb, 1);
106		break;
107	case UX500_MUSB_VBUS:
108		dev_dbg(musb->controller, "VBUS Connect\n");
109		break;
110	case UX500_MUSB_NONE:
111		dev_dbg(musb->controller, "VBUS Disconnect\n");
112		if (is_host_active(musb))
113			ux500_musb_set_vbus(musb, 0);
114		else
115			musb->xceiv->otg->state = OTG_STATE_B_IDLE;
116		break;
117	default:
118		dev_dbg(musb->controller, "ID float\n");
119		return NOTIFY_DONE;
120	}
121	return NOTIFY_OK;
122}
123
124static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
125{
126	unsigned long   flags;
127	irqreturn_t     retval = IRQ_NONE;
128	struct musb     *musb = __hci;
129
130	spin_lock_irqsave(&musb->lock, flags);
131
132	musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
133	musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
134	musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
135
136	if (musb->int_usb || musb->int_tx || musb->int_rx)
137		retval = musb_interrupt(musb);
138
139	spin_unlock_irqrestore(&musb->lock, flags);
140
141	return retval;
142}
143
144static int ux500_musb_init(struct musb *musb)
145{
146	int status;
147
148	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
149	if (IS_ERR_OR_NULL(musb->xceiv)) {
150		pr_err("HS USB OTG: no transceiver configured\n");
151		return -EPROBE_DEFER;
152	}
153
154	musb->nb.notifier_call = musb_otg_notifications;
155	status = usb_register_notifier(musb->xceiv, &musb->nb);
156	if (status < 0) {
157		dev_dbg(musb->controller, "notification register failed\n");
158		return status;
159	}
160
161	musb->isr = ux500_musb_interrupt;
162
163	return 0;
164}
165
166static int ux500_musb_exit(struct musb *musb)
167{
168	usb_unregister_notifier(musb->xceiv, &musb->nb);
169
170	usb_put_phy(musb->xceiv);
171
172	return 0;
173}
174
175static const struct musb_platform_ops ux500_ops = {
176	.quirks		= MUSB_DMA_UX500 | MUSB_INDEXED_EP,
177#ifdef CONFIG_USB_UX500_DMA
178	.dma_init	= ux500_dma_controller_create,
179	.dma_exit	= ux500_dma_controller_destroy,
180#endif
181	.init		= ux500_musb_init,
182	.exit		= ux500_musb_exit,
183	.fifo_mode	= 5,
184
185	.set_vbus	= ux500_musb_set_vbus,
186};
187
188static struct musb_hdrc_platform_data *
189ux500_of_probe(struct platform_device *pdev, struct device_node *np)
190{
191	struct musb_hdrc_platform_data *pdata;
192	const char *mode;
193	int strlen;
194
195	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
196	if (!pdata)
197		return NULL;
198
199	mode = of_get_property(np, "dr_mode", &strlen);
200	if (!mode) {
201		dev_err(&pdev->dev, "No 'dr_mode' property found\n");
202		return NULL;
203	}
204
205	if (strlen > 0) {
206		if (!strcmp(mode, "host"))
207			pdata->mode = MUSB_HOST;
208		if (!strcmp(mode, "otg"))
209			pdata->mode = MUSB_OTG;
210		if (!strcmp(mode, "peripheral"))
211			pdata->mode = MUSB_PERIPHERAL;
212	}
213
214	return pdata;
215}
216
217static int ux500_probe(struct platform_device *pdev)
218{
219	struct resource musb_resources[2];
220	struct musb_hdrc_platform_data	*pdata = dev_get_platdata(&pdev->dev);
221	struct device_node		*np = pdev->dev.of_node;
222	struct platform_device		*musb;
223	struct ux500_glue		*glue;
224	struct clk			*clk;
225	int				ret = -ENOMEM;
226
227	if (!pdata) {
228		if (np) {
229			pdata = ux500_of_probe(pdev, np);
230			if (!pdata)
231				goto err0;
232
233			pdev->dev.platform_data = pdata;
234		} else {
235			dev_err(&pdev->dev, "no pdata or device tree found\n");
236			goto err0;
237		}
238	}
239
240	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
241	if (!glue)
242		goto err0;
243
244	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
245	if (!musb) {
246		dev_err(&pdev->dev, "failed to allocate musb device\n");
247		goto err0;
248	}
249
250	clk = devm_clk_get(&pdev->dev, NULL);
251	if (IS_ERR(clk)) {
252		dev_err(&pdev->dev, "failed to get clock\n");
253		ret = PTR_ERR(clk);
254		goto err1;
255	}
256
257	ret = clk_prepare_enable(clk);
258	if (ret) {
259		dev_err(&pdev->dev, "failed to enable clock\n");
260		goto err1;
261	}
262
263	musb->dev.parent		= &pdev->dev;
264	musb->dev.dma_mask		= &pdev->dev.coherent_dma_mask;
265	musb->dev.coherent_dma_mask	= pdev->dev.coherent_dma_mask;
266
267	glue->dev			= &pdev->dev;
268	glue->musb			= musb;
269	glue->clk			= clk;
270
271	pdata->platform_ops		= &ux500_ops;
272	pdata->config 			= &ux500_musb_hdrc_config;
273
274	platform_set_drvdata(pdev, glue);
275
276	memset(musb_resources, 0x00, sizeof(*musb_resources) *
277			ARRAY_SIZE(musb_resources));
278
279	musb_resources[0].name = pdev->resource[0].name;
280	musb_resources[0].start = pdev->resource[0].start;
281	musb_resources[0].end = pdev->resource[0].end;
282	musb_resources[0].flags = pdev->resource[0].flags;
283
284	musb_resources[1].name = pdev->resource[1].name;
285	musb_resources[1].start = pdev->resource[1].start;
286	musb_resources[1].end = pdev->resource[1].end;
287	musb_resources[1].flags = pdev->resource[1].flags;
288
289	ret = platform_device_add_resources(musb, musb_resources,
290			ARRAY_SIZE(musb_resources));
291	if (ret) {
292		dev_err(&pdev->dev, "failed to add resources\n");
293		goto err2;
294	}
295
296	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
297	if (ret) {
298		dev_err(&pdev->dev, "failed to add platform_data\n");
299		goto err2;
300	}
301
302	ret = platform_device_add(musb);
303	if (ret) {
304		dev_err(&pdev->dev, "failed to register musb device\n");
305		goto err2;
306	}
307
308	return 0;
309
310err2:
311	clk_disable_unprepare(clk);
312
313err1:
314	platform_device_put(musb);
315
316err0:
317	return ret;
318}
319
320static int ux500_remove(struct platform_device *pdev)
321{
322	struct ux500_glue	*glue = platform_get_drvdata(pdev);
323
324	platform_device_unregister(glue->musb);
325	clk_disable_unprepare(glue->clk);
326
327	return 0;
328}
329
330#ifdef CONFIG_PM_SLEEP
331static int ux500_suspend(struct device *dev)
332{
333	struct ux500_glue	*glue = dev_get_drvdata(dev);
334	struct musb		*musb = glue_to_musb(glue);
335
336	if (musb)
337		usb_phy_set_suspend(musb->xceiv, 1);
338
339	clk_disable_unprepare(glue->clk);
340
341	return 0;
342}
343
344static int ux500_resume(struct device *dev)
345{
346	struct ux500_glue	*glue = dev_get_drvdata(dev);
347	struct musb		*musb = glue_to_musb(glue);
348	int			ret;
349
350	ret = clk_prepare_enable(glue->clk);
351	if (ret) {
352		dev_err(dev, "failed to enable clock\n");
353		return ret;
354	}
355
356	if (musb)
357		usb_phy_set_suspend(musb->xceiv, 0);
358
359	return 0;
360}
361#endif
362
363static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume);
364
365static const struct of_device_id ux500_match[] = {
366        { .compatible = "stericsson,db8500-musb", },
367        {}
368};
369
370MODULE_DEVICE_TABLE(of, ux500_match);
371
372static struct platform_driver ux500_driver = {
373	.probe		= ux500_probe,
374	.remove		= ux500_remove,
375	.driver		= {
376		.name	= "musb-ux500",
377		.pm	= &ux500_pm_ops,
378		.of_match_table = ux500_match,
379	},
380};
381
382MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
383MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
384MODULE_LICENSE("GPL v2");
385module_platform_driver(ux500_driver);