blob: cce349b66241c7cb21ca99e9e36e7e19299b0829 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2013 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <err.h>
24#include <debug.h>
25#include <stdio.h>
26#include <target.h>
27#include <compiler.h>
28#include <dev/usb.h>
29#include <hw/usb.h>
30#include <lk/init.h>
31
32#define W(w) (w & 0xff), (w >> 8)
33#define W3(w) (w & 0xff), ((w >> 8) & 0xff), ((w >> 16) & 0xff)
34
35/* top level device descriptor */
36static const uint8_t dev_descr[] = {
37 0x12, /* descriptor length */
38 DEVICE, /* Device Descriptor type */
39 W(0x0200), /* USB Version */
40 0xff, /* class */
41 0xff, /* subclass */
42 0xff, /* protocol */
43 64, /* max packet size, ept0 */
44 W(0x9999), /* vendor */
45 W(0x9999), /* product */
46 W(0x9999), /* release */
47 0x0, /* manufacturer string */
48 0x0, /* product string */
49 0x0, /* serialno string */
50 0x1, /* num configs */
51};
52
53/* high/low speed device qualifier */
54static const uint8_t devqual_descr[] = {
55 0x0a, /* len */
56 DEVICE_QUALIFIER, /* Device Qualifier type */
57 W(0x0200), /* USB version */
58 0x00, /* class */
59 0x00, /* subclass */
60 0x00, /* protocol */
61 64, /* max packet size, ept0 */
62 0x01, /* num configs */
63 0x00 /* reserved */
64};
65
66static const uint8_t cfg_descr[] = {
67 0x09, /* Length of Cfg Descr */
68 CONFIGURATION, /* Type of Cfg Descr */
69 W(0x09), /* Total Length (incl ifc, ept) */
70 0x00, /* # Interfaces */
71 0x01, /* Cfg Value */
72 0x00, /* Cfg String */
73 0xc0, /* Attributes -- self powered */
74 250, /* Power Consumption - 500mA */
75};
76
77static const uchar langid[] = { 0x04, 0x03, 0x09, 0x04 };
78
79static const uint8_t if_descriptor_lowspeed[] = {
80 0x09, /* length */
81 INTERFACE, /* type */
82 0x01, /* interface num */
83 0x00, /* alternates */
84 0x02, /* endpoint count */
85 0xff, /* interface class */
86 0xff, /* interface subclass */
87 0x00, /* interface protocol */
88 0x00, /* string index */
89
90 /* endpoint 1 IN */
91 0x07, /* length */
92 ENDPOINT, /* type */
93 0x81, /* address: 1 IN */
94 0x02, /* type: bulk */
95 W(64), /* max packet size: 64 */
96 00, /* interval */
97
98 /* endpoint 1 OUT */
99 0x07, /* length */
100 ENDPOINT, /* type */
101 0x01, /* address: 1 OUT */
102 0x02, /* type: bulk */
103 W(64), /* max packet size: 64 */
104 00, /* interval */
105};
106
107usb_config config = {
108 .lowspeed = {
109 .device = USB_DESC_STATIC(dev_descr),
110 .device_qual = USB_DESC_STATIC(devqual_descr),
111 .config = USB_DESC_STATIC(cfg_descr),
112 },
113 .highspeed = {
114 .device = USB_DESC_STATIC(dev_descr),
115 .device_qual = USB_DESC_STATIC(devqual_descr),
116 .config = USB_DESC_STATIC(cfg_descr),
117 },
118
119 .langid = USB_DESC_STATIC(langid),
120};
121
122void target_usb_setup(void)
123{
124 usb_setup(&config);
125 printf("appending interfaces\n");
126 usb_append_interface_lowspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
127 usb_append_interface_highspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
128
129 usb_start();
130}
131
132// vim: set ts=4 sw=4 expandtab: