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

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

libusbhost: Add status hook.

Implement in UHCI, OHCI

  • 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"
48// TODO: This should be merged to hc_interrupt
49static void ohci_interrupt(hcd_t *hcd, uint32_t status)
50{
51 assert(hcd);
52 if (hcd->driver.data)
53 hc_interrupt(hcd->driver.data, status);
54}
55
56static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
57{
58 assert(hcd);
59 assert(hcd->driver.data == NULL);
60
61 hc_t *instance = malloc(sizeof(hc_t));
62 if (!instance)
63 return ENOMEM;
64
65 const int ret = hc_init(instance, res, irq);
66 if (ret == EOK)
67 hcd_set_implementation(hcd, instance, hc_schedule,
68 ohci_endpoint_init, ohci_endpoint_fini, ohci_interrupt,
69 hc_status);
70 return ret;
71}
72
73static void ohci_driver_fini(hcd_t *hcd)
74{
75 assert(hcd);
76 if (hcd->driver.data)
77 hc_fini(hcd->driver.data);
78
79 free(hcd->driver.data);
80 hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
81}
82
83/** Initializes a new ddf driver instance of OHCI hcd.
84 *
85 * @param[in] device DDF instance of the device to initialize.
86 * @return Error code.
87 */
88static int ohci_dev_add(ddf_dev_t *device)
89{
90 usb_log_debug("ohci_dev_add() called\n");
91 assert(device);
92
93 const int ret = ddf_hcd_device_setup_all(device, USB_SPEED_FULL,
94 BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11,
95 ddf_hcd_gen_irq_handler, hc_gen_irq_code,
96 ohci_driver_init, ohci_driver_fini);
97 if (ret != EOK) {
98 usb_log_error("Failed to initialize OHCI driver: %s.\n",
99 str_error(ret));
100 }
101 usb_log_info("Controlling new OHCI device '%s'.\n",
102 ddf_dev_get_name(device));
103
104 return ret;
105}
106
107static const driver_ops_t ohci_driver_ops = {
108 .dev_add = ohci_dev_add,
109};
110
111static const driver_t ohci_driver = {
112 .name = NAME,
113 .driver_ops = &ohci_driver_ops
114};
115
116/** Initializes global driver structures (NONE).
117 *
118 * @param[in] argc Nmber of arguments in argv vector (ignored).
119 * @param[in] argv Cmdline argument vector (ignored).
120 * @return Error code.
121 *
122 * Driver debug level is set here.
123 */
124int main(int argc, char *argv[])
125{
126 log_init(NAME);
127 return ddf_driver_main(&ohci_driver);
128}
129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.