1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12#include <usb/otg.h>
13#include "plat/usb_otg.h"
14#include "services.h"
15#include <stdio.h>
16
17int usb_otg_init(int id, usb_otg_t * otg_ptr, ps_io_ops_t ioops)
18{
19	usb_otg_t otg;
20	int err;
21	/* Validate the id */
22	if (id < 0 || id > USB_NOTGS) {
23		return -1;
24	}
25	/* Allocate host memory */
26	otg = usb_malloc(sizeof(*otg));
27	if (otg == NULL) {
28		ZF_LOGE("OTG: Out of memory\n");
29		return -1;
30	}
31	otg->dman = &ioops.dma_manager;
32	otg->id = id;
33	otg->ep0_setup = NULL;
34	otg->prime = NULL;
35	err = usb_plat_otg_init(otg, &ioops);
36	if (!err) {
37		*otg_ptr = otg;
38	}
39	return err;
40}
41
42void otg_handle_irq(usb_otg_t otg)
43{
44	otg_plat_handle_irq(otg);
45}
46
47int otg_ep0_setup(usb_otg_t otg, otg_setup_cb cb, void *token)
48{
49	if (!otg || !otg->ep0_setup) {
50		ZF_LOGF("OTG: Invalid arguments\n");
51	}
52	return otg->ep0_setup(otg, cb, token);
53}
54
55int
56otg_prime(usb_otg_t otg, int ep, enum usb_xact_type dir,
57	  void *vbuf, uintptr_t pbuf, int len, otg_prime_cb cb, void *token)
58{
59	return otg->prime(otg, ep, dir, vbuf, pbuf, len, cb, token);
60}
61