Changeset 92574f4 in mainline for uspace/drv/usbmid/main.c


Ignore:
Timestamp:
2011-02-24T12:03:27Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e7b7ebd5
Parents:
4837092 (diff), a80849c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged development (changes in DDF, etc.).

Conflicts in uspace/drv/usbkbd/main.c

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmid/main.c

    r4837092 r92574f4  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 #include <usb/hcdhubd.h>
    29 #include <usb_iface.h>
    30 #include <usb/debug.h>
     28
     29/** @addtogroup drvusbmid
     30 * @{
     31 */
     32/**
     33 * @file
     34 * Main routines of USB multi interface device driver.
     35 */
    3136#include <errno.h>
    3237#include <str_error.h>
    33 #include <driver.h>
    34 #include "uhci.h"
     38#include <usb/debug.h>
     39#include <usb/classes/classes.h>
     40#include <usb/request.h>
     41#include <usb/descriptor.h>
     42#include <usb/pipes.h>
    3543
    36 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     44#include "usbmid.h"
     45
     46static int usbmid_add_device(ddf_dev_t *gen_dev)
    3747{
    38         /* This shall be called only for the UHCI itself. */
    39         assert(dev->parent == NULL);
     48        usbmid_device_t *dev = usbmid_device_create(gen_dev);
     49        if (dev == NULL) {
     50                return ENOMEM;
     51        }
    4052
    41         *handle = dev->handle;
     53        usb_log_info("Taking care of new MID: addr %d (HC %zu)\n",
     54            dev->wire.address, dev->wire.hc_handle);
     55
     56        int rc;
     57
     58        rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
     59        if (rc != EOK) {
     60                usb_log_error("Failed to start session on control pipe: %s.\n",
     61                    str_error(rc));
     62                goto error_leave;
     63        }
     64
     65        bool accept = usbmid_explore_device(dev);
     66
     67        rc = usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
     68        if (rc != EOK) {
     69                usb_log_warning("Failed to end session on control pipe: %s.\n",
     70                    str_error(rc));
     71        }
     72
     73        if (!accept) {
     74                rc = ENOTSUP;
     75                goto error_leave;
     76        }
     77
     78        gen_dev->driver_data = dev;
     79
    4280        return EOK;
     81
     82
     83error_leave:
     84        free(dev);
     85        return rc;
    4386}
    4487
    45 static usb_iface_t hc_usb_iface = {
    46         .get_hc_handle = usb_iface_get_hc_handle
     88static driver_ops_t mid_driver_ops = {
     89        .add_device = usbmid_add_device,
    4790};
    4891
    49 static device_ops_t uhci_ops = {
    50         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    51         .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    52 };
    53 
    54 static int uhci_add_device(device_t *device)
    55 {
    56         usb_dprintf(NAME, 1, "uhci_add_device() called\n");
    57         device->ops = &uhci_ops;
    58 
    59         uintptr_t io_reg_base;
    60         size_t io_reg_size;
    61         int irq;
    62 
    63         int rc = pci_get_my_registers(device,
    64             &io_reg_base, &io_reg_size, &irq);
    65 
    66         if (rc != EOK) {
    67                 fprintf(stderr,
    68                     NAME ": failed to get I/O registers addresses: %s.\n",
    69                     str_error(rc));
    70                 return rc;
    71         }
    72 
    73         usb_dprintf(NAME, 2, "I/O regs at 0x%X (size %zu), IRQ %d.\n",
    74             io_reg_base, io_reg_size, irq);
    75 
    76         /*
    77          * We need to announce the presence of our root hub.
    78          */
    79         usb_dprintf(NAME, 2, "adding root hub\n");
    80         usb_hcd_add_root_hub(device);
    81 
    82         return EOK;
    83 }
    84 
    85 static driver_ops_t uhci_driver_ops = {
    86         .add_device = uhci_add_device,
    87 };
    88 
    89 static driver_t uhci_driver = {
     92static driver_t mid_driver = {
    9093        .name = NAME,
    91         .driver_ops = &uhci_driver_ops
     94        .driver_ops = &mid_driver_ops
    9295};
    9396
    9497int main(int argc, char *argv[])
    9598{
    96         /*
    97          * Do some global initializations.
    98          */
    99         sleep(5);
    100         usb_dprintf_enable(NAME, 5);
     99        printf(NAME ": USB multi interface device driver.\n");
    101100
    102         return driver_main(&uhci_driver);
     101        usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
     102        return ddf_driver_main(&mid_driver);
    103103}
     104
     105/**
     106 * @}
     107 */
Note: See TracChangeset for help on using the changeset viewer.