Changeset 4d0c40b in mainline


Ignore:
Timestamp:
2011-03-22T22:30:55Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8421c4
Parents:
41ef5b9
Message:

ohci root hub implementation basis, missing descriptors and interrupt transfer

Location:
uspace/drv
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/root_hub.c

    r41ef5b9 r4d0c40b  
    3939
    4040#include "root_hub.h"
     41#include <usb/request.h>
     42#include <usb/classes/hub.h>
     43
    4144
    4245/** Root hub initialization
     
    5053        instance->device = dev;
    5154
     55
    5256        usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
    5357
     58        //start generic usb hub driver
     59       
    5460        /* TODO: implement */
    5561        return EOK;
    5662}
    5763/*----------------------------------------------------------------------------*/
     64
     65
     66static int process_get_port_status_request(rh_t *instance, uint16_t port,
     67                char * buffer){
     68        if(port<1 || port>instance->port_count)
     69                return EINVAL;
     70        uint32_t * uint32_buffer = (uint32_t*)buffer;
     71        uint32_buffer[0] = instance->registers->rh_port_status[port -1];
     72        return EOK;
     73}
     74
     75static int process_get_hub_status_request(rh_t *instance,char * buffer){
     76        uint32_t * uint32_buffer = (uint32_t*)buffer;
     77        //bits, 0,1,16,17
     78        uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
     79        uint32_buffer[0] = mask & instance->registers->rh_status;
     80        return EOK;
     81
     82}
     83
     84
     85static int process_get_status_request(rh_t *instance,char * buffer,
     86                size_t buffer_size, usb_device_request_setup_packet_t * request){
     87
     88        usb_hub_bm_request_type_t request_type = request->request_type;
     89        if(buffer_size!=4) return EINVAL;
     90        if(request_type == USB_HUB_REQ_TYPE_GET_HUB_STATUS)
     91                return process_get_hub_status_request(instance, buffer);
     92        if(request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
     93                return process_get_port_status_request(instance, request->index,
     94                                buffer);
     95        return ENOTSUP;
     96}
     97
     98static int process_get_descriptor_request(rh_t *instance,
     99                usb_transfer_batch_t *request){
     100        /// \TODO
     101        usb_device_request_setup_packet_t * setup_request =
     102                        (usb_device_request_setup_packet_t*)request->setup_buffer;
     103        if(setup_request->value == USB_DESCTYPE_HUB){
     104                //create hub descriptor
     105        }else if(setup_request->value == USB_DESCTYPE_HUB){
     106                //create std device descriptor
     107        }else{
     108                return EINVAL;
     109        }
     110        return EOK;
     111}
     112
     113static int process_get_configuration_request(rh_t *instance, char * buffer,
     114        size_t buffer_size
     115){
     116        //set and get configuration requests do not have any meaning, only dummy
     117        //values are returned
     118        if(buffer_size != 1)
     119                return EINVAL;
     120        buffer[0] = 1;
     121        return EOK;
     122}
     123
     124static int process_hub_feature_set_request(rh_t *instance,
     125                uint16_t feature, bool enable){
     126        if(feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)
     127                return EINVAL;
     128        instance->registers->rh_status =
     129                        enable ?
     130                        (instance->registers->rh_status | (1<<feature))
     131                        :
     132                        (instance->registers->rh_status & (~(1<<feature)));
     133        /// \TODO any error?
     134        return EOK;
     135}
     136
     137static int process_port_feature_set_request(rh_t *instance,
     138                uint16_t feature, uint16_t port, bool enable){
     139        if(feature > USB_HUB_FEATURE_C_PORT_RESET)
     140                return EINVAL;
     141        if(port<1 || port>instance->port_count)
     142                return EINVAL;
     143        instance->registers->rh_port_status[port - 1] =
     144                        enable ?
     145                        (instance->registers->rh_port_status[port - 1] | (1<<feature))
     146                        :
     147                        (instance->registers->rh_port_status[port - 1] & (~(1<<feature)));
     148        /// \TODO any error?
     149        return EOK;
     150
     151}
     152
     153static int process_request_with_output(rh_t *instance,
     154                usb_transfer_batch_t *request){
     155        usb_device_request_setup_packet_t * setup_request =
     156                        (usb_device_request_setup_packet_t*)request->setup_buffer;
     157        if(setup_request->request == USB_DEVREQ_GET_STATUS){
     158                return process_get_status_request(instance, request->buffer,
     159                                request->buffer_size,
     160                                setup_request);
     161        }
     162        if(setup_request->request == USB_DEVREQ_GET_DESCRIPTOR){
     163                return process_get_descriptor_request(instance, request);
     164        }
     165        if(setup_request->request == USB_DEVREQ_GET_CONFIGURATION){
     166                return process_get_configuration_request(instance, request->buffer,
     167                                request->buffer_size);
     168        }
     169        return ENOTSUP;
     170}
     171
     172static int process_request_with_input(rh_t *instance,
     173                usb_transfer_batch_t *request){
     174        usb_device_request_setup_packet_t * setup_request =
     175                        (usb_device_request_setup_packet_t*)request->setup_buffer;
     176        if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR){
     177                return ENOTSUP;
     178        }
     179        if(setup_request->request == USB_DEVREQ_SET_CONFIGURATION){
     180                //set and get configuration requests do not have any meaning,
     181                //only dummy values are returned
     182                return EOK;
     183        }
     184        return ENOTSUP;
     185}
     186
     187
     188static int process_request_without_data(rh_t *instance,
     189                usb_transfer_batch_t *request){
     190        usb_device_request_setup_packet_t * setup_request =
     191                        (usb_device_request_setup_packet_t*)request->setup_buffer;
     192        if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
     193                return process_hub_feature_set_request(instance, setup_request->value,
     194                                setup_request->request == USB_DEVREQ_SET_FEATURE);
     195        }
     196        if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
     197                return process_port_feature_set_request(instance, setup_request->value,
     198                                setup_request->index,
     199                                setup_request->request == USB_DEVREQ_SET_FEATURE);
     200        }
     201        return ENOTSUP;
     202}
     203
     204
     205/**
     206 *
     207 * @param instance
     208 * @param request
     209 * @return
     210 */
    58211int rh_request(rh_t *instance, usb_transfer_batch_t *request)
    59212{
    60213        assert(instance);
    61214        assert(request);
    62         /* TODO: implement */
     215        int opResult;
    63216        if (request->setup_buffer) {
    64217                usb_log_info("Root hub got SETUP packet: %s.\n",
    65218                    usb_debug_str_buffer((const uint8_t *)request->setup_buffer, 8, 8));
    66         }
    67         usb_log_error("Root hub request processing not implemented.\n");
    68         usb_transfer_batch_finish(request, ENOTSUP);
     219                if(sizeof(usb_device_request_setup_packet_t)>request->setup_size){
     220                        usb_log_error("setup packet too small\n");
     221                        return EINVAL;
     222                }
     223                usb_device_request_setup_packet_t * setup_request =
     224                                (usb_device_request_setup_packet_t*)request->setup_buffer;
     225                if(
     226                        setup_request->request == USB_DEVREQ_GET_STATUS
     227                        || setup_request->request == USB_DEVREQ_GET_DESCRIPTOR
     228                        || setup_request->request == USB_DEVREQ_GET_CONFIGURATION
     229                ){
     230                        usb_log_debug("processing request with output\n");
     231                        opResult = process_request_with_output(instance,request);
     232                }else if(
     233                        setup_request->request == USB_DEVREQ_CLEAR_FEATURE
     234                        || setup_request->request == USB_DEVREQ_SET_FEATURE
     235                ){
     236                        usb_log_debug("processing request without additional data\n");
     237                        opResult = process_request_without_data(instance,request);
     238                }else if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR
     239                                || setup_request->request == USB_DEVREQ_SET_CONFIGURATION
     240                ){
     241                        usb_log_debug("processing request with input\n");
     242                        opResult = process_request_with_input(instance,request);
     243                }else{
     244                        usb_log_warning("received unsuported request: %d\n",
     245                                        setup_request->request
     246                                        );
     247                        opResult = ENOTSUP;
     248                }
     249        }else{
     250                usb_log_error("root hub received empty transaction?");
     251                opResult = EINVAL;
     252        }
     253        usb_transfer_batch_finish(request, opResult);
    69254        return EOK;
    70255}
    71256/*----------------------------------------------------------------------------*/
     257//is this status change?
    72258void rh_interrupt(rh_t *instance)
    73259{
  • uspace/drv/ohci/root_hub.h

    r41ef5b9 r4d0c40b  
    4545        usb_address_t address;
    4646        ddf_dev_t *device;
     47        int port_count;
    4748} rh_t;
    4849
  • uspace/drv/usbhub/port_status.h

    r41ef5b9 r4d0c40b  
    3030 */
    3131
    32 #ifndef PORT_STATUS_H
    33 #define PORT_STATUS_H
     32#ifndef HUB_PORT_STATUS_H
     33#define HUB_PORT_STATUS_H
    3434
    3535#include <bool.h>
     
    335335
    336336
    337 #endif  /* PORT_STATUS_H */
     337#endif  /* HUB_PORT_STATUS_H */
    338338
    339339/**
  • uspace/drv/usbhub/usbhub.c

    r41ef5b9 r4d0c40b  
    162162            std_descriptor->configuration_count);
    163163        if(std_descriptor->configuration_count<1){
    164                 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n");
    165                 //shouldn`t I return?
    166                 //definitely
     164                usb_log_error("there are no configurations available\n");
    167165                return EINVAL;
    168166        }
Note: See TracChangeset for help on using the changeset viewer.