Changeset 92574f4 in mainline for uspace/drv/usbhid/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 edited

Legend:

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

    r4837092 r92574f4  
    3636 */
    3737
    38 #include <usb/usbdrv.h>
    39 #include <driver.h>
     38#include <ddf/driver.h>
    4039#include <ipc/driver.h>
    4140#include <ipc/kbd.h>
     
    4544#include <str_error.h>
    4645#include <fibril.h>
     46#include <usb/debug.h>
     47#include <usb/classes/classes.h>
    4748#include <usb/classes/hid.h>
    4849#include <usb/classes/hidparser.h>
    49 #include <usb/devreq.h>
     50#include <usb/request.h>
    5051#include <usb/descriptor.h>
    51 #include <usb/debug.h>
    5252#include <io/console.h>
    5353#include <stdint.h>
     
    5858#include "layout.h"
    5959
    60 #define BUFFER_SIZE 32
     60#define BUFFER_SIZE 8
    6161#define NAME "usbhid"
    6262
     
    6464#define BOOTP_REPORT_SIZE 6
    6565
    66 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
    67 static device_ops_t keyboard_ops = {
     66/** Keyboard polling endpoint description for boot protocol class. */
     67static usb_endpoint_description_t poll_endpoint_description = {
     68        .transfer_type = USB_TRANSFER_INTERRUPT,
     69        .direction = USB_DIRECTION_IN,
     70        .interface_class = USB_CLASS_HID,
     71        .interface_subclass = USB_HID_SUBCLASS_BOOT,
     72        .interface_protocol = USB_HID_PROTOCOL_KEYBOARD,
     73        .flags = 0
     74};
     75
     76static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
     77static ddf_dev_ops_t keyboard_ops = {
    6878        .default_handler = default_connection_handler
    6979};
     
    7787 * @param icall Call data.
    7888 */
    79 void default_connection_handler(device_t *dev,
     89void default_connection_handler(ddf_fun_t *fun,
    8090    ipc_callid_t icallid, ipc_call_t *icall)
    8191{
     
    8696
    8797                if (console_callback_phone != -1) {
    88                         ipc_answer_0(icallid, ELIMIT);
     98                        async_answer_0(icallid, ELIMIT);
    8999                        return;
    90100                }
    91101
    92102                console_callback_phone = callback;
    93                 ipc_answer_0(icallid, EOK);
     103                async_answer_0(icallid, EOK);
    94104                return;
    95105        }
    96106
    97         ipc_answer_0(icallid, EINVAL);
     107        async_answer_0(icallid, EINVAL);
    98108}
    99109
     
    387397               
    388398                // get the descriptor from the device
    389                 int rc = usb_drv_req_get_descriptor(
    390                     kbd_dev->device->parent_phone, kbd_dev->address,
    391                     USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
    392                     0, i, kbd_dev->conf->interfaces[i].report_desc, length,
     399                int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe,
     400                    USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     401                    i, 0,
     402                    kbd_dev->conf->interfaces[i].report_desc, length,
    393403                    &actual_size);
    394404
     
    411421        usb_standard_configuration_descriptor_t config_desc;
    412422       
    413         int rc = usb_drv_req_get_bare_configuration_descriptor(
    414             kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
     423        int rc;
     424        rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe,
     425            0, &config_desc);
    415426       
    416427        if (rc != EOK) {
     
    426437        size_t transferred = 0;
    427438        // get full configuration descriptor
    428         rc = usb_drv_req_get_full_configuration_descriptor(
    429             kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
     439        rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,
     440            0, descriptors,
    430441            config_desc.total_length, &transferred);
    431442       
     
    437448        }
    438449       
     450        /*
     451         * Initialize the interrupt in endpoint.
     452         */
     453        usb_endpoint_mapping_t endpoint_mapping[1] = {
     454                {
     455                        .pipe = &kbd_dev->poll_pipe,
     456                        .description = &poll_endpoint_description,
     457                        .interface_no =
     458                            usb_device_get_assigned_interface(kbd_dev->device)
     459                }
     460        };
     461        rc = usb_endpoint_pipe_initialize_from_configuration(
     462            endpoint_mapping, 1,
     463            descriptors, config_desc.total_length,
     464            &kbd_dev->wire);
     465        if (rc != EOK) {
     466                usb_log_error("Failed to initialize poll pipe: %s.\n",
     467                    str_error(rc));
     468                return rc;
     469        }
     470        if (!endpoint_mapping[0].present) {
     471                usb_log_warning("Not accepting device, " \
     472                    "not boot-protocol keyboard.\n");
     473                return EREFUSED;
     474        }
     475
     476
     477
     478
    439479        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    440480            sizeof(usb_hid_configuration_t));
     
    444484        }
    445485       
    446         rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
     486        /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    447487        free(descriptors);
    448488        if (rc != EOK) {
     
    451491        }
    452492
    453         // get and report descriptors
     493        // get and report descriptors*/
    454494        rc = usbkbd_get_report_descriptor(kbd_dev);
    455495        if (rc != EOK) {
     
    469509         *    as the endpoint for polling
    470510         */
    471        
     511
    472512        return EOK;
    473513}
    474514
    475 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    476 {
     515static usb_hid_dev_kbd_t *usbkbd_init_device(ddf_dev_t *dev)
     516{
     517        int rc;
     518
    477519        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    478520            sizeof(usb_hid_dev_kbd_t));
     
    485527        kbd_dev->device = dev;
    486528
    487         // get phone to my HC and save it as my parent's phone
    488         // TODO: maybe not a good idea if DDF will use parent_phone
    489         int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    490         if (rc < 0) {
    491                 usb_log_error("Problem setting phone to HC.\n");
     529        /*
     530         * Initialize the backing connection to the host controller.
     531         */
     532        rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);
     533        if (rc != EOK) {
     534                printf("Problem initializing connection to device: %s.\n",
     535                    str_error(rc));
    492536                goto error_leave;
    493537        }
    494538
    495         rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
    496         if (rc < 0) {
    497                 usb_log_error("Problem getting address of the device.\n");
     539        /*
     540         * Initialize device pipes.
     541         */
     542        rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe,
     543            &kbd_dev->wire);
     544        if (rc != EOK) {
     545                printf("Failed to initialize default control pipe: %s.\n",
     546                    str_error(rc));
    498547                goto error_leave;
    499548        }
    500549
    501         // doesn't matter now that we have no address
    502 //      if (kbd_dev->address < 0) {
    503 //              usb_log_error("No device address!\n");
    504 //              free(kbd_dev);
    505 //              return NULL;
    506 //      }
    507 
    508550        /*
    509551         * will need all descriptors:
    510          * 1) choose one configuration from configuration descriptors 
     552         * 1) choose one configuration from configuration descriptors
    511553         *    (set it to the device)
    512554         * 2) set endpoints from endpoint descriptors
    513555         */
    514556
    515         usbkbd_process_descriptors(kbd_dev);
    516        
    517         // save the size of the report
    518         kbd_dev->keycode_count = BOOTP_REPORT_SIZE;
    519         kbd_dev->keycodes = (uint8_t *)calloc(
    520             kbd_dev->keycode_count, sizeof(uint8_t));
    521        
    522         if (kbd_dev->keycodes == NULL) {
    523                 usb_log_fatal("No memory!\n");
     557        // TODO: get descriptors, parse descriptors and save endpoints
     558        usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
     559        //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
     560        rc = usbkbd_process_descriptors(kbd_dev);
     561        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     562        if (rc != EOK) {
    524563                goto error_leave;
    525564        }
    526        
    527         // set configuration to the first one
    528         // TODO: handle case with no configurations
    529         usb_drv_req_set_configuration(kbd_dev->device->parent_phone,
    530             kbd_dev->address,
    531             kbd_dev->conf->config_descriptor.configuration_number);
    532        
    533         /*
    534          * Initialize the backing connection to the host controller.
    535          */
    536         rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);
    537         if (rc != EOK) {
    538                 usb_log_error("Problem initializing connection to device: %s."
    539                     "\n", str_error(rc));
    540                 goto error_leave;
    541         }
    542 
    543         /*
    544          * Initialize device pipes.
    545          */
    546         rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
    547             GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
    548         if (rc != EOK) {
    549                 usb_log_error("Failed to initialize interrupt in pipe: %s.\n",
    550                     str_error(rc));
    551                 goto error_leave;
    552         }
    553 
    554565
    555566        return kbd_dev;
     
    591602
    592603        while (true) {
    593                 async_usleep(1000 * 1000 * 2);
     604                async_usleep(1000 * 10);
    594605
    595606                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
     
    643654        }
    644655
    645         device_t *dev = (device_t *)arg;
     656        ddf_dev_t *dev = (ddf_dev_t *)arg;
    646657
    647658        // initialize device (get and process descriptors, get address, etc.)
     
    657668}
    658669
    659 static int usbkbd_add_device(device_t *dev)
     670static int usbkbd_add_device(ddf_dev_t *dev)
    660671{
    661672        /* For now, fail immediately. */
     
    679690
    680691        /*
     692         * Create default function.
     693         */
     694        // FIXME - check for errors
     695        ddf_fun_t *kbd_fun = ddf_fun_create(dev, fun_exposed, "keyboard");
     696        assert(kbd_fun != NULL);
     697        kbd_fun->ops = &keyboard_ops;
     698
     699        int rc = ddf_fun_bind(kbd_fun);
     700        assert(rc == EOK);
     701        rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
     702        assert(rc == EOK);
     703
     704        /*
    681705         * Create new fibril for handling this keyboard
    682706         */
     
    688712        fibril_add_ready(fid);
    689713
    690         dev->ops = &keyboard_ops;
    691 
    692         add_device_to_class(dev, "keyboard");
     714        //dev->ops = &keyboard_ops;
     715        (void)keyboard_ops;
     716
     717        //add_device_to_class(dev, "keyboard");
    693718
    694719        /*
     
    710735{
    711736        usb_log_enable(USB_LOG_LEVEL_MAX, NAME);
    712         return driver_main(&kbd_driver);
     737        return ddf_driver_main(&kbd_driver);
    713738}
    714739
Note: See TracChangeset for help on using the changeset viewer.