1 | #include <async.h>
|
---|
2 | #include <ddi.h>
|
---|
3 | #include <errno.h>
|
---|
4 | #include <stdint.h>
|
---|
5 | #include <stdio.h>
|
---|
6 |
|
---|
7 | #include <usb/usbdrv.h>
|
---|
8 | #include <usb/debug.h>
|
---|
9 |
|
---|
10 | #include "root_hub.h"
|
---|
11 |
|
---|
12 |
|
---|
13 | int uhci_root_hub_init(
|
---|
14 | uhci_root_hub_t *instance, void *addr, size_t size, device_t *rh)
|
---|
15 | {
|
---|
16 | assert(instance);
|
---|
17 | assert(rh);
|
---|
18 | int ret;
|
---|
19 | ret = usb_drv_find_hc(rh, &instance->hc_handle);
|
---|
20 | usb_log_info("rh found(%d) hc handle: %d.\n", ret, instance->hc_handle);
|
---|
21 | if (ret != EOK) {
|
---|
22 | return ret;
|
---|
23 | }
|
---|
24 |
|
---|
25 | /* connect to the parent device (HC) */
|
---|
26 | rh->parent_phone = devman_device_connect(8, 0);
|
---|
27 | //usb_drv_hc_connect(rh, instance->hc_handle, 0);
|
---|
28 | if (rh->parent_phone < 0) {
|
---|
29 | usb_log_error("Failed to connect to the HC device.\n");
|
---|
30 | return rh->parent_phone;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /* allow access to root hub registers */
|
---|
34 | assert(sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT == size);
|
---|
35 | port_status_t *regs;
|
---|
36 | ret = pio_enable(
|
---|
37 | addr, sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT, (void**)®s);
|
---|
38 |
|
---|
39 | if (ret < 0) {
|
---|
40 | usb_log_error("Failed to gain access to port registers at %p\n", regs);
|
---|
41 | return ret;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /* add fibrils for periodic port checks */
|
---|
45 | unsigned i = 0;
|
---|
46 | for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
|
---|
47 | /* mind pointer arithmetics */
|
---|
48 | int ret = uhci_port_init(
|
---|
49 | &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh);
|
---|
50 | if (ret != EOK) {
|
---|
51 | unsigned j = 0;
|
---|
52 | for (;j < i; ++j)
|
---|
53 | uhci_port_fini(&instance->ports[j]);
|
---|
54 | return ret;
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | return EOK;
|
---|
59 | }
|
---|
60 | /*----------------------------------------------------------------------------*/
|
---|
61 | int uhci_root_hub_fini( uhci_root_hub_t* instance )
|
---|
62 | {
|
---|
63 | assert( instance );
|
---|
64 | // TODO:
|
---|
65 | //destroy fibril here
|
---|
66 | //disable access to registers
|
---|
67 | return EOK;
|
---|
68 | }
|
---|
69 | /*----------------------------------------------------------------------------*/
|
---|