diff options
author | Ezequiel GarcĂa <elezegarcia@gmail.com> | 2012-02-24 09:24:19 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-05-15 07:59:40 -0400 |
commit | de6ffc5e5a4ce0c4f078eaa2189bc906e8963d11 (patch) | |
tree | 0a8a73fa83dc95edbc8e2f99974399fdf47c6933 /drivers | |
parent | 217d55f2ba0511a18f7427c4a0c10ea21c2eb7d0 (diff) |
[media] staging: easycap: Split audio buffer and urb allocation
When the device is probed, this driver allocates
audio buffers, and audio urbs.
This patch just split this into separate functions,
which helps clearing the currently gigantic probe function.
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/media/easycap/easycap_main.c | 229 |
1 files changed, 124 insertions, 105 deletions
diff --git a/drivers/staging/media/easycap/easycap_main.c b/drivers/staging/media/easycap/easycap_main.c index 68af1a2297be..6e1734d8d276 100644 --- a/drivers/staging/media/easycap/easycap_main.c +++ b/drivers/staging/media/easycap/easycap_main.c | |||
@@ -3245,6 +3245,123 @@ static int create_video_urbs(struct easycap *peasycap) | |||
3245 | return 0; | 3245 | return 0; |
3246 | } | 3246 | } |
3247 | 3247 | ||
3248 | static int alloc_audio_buffers(struct easycap *peasycap) | ||
3249 | { | ||
3250 | void *pbuf; | ||
3251 | int k; | ||
3252 | |||
3253 | JOM(4, "allocating %i isoc audio buffers of size %i\n", | ||
3254 | AUDIO_ISOC_BUFFER_MANY, | ||
3255 | peasycap->audio_isoc_buffer_size); | ||
3256 | JOM(4, ".... each occupying contiguous memory pages\n"); | ||
3257 | |||
3258 | for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { | ||
3259 | pbuf = (void *)__get_free_pages(GFP_KERNEL, AUDIO_ISOC_ORDER); | ||
3260 | if (!pbuf) { | ||
3261 | SAM("ERROR: Could not allocate isoc audio buffer %i\n", | ||
3262 | k); | ||
3263 | return -ENOMEM; | ||
3264 | } | ||
3265 | peasycap->allocation_audio_page += BIT(AUDIO_ISOC_ORDER); | ||
3266 | |||
3267 | peasycap->audio_isoc_buffer[k].pgo = pbuf; | ||
3268 | peasycap->audio_isoc_buffer[k].pto = | ||
3269 | pbuf + peasycap->audio_isoc_buffer_size; | ||
3270 | peasycap->audio_isoc_buffer[k].kount = k; | ||
3271 | } | ||
3272 | |||
3273 | JOM(4, "allocation of isoc audio buffers done.\n"); | ||
3274 | return 0; | ||
3275 | } | ||
3276 | |||
3277 | static int create_audio_urbs(struct easycap *peasycap) | ||
3278 | { | ||
3279 | struct urb *purb; | ||
3280 | struct data_urb *pdata_urb; | ||
3281 | int k, j; | ||
3282 | |||
3283 | JOM(4, "allocating %i struct urb.\n", AUDIO_ISOC_BUFFER_MANY); | ||
3284 | JOM(4, "using %i=peasycap->audio_isoc_framesperdesc\n", | ||
3285 | peasycap->audio_isoc_framesperdesc); | ||
3286 | JOM(4, "using %i=peasycap->audio_isoc_maxframesize\n", | ||
3287 | peasycap->audio_isoc_maxframesize); | ||
3288 | JOM(4, "using %i=peasycap->audio_isoc_buffer_size\n", | ||
3289 | peasycap->audio_isoc_buffer_size); | ||
3290 | |||
3291 | for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { | ||
3292 | purb = usb_alloc_urb(peasycap->audio_isoc_framesperdesc, | ||
3293 | GFP_KERNEL); | ||
3294 | if (!purb) { | ||
3295 | SAM("ERROR: usb_alloc_urb returned NULL for buffer " | ||
3296 | "%i\n", k); | ||
3297 | return -ENOMEM; | ||
3298 | } | ||
3299 | peasycap->allocation_audio_urb += 1 ; | ||
3300 | pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL); | ||
3301 | if (!pdata_urb) { | ||
3302 | usb_free_urb(purb); | ||
3303 | SAM("ERROR: Could not allocate struct data_urb.\n"); | ||
3304 | return -ENOMEM; | ||
3305 | } | ||
3306 | peasycap->allocation_audio_struct += | ||
3307 | sizeof(struct data_urb); | ||
3308 | |||
3309 | pdata_urb->purb = purb; | ||
3310 | pdata_urb->isbuf = k; | ||
3311 | pdata_urb->length = 0; | ||
3312 | list_add_tail(&(pdata_urb->list_head), | ||
3313 | peasycap->purb_audio_head); | ||
3314 | |||
3315 | if (!k) { | ||
3316 | JOM(4, "initializing audio urbs thus:\n"); | ||
3317 | JOM(4, " purb->interval = 1;\n"); | ||
3318 | JOM(4, " purb->dev = peasycap->pusb_device;\n"); | ||
3319 | JOM(4, " purb->pipe = usb_rcvisocpipe(peasycap->" | ||
3320 | "pusb_device,%i);\n", | ||
3321 | peasycap->audio_endpointnumber); | ||
3322 | JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n"); | ||
3323 | JOM(4, " purb->transfer_buffer = " | ||
3324 | "peasycap->audio_isoc_buffer[.].pgo;\n"); | ||
3325 | JOM(4, " purb->transfer_buffer_length = %i;\n", | ||
3326 | peasycap->audio_isoc_buffer_size); | ||
3327 | JOM(4, " purb->complete = easycap_alsa_complete;\n"); | ||
3328 | JOM(4, " purb->context = peasycap;\n"); | ||
3329 | JOM(4, " purb->start_frame = 0;\n"); | ||
3330 | JOM(4, " purb->number_of_packets = %i;\n", | ||
3331 | peasycap->audio_isoc_framesperdesc); | ||
3332 | JOM(4, " for (j = 0; j < %i; j++)\n", | ||
3333 | peasycap->audio_isoc_framesperdesc); | ||
3334 | JOM(4, " {\n"); | ||
3335 | JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n", | ||
3336 | peasycap->audio_isoc_maxframesize); | ||
3337 | JOM(4, " purb->iso_frame_desc[j].length = %i;\n", | ||
3338 | peasycap->audio_isoc_maxframesize); | ||
3339 | JOM(4, " }\n"); | ||
3340 | } | ||
3341 | |||
3342 | purb->interval = 1; | ||
3343 | purb->dev = peasycap->pusb_device; | ||
3344 | purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, | ||
3345 | peasycap->audio_endpointnumber); | ||
3346 | purb->transfer_flags = URB_ISO_ASAP; | ||
3347 | purb->transfer_buffer = peasycap->audio_isoc_buffer[k].pgo; | ||
3348 | purb->transfer_buffer_length = | ||
3349 | peasycap->audio_isoc_buffer_size; | ||
3350 | purb->complete = easycap_alsa_complete; | ||
3351 | purb->context = peasycap; | ||
3352 | purb->start_frame = 0; | ||
3353 | purb->number_of_packets = peasycap->audio_isoc_framesperdesc; | ||
3354 | for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) { | ||
3355 | purb->iso_frame_desc[j].offset = | ||
3356 | j * peasycap->audio_isoc_maxframesize; | ||
3357 | purb->iso_frame_desc[j].length = | ||
3358 | peasycap->audio_isoc_maxframesize; | ||
3359 | } | ||
3360 | } | ||
3361 | JOM(4, "allocation of %i struct urb done.\n", k); | ||
3362 | return 0; | ||
3363 | } | ||
3364 | |||
3248 | static void config_easycap(struct easycap *peasycap, | 3365 | static void config_easycap(struct easycap *peasycap, |
3249 | u8 bInterfaceNumber, | 3366 | u8 bInterfaceNumber, |
3250 | u8 bInterfaceClass, | 3367 | u8 bInterfaceClass, |
@@ -3333,14 +3450,11 @@ static int easycap_usb_probe(struct usb_interface *intf, | |||
3333 | struct usb_host_interface *alt; | 3450 | struct usb_host_interface *alt; |
3334 | struct usb_endpoint_descriptor *ep; | 3451 | struct usb_endpoint_descriptor *ep; |
3335 | struct usb_interface_descriptor *interface; | 3452 | struct usb_interface_descriptor *interface; |
3336 | struct urb *purb; | ||
3337 | struct easycap *peasycap; | 3453 | struct easycap *peasycap; |
3338 | struct data_urb *pdata_urb; | 3454 | int i, j, rc; |
3339 | int i, j, k, rc; | ||
3340 | u8 bInterfaceNumber; | 3455 | u8 bInterfaceNumber; |
3341 | u8 bInterfaceClass; | 3456 | u8 bInterfaceClass; |
3342 | u8 bInterfaceSubClass; | 3457 | u8 bInterfaceSubClass; |
3343 | void *pbuf; | ||
3344 | int okalt[8], isokalt; | 3458 | int okalt[8], isokalt; |
3345 | int okepn[8]; | 3459 | int okepn[8]; |
3346 | int okmps[8]; | 3460 | int okmps[8]; |
@@ -3823,109 +3937,14 @@ static int easycap_usb_probe(struct usb_interface *intf, | |||
3823 | INIT_LIST_HEAD(&(peasycap->urb_audio_head)); | 3937 | INIT_LIST_HEAD(&(peasycap->urb_audio_head)); |
3824 | peasycap->purb_audio_head = &(peasycap->urb_audio_head); | 3938 | peasycap->purb_audio_head = &(peasycap->urb_audio_head); |
3825 | 3939 | ||
3826 | JOM(4, "allocating %i isoc audio buffers of size %i\n", | 3940 | alloc_audio_buffers(peasycap); |
3827 | AUDIO_ISOC_BUFFER_MANY, | 3941 | if (rc < 0) |
3828 | peasycap->audio_isoc_buffer_size); | 3942 | return rc; |
3829 | JOM(4, ".... each occupying contiguous memory pages\n"); | ||
3830 | |||
3831 | for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { | ||
3832 | pbuf = (void *)__get_free_pages(GFP_KERNEL, | ||
3833 | AUDIO_ISOC_ORDER); | ||
3834 | if (!pbuf) { | ||
3835 | SAM("ERROR: Could not allocate isoc audio buffer " | ||
3836 | "%i\n", k); | ||
3837 | return -ENOMEM; | ||
3838 | } | ||
3839 | peasycap->allocation_audio_page += | ||
3840 | BIT(AUDIO_ISOC_ORDER); | ||
3841 | |||
3842 | peasycap->audio_isoc_buffer[k].pgo = pbuf; | ||
3843 | peasycap->audio_isoc_buffer[k].pto = pbuf + | ||
3844 | peasycap->audio_isoc_buffer_size; | ||
3845 | peasycap->audio_isoc_buffer[k].kount = k; | ||
3846 | } | ||
3847 | JOM(4, "allocation of isoc audio buffers done.\n"); | ||
3848 | 3943 | ||
3849 | /* Allocate and initialize urbs */ | 3944 | /* Allocate and initialize urbs */ |
3850 | JOM(4, "allocating %i struct urb.\n", AUDIO_ISOC_BUFFER_MANY); | 3945 | rc = create_audio_urbs(peasycap); |
3851 | JOM(4, "using %i=peasycap->audio_isoc_framesperdesc\n", | 3946 | if (rc < 0) |
3852 | peasycap->audio_isoc_framesperdesc); | 3947 | return rc; |
3853 | JOM(4, "using %i=peasycap->audio_isoc_maxframesize\n", | ||
3854 | peasycap->audio_isoc_maxframesize); | ||
3855 | JOM(4, "using %i=peasycap->audio_isoc_buffer_size\n", | ||
3856 | peasycap->audio_isoc_buffer_size); | ||
3857 | |||
3858 | for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { | ||
3859 | purb = usb_alloc_urb(peasycap->audio_isoc_framesperdesc, | ||
3860 | GFP_KERNEL); | ||
3861 | if (!purb) { | ||
3862 | SAM("ERROR: usb_alloc_urb returned NULL for buffer " | ||
3863 | "%i\n", k); | ||
3864 | return -ENOMEM; | ||
3865 | } | ||
3866 | peasycap->allocation_audio_urb += 1 ; | ||
3867 | pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL); | ||
3868 | if (!pdata_urb) { | ||
3869 | usb_free_urb(purb); | ||
3870 | SAM("ERROR: Could not allocate struct data_urb.\n"); | ||
3871 | return -ENOMEM; | ||
3872 | } | ||
3873 | peasycap->allocation_audio_struct += | ||
3874 | sizeof(struct data_urb); | ||
3875 | |||
3876 | pdata_urb->purb = purb; | ||
3877 | pdata_urb->isbuf = k; | ||
3878 | pdata_urb->length = 0; | ||
3879 | list_add_tail(&(pdata_urb->list_head), | ||
3880 | peasycap->purb_audio_head); | ||
3881 | |||
3882 | if (!k) { | ||
3883 | JOM(4, "initializing audio urbs thus:\n"); | ||
3884 | JOM(4, " purb->interval = 1;\n"); | ||
3885 | JOM(4, " purb->dev = peasycap->pusb_device;\n"); | ||
3886 | JOM(4, " purb->pipe = usb_rcvisocpipe(peasycap->" | ||
3887 | "pusb_device,%i);\n", | ||
3888 | peasycap->audio_endpointnumber); | ||
3889 | JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n"); | ||
3890 | JOM(4, " purb->transfer_buffer = " | ||
3891 | "peasycap->audio_isoc_buffer[.].pgo;\n"); | ||
3892 | JOM(4, " purb->transfer_buffer_length = %i;\n", | ||
3893 | peasycap->audio_isoc_buffer_size); | ||
3894 | JOM(4, " purb->complete = easycap_alsa_complete;\n"); | ||
3895 | JOM(4, " purb->context = peasycap;\n"); | ||
3896 | JOM(4, " purb->start_frame = 0;\n"); | ||
3897 | JOM(4, " purb->number_of_packets = %i;\n", | ||
3898 | peasycap->audio_isoc_framesperdesc); | ||
3899 | JOM(4, " for (j = 0; j < %i; j++)\n", | ||
3900 | peasycap->audio_isoc_framesperdesc); | ||
3901 | JOM(4, " {\n"); | ||
3902 | JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n", | ||
3903 | peasycap->audio_isoc_maxframesize); | ||
3904 | JOM(4, " purb->iso_frame_desc[j].length = %i;\n", | ||
3905 | peasycap->audio_isoc_maxframesize); | ||
3906 | JOM(4, " }\n"); | ||
3907 | } | ||
3908 | |||
3909 | purb->interval = 1; | ||
3910 | purb->dev = peasycap->pusb_device; | ||
3911 | purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, | ||
3912 | peasycap->audio_endpointnumber); | ||
3913 | purb->transfer_flags = URB_ISO_ASAP; | ||
3914 | purb->transfer_buffer = peasycap->audio_isoc_buffer[k].pgo; | ||
3915 | purb->transfer_buffer_length = | ||
3916 | peasycap->audio_isoc_buffer_size; | ||
3917 | purb->complete = easycap_alsa_complete; | ||
3918 | purb->context = peasycap; | ||
3919 | purb->start_frame = 0; | ||
3920 | purb->number_of_packets = peasycap->audio_isoc_framesperdesc; | ||
3921 | for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) { | ||
3922 | purb->iso_frame_desc[j].offset = j * | ||
3923 | peasycap->audio_isoc_maxframesize; | ||
3924 | purb->iso_frame_desc[j].length = | ||
3925 | peasycap->audio_isoc_maxframesize; | ||
3926 | } | ||
3927 | } | ||
3928 | JOM(4, "allocation of %i struct urb done.\n", k); | ||
3929 | 3948 | ||
3930 | /* Save pointer peasycap in this interface */ | 3949 | /* Save pointer peasycap in this interface */ |
3931 | usb_set_intfdata(intf, peasycap); | 3950 | usb_set_intfdata(intf, peasycap); |