source: mainline/uspace/drv/ohci/hc.c@ ff582d47

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

A really ugly way to register hub

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[41b96b4]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvusbohcihc
29 * @{
30 */
31/** @file
32 * @brief OHCI Host controller driver routines
33 */
34#include <errno.h>
35#include <str_error.h>
36#include <adt/list.h>
37#include <libarch/ddi.h>
38
39#include <usb/debug.h>
40#include <usb/usb.h>
[a6d1bc1]41#include <usb/hub.h>
[41b96b4]42#include <usb/ddfiface.h>
[ff582d47]43#include <usb/usbdevice.h>
[41b96b4]44
[bab71635]45#include "hc.h"
[41b96b4]46
[ff582d47]47static int dummy_reset(int foo, void *bar)
48{
49 return EOK;
50}
[a6d1bc1]51/*----------------------------------------------------------------------------*/
52int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
[e7bc999]53 uintptr_t regs, size_t reg_size, bool interrupts)
[41b96b4]54{
55 assert(instance);
[ff582d47]56 int ret = EOK;
57
58 ret = pio_enable((void*)regs, reg_size, (void**)&instance->registers);
[42dbb26]59 if (ret != EOK) {
60 usb_log_error("Failed to gain access to device registers.\n");
61 return ret;
62 }
[ff582d47]63 instance->ddf_instance = fun;
[bab71635]64 device_keeper_init(&instance->manager);
[e7bc999]65
[42dbb26]66
[a6d1bc1]67 rh_init(&instance->rh, dev, instance->registers);
[41b96b4]68 /* TODO: implement */
69 return EOK;
70}
71/*----------------------------------------------------------------------------*/
[ff582d47]72int hc_register_hub(hc_t *instance)
[a6d1bc1]73{
[ff582d47]74 async_usleep(1000000);
75#define CHECK_RET_RETURN(ret, msg...) \
76 if (ret != EOK) { \
77 usb_log_error(msg); \
78 return ret; \
79 } else (void)0
[a6d1bc1]80 assert(instance);
[ff582d47]81 assert(instance->ddf_instance);
82 assert(instance->ddf_instance->handle);
83 ddf_dev_t *dev = instance->rh.device;
84 int ret = EOK;
85
86 usb_hc_connection_t conn;
87 ret =
88 usb_hc_connection_initialize(&conn, instance->ddf_instance->handle);
89 CHECK_RET_RETURN(ret, "Failed to initialize hc connection.\n");
90
91 ret = usb_hc_connection_open(&conn);
92 CHECK_RET_RETURN(ret, "Failed to open hc connection.\n");
93
94 usb_address_t address;
95 devman_handle_t handle;
96 ret = usb_hc_new_device_wrapper(dev, &conn, USB_SPEED_FULL, dummy_reset,
97 0, NULL, &address, &handle, NULL, NULL, NULL);
98 CHECK_RET_RETURN(ret, "Failed to add rh device.\n");
99
100 ret = usb_hc_connection_close(&conn);
101 CHECK_RET_RETURN(ret, "Failed to close hc connection.\n");
[8627377]102 return EOK;
[a6d1bc1]103}
104/*----------------------------------------------------------------------------*/
[bab71635]105int hc_schedule(hc_t *instance, batch_t *batch)
[41b96b4]106{
107 assert(instance);
108 assert(batch);
109 if (batch->target.address == instance->rh.address) {
[bab71635]110 rh_request(&instance->rh, batch);
[41b96b4]111 return EOK;
112 }
113 /* TODO: implement */
[a6d1bc1]114 return ENOTSUP;
[41b96b4]115}
116/*----------------------------------------------------------------------------*/
[bab71635]117void hc_interrupt(hc_t *instance, uint16_t status)
[41b96b4]118{
119 assert(instance);
[e7bc999]120 /* TODO: Check for interrupt cause */
[bab71635]121 rh_interrupt(&instance->rh);
[41b96b4]122 /* TODO: implement */
123}
124/**
125 * @}
126 */
Note: See TracBrowser for help on using the repository browser.