source: mainline/uspace/drv/bus/usb/ohci/main.c@ b5f813c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b5f813c was b5f813c, checked in by Jan Vesely <jano.vesely@…>, 10 years ago

libusbhost,ehci,ohci,uhci,vhc: Pass ops structure instead of function pointers to intialization

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * Copyright (c) 2011 Vojtech Horky
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/** @addtogroup drvusbohci
30 * @{
31 */
32/** @file
33 * Main routines of OHCI driver.
34 */
35
36#include <assert.h>
37#include <ddf/driver.h>
38#include <errno.h>
39#include <io/log.h>
40#include <str_error.h>
41
42#include <usb/debug.h>
43#include <usb/host/ddf_helpers.h>
44
45#include "hc.h"
46
47#define NAME "ohci"
48static int ohci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
49static void ohci_driver_fini(hcd_t *);
50
51static const ddf_hc_driver_t ohci_hc_driver = {
52 .hc_speed = USB_SPEED_FULL,
53 .irq_code_gen = ohci_hc_gen_irq_code,
54 .init = ohci_driver_init,
55 .fini = ohci_driver_fini,
56 .name = "OHCI",
57 .ops = {
58 .schedule = ohci_hc_schedule,
59 .ep_add_hook = ohci_endpoint_init,
60 .ep_remove_hook = ohci_endpoint_fini,
61 .irq_hook = ohci_hc_interrupt,
62 .status_hook = ohci_hc_status,
63 },
64};
65
66
67static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
68{
69 assert(hcd);
70 assert(hcd_get_driver_data(hcd) == NULL);
71
72 hc_t *instance = malloc(sizeof(hc_t));
73 if (!instance)
74 return ENOMEM;
75
76 const int ret = hc_init(instance, res, irq);
77 if (ret == EOK)
78 hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops);
79 return ret;
80}
81
82static void ohci_driver_fini(hcd_t *hcd)
83{
84 assert(hcd);
85 hc_t *hc = hcd_get_driver_data(hcd);
86 if (hc)
87 hc_fini(hc);
88
89 hcd_set_implementation(hcd, NULL, NULL);
90 free(hc);
91}
92
93/** Initializes a new ddf driver instance of OHCI hcd.
94 *
95 * @param[in] device DDF instance of the device to initialize.
96 * @return Error code.
97 */
98static int ohci_dev_add(ddf_dev_t *device)
99{
100 usb_log_debug("ohci_dev_add() called\n");
101 assert(device);
102 return hcd_ddf_add_hc(device, &ohci_hc_driver);
103}
104
105static const driver_ops_t ohci_driver_ops = {
106 .dev_add = ohci_dev_add,
107};
108
109static const driver_t ohci_driver = {
110 .name = NAME,
111 .driver_ops = &ohci_driver_ops
112};
113
114/** Initializes global driver structures (NONE).
115 *
116 * @param[in] argc Nmber of arguments in argv vector (ignored).
117 * @param[in] argv Cmdline argument vector (ignored).
118 * @return Error code.
119 *
120 * Driver debug level is set here.
121 */
122int main(int argc, char *argv[])
123{
124 log_init(NAME);
125 return ddf_driver_main(&ohci_driver);
126}
127/**
128 * @}
129 */
Note: See TracBrowser for help on using the repository browser.