1 /*
2 * Copyright (c) 2024, sakumisu
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "usb_config.h"
7 #include "stdint.h"
8 #include "usb_musb_reg.h"
9
10 #ifndef CONFIG_USB_MUSB_SUNXI
11 #error must define CONFIG_USB_MUSB_SUNXI when use sunxi chips
12 #endif
13
14 #if CONFIG_USB_MUSB_EP_NUM != 4
15 #error sunxi chips only support 4 endpoints
16 #endif
17
18 #if CONFIG_USB_MUSB_PIPE_NUM != 4
19 #error sunxi chips only support 4 pipes
20 #endif
21
22 // clang-format off
23 static struct musb_fifo_cfg musb_device_table[] = {
24 { .ep_num = 0, .style = FIFO_TXRX, .maxpacket = 64, },
25 { .ep_num = 1, .style = FIFO_TX, .maxpacket = 1024, },
26 { .ep_num = 1, .style = FIFO_RX, .maxpacket = 1024, },
27 { .ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
28 { .ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
29 { .ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
30 { .ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
31 };
32
33 static struct musb_fifo_cfg musb_host_table[] = {
34 { .ep_num = 0, .style = FIFO_TXRX, .maxpacket = 64, },
35 { .ep_num = 1, .style = FIFO_TX, .maxpacket = 1024, },
36 { .ep_num = 1, .style = FIFO_RX, .maxpacket = 1024, },
37 { .ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
38 { .ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
39 { .ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
40 { .ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
41 };
42 // clang-format on
43
usbd_get_musb_fifo_cfg(struct musb_fifo_cfg ** cfg)44 uint8_t usbd_get_musb_fifo_cfg(struct musb_fifo_cfg **cfg)
45 {
46 *cfg = musb_device_table;
47 return sizeof(musb_device_table) / sizeof(musb_device_table[0]);
48 }
49
usbh_get_musb_fifo_cfg(struct musb_fifo_cfg ** cfg)50 uint8_t usbh_get_musb_fifo_cfg(struct musb_fifo_cfg **cfg)
51 {
52 *cfg = musb_host_table;
53 return sizeof(musb_host_table) / sizeof(musb_host_table[0]);
54 }
55
usb_get_musb_ram_size(void)56 uint32_t usb_get_musb_ram_size(void)
57 {
58 return 8192;
59 }
60
usbd_musb_delay_ms(uint8_t ms)61 void usbd_musb_delay_ms(uint8_t ms)
62 {
63 /* implement later */
64 }
65