blob: 9c8cc6e584439850310ee126c268346cadcbc613 [file] [log] [blame]
Ilya Yanok06bb9202012-11-06 13:48:21 +00001#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -07002#include <console.h>
Heiko Schocherc3ffe502013-06-04 11:10:01 +02003#include <watchdog.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +09004#include <linux/errno.h>
Ilya Yanok06bb9202012-11-06 13:48:21 +00005#include <linux/usb/ch9.h>
6#include <linux/usb/gadget.h>
7
Ilya Yanok06bb9202012-11-06 13:48:21 +00008#include <usb.h>
9#include "linux-compat.h"
10#include "usb-compat.h"
11#include "musb_core.h"
12#include "musb_host.h"
13#include "musb_gadget.h"
Hans de Goede59627482015-06-17 21:33:57 +020014#include "musb_uboot.h"
Ilya Yanok06bb9202012-11-06 13:48:21 +000015
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +020016#ifdef CONFIG_USB_MUSB_HOST
Hans de Goede83b18972015-01-11 20:34:54 +010017struct int_queue {
18 struct usb_host_endpoint hep;
19 struct urb urb;
20};
21
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +010022#if !CONFIG_IS_ENABLED(DM_USB)
Hans de Goede59627482015-06-17 21:33:57 +020023struct musb_host_data musb_host;
Hans de Goedefc649612015-06-17 21:33:58 +020024#endif
Ilya Yanok06bb9202012-11-06 13:48:21 +000025
26static void musb_host_complete_urb(struct urb *urb)
27{
28 urb->dev->status &= ~USB_ST_NOT_PROC;
29 urb->dev->act_len = urb->actual_length;
30}
31
Hans de Goede39b08452015-01-11 20:34:53 +010032static void construct_urb(struct urb *urb, struct usb_host_endpoint *hep,
33 struct usb_device *dev, int endpoint_type,
34 unsigned long pipe, void *buffer, int len,
35 struct devrequest *setup, int interval)
Ilya Yanok06bb9202012-11-06 13:48:21 +000036{
37 int epnum = usb_pipeendpoint(pipe);
38 int is_in = usb_pipein(pipe);
39
Hans de Goede39b08452015-01-11 20:34:53 +010040 memset(urb, 0, sizeof(struct urb));
41 memset(hep, 0, sizeof(struct usb_host_endpoint));
42 INIT_LIST_HEAD(&hep->urb_list);
43 INIT_LIST_HEAD(&urb->urb_list);
44 urb->ep = hep;
45 urb->complete = musb_host_complete_urb;
46 urb->status = -EINPROGRESS;
47 urb->dev = dev;
48 urb->pipe = pipe;
49 urb->transfer_buffer = buffer;
50 urb->transfer_dma = (unsigned long)buffer;
51 urb->transfer_buffer_length = len;
52 urb->setup_packet = (unsigned char *)setup;
Ilya Yanok06bb9202012-11-06 13:48:21 +000053
Hans de Goede39b08452015-01-11 20:34:53 +010054 urb->ep->desc.wMaxPacketSize =
Ilya Yanok06bb9202012-11-06 13:48:21 +000055 __cpu_to_le16(is_in ? dev->epmaxpacketin[epnum] :
56 dev->epmaxpacketout[epnum]);
Hans de Goede39b08452015-01-11 20:34:53 +010057 urb->ep->desc.bmAttributes = endpoint_type;
58 urb->ep->desc.bEndpointAddress =
Ilya Yanok06bb9202012-11-06 13:48:21 +000059 (is_in ? USB_DIR_IN : USB_DIR_OUT) | epnum;
Hans de Goede39b08452015-01-11 20:34:53 +010060 urb->ep->desc.bInterval = interval;
Ilya Yanok06bb9202012-11-06 13:48:21 +000061}
62
Ilya Yanok06bb9202012-11-06 13:48:21 +000063static int submit_urb(struct usb_hcd *hcd, struct urb *urb)
64{
65 struct musb *host = hcd->hcd_priv;
66 int ret;
Hans de Goede8de4ded2015-01-11 20:34:49 +010067 unsigned long timeout;
Ilya Yanok06bb9202012-11-06 13:48:21 +000068
69 ret = musb_urb_enqueue(hcd, urb, 0);
70 if (ret < 0) {
71 printf("Failed to enqueue URB to controller\n");
72 return ret;
73 }
74
Hans de Goede8de4ded2015-01-11 20:34:49 +010075 timeout = get_timer(0) + USB_TIMEOUT_MS(urb->pipe);
Ilya Yanok06bb9202012-11-06 13:48:21 +000076 do {
77 if (ctrlc())
78 return -EIO;
79 host->isr(0, host);
Hans de Goede24fd7772015-01-11 20:34:50 +010080 } while (urb->status == -EINPROGRESS &&
Hans de Goede8de4ded2015-01-11 20:34:49 +010081 get_timer(0) < timeout);
Ilya Yanok06bb9202012-11-06 13:48:21 +000082
Hans de Goede0e4da952015-01-11 20:34:52 +010083 if (urb->status == -EINPROGRESS)
84 musb_urb_dequeue(hcd, urb, -ETIME);
85
Ilya Yanok06bb9202012-11-06 13:48:21 +000086 return urb->status;
87}
88
Hans de Goede59627482015-06-17 21:33:57 +020089static int _musb_submit_control_msg(struct musb_host_data *host,
90 struct usb_device *dev, unsigned long pipe,
91 void *buffer, int len, struct devrequest *setup)
Ilya Yanok06bb9202012-11-06 13:48:21 +000092{
Hans de Goede59627482015-06-17 21:33:57 +020093 construct_urb(&host->urb, &host->hep, dev, USB_ENDPOINT_XFER_CONTROL,
94 pipe, buffer, len, setup, 0);
Ilya Yanok06bb9202012-11-06 13:48:21 +000095
96 /* Fix speed for non hub-attached devices */
Hans de Goede4d8b8df2015-06-17 21:33:55 +020097 if (!usb_dev_get_parent(dev))
Hans de Goede59627482015-06-17 21:33:57 +020098 dev->speed = host->host_speed;
Ilya Yanok06bb9202012-11-06 13:48:21 +000099
Hans de Goede59627482015-06-17 21:33:57 +0200100 return submit_urb(&host->hcd, &host->urb);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000101}
102
Hans de Goede59627482015-06-17 21:33:57 +0200103static int _musb_submit_bulk_msg(struct musb_host_data *host,
104 struct usb_device *dev, unsigned long pipe, void *buffer, int len)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000105{
Hans de Goede59627482015-06-17 21:33:57 +0200106 construct_urb(&host->urb, &host->hep, dev, USB_ENDPOINT_XFER_BULK,
107 pipe, buffer, len, NULL, 0);
108 return submit_urb(&host->hcd, &host->urb);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000109}
110
Hans de Goede59627482015-06-17 21:33:57 +0200111static int _musb_submit_int_msg(struct musb_host_data *host,
112 struct usb_device *dev, unsigned long pipe,
113 void *buffer, int len, int interval)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000114{
Hans de Goede59627482015-06-17 21:33:57 +0200115 construct_urb(&host->urb, &host->hep, dev, USB_ENDPOINT_XFER_INT, pipe,
Hans de Goede39b08452015-01-11 20:34:53 +0100116 buffer, len, NULL, interval);
Hans de Goede59627482015-06-17 21:33:57 +0200117 return submit_urb(&host->hcd, &host->urb);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000118}
119
Hans de Goede59627482015-06-17 21:33:57 +0200120static struct int_queue *_musb_create_int_queue(struct musb_host_data *host,
121 struct usb_device *dev, unsigned long pipe, int queuesize,
122 int elementsize, void *buffer, int interval)
Hans de Goede83b18972015-01-11 20:34:54 +0100123{
124 struct int_queue *queue;
125 int ret, index = usb_pipein(pipe) * 16 + usb_pipeendpoint(pipe);
126
127 if (queuesize != 1) {
128 printf("ERROR musb int-queues only support queuesize 1\n");
129 return NULL;
130 }
131
132 if (dev->int_pending & (1 << index)) {
133 printf("ERROR int-urb is already pending on pipe %lx\n", pipe);
134 return NULL;
135 }
136
137 queue = malloc(sizeof(*queue));
138 if (!queue)
139 return NULL;
140
141 construct_urb(&queue->urb, &queue->hep, dev, USB_ENDPOINT_XFER_INT,
142 pipe, buffer, elementsize, NULL, interval);
143
Hans de Goede59627482015-06-17 21:33:57 +0200144 ret = musb_urb_enqueue(&host->hcd, &queue->urb, 0);
Hans de Goede83b18972015-01-11 20:34:54 +0100145 if (ret < 0) {
146 printf("Failed to enqueue URB to controller\n");
147 free(queue);
148 return NULL;
149 }
150
151 dev->int_pending |= 1 << index;
152 return queue;
153}
154
Hans de Goede59627482015-06-17 21:33:57 +0200155static int _musb_destroy_int_queue(struct musb_host_data *host,
156 struct usb_device *dev, struct int_queue *queue)
Hans de Goede83b18972015-01-11 20:34:54 +0100157{
158 int index = usb_pipein(queue->urb.pipe) * 16 +
159 usb_pipeendpoint(queue->urb.pipe);
160
161 if (queue->urb.status == -EINPROGRESS)
Hans de Goede59627482015-06-17 21:33:57 +0200162 musb_urb_dequeue(&host->hcd, &queue->urb, -ETIME);
Hans de Goede83b18972015-01-11 20:34:54 +0100163
164 dev->int_pending &= ~(1 << index);
165 free(queue);
166 return 0;
167}
168
Hans de Goede59627482015-06-17 21:33:57 +0200169static void *_musb_poll_int_queue(struct musb_host_data *host,
170 struct usb_device *dev, struct int_queue *queue)
Hans de Goede83b18972015-01-11 20:34:54 +0100171{
172 if (queue->urb.status != -EINPROGRESS)
173 return NULL; /* URB has already completed in a prev. poll */
174
Hans de Goede59627482015-06-17 21:33:57 +0200175 host->host->isr(0, host->host);
Hans de Goede83b18972015-01-11 20:34:54 +0100176
177 if (queue->urb.status != -EINPROGRESS)
178 return queue->urb.transfer_buffer; /* Done */
179
180 return NULL; /* URB still pending */
181}
182
Hans de Goede59627482015-06-17 21:33:57 +0200183static int _musb_reset_root_port(struct musb_host_data *host,
184 struct usb_device *dev)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000185{
Hans de Goede59627482015-06-17 21:33:57 +0200186 void *mbase = host->host->mregs;
Ilya Yanok06bb9202012-11-06 13:48:21 +0000187 u8 power;
Hans de Goede498ab952015-01-11 20:34:51 +0100188
189 power = musb_readb(mbase, MUSB_POWER);
190 power &= 0xf0;
191 musb_writeb(mbase, MUSB_POWER, MUSB_POWER_RESET | power);
192 mdelay(50);
Jagan Teki37671e12018-05-07 13:03:37 +0530193
194 if (host->host->ops->pre_root_reset_end)
195 host->host->ops->pre_root_reset_end(host->host);
196
Hans de Goede498ab952015-01-11 20:34:51 +0100197 power = musb_readb(mbase, MUSB_POWER);
198 musb_writeb(mbase, MUSB_POWER, ~MUSB_POWER_RESET & power);
Jagan Teki37671e12018-05-07 13:03:37 +0530199
200 if (host->host->ops->post_root_reset_end)
201 host->host->ops->post_root_reset_end(host->host);
202
Hans de Goede59627482015-06-17 21:33:57 +0200203 host->host->isr(0, host->host);
204 host->host_speed = (musb_readb(mbase, MUSB_POWER) & MUSB_POWER_HSMODE) ?
Hans de Goede498ab952015-01-11 20:34:51 +0100205 USB_SPEED_HIGH :
206 (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_FSDEV) ?
207 USB_SPEED_FULL : USB_SPEED_LOW;
Hans de Goede59627482015-06-17 21:33:57 +0200208 mdelay((host->host_speed == USB_SPEED_LOW) ? 200 : 50);
Simon Glass9b82eeb2015-03-25 12:21:59 -0600209
210 return 0;
Hans de Goede498ab952015-01-11 20:34:51 +0100211}
212
Hans de Goede59627482015-06-17 21:33:57 +0200213int musb_lowlevel_init(struct musb_host_data *host)
Hans de Goede498ab952015-01-11 20:34:51 +0100214{
Ilya Yanok06bb9202012-11-06 13:48:21 +0000215 void *mbase;
Hans de Goede8de4ded2015-01-11 20:34:49 +0100216 /* USB spec says it may take up to 1 second for a device to connect */
217 unsigned long timeout = get_timer(0) + 1000;
Hans de Goede81c49982015-06-17 21:33:54 +0200218 int ret;
Ilya Yanok06bb9202012-11-06 13:48:21 +0000219
Hans de Goede59627482015-06-17 21:33:57 +0200220 if (!host->host) {
Ilya Yanok06bb9202012-11-06 13:48:21 +0000221 printf("MUSB host is not registered\n");
222 return -ENODEV;
223 }
224
Hans de Goede59627482015-06-17 21:33:57 +0200225 ret = musb_start(host->host);
Hans de Goede81c49982015-06-17 21:33:54 +0200226 if (ret)
227 return ret;
228
Hans de Goede59627482015-06-17 21:33:57 +0200229 mbase = host->host->mregs;
Ilya Yanok06bb9202012-11-06 13:48:21 +0000230 do {
231 if (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_HM)
232 break;
Hans de Goede8de4ded2015-01-11 20:34:49 +0100233 } while (get_timer(0) < timeout);
Hans de Goede2ec5be62016-04-02 20:46:10 +0200234 if (get_timer(0) >= timeout) {
235 musb_stop(host->host);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000236 return -ENODEV;
Hans de Goede2ec5be62016-04-02 20:46:10 +0200237 }
Ilya Yanok06bb9202012-11-06 13:48:21 +0000238
Hans de Goede59627482015-06-17 21:33:57 +0200239 _musb_reset_root_port(host, NULL);
240 host->host->is_active = 1;
241 host->hcd.hcd_priv = host->host;
Ilya Yanok06bb9202012-11-06 13:48:21 +0000242
243 return 0;
244}
245
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100246#if !CONFIG_IS_ENABLED(DM_USB)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000247int usb_lowlevel_stop(int index)
248{
Hans de Goede59627482015-06-17 21:33:57 +0200249 if (!musb_host.host) {
Ilya Yanok06bb9202012-11-06 13:48:21 +0000250 printf("MUSB host is not registered\n");
251 return -ENODEV;
252 }
253
Hans de Goede59627482015-06-17 21:33:57 +0200254 musb_stop(musb_host.host);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000255 return 0;
256}
Hans de Goede52666e22015-06-17 21:33:56 +0200257
258int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
259 void *buffer, int length)
260{
Hans de Goede59627482015-06-17 21:33:57 +0200261 return _musb_submit_bulk_msg(&musb_host, dev, pipe, buffer, length);
Hans de Goede52666e22015-06-17 21:33:56 +0200262}
263
264int submit_control_msg(struct usb_device *dev, unsigned long pipe,
265 void *buffer, int length, struct devrequest *setup)
266{
Hans de Goede59627482015-06-17 21:33:57 +0200267 return _musb_submit_control_msg(&musb_host, dev, pipe, buffer, length, setup);
Hans de Goede52666e22015-06-17 21:33:56 +0200268}
269
270int submit_int_msg(struct usb_device *dev, unsigned long pipe,
271 void *buffer, int length, int interval)
272{
Hans de Goede59627482015-06-17 21:33:57 +0200273 return _musb_submit_int_msg(&musb_host, dev, pipe, buffer, length, interval);
Hans de Goede52666e22015-06-17 21:33:56 +0200274}
275
276struct int_queue *create_int_queue(struct usb_device *dev,
277 unsigned long pipe, int queuesize, int elementsize,
278 void *buffer, int interval)
279{
Hans de Goede59627482015-06-17 21:33:57 +0200280 return _musb_create_int_queue(&musb_host, dev, pipe, queuesize, elementsize,
Hans de Goede52666e22015-06-17 21:33:56 +0200281 buffer, interval);
282}
283
284void *poll_int_queue(struct usb_device *dev, struct int_queue *queue)
285{
Hans de Goede59627482015-06-17 21:33:57 +0200286 return _musb_poll_int_queue(&musb_host, dev, queue);
Hans de Goede52666e22015-06-17 21:33:56 +0200287}
288
289int destroy_int_queue(struct usb_device *dev, struct int_queue *queue)
290{
Hans de Goede59627482015-06-17 21:33:57 +0200291 return _musb_destroy_int_queue(&musb_host, dev, queue);
Hans de Goede52666e22015-06-17 21:33:56 +0200292}
293
294int usb_reset_root_port(struct usb_device *dev)
295{
Hans de Goede59627482015-06-17 21:33:57 +0200296 return _musb_reset_root_port(&musb_host, dev);
Hans de Goede52666e22015-06-17 21:33:56 +0200297}
298
299int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
300{
Hans de Goede59627482015-06-17 21:33:57 +0200301 return musb_lowlevel_init(&musb_host);
Hans de Goede52666e22015-06-17 21:33:56 +0200302}
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100303#endif /* !CONFIG_IS_ENABLED(DM_USB) */
Hans de Goedefc649612015-06-17 21:33:58 +0200304
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100305#if CONFIG_IS_ENABLED(DM_USB)
Hans de Goedefc649612015-06-17 21:33:58 +0200306static int musb_submit_control_msg(struct udevice *dev, struct usb_device *udev,
307 unsigned long pipe, void *buffer, int length,
308 struct devrequest *setup)
309{
310 struct musb_host_data *host = dev_get_priv(dev);
311 return _musb_submit_control_msg(host, udev, pipe, buffer, length, setup);
312}
313
314static int musb_submit_bulk_msg(struct udevice *dev, struct usb_device *udev,
315 unsigned long pipe, void *buffer, int length)
316{
317 struct musb_host_data *host = dev_get_priv(dev);
318 return _musb_submit_bulk_msg(host, udev, pipe, buffer, length);
319}
320
321static int musb_submit_int_msg(struct udevice *dev, struct usb_device *udev,
322 unsigned long pipe, void *buffer, int length,
323 int interval)
324{
325 struct musb_host_data *host = dev_get_priv(dev);
326 return _musb_submit_int_msg(host, udev, pipe, buffer, length, interval);
327}
328
329static struct int_queue *musb_create_int_queue(struct udevice *dev,
330 struct usb_device *udev, unsigned long pipe, int queuesize,
331 int elementsize, void *buffer, int interval)
332{
333 struct musb_host_data *host = dev_get_priv(dev);
334 return _musb_create_int_queue(host, udev, pipe, queuesize, elementsize,
335 buffer, interval);
336}
337
338static void *musb_poll_int_queue(struct udevice *dev, struct usb_device *udev,
339 struct int_queue *queue)
340{
341 struct musb_host_data *host = dev_get_priv(dev);
342 return _musb_poll_int_queue(host, udev, queue);
343}
344
345static int musb_destroy_int_queue(struct udevice *dev, struct usb_device *udev,
346 struct int_queue *queue)
347{
348 struct musb_host_data *host = dev_get_priv(dev);
349 return _musb_destroy_int_queue(host, udev, queue);
350}
351
352static int musb_reset_root_port(struct udevice *dev, struct usb_device *udev)
353{
354 struct musb_host_data *host = dev_get_priv(dev);
355 return _musb_reset_root_port(host, udev);
356}
357
358struct dm_usb_ops musb_usb_ops = {
359 .control = musb_submit_control_msg,
360 .bulk = musb_submit_bulk_msg,
361 .interrupt = musb_submit_int_msg,
362 .create_int_queue = musb_create_int_queue,
363 .poll_int_queue = musb_poll_int_queue,
364 .destroy_int_queue = musb_destroy_int_queue,
365 .reset_root_port = musb_reset_root_port,
366};
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100367#endif /* CONFIG_IS_ENABLED(DM_USB) */
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200368#endif /* CONFIG_USB_MUSB_HOST */
Ilya Yanok06bb9202012-11-06 13:48:21 +0000369
Jean-Jacques Hiblot57118f62018-12-04 11:30:57 +0100370#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000371static struct musb *gadget;
372
Kishon Vijay Abraham I4763e162015-02-23 18:40:23 +0530373int usb_gadget_handle_interrupts(int index)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000374{
Heiko Schocherc3ffe502013-06-04 11:10:01 +0200375 WATCHDOG_RESET();
Ilya Yanok06bb9202012-11-06 13:48:21 +0000376 if (!gadget || !gadget->isr)
377 return -EINVAL;
378
379 return gadget->isr(0, gadget);
380}
381
382int usb_gadget_register_driver(struct usb_gadget_driver *driver)
383{
384 int ret;
385
Bin Liu28f2f352013-03-21 05:27:49 +0000386 if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind ||
Ilya Yanok06bb9202012-11-06 13:48:21 +0000387 !driver->setup) {
388 printf("bad parameter.\n");
389 return -EINVAL;
390 }
391
392 if (!gadget) {
393 printf("Controller uninitialized\n");
394 return -ENXIO;
395 }
396
397 ret = musb_gadget_start(&gadget->g, driver);
398 if (ret < 0) {
399 printf("gadget_start failed with %d\n", ret);
400 return ret;
401 }
402
403 ret = driver->bind(&gadget->g);
404 if (ret < 0) {
405 printf("bind failed with %d\n", ret);
406 return ret;
407 }
408
409 return 0;
410}
411
412int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
413{
Rob Herring15175e72014-04-18 08:54:30 -0500414 if (driver->disconnect)
415 driver->disconnect(&gadget->g);
416 if (driver->unbind)
417 driver->unbind(&gadget->g);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000418 return 0;
419}
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200420#endif /* CONFIG_USB_MUSB_GADGET */
Ilya Yanok06bb9202012-11-06 13:48:21 +0000421
Jagan Tekif0a6d792018-07-20 12:43:56 +0530422struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
423 void *ctl_regs)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000424{
425 struct musb **musbp;
426
427 switch (plat->mode) {
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100428#if defined(CONFIG_USB_MUSB_HOST) && !CONFIG_IS_ENABLED(DM_USB)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000429 case MUSB_HOST:
Hans de Goede59627482015-06-17 21:33:57 +0200430 musbp = &musb_host.host;
Ilya Yanok06bb9202012-11-06 13:48:21 +0000431 break;
432#endif
Jean-Jacques Hiblot57118f62018-12-04 11:30:57 +0100433#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET)
Ilya Yanok06bb9202012-11-06 13:48:21 +0000434 case MUSB_PERIPHERAL:
435 musbp = &gadget;
436 break;
437#endif
438 default:
Jagan Tekif0a6d792018-07-20 12:43:56 +0530439 return ERR_PTR(-EINVAL);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000440 }
441
442 *musbp = musb_init_controller(plat, (struct device *)bdata, ctl_regs);
Jagan Tekif0a6d792018-07-20 12:43:56 +0530443 if (IS_ERR(*musbp)) {
Ilya Yanok06bb9202012-11-06 13:48:21 +0000444 printf("Failed to init the controller\n");
Jagan Tekif0a6d792018-07-20 12:43:56 +0530445 return ERR_CAST(*musbp);
Ilya Yanok06bb9202012-11-06 13:48:21 +0000446 }
447
Jagan Tekif0a6d792018-07-20 12:43:56 +0530448 return *musbp;
Ilya Yanok06bb9202012-11-06 13:48:21 +0000449}