aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/usbvision/usbvision-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/usbvision/usbvision-core.c')
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c83
1 files changed, 32 insertions, 51 deletions
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 797b97baf9ed..a807d971e273 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -118,7 +118,7 @@ static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision);
118 * This is used when initializing the contents of the area. 118 * This is used when initializing the contents of the area.
119 */ 119 */
120 120
121void *usbvision_rvmalloc(unsigned long size) 121static void *usbvision_rvmalloc(unsigned long size)
122{ 122{
123 void *mem; 123 void *mem;
124 unsigned long adr; 124 unsigned long adr;
@@ -181,7 +181,7 @@ static void usbvision_hexdump(const unsigned char *data, int len)
181/******************************** 181/********************************
182 * scratch ring buffer handling 182 * scratch ring buffer handling
183 ********************************/ 183 ********************************/
184int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */ 184static int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */
185{ 185{
186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; 186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
187 if (len < 0) { 187 if (len < 0) {
@@ -194,7 +194,7 @@ int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of
194 194
195 195
196/* This returns the free space left in the buffer */ 196/* This returns the free space left in the buffer */
197int scratch_free(struct usb_usbvision *usbvision) 197static int scratch_free(struct usb_usbvision *usbvision)
198{ 198{
199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; 199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
200 if (free <= 0) { 200 if (free <= 0) {
@@ -211,7 +211,8 @@ int scratch_free(struct usb_usbvision *usbvision)
211 211
212 212
213/* This puts data into the buffer */ 213/* This puts data into the buffer */
214int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len) 214static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
215 int len)
215{ 216{
216 int len_part; 217 int len_part;
217 218
@@ -237,7 +238,7 @@ int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len)
237} 238}
238 239
239/* This marks the write_ptr as position of new frame header */ 240/* This marks the write_ptr as position of new frame header */
240void scratch_mark_header(struct usb_usbvision *usbvision) 241static void scratch_mark_header(struct usb_usbvision *usbvision)
241{ 242{
242 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr); 243 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr);
243 244
@@ -248,7 +249,8 @@ void scratch_mark_header(struct usb_usbvision *usbvision)
248} 249}
249 250
250/* This gets data from the buffer at the given "ptr" position */ 251/* This gets data from the buffer at the given "ptr" position */
251int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int *ptr, int len) 252static int scratch_get_extra(struct usb_usbvision *usbvision,
253 unsigned char *data, int *ptr, int len)
252{ 254{
253 int len_part; 255 int len_part;
254 if (*ptr + len < scratch_buf_size) { 256 if (*ptr + len < scratch_buf_size) {
@@ -274,7 +276,8 @@ int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int
274 276
275 277
276/* This sets the scratch extra read pointer */ 278/* This sets the scratch extra read pointer */
277void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len) 279static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
280 int len)
278{ 281{
279 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size; 282 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size;
280 283
@@ -283,7 +286,7 @@ void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len)
283 286
284 287
285/*This increments the scratch extra read pointer */ 288/*This increments the scratch extra read pointer */
286void scratch_inc_extra_ptr(int *ptr, int len) 289static void scratch_inc_extra_ptr(int *ptr, int len)
287{ 290{
288 *ptr = (*ptr + len) % scratch_buf_size; 291 *ptr = (*ptr + len) % scratch_buf_size;
289 292
@@ -292,7 +295,8 @@ void scratch_inc_extra_ptr(int *ptr, int len)
292 295
293 296
294/* This gets data from the buffer */ 297/* This gets data from the buffer */
295int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len) 298static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
299 int len)
296{ 300{
297 int len_part; 301 int len_part;
298 if (usbvision->scratch_read_ptr + len < scratch_buf_size) { 302 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
@@ -318,7 +322,8 @@ int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len)
318 322
319 323
320/* This sets read pointer to next header and returns it */ 324/* This sets read pointer to next header and returns it */
321int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_header *header) 325static int scratch_get_header(struct usb_usbvision *usbvision,
326 struct usbvision_frame_header *header)
322{ 327{
323 int errCode = 0; 328 int errCode = 0;
324 329
@@ -346,7 +351,7 @@ int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_he
346 351
347 352
348/*This removes len bytes of old data from the buffer */ 353/*This removes len bytes of old data from the buffer */
349void scratch_rm_old(struct usb_usbvision *usbvision, int len) 354static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
350{ 355{
351 356
352 usbvision->scratch_read_ptr += len; 357 usbvision->scratch_read_ptr += len;
@@ -356,7 +361,7 @@ void scratch_rm_old(struct usb_usbvision *usbvision, int len)
356 361
357 362
358/*This resets the buffer - kills all data in it too */ 363/*This resets the buffer - kills all data in it too */
359void scratch_reset(struct usb_usbvision *usbvision) 364static void scratch_reset(struct usb_usbvision *usbvision)
360{ 365{
361 PDEBUG(DBG_SCRATCH, "\n"); 366 PDEBUG(DBG_SCRATCH, "\n");
362 367
@@ -369,7 +374,7 @@ void scratch_reset(struct usb_usbvision *usbvision)
369 374
370int usbvision_scratch_alloc(struct usb_usbvision *usbvision) 375int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
371{ 376{
372 usbvision->scratch = vmalloc(scratch_buf_size); 377 usbvision->scratch = vmalloc_32(scratch_buf_size);
373 scratch_reset(usbvision); 378 scratch_reset(usbvision);
374 if(usbvision->scratch == NULL) { 379 if(usbvision->scratch == NULL) {
375 err("%s: unable to allocate %d bytes for scratch", 380 err("%s: unable to allocate %d bytes for scratch",
@@ -399,8 +404,8 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision)
399 * 1: Draw a colored grid 404 * 1: Draw a colored grid
400 * 405 *
401 */ 406 */
402void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe, 407static void usbvision_testpattern(struct usb_usbvision *usbvision,
403 int pmode) 408 int fullframe, int pmode)
404{ 409{
405 static const char proc[] = "usbvision_testpattern"; 410 static const char proc[] = "usbvision_testpattern";
406 struct usbvision_frame *frame; 411 struct usbvision_frame *frame;
@@ -480,7 +485,7 @@ void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe,
480int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 485int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
481{ 486{
482 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 487 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
483 usbvision->IntraFrameBuffer = vmalloc(IFB_size); 488 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
484 if (usbvision->IntraFrameBuffer == NULL) { 489 if (usbvision->IntraFrameBuffer == NULL) {
485 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size); 490 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size);
486 return -ENOMEM; 491 return -ENOMEM;
@@ -2199,6 +2204,7 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
2199 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2204 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2200 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2205 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2201 USBVISION_SSPND_EN | USBVISION_RES2); 2206 USBVISION_SSPND_EN | USBVISION_RES2);
2207
2202 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2208 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2203 USBVISION_SSPND_EN | USBVISION_PWR_VID); 2209 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2204 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2210 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
@@ -2305,7 +2311,7 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2305 usbvision->Vin_Reg2_Preset)) < 0) return ret; 2311 usbvision->Vin_Reg2_Preset)) < 0) return ret;
2306 2312
2307 /* TODO: schedule timeout */ 2313 /* TODO: schedule timeout */
2308 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) && 0x01) != 1); 2314 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1);
2309 2315
2310 return 0; 2316 return 0;
2311} 2317}
@@ -2346,40 +2352,6 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format)
2346 return USBVISION_IS_OPERATIONAL(usbvision); 2352 return USBVISION_IS_OPERATIONAL(usbvision);
2347} 2353}
2348 2354
2349
2350int usbvision_sbuf_alloc(struct usb_usbvision *usbvision)
2351{
2352 int i, errCode = 0;
2353 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2354
2355 /* Clean pointers so we know if we allocated something */
2356 for (i = 0; i < USBVISION_NUMSBUF; i++)
2357 usbvision->sbuf[i].data = NULL;
2358
2359 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2360 usbvision->sbuf[i].data = kzalloc(sb_size, GFP_KERNEL);
2361 if (usbvision->sbuf[i].data == NULL) {
2362 err("%s: unable to allocate %d bytes for sbuf", __FUNCTION__, sb_size);
2363 errCode = -ENOMEM;
2364 break;
2365 }
2366 }
2367 return errCode;
2368}
2369
2370
2371void usbvision_sbuf_free(struct usb_usbvision *usbvision)
2372{
2373 int i;
2374
2375 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2376 if (usbvision->sbuf[i].data != NULL) {
2377 kfree(usbvision->sbuf[i].data);
2378 usbvision->sbuf[i].data = NULL;
2379 }
2380 }
2381}
2382
2383/* 2355/*
2384 * usbvision_init_isoc() 2356 * usbvision_init_isoc()
2385 * 2357 *
@@ -2388,6 +2360,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2388{ 2360{
2389 struct usb_device *dev = usbvision->dev; 2361 struct usb_device *dev = usbvision->dev;
2390 int bufIdx, errCode, regValue; 2362 int bufIdx, errCode, regValue;
2363 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2391 2364
2392 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2365 if (!USBVISION_IS_OPERATIONAL(usbvision))
2393 return -EFAULT; 2366 return -EFAULT;
@@ -2423,6 +2396,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2423 return -ENOMEM; 2396 return -ENOMEM;
2424 } 2397 }
2425 usbvision->sbuf[bufIdx].urb = urb; 2398 usbvision->sbuf[bufIdx].urb = urb;
2399 usbvision->sbuf[bufIdx].data = usb_buffer_alloc(usbvision->dev, sb_size, GFP_KERNEL,&urb->transfer_dma);
2426 urb->dev = dev; 2400 urb->dev = dev;
2427 urb->context = usbvision; 2401 urb->context = usbvision;
2428 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2402 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
@@ -2464,6 +2438,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2464void usbvision_stop_isoc(struct usb_usbvision *usbvision) 2438void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2465{ 2439{
2466 int bufIdx, errCode, regValue; 2440 int bufIdx, errCode, regValue;
2441 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2467 2442
2468 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL)) 2443 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL))
2469 return; 2444 return;
@@ -2471,6 +2446,12 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2471 /* Unschedule all of the iso td's */ 2446 /* Unschedule all of the iso td's */
2472 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2447 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2473 usb_kill_urb(usbvision->sbuf[bufIdx].urb); 2448 usb_kill_urb(usbvision->sbuf[bufIdx].urb);
2449 if (usbvision->sbuf[bufIdx].data){
2450 usb_buffer_free(usbvision->dev,
2451 sb_size,
2452 usbvision->sbuf[bufIdx].data,
2453 usbvision->sbuf[bufIdx].urb->transfer_dma);
2454 }
2474 usb_free_urb(usbvision->sbuf[bufIdx].urb); 2455 usb_free_urb(usbvision->sbuf[bufIdx].urb);
2475 usbvision->sbuf[bufIdx].urb = NULL; 2456 usbvision->sbuf[bufIdx].urb = NULL;
2476 } 2457 }