Changeset 6e3c005 in mainline
- Timestamp:
- 2011-12-14T15:29:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a0487a2
- Parents:
- 22ecbde
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhcirh/port.c
r22ecbde r6e3c005 313 313 314 314 /* Driver stopped, free used address */ 315 ret = usb_h c_unregister_device(&port->hc_connection,316 port->attached_device.address);315 ret = usb_hub_unregister_device(&port->hc_connection, 316 &port->attached_device); 317 317 if (ret != EOK) { 318 318 usb_log_error("%s: Failed to unregister address of removed " -
uspace/drv/bus/usb/usbhub/port.c
r22ecbde r6e3c005 288 288 port->attached_device.fun = NULL; 289 289 290 ret = usb_h c_unregister_device(&hub->usb_device->hc_conn,291 port->attached_device.address);290 ret = usb_hub_unregister_device(&hub->usb_device->hc_conn, 291 &port->attached_device); 292 292 if (ret != EOK) { 293 293 usb_log_warning("Failed to unregister address of the " -
uspace/lib/usbdev/include/usb/dev/hub.h
r22ecbde r6e3c005 40 40 #include <ddf/driver.h> 41 41 #include <sys/types.h> 42 #include <errno.h> 42 43 #include <usb/hc.h> 43 44 … … 59 60 } usb_hub_attached_device_t; 60 61 61 usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_address_t, 62 bool, usb_speed_t); 63 int usb_hc_register_device(usb_hc_connection_t *, 62 int usb_hub_register_device(usb_hc_connection_t *, 64 63 const usb_hub_attached_device_t *); 65 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t); 64 65 static inline int usb_hub_unregister_device(usb_hc_connection_t *conn, 66 const usb_hub_attached_device_t *attached_device) 67 { 68 assert(conn); 69 if (attached_device == NULL) 70 return EBADMEM; 71 return usb_hc_release_address(conn, attached_device->address); 72 } 66 73 67 74 #endif -
uspace/lib/usbdev/include/usb/dev/poll.h
r22ecbde r6e3c005 39 39 #include <time.h> 40 40 41 /** Parameters and callbacks for automated polling. */ 41 42 typedef struct { 42 43 /** Level of debugging messages from auto polling. -
uspace/lib/usbdev/include/usb/dev/usb_device_connection.h
r22ecbde r6e3c005 52 52 } usb_device_connection_t; 53 53 54 /** Initialize device connection. Set address and hc connection. 55 * @param instance Structure to initialize. 56 * @param hc_connection. Host controller connection to use. 57 * @param address USB address. 58 * @return Error code. 59 */ 54 60 static inline int usb_device_connection_initialize( 55 usb_device_connection_t * connection, usb_hc_connection_t *hc_connection,61 usb_device_connection_t *instance, usb_hc_connection_t *hc_connection, 56 62 usb_address_t address) 57 63 { 58 assert( connection);64 assert(instance); 59 65 if (hc_connection == NULL) 60 66 return EBADMEM; … … 62 68 return EINVAL; 63 69 64 connection->hc_connection = hc_connection;65 connection->address = address;70 instance->hc_connection = hc_connection; 71 instance->address = address; 66 72 return EOK; 67 73 } 68 74 /*----------------------------------------------------------------------------*/ 69 static inline int usb_device_register_endpoint(usb_device_connection_t *conn, 70 usb_endpoint_t ep, usb_transfer_type_t type, usb_direction_t direction, 75 /** Register endpoint on the device. 76 * @param instance device connection structure to use. 77 * @param ep USB endpoint number. 78 * @param type Communication type of the endpoint. 79 * @param direction Communication direction. 80 * @param packet_size Maximum packet size for the endpoint. 81 * @param interval Preferrred interval between communication. 82 * @return Error code. 83 */ 84 static inline int usb_device_register_endpoint( 85 usb_device_connection_t *instance, usb_endpoint_t ep, 86 usb_transfer_type_t type, usb_direction_t direction, 71 87 size_t packet_size, unsigned interval) 72 88 { 73 assert( conn);74 return usb_hc_register_endpoint( conn->hc_connection,75 conn->address, ep, type, direction, packet_size, interval);89 assert(instance); 90 return usb_hc_register_endpoint(instance->hc_connection, 91 instance->address, ep, type, direction, packet_size, interval); 76 92 } 77 93 /*----------------------------------------------------------------------------*/ 78 static inline int usb_device_unregister_endpoint(usb_device_connection_t *conn, 79 usb_endpoint_t ep, usb_direction_t direction) 94 /** Unregister endpoint on the device. 95 * @param instance device connection structure 96 * @param ep Endpoint number. 97 * @param dir Communication direction. 98 * @return Error code. 99 */ 100 static inline int usb_device_unregister_endpoint( 101 usb_device_connection_t *instance, usb_endpoint_t ep, usb_direction_t dir) 80 102 { 81 assert( conn);82 return usb_hc_unregister_endpoint( conn->hc_connection,83 conn->address, ep, direction);103 assert(instance); 104 return usb_hc_unregister_endpoint(instance->hc_connection, 105 instance->address, ep, dir); 84 106 } 85 107 /*----------------------------------------------------------------------------*/ 86 static inline int usb_device_control_read(usb_device_connection_t *conn, 108 /** Get data from the device. 109 * @param[in] instance device connection structure to use. 110 * @param[in] ep target endpoint's number. 111 * @param[in] setup Setup stage data (control transfers). 112 * @param[in] data data buffer. 113 * @param[in] size size of the data buffer. 114 * @param[out] rsize bytes actually copied to the buffer. 115 * @return Error code. 116 */ 117 static inline int usb_device_control_read(usb_device_connection_t *instance, 87 118 usb_endpoint_t ep, uint64_t setup, void *data, size_t size, size_t *rsize) 88 119 { 89 assert( conn);90 return usb_hc_read( conn->hc_connection,91 conn->address, ep, setup, data, size, rsize);120 assert(instance); 121 return usb_hc_read(instance->hc_connection, 122 instance->address, ep, setup, data, size, rsize); 92 123 } 93 124 /*----------------------------------------------------------------------------*/ 94 static inline int usb_device_control_write(usb_device_connection_t *conn, 125 /** Send data to the device. 126 * @param instance device connection structure to use. 127 * @param ep target endpoint's number. 128 * @param setup Setup stage data (control transfers). 129 * @param data data buffer. 130 * @param size size of the data buffer. 131 * @return Error code. 132 */ 133 static inline int usb_device_control_write(usb_device_connection_t *instance, 95 134 usb_endpoint_t ep, uint64_t setup, const void *data, size_t size) 96 135 { 97 assert( conn);98 return usb_hc_write( conn->hc_connection,99 conn->address, ep, setup, data, size);136 assert(instance); 137 return usb_hc_write(instance->hc_connection, 138 instance->address, ep, setup, data, size); 100 139 } 101 140 /*----------------------------------------------------------------------------*/ 102 141 /** Wrapper for read calls with no setup stage. 103 * @param[in] connection hc connection to use.142 * @param[in] instance device connection structure. 104 143 * @param[in] address USB device address. 105 144 * @param[in] endpoint USB device endpoint. … … 109 148 * @return Error code. 110 149 */ 111 static inline int usb_device_read(usb_device_connection_t * conn,150 static inline int usb_device_read(usb_device_connection_t *instance, 112 151 usb_endpoint_t ep, void *data, size_t size, size_t *real_size) 113 152 { 114 return usb_device_control_read( conn, ep, 0, data, size, real_size);153 return usb_device_control_read(instance, ep, 0, data, size, real_size); 115 154 } 116 155 /*----------------------------------------------------------------------------*/ 117 156 /** Wrapper for write calls with no setup stage. 118 * @param connection hc connection to use.157 * @param instance device connection structure. 119 158 * @param address USB device address. 120 159 * @param endpoint USB device endpoint. … … 123 162 * @return Error code. 124 163 */ 125 static inline int usb_device_write(usb_device_connection_t * conn,164 static inline int usb_device_write(usb_device_connection_t *instance, 126 165 usb_endpoint_t ep, const void *data, size_t size) 127 166 { 128 return usb_device_control_write( conn, ep, 0, data, size);167 return usb_device_control_write(instance, ep, 0, data, size); 129 168 } 130 169 #endif -
uspace/lib/usbdev/src/altiface.c
r22ecbde r6e3c005 167 167 } 168 168 169 void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *alternate) 169 /** Clean initialized structure. 170 * @param instance structure do deinitialize. 171 */ 172 void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *instance) 170 173 { 171 if (! alternate)174 if (!instance) 172 175 return; 173 free(alternate->alternatives); 176 free(instance->alternatives); 177 instance->alternatives = NULL; 174 178 } 175 179 /** -
uspace/lib/usbdev/src/devdrv.c
r22ecbde r6e3c005 516 516 } 517 517 518 /* Open hc connection for pipe registration. */ 518 519 rc = usb_hc_connection_open(&usb_dev->hc_conn); 519 520 if (rc != EOK) { … … 575 576 } 576 577 578 /** Allocate driver specific data. 579 * @param usb_dev usb_device structure. 580 * @param size requested data size. 581 * @return Pointer to the newly allocated space, NULL on failure. 582 */ 577 583 void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size) 578 584 { -
uspace/lib/usbdev/src/devpoll.c
r22ecbde r6e3c005 46 46 /** Data needed for polling. */ 47 47 typedef struct { 48 /** Parameters for automated polling. */ 48 49 usb_device_auto_polling_t auto_polling; 49 50 51 /** USB device to poll. */ 50 52 usb_device_t *dev; 53 /** Device pipe to use for polling. */ 51 54 size_t pipe_index; 55 /** Size of the recieved data. */ 52 56 size_t request_size; 57 /** Data buffer. */ 53 58 uint8_t *buffer; 59 /** Argument to pass to callbacks. */ 54 60 void *custom_arg; 55 61 } polling_data_t; -
uspace/lib/usbdev/src/hub.c
r22ecbde r6e3c005 38 38 #include <usb/dev/recognise.h> 39 39 #include <usb/debug.h> 40 #include <usbhc_iface.h>41 40 #include <errno.h> 42 41 #include <assert.h> … … 45 44 #include <async.h> 46 45 47 /** How much time to wait between attempts to register endpoint 0:0.46 /** How much time to wait between attempts to get the default address. 48 47 * The value is based on typical value for port reset + some overhead. 49 48 */ 50 #define ENDPOINT_0_0_REGISTER_ATTEMPT_DELAY_USEC (1000 * (10 + 2)) 51 52 /** Check that HC connection is alright. 53 * 54 * @param conn Connection to be checked. 55 */ 56 #define CHECK_CONNECTION(conn) \ 57 do { \ 58 assert((conn)); \ 59 if (!usb_hc_connection_is_opened((conn))) { \ 60 usb_log_error("Connection not open.\n"); \ 61 return ENOTCONN; \ 62 } \ 63 } while (false) 64 49 #define DEFAULT_ADDRESS_ATTEMPT_DELAY_USEC (1000 * (10 + 2)) 65 50 66 51 /** Inform host controller about new device. … … 70 55 * @return Error code. 71 56 */ 72 int usb_h c_register_device(usb_hc_connection_t *connection,57 int usb_hub_register_device(usb_hc_connection_t *connection, 73 58 const usb_hub_attached_device_t *attached_device) 74 59 { 75 // CHECK_CONNECTION(connection);60 assert(connection); 76 61 if (attached_device == NULL || attached_device->fun == NULL) 77 return EINVAL; 78 79 async_exch_t *exch = async_exchange_begin(connection->hc_sess); 80 if (!exch) 81 return ENOMEM; 82 const int ret = usbhc_bind_address(exch, 62 return EBADMEM; 63 return usb_hc_bind_address(connection, 83 64 attached_device->address, attached_device->fun->handle); 84 async_exchange_end(exch);85 86 return ret;87 }88 89 /** Inform host controller about device removal.90 *91 * @param connection Opened connection to host controller.92 * @param address Address of the device that is being removed.93 * @return Error code.94 */95 int usb_hc_unregister_device(usb_hc_connection_t *connection,96 usb_address_t address)97 {98 // CHECK_CONNECTION(connection);99 100 async_exch_t *exch = async_exchange_begin(connection->hc_sess);101 if (!exch)102 return ENOMEM;103 const int ret = usbhc_release_address(exch, address);104 async_exchange_end(exch);105 106 return ret;107 65 } 108 66 … … 144 102 "Failed to unregister the old pipe on address change.\n"); 145 103 } 146 /* Address changed. We can release the default, thus 147 * allowing other to access the default address. */ 148 usb_hc_unregister_device(pipe->wire->hc_connection, 149 pipe->wire->address); 104 /* Address changed. We can release the old one, thus 105 * allowing other to us it. */ 106 usb_hc_release_address(pipe->wire->hc_connection, pipe->wire->address); 150 107 151 108 /* The address is already changed so set it in the wire */ … … 256 213 if (rc == ENOENT) { 257 214 /* Do not overheat the CPU ;-). */ 258 async_usleep( ENDPOINT_0_0_REGISTER_ATTEMPT_DELAY_USEC);215 async_usleep(DEFAULT_ADDRESS_ATTEMPT_DELAY_USEC); 259 216 } 260 217 } while (rc == ENOENT); … … 328 285 329 286 /* Inform the host controller about the handle. */ 330 rc = usb_h c_register_device(hc_conn, &new_device);287 rc = usb_hub_register_device(hc_conn, &new_device); 331 288 if (rc != EOK) { 332 289 /* We know nothing about that data. */ … … 353 310 */ 354 311 leave_release_default_address: 355 if (usb_hc_ unregister_device(hc_conn, USB_ADDRESS_DEFAULT) != EOK)356 usb_log_warning("%s: Failed to unregister defaut device.\n",312 if (usb_hc_release_address(hc_conn, USB_ADDRESS_DEFAULT) != EOK) 313 usb_log_warning("%s: Failed to release defaut address.\n", 357 314 __FUNCTION__); 358 315 … … 363 320 __FUNCTION__); 364 321 365 if (usb_hc_ unregister_device(hc_conn, dev_addr) != EOK)366 usb_log_warning("%s: Failed to unregister device.\n",367 __FUNCTION__ );322 if (usb_hc_release_address(hc_conn, dev_addr) != EOK) 323 usb_log_warning("%s: Failed to release address: %d.\n", 324 __FUNCTION__, dev_addr); 368 325 369 326 close_connection: -
uspace/lib/usbdev/src/recognise.c
r22ecbde r6e3c005 324 324 } 325 325 326 327 326 /** Index to append after device name for uniqueness. */ 328 327 static atomic_t device_name_index = {0};
Note:
See TracChangeset
for help on using the changeset viewer.