usb_util.c (194227) | usb_util.c (194228) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/usb_util.c 194227 2009-06-15 00:33:18Z thompsa $ */ | 1/* $FreeBSD: head/sys/dev/usb/usb_util.c 194228 2009-06-15 01:02:43Z thompsa $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 50 unchanged lines hidden (view full) --- 60 } 61 free(devlist, M_TEMP); 62 } 63 return (error); 64} 65#endif 66 67/*------------------------------------------------------------------------* | 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 50 unchanged lines hidden (view full) --- 60 } 61 free(devlist, M_TEMP); 62 } 63 return (error); 64} 65#endif 66 67/*------------------------------------------------------------------------* |
68 * device_set_usb2_desc | 68 * device_set_usb_desc |
69 * 70 * This function can be called at probe or attach to set the USB 71 * device supplied textual description for the given device. 72 *------------------------------------------------------------------------*/ 73void | 69 * 70 * This function can be called at probe or attach to set the USB 71 * device supplied textual description for the given device. 72 *------------------------------------------------------------------------*/ 73void |
74device_set_usb2_desc(device_t dev) | 74device_set_usb_desc(device_t dev) |
75{ 76 struct usb_attach_arg *uaa; 77 struct usb_device *udev; 78 struct usb_interface *iface; 79 char *temp_p; 80 usb_error_t err; 81 82 if (dev == NULL) { --- 15 unchanged lines hidden (view full) --- 98 } else { 99 err = 0; 100 } 101 102 temp_p = (char *)udev->bus->scratch[0].data; 103 104 if (!err) { 105 /* try to get the interface string ! */ | 75{ 76 struct usb_attach_arg *uaa; 77 struct usb_device *udev; 78 struct usb_interface *iface; 79 char *temp_p; 80 usb_error_t err; 81 82 if (dev == NULL) { --- 15 unchanged lines hidden (view full) --- 98 } else { 99 err = 0; 100 } 101 102 temp_p = (char *)udev->bus->scratch[0].data; 103 104 if (!err) { 105 /* try to get the interface string ! */ |
106 err = usb2_req_get_string_any | 106 err = usbd_req_get_string_any |
107 (udev, NULL, temp_p, 108 sizeof(udev->bus->scratch), iface->idesc->iInterface); 109 } 110 if (err) { 111 /* use default description */ | 107 (udev, NULL, temp_p, 108 sizeof(udev->bus->scratch), iface->idesc->iInterface); 109 } 110 if (err) { 111 /* use default description */ |
112 usb2_devinfo(udev, temp_p, | 112 usb_devinfo(udev, temp_p, |
113 sizeof(udev->bus->scratch)); 114 } 115 device_set_desc_copy(dev, temp_p); 116 device_printf(dev, "<%s> on %s\n", temp_p, 117 device_get_nameunit(udev->bus->bdev)); 118} 119 120/*------------------------------------------------------------------------* | 113 sizeof(udev->bus->scratch)); 114 } 115 device_set_desc_copy(dev, temp_p); 116 device_printf(dev, "<%s> on %s\n", temp_p, 117 device_get_nameunit(udev->bus->bdev)); 118} 119 120/*------------------------------------------------------------------------* |
121 * usb2_pause_mtx - factored out code | 121 * usb_pause_mtx - factored out code |
122 * 123 * This function will delay the code by the passed number of system 124 * ticks. The passed mutex "mtx" will be dropped while waiting, if 125 * "mtx" is not NULL. 126 *------------------------------------------------------------------------*/ 127void | 122 * 123 * This function will delay the code by the passed number of system 124 * ticks. The passed mutex "mtx" will be dropped while waiting, if 125 * "mtx" is not NULL. 126 *------------------------------------------------------------------------*/ 127void |
128usb2_pause_mtx(struct mtx *mtx, int _ticks) | 128usb_pause_mtx(struct mtx *mtx, int _ticks) |
129{ 130 if (mtx != NULL) 131 mtx_unlock(mtx); 132 133 if (cold) { 134 /* convert to milliseconds */ 135 _ticks = (_ticks * 1000) / hz; 136 /* convert to microseconds, rounded up */ --- 12 unchanged lines hidden (view full) --- 149 /* ignore */ 150 } 151 } 152 if (mtx != NULL) 153 mtx_lock(mtx); 154} 155 156/*------------------------------------------------------------------------* | 129{ 130 if (mtx != NULL) 131 mtx_unlock(mtx); 132 133 if (cold) { 134 /* convert to milliseconds */ 135 _ticks = (_ticks * 1000) / hz; 136 /* convert to microseconds, rounded up */ --- 12 unchanged lines hidden (view full) --- 149 /* ignore */ 150 } 151 } 152 if (mtx != NULL) 153 mtx_lock(mtx); 154} 155 156/*------------------------------------------------------------------------* |
157 * usb2_printBCD | 157 * usb_printbcd |
158 * 159 * This function will print the version number "bcd" to the string 160 * pointed to by "p" having a maximum length of "p_len" bytes 161 * including the terminating zero. 162 *------------------------------------------------------------------------*/ 163void | 158 * 159 * This function will print the version number "bcd" to the string 160 * pointed to by "p" having a maximum length of "p_len" bytes 161 * including the terminating zero. 162 *------------------------------------------------------------------------*/ 163void |
164usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd) | 164usb_printbcd(char *p, uint16_t p_len, uint16_t bcd) |
165{ 166 if (snprintf(p, p_len, "%x.%02x", bcd >> 8, bcd & 0xff)) { 167 /* ignore any errors */ 168 } 169} 170 171/*------------------------------------------------------------------------* | 165{ 166 if (snprintf(p, p_len, "%x.%02x", bcd >> 8, bcd & 0xff)) { 167 /* ignore any errors */ 168 } 169} 170 171/*------------------------------------------------------------------------* |
172 * usb2_trim_spaces | 172 * usb_trim_spaces |
173 * 174 * This function removes spaces at the beginning and the end of the string 175 * pointed to by the "p" argument. 176 *------------------------------------------------------------------------*/ 177void | 173 * 174 * This function removes spaces at the beginning and the end of the string 175 * pointed to by the "p" argument. 176 *------------------------------------------------------------------------*/ 177void |
178usb2_trim_spaces(char *p) | 178usb_trim_spaces(char *p) |
179{ 180 char *q; 181 char *e; 182 183 if (p == NULL) 184 return; 185 q = e = p; 186 while (*q == ' ') /* skip leading spaces */ 187 q++; 188 while ((*p = *q++)) /* copy string */ 189 if (*p++ != ' ') /* remember last non-space */ 190 e = p; 191 *e = 0; /* kill trailing spaces */ 192} 193 194/*------------------------------------------------------------------------* | 179{ 180 char *q; 181 char *e; 182 183 if (p == NULL) 184 return; 185 q = e = p; 186 while (*q == ' ') /* skip leading spaces */ 187 q++; 188 while ((*p = *q++)) /* copy string */ 189 if (*p++ != ' ') /* remember last non-space */ 190 e = p; 191 *e = 0; /* kill trailing spaces */ 192} 193 194/*------------------------------------------------------------------------* |
195 * usb2_make_str_desc - convert an ASCII string into a UNICODE string | 195 * usb_make_str_desc - convert an ASCII string into a UNICODE string |
196 *------------------------------------------------------------------------*/ 197uint8_t | 196 *------------------------------------------------------------------------*/ 197uint8_t |
198usb2_make_str_desc(void *ptr, uint16_t max_len, const char *s) | 198usb_make_str_desc(void *ptr, uint16_t max_len, const char *s) |
199{ 200 struct usb_string_descriptor *p = ptr; 201 uint8_t totlen; 202 int j; 203 204 if (max_len < 2) { 205 /* invalid length */ 206 return (0); --- 24 unchanged lines hidden --- | 199{ 200 struct usb_string_descriptor *p = ptr; 201 uint8_t totlen; 202 int j; 203 204 if (max_len < 2) { 205 /* invalid length */ 206 return (0); --- 24 unchanged lines hidden --- |