source: mainline/uspace/drv/bus/usb/vhc/main.c

Last change on this file was 1433ecda, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix cstyle: make ccheck-fix and commit only files where all the changes are good.

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[355f7c2]1/*
[6cb58e6]2 * Copyright (c) 2011 Vojtech Horky
[e0a5d4c]3 * Copyright (c) 2018 Ondrej Hlavaty
[355f7c2]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[bd8c753d]30/** @addtogroup drvusbvhc
[355f7c2]31 * @{
[79ae36dd]32 */
[355f7c2]33/** @file
[6cb58e6]34 * Virtual host controller.
[355f7c2]35 */
[63b4f90]36
37#include <stdio.h>
38#include <errno.h>
39#include <str_error.h>
[eb1a2f4]40#include <ddf/driver.h>
[355f7c2]41
[01eeaaf]42#include <usb/host/ddf_helpers.h>
[944f8fdd]43#include <usb/host/utility.h>
[01eeaaf]44
[f6577d9]45#include <usb/debug.h>
[355f7c2]46#include "vhcd.h"
[f6577d9]47
[eb1a2f4]48static ddf_dev_ops_t vhc_ops = {
[6967c14]49 .close = on_client_close,
[4317827]50 .default_handler = default_connection_handler
51};
[e27595b]52
[5a6cc679]53static errno_t vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun)
[01eeaaf]54{
55 assert(dev);
56 assert(fun);
57
[eb34d8e]58 *fun = ddf_fun_create(dev, fun_exposed, "virtual");
[01eeaaf]59 if (!*fun)
60 return ENOMEM;
61
62 vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t));
63 if (!vhc) {
64 ddf_fun_destroy(*fun);
65 }
66 ddf_fun_set_ops(*fun, &vhc_ops);
[5a6cc679]67 const errno_t ret = ddf_fun_bind(*fun);
[01eeaaf]68 if (ret != EOK) {
69 ddf_fun_destroy(*fun);
70 *fun = NULL;
71 return ret;
72 }
73 return EOK;
74}
75
[5a6cc679]76static errno_t vhc_dev_add(ddf_dev_t *dev)
[355f7c2]77{
[01eeaaf]78 /* Initialize generic structures */
[5a6cc679]79 errno_t ret = hcd_ddf_setup_hc(dev, sizeof(vhc_data_t));
[01eeaaf]80 if (ret != EOK) {
[a1732929]81 usb_log_error("Failed to init HCD structures: %s.",
[1433ecda]82 str_error(ret));
[01eeaaf]83 return ret;
84 }
[32fb6bce]85 vhc_data_t *vhc = ddf_dev_data_get(dev);
86 vhc_init(vhc);
87
88 hc_device_setup(&vhc->base, (bus_t *) &vhc->bus);
[01eeaaf]89
[32fb6bce]90 /* Initialize virtual structure */
91 ddf_fun_t *ctl_fun = NULL;
92 ret = vhc_control_node(dev, &ctl_fun);
93 if (ret != EOK) {
[a1732929]94 usb_log_error("Failed to setup control node.");
[32fb6bce]95 return ret;
96 }
[01eeaaf]97
98 /* Add virtual hub device */
[32fb6bce]99 ret = vhc_virtdev_plug_hub(vhc, &vhc->hub, NULL, 0);
[01eeaaf]100 if (ret != EOK) {
[a1732929]101 usb_log_error("Failed to plug root hub: %s.", str_error(ret));
[0e97b4b5]102 ddf_fun_destroy(ctl_fun);
[01eeaaf]103 return ret;
104 }
105
[cb8ede1]106 /*
107 * Creating root hub registers a new USB device so HC
108 * needs to be ready at this time.
109 */
[129b821f]110 ret = hc_setup_virtual_root_hub(&vhc->base, USB_SPEED_HIGH);
[01eeaaf]111 if (ret != EOK) {
[a1732929]112 usb_log_error("Failed to init VHC root hub: %s",
[1433ecda]113 str_error(ret));
[01eeaaf]114 // TODO do something here...
115 }
116
117 return ret;
[355f7c2]118}
119
[4317827]120static driver_ops_t vhc_driver_ops = {
[0c0f823b]121 .dev_add = vhc_dev_add,
[4317827]122};
123
124static driver_t vhc_driver = {
[63b4f90]125 .name = NAME,
[4317827]126 .driver_ops = &vhc_driver_ops
[63b4f90]127};
128
[1433ecda]129int main(int argc, char *argv[])
[01eeaaf]130{
[920d0fc]131 log_init(NAME);
[e63a4e1]132 printf(NAME ": virtual USB host controller driver.\n");
[e27595b]133
[eb1a2f4]134 return ddf_driver_main(&vhc_driver);
[355f7c2]135}
136
137/**
138 * @}
139 */
Note: See TracBrowser for help on using the repository browser.